Temasys adapter.js ver 0.12.0 with fix for setInterval included

This commit is contained in:
paweldomas 2015-08-18 12:37:32 +02:00
parent eb63b24a9a
commit 420514b921
1 changed files with 100 additions and 290 deletions

View File

@ -1,4 +1,4 @@
/*! adapterjs - custom version from - 2015-08-12 */ /*! adapterjs - custom version from - 2015-08-18 */
// Adapter's interface. // Adapter's interface.
var AdapterJS = AdapterJS || {}; var AdapterJS = AdapterJS || {};
@ -17,7 +17,7 @@ AdapterJS.options = AdapterJS.options || {};
// AdapterJS.options.hidePluginInstallPrompt = true; // AdapterJS.options.hidePluginInstallPrompt = true;
// AdapterJS version // AdapterJS version
AdapterJS.VERSION = '0.11.1'; AdapterJS.VERSION = '0.12.0';
// This function will be called when the WebRTC API is ready to be used // This function will be called when the WebRTC API is ready to be used
// Whether it is the native implementation (Chrome, Firefox, Opera) or // Whether it is the native implementation (Chrome, Firefox, Opera) or
@ -72,6 +72,12 @@ else if(!!navigator.platform.match(/^Win/i)) {
AdapterJS.WebRTCPlugin.pluginInfo.downloadLink = 'http://bit.ly/1kkS4FN'; AdapterJS.WebRTCPlugin.pluginInfo.downloadLink = 'http://bit.ly/1kkS4FN';
} }
AdapterJS.WebRTCPlugin.TAGS = {
NONE : 'none',
AUDIO : 'audio',
VIDEO : 'video'
};
// Unique identifier of each opened page // Unique identifier of each opened page
AdapterJS.WebRTCPlugin.pageId = Math.random().toString(36).slice(2); AdapterJS.WebRTCPlugin.pageId = Math.random().toString(36).slice(2);
@ -341,23 +347,24 @@ AdapterJS.renderNotificationBar = function (text, buttonText, buttonLink, openNe
event.cancelBubble = true; event.cancelBubble = true;
} catch(error) { } } catch(error) { }
var pluginInstallInterval = setInterval(function(){ var pluginInstallInterval = setInterval(function(){
if(! isIE) { if(! isIE) {
navigator.plugins.refresh(false); navigator.plugins.refresh(false);
} }
AdapterJS.WebRTCPlugin.isPluginInstalled( AdapterJS.WebRTCPlugin.isPluginInstalled(
AdapterJS.WebRTCPlugin.pluginInfo.prefix, AdapterJS.WebRTCPlugin.pluginInfo.prefix,
AdapterJS.WebRTCPlugin.pluginInfo.plugName, AdapterJS.WebRTCPlugin.pluginInfo.plugName,
function() { AdapterJS.WebRTCPlugin.defineWebRTCInterface,
clearInterval(pluginInstallInterval); function() {
AdapterJS.WebRTCPlugin.defineWebRTCInterface(); clearInterval(pluginInstallInterval);
}, AdapterJS.WebRTCPlugin.defineWebRTCInterface();
function() { //Does nothing because not used here },
}); function() {
} , 500); //Does nothing because not used here
});
} , 500);
}); });
} else {
}else {
c.document.close(); c.document.close();
} }
AdapterJS.addEvent(c.document, 'click', function() { AdapterJS.addEvent(c.document, 'click', function() {
@ -809,8 +816,8 @@ if (navigator.mozGetUserMedia) {
AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" /> ' + AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" /> ' +
'<param name="windowless" value="false" /> ' + '<param name="windowless" value="false" /> ' +
'<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' + '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
'<param name="onload" value="' + AdapterJS.WebRTCPlugin.pluginInfo.onload + '<param name="onload" value="' + AdapterJS.WebRTCPlugin.pluginInfo.onload + '" />' +
'" />' + '<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />' +
// uncomment to be able to use virtual cams // uncomment to be able to use virtual cams
(AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') + (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
@ -844,7 +851,8 @@ if (navigator.mozGetUserMedia) {
AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '">' + AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '">' +
'<param name="windowless" value="false" /> ' + '<param name="windowless" value="false" /> ' +
(AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') + (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
'<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '">'; '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '">' +
'<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />';
document.body.appendChild(AdapterJS.WebRTCPlugin.plugin); document.body.appendChild(AdapterJS.WebRTCPlugin.plugin);
} }
@ -971,78 +979,88 @@ if (navigator.mozGetUserMedia) {
streamId = ''; streamId = '';
} }
else { else {
stream.enableSoundTracks(true); stream.enableSoundTracks(true); // TODO: remove on 0.12.0
streamId = stream.id; streamId = stream.id;
} }
if (element.nodeName.toLowerCase() !== 'audio') { var elementId = element.id.length === 0 ? Math.random().toString(36).slice(2) : element.id;
var elementId = element.id.length === 0 ? Math.random().toString(36).slice(2) : element.id; if (!element.isWebRTCPlugin || !element.isWebRTCPlugin()) {
if (!element.isWebRTCPlugin || !element.isWebRTCPlugin()) { var tag;
var frag = document.createDocumentFragment(); switch(element.nodeName.toLowerCase()) {
var temp = document.createElement('div'); case 'audio':
var classHTML = ''; tag = AdapterJS.WebRTCPlugin.TAGS.AUDIO;
if (element.className) { break;
classHTML = 'class="' + element.className + '" '; case 'video':
} else if (element.attributes && element.attributes['class']) { tag = AdapterJS.WebRTCPlugin.TAGS.VIDEO;
classHTML = 'class="' + element.attributes['class'].value + '" '; break;
default:
tag = AdapterJS.WebRTCPlugin.TAGS.NONE;
} }
temp.innerHTML = '<object id="' + elementId + '" ' + classHTML + var frag = document.createDocumentFragment();
'type="' + AdapterJS.WebRTCPlugin.pluginInfo.type + '">' + var temp = document.createElement('div');
'<param name="pluginId" value="' + elementId + '" /> ' + var classHTML = '';
'<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' + if (element.className) {
'<param name="windowless" value="true" /> ' + classHTML = 'class="' + element.className + '" ';
'<param name="streamId" value="' + streamId + '" /> ' + } else if (element.attributes && element.attributes['class']) {
'</object>'; classHTML = 'class="' + element.attributes['class'].value + '" ';
while (temp.firstChild) { }
frag.appendChild(temp.firstChild);
}
var height = ''; temp.innerHTML = '<object id="' + elementId + '" ' + classHTML +
var width = ''; 'type="' + AdapterJS.WebRTCPlugin.pluginInfo.type + '">' +
if (element.getBoundingClientRect) { '<param name="pluginId" value="' + elementId + '" /> ' +
var rectObject = element.getBoundingClientRect(); '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
width = rectObject.width + 'px'; '<param name="windowless" value="true" /> ' +
height = rectObject.height + 'px'; '<param name="streamId" value="' + streamId + '" /> ' +
} '<param name="tag" value="' + tag + '" /> ' +
else if (element.width) { '</object>';
width = element.width; while (temp.firstChild) {
height = element.height; frag.appendChild(temp.firstChild);
} else { }
// TODO: What scenario could bring us here?
}
element.parentNode.insertBefore(frag, element); var height = '';
frag = document.getElementById(elementId); var width = '';
frag.width = width; if (element.getBoundingClientRect) {
frag.height = height; var rectObject = element.getBoundingClientRect();
element.parentNode.removeChild(element); width = rectObject.width + 'px';
height = rectObject.height + 'px';
}
else if (element.width) {
width = element.width;
height = element.height;
} else { } else {
var children = element.children; // TODO: What scenario could bring us here?
for (var i = 0; i !== children.length; ++i) {
if (children[i].name === 'streamId') {
children[i].value = streamId;
break;
}
}
element.setStreamId(streamId);
} }
var newElement = document.getElementById(elementId);
newElement.onplaying = (element.onplaying) ? element.onplaying : function (arg) {}; element.parentNode.insertBefore(frag, element);
if (isIE) { // on IE the event needs to be plugged manually frag = document.getElementById(elementId);
newElement.attachEvent('onplaying', newElement.onplaying); frag.width = width;
newElement.onclick = (element.onclick) ? element.onclick : function (arg) {}; frag.height = height;
newElement._TemOnClick = function (id) { element.parentNode.removeChild(element);
var arg = {
srcElement : document.getElementById(id)
};
newElement.onclick(arg);
};
}
return newElement;
} else { } else {
return element; var children = element.children;
for (var i = 0; i !== children.length; ++i) {
if (children[i].name === 'streamId') {
children[i].value = streamId;
break;
}
}
element.setStreamId(streamId);
} }
var newElement = document.getElementById(elementId);
newElement.onplaying = (element.onplaying) ? element.onplaying : function (arg) {};
if (isIE) { // on IE the event needs to be plugged manually
newElement.attachEvent('onplaying', newElement.onplaying);
newElement.onclick = (element.onclick) ? element.onclick : function (arg) {};
newElement._TemOnClick = function (id) {
var arg = {
srcElement : document.getElementById(id)
};
newElement.onclick(arg);
};
}
return newElement;
}; };
reattachMediaStream = function (to, from) { reattachMediaStream = function (to, from) {
@ -1120,211 +1138,3 @@ if (navigator.mozGetUserMedia) {
AdapterJS.WebRTCPlugin.defineWebRTCInterface, AdapterJS.WebRTCPlugin.defineWebRTCInterface,
AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb); AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb);
} }
(function () {
'use strict';
var baseGetUserMedia = null;
AdapterJS.TEXT.EXTENSION = {
REQUIRE_INSTALLATION_FF: 'To enable screensharing you need to install the Skylink WebRTC tools Firefox Add-on.',
REQUIRE_INSTALLATION_CHROME: 'To enable screensharing you need to install the Skylink WebRTC tools Chrome Extension.',
REQUIRE_REFRESH: 'Please refresh this page after the Skylink WebRTC tools extension has been installed.',
BUTTON_FF: 'Install Now',
BUTTON_CHROME: 'Go to Chrome Web Store'
};
var clone = function(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
};
if (window.navigator.mozGetUserMedia) {
baseGetUserMedia = window.navigator.getUserMedia;
navigator.getUserMedia = function (constraints, successCb, failureCb) {
if (constraints && constraints.video && !!constraints.video.mediaSource) {
// intercepting screensharing requests
if (constraints.video.mediaSource !== 'screen' && constraints.video.mediaSource !== 'window') {
throw new Error('Only "screen" and "window" option is available as mediaSource');
}
var updatedConstraints = clone(constraints);
//constraints.video.mediaSource = constraints.video.mediaSource;
updatedConstraints.video.mozMediaSource = updatedConstraints.video.mediaSource;
// so generally, it requires for document.readyState to be completed before the getUserMedia could be invoked.
// strange but this works anyway
var checkIfReady = setInterval(function () {
if (document.readyState === 'complete') {
clearInterval(checkIfReady);
baseGetUserMedia(updatedConstraints, successCb, function (error) {
if (error.name === 'PermissionDeniedError' && window.parent.location.protocol === 'https:') {
AdapterJS.renderNotificationBar(AdapterJS.TEXT.EXTENSION.REQUIRE_INSTALLATION_FF,
AdapterJS.TEXT.EXTENSION.BUTTON_FF,
'http://skylink.io/screensharing/ff_addon.php?domain=' + window.location.hostname, false, true);
//window.location.href = 'http://skylink.io/screensharing/ff_addon.php?domain=' + window.location.hostname;
} else {
failureCb(error);
}
});
}
}, 1);
} else { // regular GetUserMediaRequest
baseGetUserMedia(constraints, successCb, failureCb);
}
};
getUserMedia = navigator.getUserMedia;
} else if (window.navigator.webkitGetUserMedia) {
baseGetUserMedia = window.navigator.getUserMedia;
navigator.getUserMedia = function (constraints, successCb, failureCb) {
if (constraints && constraints.video && !!constraints.video.mediaSource) {
if (window.webrtcDetectedBrowser !== 'chrome') {
throw new Error('Current browser does not support screensharing');
}
// would be fine since no methods
var updatedConstraints = clone(constraints);
var chromeCallback = function(error, sourceId) {
if(!error) {
updatedConstraints.video.mandatory = updatedConstraints.video.mandatory || {};
updatedConstraints.video.mandatory.chromeMediaSource = 'desktop';
updatedConstraints.video.mandatory.maxWidth = window.screen.width > 1920 ? window.screen.width : 1920;
updatedConstraints.video.mandatory.maxHeight = window.screen.height > 1080 ? window.screen.height : 1080;
if (sourceId) {
updatedConstraints.video.mandatory.chromeMediaSourceId = sourceId;
}
delete updatedConstraints.video.mediaSource;
baseGetUserMedia(updatedConstraints, successCb, failureCb);
} else {
if (error === 'permission-denied') {
throw new Error('Permission denied for screen retrieval');
} else {
throw new Error('Failed retrieving selected screen');
}
}
};
var onIFrameCallback = function (event) {
if (!event.data) {
return;
}
if (event.data.chromeMediaSourceId) {
if (event.data.chromeMediaSourceId === 'PermissionDeniedError') {
chromeCallback('permission-denied');
} else {
chromeCallback(null, event.data.chromeMediaSourceId);
}
}
if (event.data.chromeExtensionStatus) {
if (event.data.chromeExtensionStatus === 'not-installed') {
AdapterJS.renderNotificationBar(AdapterJS.TEXT.EXTENSION.REQUIRE_INSTALLATION_CHROME,
AdapterJS.TEXT.EXTENSION.BUTTON_CHROME,
event.data.data, true, true);
} else {
chromeCallback(event.data.chromeExtensionStatus, null);
}
}
// this event listener is no more needed
window.removeEventListener('message', onIFrameCallback);
};
window.addEventListener('message', onIFrameCallback);
postFrameMessage({
captureSourceId: true
});
} else {
baseGetUserMedia(constraints, successCb, failureCb);
}
};
getUserMedia = navigator.getUserMedia;
} else {
baseGetUserMedia = window.navigator.getUserMedia;
navigator.getUserMedia = function (constraints, successCb, failureCb) {
if (constraints && constraints.video && !!constraints.video.mediaSource) {
// would be fine since no methods
var updatedConstraints = clone(constraints);
// wait for plugin to be ready
AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
// check if screensharing feature is available
if (!!AdapterJS.WebRTCPlugin.plugin.HasScreensharingFeature &&
!!AdapterJS.WebRTCPlugin.plugin.isScreensharingAvailable) {
// set the constraints
updatedConstraints.video.optional = updatedConstraints.video.optional || [];
updatedConstraints.video.optional.push({
sourceId: AdapterJS.WebRTCPlugin.plugin.screensharingKey || 'Screensharing'
});
delete updatedConstraints.video.mediaSource;
} else {
throw new Error('Your WebRTC plugin does not support screensharing');
}
baseGetUserMedia(updatedConstraints, successCb, failureCb);
});
} else {
baseGetUserMedia(constraints, successCb, failureCb);
}
};
getUserMedia = window.navigator.getUserMedia;
}
if (window.webrtcDetectedBrowser === 'chrome') {
var iframe = document.createElement('iframe');
iframe.onload = function() {
iframe.isLoaded = true;
};
iframe.src = 'https://cdn.temasys.com.sg/skylink/extensions/detectRTC.html';
//'https://temasys-cdn.s3.amazonaws.com/skylink/extensions/detection-script-dev/detectRTC.html';
iframe.style.display = 'none';
(document.body || document.documentElement).appendChild(iframe);
var postFrameMessage = function (object) {
object = object || {};
if (!iframe.isLoaded) {
setTimeout(function () {
iframe.contentWindow.postMessage(object, '*');
}, 100);
return;
}
iframe.contentWindow.postMessage(object, '*');
};
}
})();