asterisk / node-ari-client

Node.js client for ARI. This library is best effort with limited support.
Other
250 stars 98 forks source link

BridgeCreated and BridgeDestroyed aren't catch #110

Open mbayou opened 6 years ago

mbayou commented 6 years ago

Hi,

I'm trying to listen theses two events BridgeCreated and BridgeDestroyed but I do not get any information.

        ari.start('my-app');

        // ... create bridge and channels (All this part works well)

        // Theses parts below are never call
        ari.on("BridgeCreated", (event, bridge) => {
            console.log("Bridge created");
        });

        ari.on("BridgeDestroyed", (event, bridge) => {
            console.log("Bridge destroyed");
        });

I didn't find any people who complain about that, then I think I made a mistake somewhere. Is that the right way to catch up theses events ?

Thanks for your answer

samuelg commented 6 years ago

You may want to move ari.start('my-app'); under where you register for events. There could technically be an event that fires while you are registering for it.

I don't see where you are creating a bridge. By default you'll only get events for the bridges you create inside your Stasis app.

mbayou commented 6 years ago

Hi @samuelg,

It's more complicated, I tried to simplify a little bit this example. So I have an application with Inversify and the ari is like a service which the other services depends on. And the subscription is an other service that create subscription for websocket client.

My bridge is created inside another service but like I said all works with the channel and bridge creation, also I get theses other events without any difficulty: ChannelEnteredBridge, ChannelLeftBridge, ChannelDestroyed, Dial, ChannelStateChange.

My only trouble comes from theses two events above.

Thanks for your help.

samuelg commented 5 years ago

Bridges can be reused so it's possible an existing bridge (unused) bridge was used. Without knowing how your application is interacting with bridges/channels it's hard to tell what might be wrong.

Are you creating/destroying said bridges yourself? You might not get the events if the bridges are being created/destroyed by another app unless you register for bridge events. The events you are getting you list above are technically Channel events. As long as your application is handling StasisStart events or originating the channels, you'll be auto subscribed to the Channel events which is why you would be receiving them but not necessarily receiving Bridge events.

Hope that helps.

MattRiddell commented 5 years ago

Yeah I'm having the same problem.

I'm trying to maintain state even over crashes so I do the following:

Save bridges to DB when created/delete when destroyed If I start up and there are empty bridges I clear them If I start up and there are non empty bridges I'd like to clean them up when they are destroyed

I have:

ari.on('BridgeDestroyed', destroyBridge);

but the function doesn't get called when the bridge is destroyed.

Is there a better way to know that this has happened so I can clear it out of my DB?

MattRiddell commented 5 years ago

Looks like in my case I should be able to subscribe my application to the bridge but I can't see how to do that from ari-client

MattRiddell commented 5 years ago

I didn't get the bridge destroyed but I guess that's because it just sits there empty. I subscribed to the channel destroyed and then checked for empty bridges to destroy and it worked fine.

timo-klarshift commented 1 year ago

You only would receive those events if you use subscribeAll=true or if you explicitly subscribe to the bridges eventSource, see here: https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Applications+REST+API#Asterisk13ApplicationsRESTAPI-subscribe