Skip to content
Browse files

rework Wait + add transferEnabled flag to Wait grammar

  • Loading branch information...
1 parent a57bab3 commit 0e5477b4985b3de5bfa226577201bf0f0e626a3b @tamiel tamiel committed May 21, 2011
Showing with 14 additions and 14 deletions.
  1. +13 −14 src/plivo/rest/freeswitch/grammar.py
  2. +1 −0 src/plivo/rest/freeswitch/outbound_socket.py
View
27 src/plivo/rest/freeswitch/grammar.py
@@ -5,8 +5,6 @@
from datetime import datetime
import re
import uuid
-import gevent
-import gevent.timeout
from plivo.rest.freeswitch.helpers import is_valid_url, url_exists, \
file_exists
@@ -554,25 +552,26 @@ def parse_grammar(self, element, uri=None):
length = int(self.extract_attribute_value("length"))
except ValueError:
raise RESTFormatException("Wait length must be an integer")
+ transfer = self.extract_attribute_value("transferEnabled")
+ if transfer == 'true':
+ self.transfer = True
+ else:
+ self.transfer = False
if length < 0:
raise RESTFormatException("Wait length must be a positive integer")
self.length = length
def run(self, outbound_socket):
outbound_socket.log.info("Wait Started for %d seconds" \
% self.length)
- timer = gevent.timeout.Timeout(self.length, False)
- try:
- timer.start()
- try:
- while not outbound_socket.has_hangup():
- gevent.sleep(0.1)
- outbound_socket.log.info("Wait break after hangup")
- except gevent.timeout.Timeout:
- outbound_socket.log.info("Wait break after %d seconds" \
- % self.length)
- finally:
- timer.cancel()
+ if self.transfer:
+ outbound_socket.log.warn("Wait with transfer enabled")
+ pause_str = 'silence_stream://%s'\
+ % str(self.length * 1000)
+ outbound_socket.playback(pause_str)
+ else:
+ outbound_socket.sleep(str(self.length * 1000))
+ event = outbound_socket._action_queue.get()
outbound_socket.log.info("Wait Done")
View
1 src/plivo/rest/freeswitch/outbound_socket.py
@@ -133,6 +133,7 @@ def on_channel_execute_complete(self, event):
event.get_header('Application') == 'play_and_get_digits' or \
event.get_header('Application') == 'bridge' or \
event.get_header('Application') == 'say' or \
+ event.get_header('Application') == 'sleep' or \
event.get_header('Application') == 'speak':
self._action_queue.put(event)

0 comments on commit 0e5477b

Please sign in to comment.
Something went wrong with that request. Please try again.