Asterisk 18.x How can we terminate the call when Web browser is exited

Hi All,

We are looking for a solution for the situation below
I appreciate if you have any advice for me

Browser_phone ----------[Kamailio]----------------------[Asterisk]

When we exit the web browser (click x button on browser).
The call channel is NOT disconnected in Asterisk.

We are looking for a way to drop the call immediately when Web Browser is exited.

  1. We intent to send a BYE from Browserphone, but the problem is that, when Web browser is exited, we can’t catch any events for triggering a BYE

  2. We tried to monitor the WSS connection from Kamailio but it seems that Kamailio is a Proxy which just forward the message, we could not send a BYE from Kamailio

  3. Is there any way to catch the WSS connection from Asterisk ?
    I meant, when WSS connection is disconnected, is there any event like AMI… which we can catch from AMI or dialplan interface and then trigger a script to send a BYE to disconnect the call ?

You can get it to eventually drop using an RTP timeout. I don’t know if session timers work with WebRTC, but if they do, you could set a short timeout.

Hi @david551 ,

Thank you very much for your reply,

Actually we already proposed this solution to our Customer but they did not agree.
They want the call to be terminated immediately when the web browser is exited.

Is there any other suggestion/recommendation ?

Create and monitor a WebSocket connection. As soon as that closes, you know the session is gone.

Hi @ldo ,

Many thanks for your reply,

Do you mean we setup the system as below ?
Browser phone -----------------[FE/BE server] ---------[Kamailio] --------[Asterisk]

so we can monitor the websocket connection at FE or BE server
am I correct ?

Humn if so we have to change our design a lot.

If I misunderstood your point, please help to give us some hints how to monitor the WebSocket connection ? can we do that on Asterisk ?

A WebSocket server is really quite a separate thing from a Web server–different port, different protocol, different behaviour.

I assume you have control over the pages being served through the Web server? So you can include the necessary scripting to manage the WebSocket connection? I don’t think you need to do any more than periodically ping it to confirm the application is still live–as soon as that stops, you know the page has been closed.

I think they want a ping frequency of less than a second!

That would be fine: it would just be between the page and your WebSockets server process, which doesn’t need to do anything else.

Many thanks for your help @david551 , @ldo ,

After discussion, our Customer agreed with using an RTP timeout, we are trying to apply this solution to our Customer lab. Please be informed

Please give us the info you got. We are also facing the same problem. Calls need to be terminated immediately after a web socket connection breaks within a user agent.

Here is a very simple example Python script, using ASGI, to demonstrate how to have a Web page that keeps a WebSocket connection alive as long as it is open in the browser. Soon as the page is closed, the WebSocket disconnects, and you can take whatever action you like–here it just logs an informational message. (6.8 KB)

For us, we have set the RTP timeout at the field ps_endpoints.rtp_timeout in table ps_endpoints

We found our solution here How to hangup all calls in a channel immediately when one endpoint becomes unreachable / web sockets connection breaks - #3 by jeroenvip

rtp_timeout - Maximum number of seconds without receiving RTP (while off hold) before terminating call.

That depends on a timeout, though.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.