0

My issue of concern is to find out the possible mistakes in my code which might hamper the working of opentok services to run smoothly(without any error) in my code. There something might be going wrong with my code. Please examine How Am I ending any video chat through my code.And other codes might have been written incorrectly
The library version I'm using is this

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

I'm using dot net sdk to generate sessionId and tokens on server side

I have published my application online , and it runs well 30 % time but 70% time it throws errors like sessionInfoError or many other errors

Api key secret and other settings aremade in web.config file like this

<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"/>

Rest of the code and functions written with the help of tokbox documentation are like this

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);

 }

There is a setInterval function which calls itself every second and will end video chat when fixed time become 00:00:00

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

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

I have a button for disconnecting from session

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

it calls the sessionDestroy() function on clicking

Please examine these codes like a doctor

1 Answers1

2

You code looks alright. Please keep in mind that Stack Overflow is used to ask questions and solve bugs. Using it as a place to proofread your code is not the intended idea.

songz
  • 2,072
  • 1
  • 13
  • 18