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 41KB

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