I have the requirement to collect the total number of streamed minutes for all the tokbox sessions of the past month. Basically something similar to the billing report tokbox provides. I don't need it "live", a delay of minutes or even hours would be acceptable.
The inspector does not seem to have an API, and we are currently not archiving the sessions.
My current idea would be to use the Session Monitoring events and collect all Stream Destroyed
events. I would then store them somewhere and use timestamp - stream.createdAt
as the duration of each stream.
It feels a bit brittle at first glance - I don't want to report wrong numbers or miss something. Am I on the right track or is there an easier/better solution?
{
"sessionId": "2_MX4xMzExMjU3MX5-MTQ3MDI1NzY3OTkxOH45QXRr",
"projectId": "123456",
"event": "streamDestroyed",
"reason": "clientDisconnected",
"timestamp": 1470258896953,
"stream": {
"id": "63245362-e00e-4834-8371-9397deb3e452",
"connection": {
"id": "c053fcc8-c681-41d5-8ec2-7a9e1434a21e",
"createdAt": 1470257688143,
"data": ""
},
"createdAt": 1470258845416,
"name": "",
"videoType": "camera"
}
}
TokBox support confirmed that is is a valid way to go and that the Session Monitoring events are reliable enough. So we will go ahead with the idea of using the StreamDestroyed
events.
Unfortunately, this is not equivalent to the subscribed minutes. Calculating those should be possible using the events, but could become quite complex.
{
"sessionId": "2_MX4xMzExMjU3MX5-MTQ3MDI1NzY3OTkxOH45QXRr",
"projectId": "123456",
"event": "streamDestroyed",
"reason": "clientDisconnected",
"timestamp": 1470258896953,
"stream": {
"id": "63245362-e00e-4834-8371-9397deb3e452",
"connection": {
"id": "c053fcc8-c681-41d5-8ec2-7a9e1434a21e",
"createdAt": 1470257688143,
"data": ""
},
"createdAt": 1470258845416,
"name": "",
"videoType": "camera"
}
}