I am trying to implement screen sharing using TokBox service in chrome and chromium. After chrome prompts to select a window everything works correctly but when I stop the screen sharing clicking on the "Stop sharing" button in the "pop up" that appears when screen sharing is in progress an 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 does not happen: http://meet.tokbox.com
I modified the basic tokbox tutorial code to reproduce this problem:
<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>