Skip to content
This repository has been archived by the owner on Feb 11, 2019. It is now read-only.

Commit

Permalink
Merge tag 'vxfreeswitch-0.1.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Giesler committed Jun 22, 2016
2 parents 7c355b6 + 349f8f0 commit a3db6df
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="vxfreeswitch",
version="0.1.15",
version="0.1.16",
url='http://github.com/praekelt/vumi-freeswitch-esl',
license='BSD',
description="A Freeswitch eventsocket transport for Vumi.",
Expand Down
2 changes: 1 addition & 1 deletion vxfreeswitch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .voice import VoiceServerTransport

__version__ = "0.1.15"
__version__ = "0.1.16"

__all__ = ['VoiceServerTransport']
38 changes: 35 additions & 3 deletions vxfreeswitch/tests/test_voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import md5
import os

from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet import defer, reactor

from vumi.message import TransportUserMessage
from vumi.tests.helpers import VumiTestCase
Expand Down Expand Up @@ -529,6 +530,7 @@ def test_barge_in_collecting_digits(self):
class TestVoiceServerTransportOutboundCalls(VumiTestCase):

transport_class = VoiceServerTransport
SLEEP_TIME = 0.01

def setUp(self):
self.tx_helper = self.add_helper(TransportHelper(self.transport_class))
Expand All @@ -548,6 +550,31 @@ def create_worker(self, config={}):
default.update(config)
return self.tx_helper.get_transport(default)

def sleep(self, time=SLEEP_TIME):
d = defer.Deferred()
reactor.callLater(time, d.callback, None)
return d

@inlineCallbacks
def wait_for_client_registration(self, worker, clientid):
'''Waits until the client has registered itself to the worker. Returns
False if it times out waiting.'''
for _ in range(5):
if worker._originated_calls.get(clientid, None) is None:
returnValue(True)
yield self.sleep()
returnValue(False)

@inlineCallbacks
def wait_for_call_answer(self, worker, callid):
'''Waits until the call has been answered. Returns False if it times
out waiting.'''
for _ in range(5):
if worker._unanswered_channels.get(callid, None) is None:
returnValue(True)
yield self.sleep()
returnValue(False)

@inlineCallbacks
def test_create_call(self):
self.worker = yield self.create_worker()
Expand All @@ -560,16 +587,21 @@ def test_create_call(self):
msg = self.tx_helper.make_outbound(
'foobar', '12345', '54321', session_event='new')

client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')

with LogCatcher(log_level=logging.WARN) as lc:
yield self.tx_helper.dispatch_outbound(msg)
self.assertEqual(lc.messages(), [])

client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')
# We need to wait for the client to be registered on the worker
r = yield self.wait_for_client_registration(self.worker, 'uuid-1234')
self.assertTrue(r)

events = yield self.tx_helper.get_dispatched_events()
self.assertEqual(events, [])

client.sendChannelAnswerEvent()
r = yield self.wait_for_call_answer(self.worker, 'uuid-1234')
self.assertTrue(r)

cmd = yield client.queue.get()
self.assertEqual(cmd, EslCommand.from_dict({
Expand Down
6 changes: 4 additions & 2 deletions vxfreeswitch/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ def send_outbound_message(self, client, message):
# Wait if call isn't answered
if self._unanswered_channels.get(client.get_address()):
try:
yield self._unanswered_channels.pop(client.get_address())
yield self._unanswered_channels.get(client.get_address())
except FreeSwitchClientError:
yield self.publish_nack(
message['message_id'], 'Unanswered Call')
returnValue(None)
finally:
self._unanswered_channels.pop(client.get_address())

if overrideURL is None:
yield client.output_message("%s\n" % content, voicemeta)
Expand All @@ -474,7 +476,7 @@ def send_outbound_message(self, client, message):
def client_answered(self, client):
"""Function that is called when the ChannelAnswer event is received.
Fires the deferred related to the outbound call"""
d = self._unanswered_channels.pop(client.get_address(), None)
d = self._unanswered_channels.get(client.get_address(), None)
if d:
d.callback(None)
else:
Expand Down

0 comments on commit a3db6df

Please sign in to comment.