可能妨碍opentok视频聊天应用程序的错误(错误)

时间:2014-03-29 06:00:06

标签: javascript video-streaming webrtc opentok tokbox

我关心的问题是找出我的代码中可能存在的错误,这些错误可能会妨碍我的代码中opentok服务的运行顺利运行(没有任何错误)。我的代码可能出现问题。 请检查我如何通过我的代码结束任何视频聊天。其他代码可能写错了
我正在使用的库版本是

<script type="text/javascript" src="http://static.opentok.com/webrtc/v2.2/js/TB.min.js" ></script> 

我使用dot net sdk在服务器端生成sessionId和令牌

我已经在线发布了我的应用程序,它运行时间长达30%,但有70%的时间会导致错误,例如sessionInfoErrormany other errors

Api密钥秘密和其他设置在web.config文件中进行,如下所示

<appSettings>
        <add key="opentok_key" value="******"/>
        <add key="opentok_secret" value="***********************"/>
        <add key="opentok_server" value="https://api.opentok.com"/>
        <add key="opentok_token_sentinel" value="T1=="/>
        <add key="opentok_sdk_version" value="tbdotnet"/>

在tokbox文档的帮助下编写的其余代码和函数就像这样

var sessionId;
 var token;
 var apiKey = "*******";
 var publisher_connections = {};
 var publisher;
 var session;
 var Id;
 var streamedTime;
 var hours;
 var minutes;
 var seconds;
 function a() {
     sessionId = document.getElementById('<%= hdn.ClientID%>').value;
      token = document.getElementById('<%= hdn1.ClientID%>').value;



     session = TB.initSession(sessionId);
     session.addEventListener("sessionConnected", sessionConnectedHandler);
     session.addEventListener('sessionDisconnected', sessionDisconnectedHandler);
     session.addEventListener("streamCreated", streamCreatedHandler);
     session.addEventListener("sessionDestroyed", sessionDestroy);
     session.addEventListener("signal", signalHandler);
     session.addEventListener("streamDestroyed", streamDestroyedHandler);
     session.addEventListener('connectionCreated', connectionCreatedHandler);
     session.addEventListener('connectionDestroyed', connectionDestroyedHandler);
     TB.addEventListener("exception", exceptionHandler);
     TB.setLogLevel(TB.DEBUG);
     session.connect(apiKey, token);

 }

 function sessionConnectedHandler(event) {
     console.log("connected");
     subscribeToStreams(event.streams);
     session.publish();


 }

 function sessionDisconnectedHandler(event) {
     alert("Session Disconnected");
     for (var i = 0; i < event.streams.length; i++) {alert(event.streams[i].connection.connectionId);
         delete publisher_connections[event.streams[i].connection.connectionId];
     }
     publisher = null;


 }


 function streamCreatedHandler(event) {
     console.log("created");
     subscribeToStreams(event.streams);

     for (var i = 0; i < event.streams.length; i++) {
         publisher_connections[event.streams[i].connection.connectionId] = 1;


     }

 }

 function subscribeToStreams(streams) {
     for (var i = 0; i < streams.length; i++) {
         var stream = streams[i];

         if (stream.connection.connectionId != session.connection.connectionId) {

             var subscriber = session.subscribe(stream);

             if (stream.connection.data == "accept") {
                 alert(stream.connection.data + " Joined You");
                 startTimer();
             }
             else {
                 alert(stream.connection.data + " Joined You");
                 UpdateInitializedTime();
                 startTimer();
             }
         }
     }
 }

 function exceptionHandler(event) {
     alert(event.message);
 }

 function sessionDestroy(event) {

         session.disconnect();
         alert("Session Destroyed");
       }

 }

 function streamDestroyedHandler(event) {
     for (var i = 0; i < event.streams.length; i++) {
         delete publisher_connections[event.streams[i].connection.connectionId];

         //alert("Someone left you");


     }

 }


 function connectionDestroyedHandler(event) {

     alert(event.streams[i].connection.connectionId + " left the conversation");
     // This signals that connections were destroyed
 }

 function connectionCreatedHandler(event) {
     // This signals new connections have been created.
   //  alert("this");

    // alert(connection.data);

 }

有一个setInterval函数,它每秒调用一次,并在固定时间变为00:00:00时结束视频聊天

function timeOver(){
            if (hours == 00 && minutes == 00 && seconds == 00) {

            session.disconnect();
            alert("Time Given For this Video Chat is Over");
          }
      }

我有一个用于断开会话

的按钮
<input type="button" value="Disconnect" id="btnDisconnect"  onclick="sessionDestroy()" />

点击

时调用sessionDestroy()功能

请像医生一样检查这些代码

1 个答案:

答案 0 :(得分:2)

你的代码看起来没问题。请记住,Stack Overflow用于提问和解决错误。使用它作为校对代码的地方不是预期的想法。