You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adapter.screenshare.js 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*! adapterjs - v0.12.0 - 2015-09-04 */
  2. // Adapter's interface.
  3. var AdapterJS = AdapterJS || {};
  4. // Browserify compatibility
  5. if(typeof exports !== 'undefined') {
  6. module.exports = AdapterJS;
  7. }
  8. AdapterJS.options = AdapterJS.options || {};
  9. // uncomment to get virtual webcams
  10. // AdapterJS.options.getAllCams = true;
  11. // uncomment to prevent the install prompt when the plugin in not yet installed
  12. // AdapterJS.options.hidePluginInstallPrompt = true;
  13. // AdapterJS version
  14. AdapterJS.VERSION = '0.12.0';
  15. // This function will be called when the WebRTC API is ready to be used
  16. // Whether it is the native implementation (Chrome, Firefox, Opera) or
  17. // the plugin
  18. // You may Override this function to synchronise the start of your application
  19. // with the WebRTC API being ready.
  20. // If you decide not to override use this synchronisation, it may result in
  21. // an extensive CPU usage on the plugin start (once per tab loaded)
  22. // Params:
  23. // - isUsingPlugin: true is the WebRTC plugin is being used, false otherwise
  24. //
  25. AdapterJS.onwebrtcready = AdapterJS.onwebrtcready || function(isUsingPlugin) {
  26. // The WebRTC API is ready.
  27. // Override me and do whatever you want here
  28. };
  29. // Sets a callback function to be called when the WebRTC interface is ready.
  30. // The first argument is the function to callback.\
  31. // Throws an error if the first argument is not a function
  32. AdapterJS.webRTCReady = function (callback) {
  33. if (typeof callback !== 'function') {
  34. throw new Error('Callback provided is not a function');
  35. }
  36. if (true === AdapterJS.onwebrtcreadyDone) {
  37. // All WebRTC interfaces are ready, just call the callback
  38. callback(null !== AdapterJS.WebRTCPlugin.plugin);
  39. } else {
  40. // will be triggered automatically when your browser/plugin is ready.
  41. AdapterJS.onwebrtcready = callback;
  42. }
  43. };
  44. // Plugin namespace
  45. AdapterJS.WebRTCPlugin = AdapterJS.WebRTCPlugin || {};
  46. // The object to store plugin information
  47. AdapterJS.WebRTCPlugin.pluginInfo = {
  48. prefix : 'Tem',
  49. plugName : 'TemWebRTCPlugin',
  50. pluginId : 'plugin0',
  51. type : 'application/x-temwebrtcplugin',
  52. onload : '__TemWebRTCReady0',
  53. portalLink : 'http://skylink.io/plugin/',
  54. downloadLink : null, //set below
  55. companyName: 'Temasys'
  56. };
  57. if(!!navigator.platform.match(/^Mac/i)) {
  58. AdapterJS.WebRTCPlugin.pluginInfo.downloadLink = 'http://bit.ly/1n77hco';
  59. }
  60. else if(!!navigator.platform.match(/^Win/i)) {
  61. AdapterJS.WebRTCPlugin.pluginInfo.downloadLink = 'http://bit.ly/1kkS4FN';
  62. }
  63. AdapterJS.WebRTCPlugin.TAGS = {
  64. NONE : 'none',
  65. AUDIO : 'audio',
  66. VIDEO : 'video'
  67. };
  68. // Unique identifier of each opened page
  69. AdapterJS.WebRTCPlugin.pageId = Math.random().toString(36).slice(2);
  70. // Use this whenever you want to call the plugin.
  71. AdapterJS.WebRTCPlugin.plugin = null;
  72. // Set log level for the plugin once it is ready.
  73. // The different values are
  74. // This is an asynchronous function that will run when the plugin is ready
  75. AdapterJS.WebRTCPlugin.setLogLevel = null;
  76. // Defines webrtc's JS interface according to the plugin's implementation.
  77. // Define plugin Browsers as WebRTC Interface.
  78. AdapterJS.WebRTCPlugin.defineWebRTCInterface = null;
  79. // This function detects whether or not a plugin is installed.
  80. // Checks if Not IE (firefox, for example), else if it's IE,
  81. // we're running IE and do something. If not it is not supported.
  82. AdapterJS.WebRTCPlugin.isPluginInstalled = null;
  83. // Lets adapter.js wait until the the document is ready before injecting the plugin
  84. AdapterJS.WebRTCPlugin.pluginInjectionInterval = null;
  85. // Inject the HTML DOM object element into the page.
  86. AdapterJS.WebRTCPlugin.injectPlugin = null;
  87. // States of readiness that the plugin goes through when
  88. // being injected and stated
  89. AdapterJS.WebRTCPlugin.PLUGIN_STATES = {
  90. NONE : 0, // no plugin use
  91. INITIALIZING : 1, // Detected need for plugin
  92. INJECTING : 2, // Injecting plugin
  93. INJECTED: 3, // Plugin element injected but not usable yet
  94. READY: 4 // Plugin ready to be used
  95. };
  96. // Current state of the plugin. You cannot use the plugin before this is
  97. // equal to AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY
  98. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.NONE;
  99. // True is AdapterJS.onwebrtcready was already called, false otherwise
  100. // Used to make sure AdapterJS.onwebrtcready is only called once
  101. AdapterJS.onwebrtcreadyDone = false;
  102. // Log levels for the plugin.
  103. // To be set by calling AdapterJS.WebRTCPlugin.setLogLevel
  104. /*
  105. Log outputs are prefixed in some cases.
  106. INFO: Information reported by the plugin.
  107. ERROR: Errors originating from within the plugin.
  108. WEBRTC: Error originating from within the libWebRTC library
  109. */
  110. // From the least verbose to the most verbose
  111. AdapterJS.WebRTCPlugin.PLUGIN_LOG_LEVELS = {
  112. NONE : 'NONE',
  113. ERROR : 'ERROR',
  114. WARNING : 'WARNING',
  115. INFO: 'INFO',
  116. VERBOSE: 'VERBOSE',
  117. SENSITIVE: 'SENSITIVE'
  118. };
  119. // Does a waiting check before proceeding to load the plugin.
  120. AdapterJS.WebRTCPlugin.WaitForPluginReady = null;
  121. // This methid will use an interval to wait for the plugin to be ready.
  122. AdapterJS.WebRTCPlugin.callWhenPluginReady = null;
  123. // !!!! WARNING: DO NOT OVERRIDE THIS FUNCTION. !!!
  124. // This function will be called when plugin is ready. It sends necessary
  125. // details to the plugin.
  126. // The function will wait for the document to be ready and the set the
  127. // plugin state to AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY,
  128. // indicating that it can start being requested.
  129. // This function is not in the IE/Safari condition brackets so that
  130. // TemPluginLoaded function might be called on Chrome/Firefox.
  131. // This function is the only private function that is not encapsulated to
  132. // allow the plugin method to be called.
  133. __TemWebRTCReady0 = function () {
  134. if (document.readyState === 'complete') {
  135. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY;
  136. AdapterJS.maybeThroughWebRTCReady();
  137. } else {
  138. AdapterJS.WebRTCPlugin.documentReadyInterval = setInterval(function () {
  139. if (document.readyState === 'complete') {
  140. // TODO: update comments, we wait for the document to be ready
  141. clearInterval(AdapterJS.WebRTCPlugin.documentReadyInterval);
  142. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY;
  143. AdapterJS.maybeThroughWebRTCReady();
  144. }
  145. }, 100);
  146. }
  147. };
  148. AdapterJS.maybeThroughWebRTCReady = function() {
  149. if (!AdapterJS.onwebrtcreadyDone) {
  150. AdapterJS.onwebrtcreadyDone = true;
  151. if (typeof(AdapterJS.onwebrtcready) === 'function') {
  152. AdapterJS.onwebrtcready(AdapterJS.WebRTCPlugin.plugin !== null);
  153. }
  154. }
  155. };
  156. // Text namespace
  157. AdapterJS.TEXT = {
  158. PLUGIN: {
  159. REQUIRE_INSTALLATION: 'This website requires you to install a WebRTC-enabling plugin ' +
  160. 'to work on this browser.',
  161. NOT_SUPPORTED: 'Your browser does not support WebRTC.',
  162. BUTTON: 'Install Now'
  163. },
  164. REFRESH: {
  165. REQUIRE_REFRESH: 'Please refresh page',
  166. BUTTON: 'Refresh Page'
  167. }
  168. };
  169. // The result of ice connection states.
  170. // - starting: Ice connection is starting.
  171. // - checking: Ice connection is checking.
  172. // - connected Ice connection is connected.
  173. // - completed Ice connection is connected.
  174. // - done Ice connection has been completed.
  175. // - disconnected Ice connection has been disconnected.
  176. // - failed Ice connection has failed.
  177. // - closed Ice connection is closed.
  178. AdapterJS._iceConnectionStates = {
  179. starting : 'starting',
  180. checking : 'checking',
  181. connected : 'connected',
  182. completed : 'connected',
  183. done : 'completed',
  184. disconnected : 'disconnected',
  185. failed : 'failed',
  186. closed : 'closed'
  187. };
  188. //The IceConnection states that has been fired for each peer.
  189. AdapterJS._iceConnectionFiredStates = [];
  190. // Check if WebRTC Interface is defined.
  191. AdapterJS.isDefined = null;
  192. // This function helps to retrieve the webrtc detected browser information.
  193. // This sets:
  194. // - webrtcDetectedBrowser: The browser agent name.
  195. // - webrtcDetectedVersion: The browser version.
  196. // - webrtcDetectedType: The types of webRTC support.
  197. // - 'moz': Mozilla implementation of webRTC.
  198. // - 'webkit': WebKit implementation of webRTC.
  199. // - 'plugin': Using the plugin implementation.
  200. AdapterJS.parseWebrtcDetectedBrowser = function () {
  201. var hasMatch, checkMatch = navigator.userAgent.match(
  202. /(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
  203. if (/trident/i.test(checkMatch[1])) {
  204. hasMatch = /\brv[ :]+(\d+)/g.exec(navigator.userAgent) || [];
  205. webrtcDetectedBrowser = 'IE';
  206. webrtcDetectedVersion = parseInt(hasMatch[1] || '0', 10);
  207. } else if (checkMatch[1] === 'Chrome') {
  208. hasMatch = navigator.userAgent.match(/\bOPR\/(\d+)/);
  209. if (hasMatch !== null) {
  210. webrtcDetectedBrowser = 'opera';
  211. webrtcDetectedVersion = parseInt(hasMatch[1], 10);
  212. }
  213. }
  214. if (navigator.userAgent.indexOf('Safari')) {
  215. if (typeof InstallTrigger !== 'undefined') {
  216. webrtcDetectedBrowser = 'firefox';
  217. } else if (/*@cc_on!@*/ false || !!document.documentMode) {
  218. webrtcDetectedBrowser = 'IE';
  219. } else if (
  220. Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) {
  221. webrtcDetectedBrowser = 'safari';
  222. } else if (!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
  223. webrtcDetectedBrowser = 'opera';
  224. } else if (!!window.chrome) {
  225. webrtcDetectedBrowser = 'chrome';
  226. }
  227. }
  228. if (!webrtcDetectedBrowser) {
  229. webrtcDetectedVersion = checkMatch[1];
  230. }
  231. if (!webrtcDetectedVersion) {
  232. try {
  233. checkMatch = (checkMatch[2]) ? [checkMatch[1], checkMatch[2]] :
  234. [navigator.appName, navigator.appVersion, '-?'];
  235. if ((hasMatch = navigator.userAgent.match(/version\/(\d+)/i)) !== null) {
  236. checkMatch.splice(1, 1, hasMatch[1]);
  237. }
  238. webrtcDetectedVersion = parseInt(checkMatch[1], 10);
  239. } catch (error) { }
  240. }
  241. };
  242. // To fix configuration as some browsers does not support
  243. // the 'urls' attribute.
  244. AdapterJS.maybeFixConfiguration = function (pcConfig) {
  245. if (pcConfig === null) {
  246. return;
  247. }
  248. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  249. if (pcConfig.iceServers[i].hasOwnProperty('urls')) {
  250. pcConfig.iceServers[i].url = pcConfig.iceServers[i].urls;
  251. delete pcConfig.iceServers[i].urls;
  252. }
  253. }
  254. };
  255. AdapterJS.addEvent = function(elem, evnt, func) {
  256. if (elem.addEventListener) { // W3C DOM
  257. elem.addEventListener(evnt, func, false);
  258. } else if (elem.attachEvent) {// OLD IE DOM
  259. elem.attachEvent('on'+evnt, func);
  260. } else { // No much to do
  261. elem[evnt] = func;
  262. }
  263. };
  264. AdapterJS.renderNotificationBar = function (text, buttonText, buttonLink, openNewTab, displayRefreshBar) {
  265. // only inject once the page is ready
  266. if (document.readyState !== 'complete') {
  267. return;
  268. }
  269. var w = window;
  270. var i = document.createElement('iframe');
  271. i.style.position = 'fixed';
  272. i.style.top = '-41px';
  273. i.style.left = 0;
  274. i.style.right = 0;
  275. i.style.width = '100%';
  276. i.style.height = '40px';
  277. i.style.backgroundColor = '#ffffe1';
  278. i.style.border = 'none';
  279. i.style.borderBottom = '1px solid #888888';
  280. i.style.zIndex = '9999999';
  281. if(typeof i.style.webkitTransition === 'string') {
  282. i.style.webkitTransition = 'all .5s ease-out';
  283. } else if(typeof i.style.transition === 'string') {
  284. i.style.transition = 'all .5s ease-out';
  285. }
  286. document.body.appendChild(i);
  287. c = (i.contentWindow) ? i.contentWindow :
  288. (i.contentDocument.document) ? i.contentDocument.document : i.contentDocument;
  289. c.document.open();
  290. c.document.write('<span style="display: inline-block; font-family: Helvetica, Arial,' +
  291. 'sans-serif; font-size: .9rem; padding: 4px; vertical-align: ' +
  292. 'middle; cursor: default;">' + text + '</span>');
  293. if(buttonText && buttonLink) {
  294. c.document.write('<button id="okay">' + buttonText + '</button><button id="cancel">Cancel</button>');
  295. c.document.close();
  296. // On click on okay
  297. AdapterJS.addEvent(c.document.getElementById('okay'), 'click', function(e) {
  298. if (!!displayRefreshBar) {
  299. AdapterJS.renderNotificationBar(AdapterJS.TEXT.EXTENSION ?
  300. AdapterJS.TEXT.EXTENSION.REQUIRE_REFRESH : AdapterJS.TEXT.REFRESH.REQUIRE_REFRESH,
  301. AdapterJS.TEXT.REFRESH.BUTTON, 'javascript:location.reload()');
  302. }
  303. window.open(buttonLink, !!openNewTab ? '_blank' : '_top');
  304. e.preventDefault();
  305. try {
  306. event.cancelBubble = true;
  307. } catch(error) { }
  308. var pluginInstallInterval = setInterval(function(){
  309. if(! isIE) {
  310. navigator.plugins.refresh(false);
  311. }
  312. AdapterJS.WebRTCPlugin.isPluginInstalled(
  313. AdapterJS.WebRTCPlugin.pluginInfo.prefix,
  314. AdapterJS.WebRTCPlugin.pluginInfo.plugName,
  315. function() { // plugin now installed
  316. clearInterval(pluginInstallInterval);
  317. AdapterJS.WebRTCPlugin.defineWebRTCInterface();
  318. },
  319. function() {
  320. // still no plugin detected, nothing to do
  321. });
  322. } , 500);
  323. });
  324. // On click on Cancel
  325. AdapterJS.addEvent(c.document.getElementById('cancel'), 'click', function(e) {
  326. w.document.body.removeChild(i);
  327. });
  328. } else {
  329. c.document.close();
  330. }
  331. setTimeout(function() {
  332. if(typeof i.style.webkitTransform === 'string') {
  333. i.style.webkitTransform = 'translateY(40px)';
  334. } else if(typeof i.style.transform === 'string') {
  335. i.style.transform = 'translateY(40px)';
  336. } else {
  337. i.style.top = '0px';
  338. }
  339. }, 300);
  340. };
  341. // -----------------------------------------------------------
  342. // Detected webrtc implementation. Types are:
  343. // - 'moz': Mozilla implementation of webRTC.
  344. // - 'webkit': WebKit implementation of webRTC.
  345. // - 'plugin': Using the plugin implementation.
  346. webrtcDetectedType = null;
  347. // Detected webrtc datachannel support. Types are:
  348. // - 'SCTP': SCTP datachannel support.
  349. // - 'RTP': RTP datachannel support.
  350. webrtcDetectedDCSupport = null;
  351. // Set the settings for creating DataChannels, MediaStream for
  352. // Cross-browser compability.
  353. // - This is only for SCTP based support browsers.
  354. // the 'urls' attribute.
  355. checkMediaDataChannelSettings =
  356. function (peerBrowserAgent, peerBrowserVersion, callback, constraints) {
  357. if (typeof callback !== 'function') {
  358. return;
  359. }
  360. var beOfferer = true;
  361. var isLocalFirefox = webrtcDetectedBrowser === 'firefox';
  362. // Nightly version does not require MozDontOfferDataChannel for interop
  363. var isLocalFirefoxInterop = webrtcDetectedType === 'moz' && webrtcDetectedVersion > 30;
  364. var isPeerFirefox = peerBrowserAgent === 'firefox';
  365. var isPeerFirefoxInterop = peerBrowserAgent === 'firefox' &&
  366. ((peerBrowserVersion) ? (peerBrowserVersion > 30) : false);
  367. // Resends an updated version of constraints for MozDataChannel to work
  368. // If other userAgent is firefox and user is firefox, remove MozDataChannel
  369. if ((isLocalFirefox && isPeerFirefox) || (isLocalFirefoxInterop)) {
  370. try {
  371. delete constraints.mandatory.MozDontOfferDataChannel;
  372. } catch (error) {
  373. console.error('Failed deleting MozDontOfferDataChannel');
  374. console.error(error);
  375. }
  376. } else if ((isLocalFirefox && !isPeerFirefox)) {
  377. constraints.mandatory.MozDontOfferDataChannel = true;
  378. }
  379. if (!isLocalFirefox) {
  380. // temporary measure to remove Moz* constraints in non Firefox browsers
  381. for (var prop in constraints.mandatory) {
  382. if (constraints.mandatory.hasOwnProperty(prop)) {
  383. if (prop.indexOf('Moz') !== -1) {
  384. delete constraints.mandatory[prop];
  385. }
  386. }
  387. }
  388. }
  389. // Firefox (not interopable) cannot offer DataChannel as it will cause problems to the
  390. // interopability of the media stream
  391. if (isLocalFirefox && !isPeerFirefox && !isLocalFirefoxInterop) {
  392. beOfferer = false;
  393. }
  394. callback(beOfferer, constraints);
  395. };
  396. // Handles the differences for all browsers ice connection state output.
  397. // - Tested outcomes are:
  398. // - Chrome (offerer) : 'checking' > 'completed' > 'completed'
  399. // - Chrome (answerer) : 'checking' > 'connected'
  400. // - Firefox (offerer) : 'checking' > 'connected'
  401. // - Firefox (answerer): 'checking' > 'connected'
  402. checkIceConnectionState = function (peerId, iceConnectionState, callback) {
  403. if (typeof callback !== 'function') {
  404. console.warn('No callback specified in checkIceConnectionState. Aborted.');
  405. return;
  406. }
  407. peerId = (peerId) ? peerId : 'peer';
  408. if (!AdapterJS._iceConnectionFiredStates[peerId] ||
  409. iceConnectionState === AdapterJS._iceConnectionStates.disconnected ||
  410. iceConnectionState === AdapterJS._iceConnectionStates.failed ||
  411. iceConnectionState === AdapterJS._iceConnectionStates.closed) {
  412. AdapterJS._iceConnectionFiredStates[peerId] = [];
  413. }
  414. iceConnectionState = AdapterJS._iceConnectionStates[iceConnectionState];
  415. if (AdapterJS._iceConnectionFiredStates[peerId].indexOf(iceConnectionState) < 0) {
  416. AdapterJS._iceConnectionFiredStates[peerId].push(iceConnectionState);
  417. if (iceConnectionState === AdapterJS._iceConnectionStates.connected) {
  418. setTimeout(function () {
  419. AdapterJS._iceConnectionFiredStates[peerId]
  420. .push(AdapterJS._iceConnectionStates.done);
  421. callback(AdapterJS._iceConnectionStates.done);
  422. }, 1000);
  423. }
  424. callback(iceConnectionState);
  425. }
  426. return;
  427. };
  428. // Firefox:
  429. // - Creates iceServer from the url for Firefox.
  430. // - Create iceServer with stun url.
  431. // - Create iceServer with turn url.
  432. // - Ignore the transport parameter from TURN url for FF version <=27.
  433. // - Return null for createIceServer if transport=tcp.
  434. // - FF 27 and above supports transport parameters in TURN url,
  435. // - So passing in the full url to create iceServer.
  436. // Chrome:
  437. // - Creates iceServer from the url for Chrome M33 and earlier.
  438. // - Create iceServer with stun url.
  439. // - Chrome M28 & above uses below TURN format.
  440. // Plugin:
  441. // - Creates Ice Server for Plugin Browsers
  442. // - If Stun - Create iceServer with stun url.
  443. // - Else - Create iceServer with turn url
  444. // - This is a WebRTC Function
  445. createIceServer = null;
  446. // Firefox:
  447. // - Creates IceServers for Firefox
  448. // - Use .url for FireFox.
  449. // - Multiple Urls support
  450. // Chrome:
  451. // - Creates iceServers from the urls for Chrome M34 and above.
  452. // - .urls is supported since Chrome M34.
  453. // - Multiple Urls support
  454. // Plugin:
  455. // - Creates Ice Servers for Plugin Browsers
  456. // - Multiple Urls support
  457. // - This is a WebRTC Function
  458. createIceServers = null;
  459. //------------------------------------------------------------
  460. //The RTCPeerConnection object.
  461. RTCPeerConnection = null;
  462. // Creates RTCSessionDescription object for Plugin Browsers
  463. RTCSessionDescription = (typeof RTCSessionDescription === 'function') ?
  464. RTCSessionDescription : null;
  465. // Creates RTCIceCandidate object for Plugin Browsers
  466. RTCIceCandidate = (typeof RTCIceCandidate === 'function') ?
  467. RTCIceCandidate : null;
  468. // Get UserMedia (only difference is the prefix).
  469. // Code from Adam Barth.
  470. getUserMedia = null;
  471. // Attach a media stream to an element.
  472. attachMediaStream = null;
  473. // Re-attach a media stream to an element.
  474. reattachMediaStream = null;
  475. // Detected browser agent name. Types are:
  476. // - 'firefox': Firefox browser.
  477. // - 'chrome': Chrome browser.
  478. // - 'opera': Opera browser.
  479. // - 'safari': Safari browser.
  480. // - 'IE' - Internet Explorer browser.
  481. webrtcDetectedBrowser = null;
  482. // Detected browser version.
  483. webrtcDetectedVersion = null;
  484. // Check for browser types and react accordingly
  485. if (navigator.mozGetUserMedia) {
  486. webrtcDetectedBrowser = 'firefox';
  487. webrtcDetectedVersion = parseInt(navigator
  488. .userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
  489. webrtcDetectedType = 'moz';
  490. webrtcDetectedDCSupport = 'SCTP';
  491. RTCPeerConnection = function (pcConfig, pcConstraints) {
  492. AdapterJS.maybeFixConfiguration(pcConfig);
  493. return new mozRTCPeerConnection(pcConfig, pcConstraints);
  494. };
  495. // The RTCSessionDescription object.
  496. RTCSessionDescription = mozRTCSessionDescription;
  497. window.RTCSessionDescription = RTCSessionDescription;
  498. // The RTCIceCandidate object.
  499. RTCIceCandidate = mozRTCIceCandidate;
  500. window.RTCIceCandidate = RTCIceCandidate;
  501. window.getUserMedia = navigator.mozGetUserMedia.bind(navigator);
  502. navigator.getUserMedia = window.getUserMedia;
  503. // Shim for MediaStreamTrack.getSources.
  504. MediaStreamTrack.getSources = function(successCb) {
  505. setTimeout(function() {
  506. var infos = [
  507. { kind: 'audio', id: 'default', label:'', facing:'' },
  508. { kind: 'video', id: 'default', label:'', facing:'' }
  509. ];
  510. successCb(infos);
  511. }, 0);
  512. };
  513. createIceServer = function (url, username, password) {
  514. var iceServer = null;
  515. var url_parts = url.split(':');
  516. if (url_parts[0].indexOf('stun') === 0) {
  517. iceServer = { url : url };
  518. } else if (url_parts[0].indexOf('turn') === 0) {
  519. if (webrtcDetectedVersion < 27) {
  520. var turn_url_parts = url.split('?');
  521. if (turn_url_parts.length === 1 ||
  522. turn_url_parts[1].indexOf('transport=udp') === 0) {
  523. iceServer = {
  524. url : turn_url_parts[0],
  525. credential : password,
  526. username : username
  527. };
  528. }
  529. } else {
  530. iceServer = {
  531. url : url,
  532. credential : password,
  533. username : username
  534. };
  535. }
  536. }
  537. return iceServer;
  538. };
  539. createIceServers = function (urls, username, password) {
  540. var iceServers = [];
  541. for (i = 0; i < urls.length; i++) {
  542. var iceServer = createIceServer(urls[i], username, password);
  543. if (iceServer !== null) {
  544. iceServers.push(iceServer);
  545. }
  546. }
  547. return iceServers;
  548. };
  549. attachMediaStream = function (element, stream) {
  550. element.mozSrcObject = stream;
  551. if (stream !== null)
  552. element.play();
  553. return element;
  554. };
  555. reattachMediaStream = function (to, from) {
  556. to.mozSrcObject = from.mozSrcObject;
  557. to.play();
  558. return to;
  559. };
  560. MediaStreamTrack.getSources = MediaStreamTrack.getSources || function (callback) {
  561. if (!callback) {
  562. throw new TypeError('Failed to execute \'getSources\' on \'MediaStreamTrack\'' +
  563. ': 1 argument required, but only 0 present.');
  564. }
  565. return callback([]);
  566. };
  567. // Fake get{Video,Audio}Tracks
  568. if (!MediaStream.prototype.getVideoTracks) {
  569. MediaStream.prototype.getVideoTracks = function () {
  570. return [];
  571. };
  572. }
  573. if (!MediaStream.prototype.getAudioTracks) {
  574. MediaStream.prototype.getAudioTracks = function () {
  575. return [];
  576. };
  577. }
  578. AdapterJS.maybeThroughWebRTCReady();
  579. } else if (navigator.webkitGetUserMedia) {
  580. webrtcDetectedBrowser = 'chrome';
  581. webrtcDetectedType = 'webkit';
  582. webrtcDetectedVersion = parseInt(navigator
  583. .userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
  584. // check if browser is opera 20+
  585. var checkIfOpera = navigator.userAgent.match(/\bOPR\/(\d+)/);
  586. if (checkIfOpera !== null) {
  587. webrtcDetectedBrowser = 'opera';
  588. webrtcDetectedVersion = parseInt(checkIfOpera[1], 10);
  589. }
  590. // check browser datachannel support
  591. if ((webrtcDetectedBrowser === 'chrome' && webrtcDetectedVersion >= 31) ||
  592. (webrtcDetectedBrowser === 'opera' && webrtcDetectedVersion >= 20)) {
  593. webrtcDetectedDCSupport = 'SCTP';
  594. } else if (webrtcDetectedBrowser === 'chrome' && webrtcDetectedVersion < 30 &&
  595. webrtcDetectedVersion > 24) {
  596. webrtcDetectedDCSupport = 'RTP';
  597. } else {
  598. webrtcDetectedDCSupport = '';
  599. }
  600. createIceServer = function (url, username, password) {
  601. var iceServer = null;
  602. var url_parts = url.split(':');
  603. if (url_parts[0].indexOf('stun') === 0) {
  604. iceServer = { 'url' : url };
  605. } else if (url_parts[0].indexOf('turn') === 0) {
  606. iceServer = {
  607. 'url' : url,
  608. 'credential' : password,
  609. 'username' : username
  610. };
  611. }
  612. return iceServer;
  613. };
  614. createIceServers = function (urls, username, password) {
  615. var iceServers = [];
  616. if (webrtcDetectedVersion >= 34) {
  617. iceServers = {
  618. 'urls' : urls,
  619. 'credential' : password,
  620. 'username' : username
  621. };
  622. } else {
  623. for (i = 0; i < urls.length; i++) {
  624. var iceServer = createIceServer(urls[i], username, password);
  625. if (iceServer !== null) {
  626. iceServers.push(iceServer);
  627. }
  628. }
  629. }
  630. return iceServers;
  631. };
  632. RTCPeerConnection = function (pcConfig, pcConstraints) {
  633. if (webrtcDetectedVersion < 34) {
  634. AdapterJS.maybeFixConfiguration(pcConfig);
  635. }
  636. return new webkitRTCPeerConnection(pcConfig, pcConstraints);
  637. };
  638. window.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  639. navigator.getUserMedia = window.getUserMedia;
  640. attachMediaStream = function (element, stream) {
  641. if (typeof element.srcObject !== 'undefined') {
  642. element.srcObject = stream;
  643. } else if (typeof element.mozSrcObject !== 'undefined') {
  644. element.mozSrcObject = stream;
  645. } else if (typeof element.src !== 'undefined') {
  646. element.src = (stream === null ? '' : URL.createObjectURL(stream));
  647. } else {
  648. console.log('Error attaching stream to element.');
  649. }
  650. return element;
  651. };
  652. reattachMediaStream = function (to, from) {
  653. to.src = from.src;
  654. return to;
  655. };
  656. AdapterJS.maybeThroughWebRTCReady();
  657. } else if (navigator.mediaDevices && navigator.userAgent.match(
  658. /Edge\/(\d+).(\d+)$/)) {
  659. webrtcDetectedBrowser = 'edge';
  660. webrtcDetectedVersion =
  661. parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10);
  662. // the minimum version still supported by adapter.
  663. webrtcMinimumVersion = 12;
  664. window.getUserMedia = navigator.getUserMedia.bind(navigator);
  665. attachMediaStream = function(element, stream) {
  666. element.srcObject = stream;
  667. return element;
  668. };
  669. reattachMediaStream = function(to, from) {
  670. to.srcObject = from.srcObject;
  671. return to;
  672. };
  673. AdapterJS.maybeThroughWebRTCReady();
  674. } else { // TRY TO USE PLUGIN
  675. // IE 9 is not offering an implementation of console.log until you open a console
  676. if (typeof console !== 'object' || typeof console.log !== 'function') {
  677. /* jshint -W020 */
  678. console = {} || console;
  679. // Implemented based on console specs from MDN
  680. // You may override these functions
  681. console.log = function (arg) {};
  682. console.info = function (arg) {};
  683. console.error = function (arg) {};
  684. console.dir = function (arg) {};
  685. console.exception = function (arg) {};
  686. console.trace = function (arg) {};
  687. console.warn = function (arg) {};
  688. console.count = function (arg) {};
  689. console.debug = function (arg) {};
  690. console.count = function (arg) {};
  691. console.time = function (arg) {};
  692. console.timeEnd = function (arg) {};
  693. console.group = function (arg) {};
  694. console.groupCollapsed = function (arg) {};
  695. console.groupEnd = function (arg) {};
  696. /* jshint +W020 */
  697. }
  698. webrtcDetectedType = 'plugin';
  699. webrtcDetectedDCSupport = 'plugin';
  700. AdapterJS.parseWebrtcDetectedBrowser();
  701. isIE = webrtcDetectedBrowser === 'IE';
  702. /* jshint -W035 */
  703. AdapterJS.WebRTCPlugin.WaitForPluginReady = function() {
  704. while (AdapterJS.WebRTCPlugin.pluginState !== AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  705. /* empty because it needs to prevent the function from running. */
  706. }
  707. };
  708. /* jshint +W035 */
  709. AdapterJS.WebRTCPlugin.callWhenPluginReady = function (callback) {
  710. if (AdapterJS.WebRTCPlugin.pluginState === AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  711. // Call immediately if possible
  712. // Once the plugin is set, the code will always take this path
  713. callback();
  714. } else {
  715. // otherwise start a 100ms interval
  716. var checkPluginReadyState = setInterval(function () {
  717. if (AdapterJS.WebRTCPlugin.pluginState === AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  718. clearInterval(checkPluginReadyState);
  719. callback();
  720. }
  721. }, 100);
  722. }
  723. };
  724. AdapterJS.WebRTCPlugin.setLogLevel = function(logLevel) {
  725. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  726. AdapterJS.WebRTCPlugin.plugin.setLogLevel(logLevel);
  727. });
  728. };
  729. AdapterJS.WebRTCPlugin.injectPlugin = function () {
  730. // only inject once the page is ready
  731. if (document.readyState !== 'complete') {
  732. return;
  733. }
  734. // Prevent multiple injections
  735. if (AdapterJS.WebRTCPlugin.pluginState !== AdapterJS.WebRTCPlugin.PLUGIN_STATES.INITIALIZING) {
  736. return;
  737. }
  738. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INJECTING;
  739. if (webrtcDetectedBrowser === 'IE' && webrtcDetectedVersion <= 10) {
  740. var frag = document.createDocumentFragment();
  741. AdapterJS.WebRTCPlugin.plugin = document.createElement('div');
  742. AdapterJS.WebRTCPlugin.plugin.innerHTML = '<object id="' +
  743. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" type="' +
  744. AdapterJS.WebRTCPlugin.pluginInfo.type + '" ' + 'width="1" height="1">' +
  745. '<param name="pluginId" value="' +
  746. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" /> ' +
  747. '<param name="windowless" value="false" /> ' +
  748. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
  749. '<param name="onload" value="' + AdapterJS.WebRTCPlugin.pluginInfo.onload + '" />' +
  750. '<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />' +
  751. // uncomment to be able to use virtual cams
  752. (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
  753. '</object>';
  754. while (AdapterJS.WebRTCPlugin.plugin.firstChild) {
  755. frag.appendChild(AdapterJS.WebRTCPlugin.plugin.firstChild);
  756. }
  757. document.body.appendChild(frag);
  758. // Need to re-fetch the plugin
  759. AdapterJS.WebRTCPlugin.plugin =
  760. document.getElementById(AdapterJS.WebRTCPlugin.pluginInfo.pluginId);
  761. } else {
  762. // Load Plugin
  763. AdapterJS.WebRTCPlugin.plugin = document.createElement('object');
  764. AdapterJS.WebRTCPlugin.plugin.id =
  765. AdapterJS.WebRTCPlugin.pluginInfo.pluginId;
  766. // IE will only start the plugin if it's ACTUALLY visible
  767. if (isIE) {
  768. AdapterJS.WebRTCPlugin.plugin.width = '1px';
  769. AdapterJS.WebRTCPlugin.plugin.height = '1px';
  770. } else { // The size of the plugin on Safari should be 0x0px
  771. // so that the autorisation prompt is at the top
  772. AdapterJS.WebRTCPlugin.plugin.width = '0px';
  773. AdapterJS.WebRTCPlugin.plugin.height = '0px';
  774. }
  775. AdapterJS.WebRTCPlugin.plugin.type = AdapterJS.WebRTCPlugin.pluginInfo.type;
  776. AdapterJS.WebRTCPlugin.plugin.innerHTML = '<param name="onload" value="' +
  777. AdapterJS.WebRTCPlugin.pluginInfo.onload + '">' +
  778. '<param name="pluginId" value="' +
  779. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '">' +
  780. '<param name="windowless" value="false" /> ' +
  781. (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
  782. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '">' +
  783. '<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />';
  784. document.body.appendChild(AdapterJS.WebRTCPlugin.plugin);
  785. }
  786. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INJECTED;
  787. };
  788. AdapterJS.WebRTCPlugin.isPluginInstalled =
  789. function (comName, plugName, installedCb, notInstalledCb) {
  790. if (!isIE) {
  791. var pluginArray = navigator.plugins;
  792. for (var i = 0; i < pluginArray.length; i++) {
  793. if (pluginArray[i].name.indexOf(plugName) >= 0) {
  794. installedCb();
  795. return;
  796. }
  797. }
  798. notInstalledCb();
  799. } else {
  800. try {
  801. var axo = new ActiveXObject(comName + '.' + plugName);
  802. } catch (e) {
  803. notInstalledCb();
  804. return;
  805. }
  806. installedCb();
  807. }
  808. };
  809. AdapterJS.WebRTCPlugin.defineWebRTCInterface = function () {
  810. if (AdapterJS.WebRTCPlugin.pluginState ===
  811. AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  812. console.error("AdapterJS - WebRTC interface has already been defined");
  813. return;
  814. }
  815. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INITIALIZING;
  816. AdapterJS.isDefined = function (variable) {
  817. return variable !== null && variable !== undefined;
  818. };
  819. createIceServer = function (url, username, password) {
  820. var iceServer = null;
  821. var url_parts = url.split(':');
  822. if (url_parts[0].indexOf('stun') === 0) {
  823. iceServer = {
  824. 'url' : url,
  825. 'hasCredentials' : false
  826. };
  827. } else if (url_parts[0].indexOf('turn') === 0) {
  828. iceServer = {
  829. 'url' : url,
  830. 'hasCredentials' : true,
  831. 'credential' : password,
  832. 'username' : username
  833. };
  834. }
  835. return iceServer;
  836. };
  837. createIceServers = function (urls, username, password) {
  838. var iceServers = [];
  839. for (var i = 0; i < urls.length; ++i) {
  840. iceServers.push(createIceServer(urls[i], username, password));
  841. }
  842. return iceServers;
  843. };
  844. RTCSessionDescription = function (info) {
  845. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  846. return AdapterJS.WebRTCPlugin.plugin.
  847. ConstructSessionDescription(info.type, info.sdp);
  848. };
  849. RTCPeerConnection = function (servers, constraints) {
  850. var iceServers = null;
  851. if (servers) {
  852. iceServers = servers.iceServers;
  853. for (var i = 0; i < iceServers.length; i++) {
  854. if (iceServers[i].urls && !iceServers[i].url) {
  855. iceServers[i].url = iceServers[i].urls;
  856. }
  857. iceServers[i].hasCredentials = AdapterJS.
  858. isDefined(iceServers[i].username) &&
  859. AdapterJS.isDefined(iceServers[i].credential);
  860. }
  861. }
  862. var mandatory = (constraints && constraints.mandatory) ?
  863. constraints.mandatory : null;
  864. var optional = (constraints && constraints.optional) ?
  865. constraints.optional : null;
  866. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  867. return AdapterJS.WebRTCPlugin.plugin.
  868. PeerConnection(AdapterJS.WebRTCPlugin.pageId,
  869. iceServers, mandatory, optional);
  870. };
  871. MediaStreamTrack = {};
  872. MediaStreamTrack.getSources = function (callback) {
  873. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  874. AdapterJS.WebRTCPlugin.plugin.GetSources(callback);
  875. });
  876. };
  877. window.getUserMedia = function (constraints, successCallback, failureCallback) {
  878. constraints.audio = constraints.audio || false;
  879. constraints.video = constraints.video || false;
  880. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  881. AdapterJS.WebRTCPlugin.plugin.
  882. getUserMedia(constraints, successCallback, failureCallback);
  883. });
  884. };
  885. window.navigator.getUserMedia = window.getUserMedia;
  886. attachMediaStream = function (element, stream) {
  887. if (!element || !element.parentNode) {
  888. return;
  889. }
  890. var streamId
  891. if (stream === null) {
  892. streamId = '';
  893. }
  894. else {
  895. stream.enableSoundTracks(true); // TODO: remove on 0.12.0
  896. streamId = stream.id;
  897. }
  898. var elementId = element.id.length === 0 ? Math.random().toString(36).slice(2) : element.id;
  899. var nodeName = element.nodeName.toLowerCase();
  900. if (nodeName !== 'object') { // not a plugin <object> tag yet
  901. var tag;
  902. switch(nodeName) {
  903. case 'audio':
  904. tag = AdapterJS.WebRTCPlugin.TAGS.AUDIO;
  905. break;
  906. case 'video':
  907. tag = AdapterJS.WebRTCPlugin.TAGS.VIDEO;
  908. break;
  909. default:
  910. tag = AdapterJS.WebRTCPlugin.TAGS.NONE;
  911. }
  912. var frag = document.createDocumentFragment();
  913. var temp = document.createElement('div');
  914. var classHTML = '';
  915. if (element.className) {
  916. classHTML = 'class="' + element.className + '" ';
  917. } else if (element.attributes && element.attributes['class']) {
  918. classHTML = 'class="' + element.attributes['class'].value + '" ';
  919. }
  920. temp.innerHTML = '<object id="' + elementId + '" ' + classHTML +
  921. 'type="' + AdapterJS.WebRTCPlugin.pluginInfo.type + '">' +
  922. '<param name="pluginId" value="' + elementId + '" /> ' +
  923. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
  924. '<param name="windowless" value="true" /> ' +
  925. '<param name="streamId" value="' + streamId + '" /> ' +
  926. '<param name="tag" value="' + tag + '" /> ' +
  927. '</object>';
  928. while (temp.firstChild) {
  929. frag.appendChild(temp.firstChild);
  930. }
  931. var height = '';
  932. var width = '';
  933. if (element.getBoundingClientRect) {
  934. var rectObject = element.getBoundingClientRect();
  935. width = rectObject.width + 'px';
  936. height = rectObject.height + 'px';
  937. }
  938. else if (element.width) {
  939. width = element.width;
  940. height = element.height;
  941. } else {
  942. // TODO: What scenario could bring us here?
  943. }
  944. element.parentNode.insertBefore(frag, element);
  945. frag = document.getElementById(elementId);
  946. frag.width = width;
  947. frag.height = height;
  948. element.parentNode.removeChild(element);
  949. } else { // already an <object> tag, just change the stream id
  950. var children = element.children;
  951. for (var i = 0; i !== children.length; ++i) {
  952. if (children[i].name === 'streamId') {
  953. children[i].value = streamId;
  954. break;
  955. }
  956. }
  957. element.setStreamId(streamId);
  958. }
  959. var newElement = document.getElementById(elementId);
  960. newElement.onplaying = (element.onplaying) ? element.onplaying : function (arg) {};
  961. newElement.onplay = (element.onplay) ? element.onplay : function (arg) {};
  962. newElement.onclick = (element.onclick) ? element.onclick : function (arg) {};
  963. if (isIE) { // on IE the event needs to be plugged manually
  964. newElement.attachEvent('onplaying', newElement.onplaying);
  965. newElement.attachEvent('onplay', newElement.onplay);
  966. newElement._TemOnClick = function (id) {
  967. var arg = {
  968. srcElement : document.getElementById(id)
  969. };
  970. newElement.onclick(arg);
  971. };
  972. }
  973. return newElement;
  974. };
  975. reattachMediaStream = function (to, from) {
  976. var stream = null;
  977. var children = from.children;
  978. for (var i = 0; i !== children.length; ++i) {
  979. if (children[i].name === 'streamId') {
  980. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  981. stream = AdapterJS.WebRTCPlugin.plugin
  982. .getStreamWithId(AdapterJS.WebRTCPlugin.pageId, children[i].value);
  983. break;
  984. }
  985. }
  986. if (stream !== null) {
  987. return attachMediaStream(to, stream);
  988. } else {
  989. console.log('Could not find the stream associated with this element');
  990. }
  991. };
  992. RTCIceCandidate = function (candidate) {
  993. if (!candidate.sdpMid) {
  994. candidate.sdpMid = '';
  995. }
  996. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  997. return AdapterJS.WebRTCPlugin.plugin.ConstructIceCandidate(
  998. candidate.sdpMid, candidate.sdpMLineIndex, candidate.candidate
  999. );
  1000. };
  1001. // inject plugin
  1002. AdapterJS.addEvent(document, 'readystatechange', AdapterJS.WebRTCPlugin.injectPlugin);
  1003. AdapterJS.WebRTCPlugin.injectPlugin();
  1004. };
  1005. // This function will be called if the plugin is needed (browser different
  1006. // from Chrome or Firefox), but the plugin is not installed.
  1007. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb = AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb ||
  1008. function() {
  1009. AdapterJS.addEvent(document,
  1010. 'readystatechange',
  1011. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv);
  1012. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv();
  1013. };
  1014. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv = function () {
  1015. if (AdapterJS.options.hidePluginInstallPrompt) {
  1016. return;
  1017. }
  1018. var downloadLink = AdapterJS.WebRTCPlugin.pluginInfo.downloadLink;
  1019. if(downloadLink) { // if download link
  1020. var popupString;
  1021. if (AdapterJS.WebRTCPlugin.pluginInfo.portalLink) { // is portal link
  1022. popupString = 'This website requires you to install the ' +
  1023. ' <a href="' + AdapterJS.WebRTCPlugin.pluginInfo.portalLink +
  1024. '" target="_blank">' + AdapterJS.WebRTCPlugin.pluginInfo.companyName +
  1025. ' WebRTC Plugin</a>' +
  1026. ' to work on this browser.';
  1027. } else { // no portal link, just print a generic explanation
  1028. popupString = AdapterJS.TEXT.PLUGIN.REQUIRE_INSTALLATION;
  1029. }
  1030. AdapterJS.renderNotificationBar(popupString, AdapterJS.TEXT.PLUGIN.BUTTON, downloadLink);
  1031. } else { // no download link, just print a generic explanation
  1032. AdapterJS.renderNotificationBar(AdapterJS.TEXT.PLUGIN.NOT_SUPPORTED);
  1033. }
  1034. };
  1035. // Try to detect the plugin and act accordingly
  1036. AdapterJS.WebRTCPlugin.isPluginInstalled(
  1037. AdapterJS.WebRTCPlugin.pluginInfo.prefix,
  1038. AdapterJS.WebRTCPlugin.pluginInfo.plugName,
  1039. AdapterJS.WebRTCPlugin.defineWebRTCInterface,
  1040. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb);
  1041. }