[asterisk-app-dev] WebSocket Stasis Control Best Practice
Matthew Jordan
mjordan at digium.com
Mon Jun 16 12:02:07 CDT 2014
On Mon, Jun 16, 2014 at 11:21 AM, Maxim Litnitskiy <litnimaxster at gmail.com>
wrote:
> Matt!
> Thank you so much for such a deep explanation.
> But You still did not reveal your plans about accessing Asterisk builtin
> apps :-)
> Once more example - a pause before playback.
> In ARI you cannot use python time.sleep(1) as it blocks the whole async
> event loop.
> How to tell a channel to wait?
>
>
Since you mention an async event loop, I'm going to assume you are using
twisted - although ari-py does not use that. If, however, you are using
twisted, I would just do something like the following:
def play_something(chan):
chan.play(media='sound:tt-monkeys')
# Assume chan is a reference to my channel
reactor.callLater(1, play_something, chan)
If you aren't using twisted, you could use the threading.Timer module [1]
to schedule a callback in a similar manner.
Or you can make Asterisk perform the pause:
chan.play(media='sound:silence/1')
Since ARI queues up sounds, that will automatically either (a) play 1
second of silence immediately, or (b) play 1 second of silence whenever the
current media operation finishes.
[1] https://docs.python.org/2/library/threading.html#timer-objects
--
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-app-dev/attachments/20140616/918e8833/attachment.html>
More information about the asterisk-app-dev
mailing list