0

I am using tokbox trial for video chatting on my website. But the problem i am facing is that ::: User 1 can see and hear User 2 clearly. User 2 can see User 1 clearly, but user 2 couldnt here user 1. And code i am using

<html>
  <head>
    <title>Monkvyasa | Test</title>
    <script src='http://static.opentok.com/webrtc/v2.2/js/opentok.min.js'></script>
    <script type="text/javascript">
      // Initialize API key, session, and token...
      // Think of a session as a room, and a token as the key to get in to the room
      // Sessions and tokens are generated on your server and passed down to the client
      var apiKey = "xxxxxxx";
      var API_KEY=apiKey;
      var sessionId = "2_MX40NTAyMDgxMn5-xxxxxxxxxxxxxxxxxxxxHBXZEZoWHN-fg";
       var token = "T1==cGFydG5lcl9pZD00NTAyMDgxMiZzaWc9ZDNiYjYyZGE2NTBkYmUzMTUyNGNjNDZjYzAzY2NjZWRhZGY3NTEyZjpyb2xlPW1vZGVyYXRvciZzZXNzaW9uX2lkPTJfTVg0xxxxxxxxxxxxxxxxxxxxxxxxBNM1JsYlRCUFdXWkhSSEJYWkVab1dITi1mZyZjcmVhdGVfdGltZT0xNDEzMjAwMjIxJm5vbmNlPTAuMTk1MzEwNTU0MzY1MjEwNSZleHBpcmVfdGltZT0xNDEzMjg0MzY5";


      // Initialize session, set up event listeners, and connect
        var session;
        var connectionCount = 0;

        function connect() {
            session = TB.initSession(sessionId);
            session.addEventListener("sessionConnected", sessionConnectHandler);
            session.addEventListener('streamCreated', function(event){
                e=event;
                console.log(e);
              for (var i = 0; i < event.streams.length; i++) {
                 streams = event.streams;
                // Make sure we don't subscribe to ourself
                alert("new user connected :)");
                if (streams[i].connection.connectionId == session.connection.connectionId) {
                  return;
                }
                // Create the div to put the subscriber element in to
                var div = document.createElement('div');
                div.setAttribute('id', 'stream' + streams[i].streamId);
                document.body.appendChild(div);
                session.subscribe(streams[i], div.id);
              }
            });

            session.connect(API_KEY, token);

            }

         function sessionConnectHandler(event) {
                var div = document.createElement('div');
                div.setAttribute('id', 'publisher');

                var publisherContainer = document.getElementById('publisherContainer');  
                    // This example assumes that a publisherContainer div exists
                publisherContainer.appendChild(div);

                var publisherProperties = {width: 500, height:450};
                publisher = TB.initPublisher(API_KEY, 'publisher', publisherProperties);
                session.publish(publisher);
            }

        function disconnect() {
          session.disconnect();
        }



        connect();
    </script>
  </head>
  <body>
    <h1>Monkvysa videofeed test!</h1>
    <input style="display:block" type="button" id="disconnectBtn" value="Disconnect" onClick="disconnect()">
    <table>
    <tr>
    <td> <div id="publisherContainer"></div></td> <td><div id="myPublisherDiv"></div></td>
    </tr>
    </table>


  </body>
</html>

Thanks in advance

sarath
  • 56
  • 12

1 Answers1

0

The code looks mostly correct, except you're using an older form of the 'streamCreated' event handler. In the latest version of the API, you no longer need to iterate through the event.streams array, you actually get one invocation of the event handler per stream.

In order to further dig into the problem, would you be able to add a link to a gist containing all the console logs? To make sure the logs are being outputted, you can call OT.setLogLevel(OT.DEBUG); at the beginning of the script.

Lastly, the newer API is greatly simplified and you could save yourself the effort of DOM element creation and iteration. What you have implemented is basically identical to our Hello World sample applications, which you can find in any of our server SDKs, for example here: https://github.com/opentok/opentok-node/blob/61fb4db35334cd30248362e9b10c0bbf5476c802/sample/HelloWorld/public/js/helloworld.js

Ankur
  • 2,792
  • 3
  • 23
  • 26
  • Thanks for the help and providing me sample codes. I have solved the problem by selecting proper audio driver while connecting. The sample code would help me to go further. Thanks again :) – sarath Oct 16 '14 at 05:25