0

我关心的问题是找出我的代码中可能存在的错误,这些错误可能会妨碍 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 key secret 和其他设置在 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()函数

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

4

1 回答 1

2

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

于 2014-04-10T20:57:55.617 回答