Commit 2605258b authored by okhin's avatar okhin
Browse files

Adding the delete/hangup channel system

parent cf0a3d05
Pipeline #27 skipped
......@@ -111,6 +111,16 @@ class Channel(object):
return ari_call(self.config, ['channels',, 'play', playback_id], 'POST', {'media': media, 'lang': lang})
def delete(self):
Delete the channel (hangup)
return ari_call(self.config, ['channels',], 'DEL', {})
class Playback(object):
This object is used to manage ARI calls for playbacks.
......@@ -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):
......@@ -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'Deleting bridge {}'.format(bridge_id))
# There's at least one channel standing
for channel in results['channels']:
chan = ari.Channel(config['asterisk'], channel)'Hanging up channel {}'.format(channel))
def dtmf(self, event):
We received a DTMF sequence
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment