问题
I connected , subscribed to a session in opentok with a token and streamed my video.
Now How do I get informations like How much time did my video streamed, and many other informations which can be useful for data analysis.
var apiKey = "*****";
var sessionId = "**************************";
var token = "************";
var publisher = TB.initPublisher(apiKey);
var session = TB.initSession(sessionId);
session.connect(apiKey, token);
session.addEventListener("sessionConnected",
sessionConnectedHandler);
session.addEventListener("streamCreated",
streamCreatedHandler);
回答1:
You have to keep track of these data yourself. For example, after creating a publisher you can send a post request to your server with the current timestamp Date.now()
When the user disconnects, you will get a sessionDisconnected event from someone else in the session, you can send an event to your server with the current timestamp Date.now()
to mark the end time.
To identify the streams that have been disconnected, simply make sure you are sending the user's connectionId in your requests: session.connection.connectionId
and stream.connection.connectionId
Alternatively, you can try out OpenTok's raptor SDK, which is simply a Java SDK that you can use in your Java backend to get a request every time a user connects/disconnects to a session and other events. Unfortunately this only works with Java for now, OpenTok will work to support more SDKs soon.
来源:https://stackoverflow.com/questions/22573441/how-to-know-the-time-duration-a-token-was-streaming-its-video-to-a-session-in-o