Opentok.js on escaping stop (Cannot read "connection" null properties)

I am trying to implement screen sharing with TokBox service in chrome and chrome. After the chrome buttons to select the window work correctly, but when I stop accessing the screen by clicking the Stop Sharing button in the popup that appears when starting screen sharing, the error occurs:

Uncaught TypeError: Cannot read property 'connections' of null ---- opentok.js line 11103

When using tokbox meet demo in the same browser, this error doesn't happen: http://meet.tokbox.com

I modified the basic code of the tokbox tutorial to reproduce this issue:

<div id="camera"></div>
<div id="screen-preview"></div>
<div id="screen"></div>

<script src="//static.opentok.com/v2/js/opentok.js"></script>

<script type="text/javascript">

  // Go to https://dashboard.tokbox.com/ to find your OpenTok
  // API key and generate a test session ID and token:
  var apiKey    = "<%= api_key %>";
  var sessionId = "<%= session_id %>";
  var token     = "<%= token %>";

  var session = OT.initSession(apiKey, sessionId);

  session.connect(token, function(error) {
    var publisher = OT.initPublisher('camera');
    session.publish(publisher);
    screenshare();
  });

  session.on('streamCreated', function(event) {
    session.subscribe(event.stream, 'screen');
  });

  // For Google Chrome only, register your extension by ID. You can
  // find it at chrome://extensions once the extension is installed.
  OT.registerScreenSharingExtension('chrome', '<%= chrome_extension_id %>');

  function screenshare() {
    OT.checkScreenSharingCapability(function(response) {
      if (!response.supported || response.extensionRegistered === false) {
        alert('This browser does not support screen sharing.');
      } else if (response.extensionInstalled === false) {
        alert('Please install the screen sharing extension and load your app over https.');
      } else {
        // Screen sharing is available. Publish the screen.
        var screenSharingPublisher = OT.initPublisher(
          'screen-preview',
          {videoSource : 'screen'},
          function(error) {
            if (error) {
              alert('Something went wrong: ' + error.message);
            } else {
              session.publish(
                screenSharingPublisher,
                function(error) {
                  if (error) {
                    alert('Something went wrong: ' + error.message);
                  }
                });
            }
          });
        }
      });
  }
</script>

      

+3


source to share





All Articles