Commit 30295f08 authored by okhin's avatar okhin

Managing destrcution of channels a bit better

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