question

TOTAL TRACK avatar image
TOTAL TRACK asked Phong Vu answered

Telephony Session Events: How to know when a call was ended

I am developing an app that uses the Telephony Session Events. The problem we face is detecting when the call is finished reliably. Initially, I assumed the call ended when all the parties involved (parties id) got the "Disconnect" message, but this algorithm failed because the events were not coming in the proper order (ordered sequence number), and on top of this, I cannot rely in the sequence number because is not sequential (there are gaps), so, I cannot assume that if I got the sequence 5, I could wait for the previous sequence in order to sort the events.

For instance, I can get the following sequence of event numbers: 3, 5, 2, 4, 7, 6, or I can get something completely different like: 2, 3, 5, 6, 4, 7


Can someone point me to the right solution?

Thanks!


@Phong Vu?

call handlingcall logsnotifications
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

Check out this article for details and this article for further implementation.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

TOTAL TRACK avatar image
TOTAL TRACK answered TOTAL TRACK edited

> A call session notification starts with a “Setup” event and ends with a “Disconnected” event.

> Basically, we can create a new active call object whenever we receive a “Setup” event.

> However, as I explained in my first blog, notification events may not arrive in the same

> order as they were generated due to some network situation.


This is exactly what I am doing, but instead of active calls per extension, I have a dictionary with the session-id (or telephony session-id) as the key and a sorted list of events for that call


> The out-of-order issue does not happen very often

It happens very often in my experience


> But we should still deal with that when it happens. There are 2 ways to solve the problem. The

> first way is to put all events from the same call session into an array then sort the array by the

> sequence numbers or by the event timestamp.


That is what I do, but how do I know in this case that the call ended and I am not going to receive more messages with the same session or telephony id in order to analyze the call? For Instance, if I receive this sequence:


Setup, Setup, Disconnect, Procedding, Disconnect, ..., Aswered, Gone, Gone


- How do I know the call ended based on the Disconnects, because you will get a Disconnect per party involved?,

- How do I know I am not going to receive more messages after the last Disconnect? (```Aswered, Gone, Gone```), so I can analyze the call and check/link to another call because it was parked?

- If the criteria to know a call ended is when all parties get disconnected, how do I know if I won't receive more messages with more Disconnects for other parties involved?



> The second way is to check the “activeCalls” array to see if an active call exists or not. If

> there is no active call with the same call party id, then we create a new active call object and

> add it to the “activeCalls” array. As we are preparing for the events out-of-order situation, we

> will check the event status from both cases. See the illustrated code below:


The last status of the call can be Disconnect, and a new message comes with the status: Parked, see my point?


@Phong Vu ?

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

Well, you can build your own logic to deal with the out-of-order events. I don't think that the delay is in minute, but rather just a second or (worst case a few secs). So when you receive the "Disconnected" event (remember that there are 2 "Disconnected" events, one for each call party), cause a delay for about 5 secs then sort the array using the event timestamps to put them in right order. Remember that for warm transfer call, the status of the original call is "Gone" and the "Disconnected" event will be sent when the transferred call is terminated.

You can try to use WebSocket subscription to see if the out-of-order is improved.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys