Commit 30295f08 authored by okhin's avatar okhin
Browse files

Managing destrcution of channels a bit better

parent 4841ab42
Pipeline #778 passed with stage
in 2 seconds
......@@ -79,6 +79,7 @@ class Bridge(object):
return ari_call(self.config, ['bridges',, 'addChannel'], 'POST', {'channel': channel})
def delete(self):
Let's delete the bridge
......@@ -216,6 +216,7 @@ class Call(object):
actions = {'Created': 'call_caller'
, 'ChannelStateChange': 'change'
, 'ChannelDtmfReceived': 'dtmf'
, 'ChannelDestroyed': 'hangup'
, 'ChannelHangupRequest': 'hangup'}
def __init__(self, caller, callee, owner, callid=None, db=None):
......@@ -279,9 +280,21 @@ class Call(object):
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.
We might also be in a case where no channel has been created … or we're still on moh.
bridge_id = '-'.join(event['channel']['id'].split('-')[:-1])
bridge = ari.Bridge(config['asterisk'], bridge_id, 'mixed')
# Not in a bridge yet. Our channel has been destroyed.
# That or we're in moh.'Channel destroyed {}'.format(event['channel']['id']))
, event['channel']['id'].split('-')[-1]]
, event['cause_txt'])
, event['timestamp']))
results = json.loads(bridge.status())
if len(results['channels']) == 0:
# We were the last channel standing
......@@ -326,11 +339,14 @@ class Call(object):
Let's change the state of the call
# First we need to check if it's really a change ie, if the new state is not the previous one
self.update((':'.join([event['channel']['state'], event['channel']['id'].split('-')[-1]]), event['timestamp'],))
, event['channel']['id'].split('-')[-1]]
, event['cause_txt'])
, event['timestamp'],))"New state for call {}: {}".format(event['channel']['id'], event['channel']['state']))
# We now need to take action according to our new state
if event['channel']['state'] == 'Up':
# Are we the caller orthe callee?
# Are we the caller or the callee?
if event['channel']['id'].endswith(self.callee):
# Step 1 create a bridge
bridge = ari.Bridge(config['asterisk'],, 'mixing')
......@@ -359,7 +375,10 @@ class Call(object):
The bridge needed to connect the calls together will be created later.
self.update((':'.join([event['type'], event['channel']['id'].split('-')[-1]]), event['timestamp'],))
, event['channel']['id'].split('-')[-1]]
, event['cause_txt'])
, event['timestamp'],))
# We want to check if the moh bridge is opened
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name'], 'holding')
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