Calculating usage for billing purposes with the Session Monitoring API.
- Session Monitoring API
To track and maintain call logs, you need to have a database of all the calls happening on a particular API key. For this, you can use the Session Monitoring API on the server side. On the server, the app will get all the events happening on clients, allowing logging for billing and other purpose.
On the client side, you have the following options:
An alternative to using Session Monitoring, or as a redundant method, is to log the events using AJAX calls from you clients to your server and have your server persist the event data.
You can listen to the Connection and Stream Events in your client application. These events are fired by the Tokbox APIs as and when they happen. Your application can log the time when the connection was created or destroyed and when the publisher started or stopped streaming in the application (through StreamCreated Event).
- ConnectionEvent - When the user creates or destroys the connection.
- StreamEvent - These events are dispatched by the Session object when another client starts or stops publishing a stream to a session.
- StreamDestroyed - The Publisher object dispatches a streamDestroyed event when it stops streaming to the session.
- Detecting when Clients have connected or disconnected
Using these APIs you can track the total minutes the two users are connected to each other. Post monitoring and capturing the data, the users can send the information to your hosted server. Or they can keep the information logged with themselves and send them in batches to your server.