Commit 536c5932 authored by okhin's avatar okhin 🚴

Fixing the infinite loop and status of the calls, it works!

parent c408af90
Pipeline #623 passed with stage
in 1 second
...@@ -19,6 +19,8 @@ def ari_call(config, verbs, method, payload): ...@@ -19,6 +19,8 @@ def ari_call(config, verbs, method, payload):
payload['app'] = config['app'] payload['app'] = config['app']
payload['api_key'] = config['key'] + ':' + config['password'] payload['api_key'] = config['key'] + ':' + config['password']
result = call(full_url, data=payload) result = call(full_url, data=payload)
print(full_url)
print(payload)
result.raise_for_status() result.raise_for_status()
if method.lower() == 'post': if method.lower() == 'post':
# We need to test if we have something in the object, to eventually return it # We need to test if we have something in the object, to eventually return it
...@@ -26,7 +28,10 @@ def ari_call(config, verbs, method, payload): ...@@ -26,7 +28,10 @@ def ari_call(config, verbs, method, payload):
return result.json() return result.json()
except: except:
result = requests.get(full_url, data=payload) result = requests.get(full_url, data=payload)
return result.json() try:
return result.json()
except:
return '{}'
except: except:
raise raise
...@@ -34,7 +39,7 @@ class Bridge(object): ...@@ -34,7 +39,7 @@ class Bridge(object):
''' '''
This is a bridge object, we use it to manage various needed calls This is a bridge object, we use it to manage various needed calls
''' '''
def __init__(self, config, name, mode): def __init__(self, config, name, mode='mixing'):
self.name = name self.name = name
self.config = config self.config = config
self.mode = mode self.mode = mode
...@@ -142,6 +147,6 @@ class Playback(object): ...@@ -142,6 +147,6 @@ class Playback(object):
Let's stop a specific playback Let's stop a specific playback
''' '''
try: try:
return ari_call(self.config, ['playbacks', self.name], 'DEL', {}) ari_call(self.config, ['playbacks', self.name], 'DEL', {})
except: except:
raise raise
...@@ -228,7 +228,6 @@ class Call(object): ...@@ -228,7 +228,6 @@ class Call(object):
else: else:
self.id = callid self.id = callid
self.db = db self.db = db
self.event_handler({'type': 'Created', 'timestamp': datetime.datetime.now().isoformat(), 'channel': {'id': 'Init'}})
except Exception as e: except Exception as e:
phone_logger.exception(e) phone_logger.exception(e)
raise e raise e
...@@ -269,13 +268,6 @@ class Call(object): ...@@ -269,13 +268,6 @@ class Call(object):
There's a new event related to our call There's a new event related to our call
''' '''
state = event['type'] state = event['type']
try:
if self.state.startswith(state):
# We're alreaydy in this state, we just need to noop
return
except IndexError:
if state in self.actions:
getattr(self, self.actions[state])(event=event)
if state in self.actions: if state in self.actions:
getattr(self, self.actions[state])(event=event) getattr(self, self.actions[state])(event=event)
...@@ -346,7 +338,7 @@ class Call(object): ...@@ -346,7 +338,7 @@ class Call(object):
bridge.create() bridge.create()
# Step 2, moving channels # Step 2, moving channels
channels = ",".join([self.id + '-' + self.caller, self.id + '-' + self.callee]) channels = ",".join([self.id + '-' + self.caller, self.id + '-' + self.callee])
phone_logger.debug("Moving channels to the created bridge: {}".format(brodge.name,)) phone_logger.debug("Moving channels to the created bridge: {}".format(bridge.name,))
bridge.addChannel(channels) bridge.addChannel(channels)
phone_logger.info("Call now fully connected: {} <-> {}".format(self.caller, self.callee)) phone_logger.info("Call now fully connected: {} <-> {}".format(self.caller, self.callee))
return return
...@@ -469,6 +461,7 @@ def originate(db, callid=None): ...@@ -469,6 +461,7 @@ def originate(db, callid=None):
else: else:
call = Call(request.params['caller'], request.params['callee'], request.params['api'], db=db) call = Call(request.params['caller'], request.params['callee'], request.params['api'], db=db)
bottle_logger.debug("Originate a call: {}".format(json.dumps(call, cls=PiphoneJSONEncoder))) bottle_logger.debug("Originate a call: {}".format(json.dumps(call, cls=PiphoneJSONEncoder)))
call.event_handler({'type': 'Created', 'timestamp': datetime.datetime.now().isoformat(), 'channel': {'id': 'Init'}})
call.save() call.save()
head = {'call': call.url head = {'call': call.url
, 'user': request.params['api'] , 'user': request.params['api']
......
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