[asterisk-app-dev] ARI ApplicationStarted or how to know that WebSocket connection established?
mjordan at digium.com
Thu Sep 25 09:29:27 CDT 2014
On Wed, Sep 24, 2014 at 8:47 PM, Maxim Litnitskiy
<litnimaxster at gmail.com> wrote:
> Hi dear developers!
> I can see ApplicationReplaced event and it's working:
> client.on_event('ApplicationReplaced', application_replaced)
An ApplicationReplaced event is only fired when a different WebSocket
connection has taken control over an application's event stream.
If you're seeing this event and you aren't expecting it, you are
probably architecting something in your client application
> When I run this code in the 2-nd thread I get this message.
> But what is I need to know when Application is started?
The application 'starts' when your WebSocket connection is made.
Asterisk uses the presence of a WebSocket connection to know that
something is able to handle the Stasis application. Without that, it
will simply bounce channels out of your Stasis application.
Because the client initiates the application, there isn't really any
need for an event. Asterisk doesn't make the decision; you do.
> Ordinary situation.
> I have a dialer app using 2 threads:
> 1) DIaler thread doing originate
> 2) Stasis thread handlng channel events.
> So if I start borth threads simultaneously dialer starts to originate before
> Stasis app is connected.
> Why not implement ApplicationStarted message similar to ApplicationReplaced?
> If ApplicationStarted existed I could use threading.Event() and wait from
> dialer thread for event.set() from ApplicationStarted event from stasis
You should not have two WebSocket connections. You should only have a
single WebSocket connection per application.
If you want to multi-thread your client application, you should have a
single thread that reads events from the WebSocket and farms them out
to handlers. Your other application threads can then take whatever
actions they desire.
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org
More information about the asterisk-app-dev