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):
except:
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):
'''
This object is used to manage ARI calls for playbacks.
......
......@@ -147,26 +147,6 @@ def sanitize_phonenumber(number):
raise TypeError('{} is not a valid international number, it should start with 00')
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
def listen(db):
'''
......@@ -178,7 +158,6 @@ def listen(db):
ws = yield from websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(
config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password']))
ws_logger.debug('Websocket connected: {}'.format(type(ws)))
yield from hold_bridge()
while running == True:
try:
event = yield from ws.recv()
......@@ -338,6 +317,7 @@ class Call(object):
if event['channel']['state'] == 'Up':
# Are we the caller or the callee?
if event['channel']['id'].endswith(sanitize_phonenumber(self.callee)):
# We are the callee
# Step 1 create a bridge
bridge = ari.Bridge(config['asterisk'], self.id, 'mixing')
phone_logger.debug("Creating a bridges to connect {} to {}".format(self.caller, self.callee,))
......@@ -345,13 +325,10 @@ class Call(object):
bridge.create()
except Exception as e:
raise e
# Step 2, removing callee channel from hold
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name'])
channel = self.id + '-' + sanitize_phonenumber(self.callee)
phone_logger.debug("Remove callee channel from moh")
moh_bridge.removeChannel(channel)
channels = ",".join([self.id
+ '-' + sanitize_phonenumber(self.caller),
# Step 2, stop playing moh to the channel
channel = ari.Channel(config['asterisk'], self.id + '-' + sanitize_phonenumber(self.caller))
channel.stopMoh()
channels = ",".join([
self.id
+ '-' + sanitize_phonenumber(self.callee)])
phone_logger.debug("Moving channels to the created bridge: {}".format(bridge.name,))
......@@ -361,12 +338,7 @@ class Call(object):
# Call is being picked up, we want to play a song
try:
channel = ari.Channel(config['asterisk'], event['channel']['id'])
# Moving the channel to the MOH Bridge
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'])
channel.startMoh(config['moh']['class'])
except Exception as e:
phone_logger.exception(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