diff options
-rw-r--r-- | js/lib/janus.nojquery.js | 117 |
1 files changed, 57 insertions, 60 deletions
diff --git a/js/lib/janus.nojquery.js b/js/lib/janus.nojquery.js index 0dfce72..2343ac6 100644 --- a/js/lib/janus.nojquery.js +++ b/js/lib/janus.nojquery.js @@ -143,7 +143,10 @@ Janus.init = function(options) { } else { Janus.error("Error attaching stream to element"); } - } else { + } else if(adapter.browserDetails.browser === 'safari' || window.navigator.userAgent.match(/iPad/i) || window.navigator.userAgent.match(/iPhone/i)) { + element.src = URL.createObjectURL(stream); + } + else { element.srcObject = stream; } }; @@ -155,7 +158,10 @@ Janus.init = function(options) { } else if(typeof to.src !== 'undefined') { to.src = from.src; } - } else { + } else if(adapter.browserDetails.browser === 'safari' || window.navigator.userAgent.match(/iPad/i) || window.navigator.userAgent.match(/iPhone/i)) { + to.src = from.src; + } + else { to.srcObject = from.srcObject; } }; @@ -192,7 +198,11 @@ Janus.init = function(options) { return; } // Got payload - params.success(JSON.parse(XHR.responseText)); + try { + params.success(JSON.parse(XHR.responseText)); + } catch(e) { + params.error(XHR, XHR.status, 'Could not parse response, error: ' + e + ', text: ' + XHR.responseText); + } }; } try { @@ -204,7 +214,11 @@ Janus.init = function(options) { return; } // Got payload - params.success(JSON.parse(XHR.responseText)); + try { + params.success(JSON.parse(XHR.responseText)); + } catch(e) { + params.error(XHR, XHR.status, 'Could not parse response, error: ' + e + ', text: ' + XHR.responseText); + } } } catch(e) { // Something broke up @@ -225,44 +239,8 @@ Janus.init = function(options) { if(oldOBF && typeof oldOBF == "function") oldOBF(); } - function addJsList(srcArray) { - if (!srcArray || !Array.isArray(srcArray) || srcArray.length == 0) { - options.callback(); - } - var count = 0; - addJs(srcArray[count],next); - - function next() { - count++; - if (count<srcArray.length) { - addJs(srcArray[count],next); - } - else { - options.callback(); - } - } - } - function addJs(src,done) { - try { - if(adapter) { - // Already loaded - Janus.debug(src + " already loaded, skipping"); - done(); - return; - } - } catch(e) {}; - var oHead = document.getElementsByTagName('head').item(0); - var oScript = document.createElement("script"); - oScript.type = "text/javascript"; - oScript.src = src; - oScript.onload = function() { - Janus.log("Library " + src + " loaded"); - done(); - } - oHead.appendChild(oScript); - } Janus.initDone = true; - addJsList(["adapter.js"]); // We may need others in the future + options.callback(); } }; @@ -460,7 +438,7 @@ function Janus(gatewayCallbacks) { } var pluginHandle = pluginHandles[sender]; if(pluginHandle === undefined || pluginHandle === null) { - Janus.warn("This handle is not attached to this session"); + Janus.debug("This handle is not attached to this session"); return; } pluginHandle.webrtcState(true); @@ -476,10 +454,10 @@ function Janus(gatewayCallbacks) { } var pluginHandle = pluginHandles[sender]; if(pluginHandle === undefined || pluginHandle === null) { - Janus.warn("This handle is not attached to this session"); + Janus.debug("This handle is not attached to this session"); return; } - pluginHandle.webrtcState(false); + pluginHandle.webrtcState(false, json["reason"]); pluginHandle.hangup(); } else if(json["janus"] === "detached") { // A plugin asked the core to detach one of our handles @@ -495,6 +473,7 @@ function Janus(gatewayCallbacks) { // Don't warn here because destroyHandle causes this situation. return; } + pluginHandle.detached = true; pluginHandle.ondetached(); pluginHandle.detach(); } else if(json["janus"] === "media") { @@ -508,7 +487,7 @@ function Janus(gatewayCallbacks) { } var pluginHandle = pluginHandles[sender]; if(pluginHandle === undefined || pluginHandle === null) { - Janus.warn("This handle is not attached to this session"); + Janus.debug("This handle is not attached to this session"); return; } pluginHandle.mediaState(json["type"], json["receiving"]); @@ -523,7 +502,7 @@ function Janus(gatewayCallbacks) { } var pluginHandle = pluginHandles[sender]; if(pluginHandle === undefined || pluginHandle === null) { - Janus.warn("This handle is not attached to this session"); + Janus.debug("This handle is not attached to this session"); return; } pluginHandle.slowLink(json["uplink"], json["nacks"]); @@ -655,7 +634,11 @@ function Janus(gatewayCallbacks) { }, 'message': function(event) { - handleEvent(JSON.parse(event.data)); + try { + handleEvent(JSON.parse(event.data)); + } catch(e) { + Janus.error('Error processing event:', e); + } }, 'close': function() { @@ -739,13 +722,7 @@ function Janus(gatewayCallbacks) { return; } delete Janus.sessions[sessionId]; - // Destroy all handles first - for(var ph in pluginHandles) { - var phv = pluginHandles[ph]; - Janus.log("Destroying handle " + phv.id + " (" + phv.plugin + ")"); - destroyHandle(phv.id, {asyncRequest: asyncRequest}); - } - // Ok, go on + // No need to destroy all handles first, Janus will do that itself var request = { "janus": "destroy", "transaction": Janus.randomString(12) }; if(token !== null && token !== undefined) request["token"] = token; @@ -822,6 +799,7 @@ function Janus(gatewayCallbacks) { callbacks.success = (typeof callbacks.success == "function") ? callbacks.success : Janus.noop; callbacks.error = (typeof callbacks.error == "function") ? callbacks.error : Janus.noop; callbacks.consentDialog = (typeof callbacks.consentDialog == "function") ? callbacks.consentDialog : Janus.noop; + callbacks.iceState = (typeof callbacks.iceState == "function") ? callbacks.iceState : Janus.noop; callbacks.mediaState = (typeof callbacks.mediaState == "function") ? callbacks.mediaState : Janus.noop; callbacks.webrtcState = (typeof callbacks.webrtcState == "function") ? callbacks.webrtcState : Janus.noop; callbacks.slowLink = (typeof callbacks.slowLink == "function") ? callbacks.slowLink : Janus.noop; @@ -865,6 +843,7 @@ function Janus(gatewayCallbacks) { session : that, plugin : plugin, id : handleId, + detached : false, webrtcStuff : { started : false, myStream : null, @@ -904,6 +883,7 @@ function Janus(gatewayCallbacks) { data : function(callbacks) { sendData(handleId, callbacks); }, dtmf : function(callbacks) { sendDtmf(handleId, callbacks); }, consentDialog : callbacks.consentDialog, + iceState : callbacks.iceState, mediaState : callbacks.mediaState, webrtcState : callbacks.webrtcState, slowLink : callbacks.slowLink, @@ -948,6 +928,7 @@ function Janus(gatewayCallbacks) { session : that, plugin : plugin, id : handleId, + detached : false, webrtcStuff : { started : false, myStream : null, @@ -987,6 +968,7 @@ function Janus(gatewayCallbacks) { data : function(callbacks) { sendData(handleId, callbacks); }, dtmf : function(callbacks) { sendDtmf(handleId, callbacks); }, consentDialog : callbacks.consentDialog, + iceState : callbacks.iceState, mediaState : callbacks.mediaState, webrtcState : callbacks.webrtcState, slowLink : callbacks.slowLink, @@ -1243,6 +1225,12 @@ function Janus(gatewayCallbacks) { asyncRequest = (callbacks.asyncRequest === true); Janus.log("Destroying handle " + handleId + " (sync=" + asyncRequest + ")"); cleanupWebrtc(handleId); + if (pluginHandles[handleId].detached) { + // Plugin was already detached by Janus, calling detach again will return a handle not found error, so just exit here + delete pluginHandles[handleId]; + callbacks.success(); + return; + } if(!connected) { Janus.warn("Is the gateway down? (connected=false)"); callbacks.error("Is the gateway down? (connected=false)"); @@ -1323,6 +1311,10 @@ function Janus(gatewayCallbacks) { config.bitrate.value = "0 kbits/sec"; } Janus.log("Preparing local SDP and gathering candidates (trickle=" + config.trickle + ")"); + config.pc.oniceconnectionstatechange = function(e) { + if(config.pc) + pluginHandle.iceState(config.pc.iceConnectionState); + }; config.pc.onicecandidate = function(event) { if (event.candidate == null || (adapter.browserDetails.browser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0)) { @@ -1354,11 +1346,11 @@ function Janus(gatewayCallbacks) { config.pc.addStream(stream); pluginHandle.onlocalstream(stream); } - config.pc.onaddstream = function(remoteStream) { + config.pc.ontrack = function(remoteStream) { Janus.log("Handling Remote Stream"); Janus.debug(remoteStream); config.remoteStream = remoteStream; - pluginHandle.onremotestream(remoteStream.stream); + pluginHandle.onremotestream(remoteStream.streams[0]); }; // Any data channel to create? if(isDataEnabled(media)) { @@ -1535,6 +1527,9 @@ function Janus(gatewayCallbacks) { } Janus.debug(videoSupport); } else if(media.video === 'screen' || media.video === 'window') { + if (!media.screenshareFrameRate) { + media.screenshareFrameRate = 3; + } // Not a webcam, but screen capture if(window.location.protocol !== 'https:') { // Screen sharing mandates HTTPS @@ -1574,7 +1569,8 @@ function Janus(gatewayCallbacks) { googLeakyBucket: true, maxWidth: window.screen.width, maxHeight: window.screen.height, - maxFrameRate: 3, + minFrameRate: media.screenshareFrameRate, + maxFrameRate: media.screenshareFrameRate, chromeMediaSource: 'screen' } }, @@ -1654,7 +1650,8 @@ function Janus(gatewayCallbacks) { chromeMediaSource: 'desktop', maxWidth: window.screen.width, maxHeight: window.screen.height, - maxFrameRate: 3 + minFrameRate: media.screenshareFrameRate, + maxFrameRate: media.screenshareFrameRate, }, optional: [ {googLeakyBucket: true}, @@ -2069,11 +2066,11 @@ function Janus(gatewayCallbacks) { } else if(config.pc.getStats && adapter.browserDetails.browser == "firefox") { // Do it the Firefox way if(config.remoteStream === null || config.remoteStream === undefined - || config.remoteStream.stream === null || config.remoteStream.stream === undefined) { + || config.remoteStream.streams[0] === null || config.remoteStream.streams[0] === undefined) { Janus.warn("Remote stream unavailable"); return "Remote stream unavailable"; } - var videoTracks = config.remoteStream.stream.getVideoTracks(); + var videoTracks = config.remoteStream.streams[0].getVideoTracks(); if(videoTracks === null || videoTracks === undefined || videoTracks.length < 1) { Janus.warn("No video track"); return "No video track"; |