How to Know the time duration a token was streaming it's video to a session in opentok

你离开我真会死。 提交于 2019-12-11 08:52:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!