0
votes

I'm trying to terminate all Tokbox connections from server-side. I have the logic the terminate connections from client-side, however, clients are unreliable that it may not get to disconnect properly(network issue, sudden app termination etc).

I'm aware of the forceDisconnect option with a connectionId either from the SDK or REST API. However, I can't find an option to list all open connections from a sessionId from server side.

I'm also aware that, I can just wait for sessions to expire. (How to disconnect all connection on a session?)

However, waiting for the tokens to expire(or the session to terminate on Tokbox Server side), costs much more, especially if you are using auto-archiving option. If you don't explicitly terminate your sessions, you'll get billed for your session + up to 1 hour of archiving.

In summary, when a tokbox session is over, what I want to do is

  • Clients will try to disconnect their own connections(Done)

  • If clients, for some reason, fail to do #1, server will list all active connections.

  • call forceDisconnect on each connections from #2

2

2 Answers

0
votes

We are having the same problem, forceDisconnect only accepts ConnectionId as parameter. But with serverSDK the only thing you can get is StreamIds..

Our approach is by using Session Monitoring to get the connectionsIds

See https://tokbox.com/developer/guides/session-monitoring/

Maybe you can listen to that hook and store in your database the connectionIds received

Is not the best solution, but maybe an approach

Another solution could be to disconnect users client-side:

https://tokbox.com/developer/guides/moderation/js/

0
votes

OpenTok Developer Advocate here.

@pompiamp is on the right track here. The best way to do this is to use the Stream Monitoring webhook.

That webhook will send events to your server for streamCreated and streamDestroyed events. The payload will resemble:

{
    "sessionId": "2_MX4xMzExMjU3MX5-MTQ3MDI1NzY3OTkxOH45QXRr",
    "projectId": "123456",
    "event": "streamCreated",
    "timestamp": 1470258860571,
    "stream": {
        "id": "63245362-e00e-4834-8371-9397deb3e452",
        "connection": {
            "id": "c053fcc8-c681-41d5-8ec2-7a9e1434a21e",
            "createdAt": 1470257688143,
            "data": ""
        },
        "createdAt": 1470258845416,
        "name": "",
        "videoType": "camera"
    }
}

You'll notice the payload includes a stream.connection.id property.

Then add some capability in your application to know the session is over and call forceDisconnect for any streams you still show as not destroyed.