Commit 2605258b authored by okhin's avatar okhin 🚴

Adding the delete/hangup channel system

parent cf0a3d05
Pipeline #27 skipped
......@@ -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.
......
......@@ -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
......
Markdown is supported
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