Created
September 7, 2015 21:59
-
-
Save jeanlescure/336844680f292ba57dd1 to your computer and use it in GitHub Desktop.
Changes to OpenTok Pre-Call test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //... | |
| var session; | |
| var publisher; | |
| var subscriber; | |
| var statusContainerEl; | |
| var statusTitleEl; | |
| var statusMessageEl; | |
| var statusIconEl; | |
| // Added these variables for later usage in allowing video or not | |
| var audioSupported = false; | |
| var videoSupported = false; | |
| //This callback can be overriden to start the OpenTok call when bandwidth test completed | |
| var onTestComplete = function(){console.log('onTestComplete(): "Nothing to do".');}; | |
| //... | |
| onSubscribe: function onSubscribe(error, subscriber) { | |
| if (error) { | |
| setText(statusMessageEl, 'Could not subscribe to video'); | |
| return; | |
| } | |
| setText(statusMessageEl, 'Checking your available bandwidth<br/>(' + (TEST_TIMEOUT_MS/1000) + ' Seconds)'); | |
| testStreamingCapability(subscriber, function(error, message) { | |
| setText(statusTitleEl, 'Result'); | |
| setText(statusMessageEl, message.text); | |
| statusIconEl.src = message.icon; | |
| onTestComplete(); // Added call to previously set onTestComplete callback | |
| callbacks.cleanup(); | |
| }); | |
| }, | |
| // ... | |
| document.addEventListener('DOMContentLoaded', function() { | |
| var container = document.createElement('div'); | |
| container.className = 'container'; | |
| container.appendChild(publisherEl); | |
| container.appendChild(subscriberEl); | |
| document.body.appendChild(container); | |
| // Refactored the following to first get the Session Id and Token | |
| // before initiating the session | |
| getJSON('/quality.session.id', function(data) { | |
| SESSION_ID = data.sessionId; | |
| getJSON('/quality.token', function(data) { | |
| TOKEN = data.token; | |
| publisher = OT.initPublisher(publisherEl, {}, callbacks.onInitPublisher); | |
| session = OT.initSession(API_KEY, SESSION_ID); | |
| session.connect(TOKEN, callbacks.onConnect); | |
| statusContainerEl = document.getElementById('status_container'); | |
| statusTitleEl = statusContainerEl.querySelector('h2'); | |
| statusMessageEl = statusContainerEl.querySelector('p'); | |
| statusIconEl = statusContainerEl.querySelector('img'); | |
| }, function(status) { | |
| alert("QUALITY TOKEN ERROR:\nSomething went wrong."); | |
| }); | |
| }, function(status) { | |
| alert("QUALITY SESSION ID ERROR:\nSomething went wrong."); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment