Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
piphone-sip
Commits
2605258b
Commit
2605258b
authored
May 09, 2016
by
okhin
Browse files
Adding the delete/hangup channel system
parent
cf0a3d05
Pipeline
#27
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ari.py
View file @
2605258b
...
...
@@ -111,6 +111,16 @@ class Channel(object):
return
ari_call
(
self
.
config
,
[
'channels'
,
self
.
name
,
'play'
,
playback_id
],
'POST'
,
{
'media'
:
media
,
'lang'
:
lang
})
except
:
raise
def
delete
(
self
):
'''
Delete the channel (hangup)
'''
try
:
return
ari_call
(
self
.
config
,
[
'channels'
,
self
.
name
],
'DEL'
,
{})
except
:
raise
class
Playback
(
object
):
'''
This object is used to manage ARI calls for playbacks.
...
...
piphone.py
View file @
2605258b
...
...
@@ -211,7 +211,8 @@ class Call(object):
history
=
[]
actions
=
{
'Created'
:
'call_caller'
,
'ChannelStateChange'
:
'change'
,
'ChannelDtmfReceived'
:
'dtmf'
}
,
'ChannelDtmfReceived'
:
'dtmf'
,
'Hangup'
:
'hangup'
}
def
__init__
(
self
,
caller
,
callee
,
owner
,
callid
=
None
,
db
=
None
):
try
:
...
...
@@ -266,6 +267,29 @@ class Call(object):
if
state
in
self
.
actions
:
getattr
(
self
,
self
.
actions
[
state
])(
event
=
event
)
def
hangup
(
self
,
event
):
'''
There's a call which has lost connection. Probably someone who hanged up the call.
We need to check if the other side is still up, which can be done by checking
the bridge item (it is in the channels part of the bridge object) and see if there's
more than one channel.
If there's more than one, then we need to send a hangup to the other side and then delete
our channel, if not we need to delete ourselves and then delete the bridge.
'''
bridge_id
=
'-'
.
join
(
event
[
'channel'
][
'id'
].
split
(
'-'
)[:
-
1
])
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
bridge_id
,
'mixed'
)
results
=
json
.
loads
(
bridge
.
status
())
if
len
(
results
[
'channels'
])
==
0
:
# We were the last channel standing
phone_logger
.
info
(
'Deleting bridge {}'
.
format
(
bridge_id
))
bridge
.
delete
()
else
:
# There's at least one channel standing
for
channel
in
results
[
'channels'
]:
chan
=
ari
.
Channel
(
config
[
'asterisk'
],
channel
)
phone_logger
.
info
(
'Hanging up channel {}'
.
format
(
channel
))
chan
.
delete
()
def
dtmf
(
self
,
event
):
'''
We received a DTMF sequence
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment