Commit ed85f806 authored by okhin's avatar okhin 🚴

Removing the music on hold bridges

parent fff062ff
Pipeline #840 passed with stage
in 2 seconds
...@@ -140,6 +140,24 @@ class Channel(object): ...@@ -140,6 +140,24 @@ class Channel(object):
except: except:
raise raise
def startMoh(self, moh_class):
'''
Start playing music on hold on the channel
'''
try:
return ari_call(self.config, ['channels', self.name, 'moh'], 'POST', {'mohClass': moh_class})
except:
raise
def stopMoh(self):
'''
Stop playing moh on the channel
'''
try:
return ari_call(self.config, ['channels', self.name, 'moh'], 'DEL', {})
except:
raise
class Playback(object): class Playback(object):
''' '''
This object is used to manage ARI calls for playbacks. This object is used to manage ARI calls for playbacks.
......
...@@ -147,26 +147,6 @@ def sanitize_phonenumber(number): ...@@ -147,26 +147,6 @@ def sanitize_phonenumber(number):
raise TypeError('{} is not a valid international number, it should start with 00') raise TypeError('{} is not a valid international number, it should start with 00')
return number return number
@asyncio.coroutine
def hold_bridge():
'''
We will create a bridge that will be used to park caller waiting for callee to join.
It will play a song in a loop.
'''
try:
bridge = ari.Bridge(config['asterisk'], config['moh']['name'], 'holding')
except Exception as e:
phone_logger.critical("No Music On Hold (moh) section in config file. Exiting")
phone_logger.exception(e)
raise e
try:
result = bridge.create()
result = bridge.startMoh(config['moh']['class'])
except Exception as e:
phone_logger.error("Cannot start 'on hold' bridge")
phone_logger.exception(e)
raise e
@asyncio.coroutine @asyncio.coroutine
def listen(db): def listen(db):
''' '''
...@@ -178,7 +158,6 @@ def listen(db): ...@@ -178,7 +158,6 @@ def listen(db):
ws = yield from websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format( ws = yield from websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(
config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password'])) config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password']))
ws_logger.debug('Websocket connected: {}'.format(type(ws))) ws_logger.debug('Websocket connected: {}'.format(type(ws)))
yield from hold_bridge()
while running == True: while running == True:
try: try:
event = yield from ws.recv() event = yield from ws.recv()
...@@ -338,6 +317,7 @@ class Call(object): ...@@ -338,6 +317,7 @@ class Call(object):
if event['channel']['state'] == 'Up': if event['channel']['state'] == 'Up':
# Are we the caller or the callee? # Are we the caller or the callee?
if event['channel']['id'].endswith(sanitize_phonenumber(self.callee)): if event['channel']['id'].endswith(sanitize_phonenumber(self.callee)):
# We are the 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')
phone_logger.debug("Creating a bridges to connect {} to {}".format(self.caller, self.callee,)) phone_logger.debug("Creating a bridges to connect {} to {}".format(self.caller, self.callee,))
...@@ -345,13 +325,10 @@ class Call(object): ...@@ -345,13 +325,10 @@ class Call(object):
bridge.create() bridge.create()
except Exception as e: except Exception as e:
raise e raise e
# Step 2, removing callee channel from hold # Step 2, stop playing moh to the channel
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name']) channel = ari.Channel(config['asterisk'], self.id + '-' + sanitize_phonenumber(self.caller))
channel = self.id + '-' + sanitize_phonenumber(self.callee) channel.stopMoh()
phone_logger.debug("Remove callee channel from moh") channels = ",".join([
moh_bridge.removeChannel(channel)
channels = ",".join([self.id
+ '-' + sanitize_phonenumber(self.caller),
self.id self.id
+ '-' + sanitize_phonenumber(self.callee)]) + '-' + sanitize_phonenumber(self.callee)])
phone_logger.debug("Moving channels to the created bridge: {}".format(bridge.name,)) phone_logger.debug("Moving channels to the created bridge: {}".format(bridge.name,))
...@@ -361,12 +338,7 @@ class Call(object): ...@@ -361,12 +338,7 @@ class Call(object):
# Call is being picked up, we want to play a song # Call is being picked up, we want to play a song
try: try:
channel = ari.Channel(config['asterisk'], event['channel']['id']) channel = ari.Channel(config['asterisk'], event['channel']['id'])
# Moving the channel to the MOH Bridge channel.startMoh(config['moh']['class'])
phone_logger.debug('Moving call {} to the garage'.format(event['channel']['id']))
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name'])
result = moh_bridge.status()
moh_bridge.addChannel(event['channel']['id'])
moh_bridge.startMoh(config['moh']['class'])
except Exception as e: except Exception as e:
phone_logger.exception(e) phone_logger.exception(e)
raise e raise e
......
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