Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

adapter.screenshare.js 40KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /*! adapterjs - custom version from - 2015-08-19 */
  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>Cancel</button>');
  295. c.document.close();
  296. AdapterJS.addEvent(c.document.getElementById('okay'), 'click', function(e) {
  297. if (!!displayRefreshBar) {
  298. AdapterJS.renderNotificationBar(AdapterJS.TEXT.EXTENSION ?
  299. AdapterJS.TEXT.EXTENSION.REQUIRE_REFRESH : AdapterJS.TEXT.REFRESH.REQUIRE_REFRESH,
  300. AdapterJS.TEXT.REFRESH.BUTTON, 'javascript:location.reload()');
  301. }
  302. window.open(buttonLink, !!openNewTab ? '_blank' : '_top');
  303. e.preventDefault();
  304. try {
  305. event.cancelBubble = true;
  306. } catch(error) { }
  307. var pluginInstallInterval = setInterval(function(){
  308. if(! isIE) {
  309. navigator.plugins.refresh(false);
  310. }
  311. AdapterJS.WebRTCPlugin.isPluginInstalled(
  312. AdapterJS.WebRTCPlugin.pluginInfo.prefix,
  313. AdapterJS.WebRTCPlugin.pluginInfo.plugName,
  314. function() { // plugin now installed
  315. clearInterval(pluginInstallInterval);
  316. AdapterJS.WebRTCPlugin.defineWebRTCInterface();
  317. },
  318. function() {
  319. // still no plugin detected, nothing to do
  320. });
  321. } , 500);
  322. });
  323. } else {
  324. c.document.close();
  325. }
  326. AdapterJS.addEvent(c.document, 'click', function() {
  327. w.document.body.removeChild(i);
  328. });
  329. setTimeout(function() {
  330. if(typeof i.style.webkitTransform === 'string') {
  331. i.style.webkitTransform = 'translateY(40px)';
  332. } else if(typeof i.style.transform === 'string') {
  333. i.style.transform = 'translateY(40px)';
  334. } else {
  335. i.style.top = '0px';
  336. }
  337. }, 300);
  338. };
  339. // -----------------------------------------------------------
  340. // Detected webrtc implementation. Types are:
  341. // - 'moz': Mozilla implementation of webRTC.
  342. // - 'webkit': WebKit implementation of webRTC.
  343. // - 'plugin': Using the plugin implementation.
  344. webrtcDetectedType = null;
  345. // Detected webrtc datachannel support. Types are:
  346. // - 'SCTP': SCTP datachannel support.
  347. // - 'RTP': RTP datachannel support.
  348. webrtcDetectedDCSupport = null;
  349. // Set the settings for creating DataChannels, MediaStream for
  350. // Cross-browser compability.
  351. // - This is only for SCTP based support browsers.
  352. // the 'urls' attribute.
  353. checkMediaDataChannelSettings =
  354. function (peerBrowserAgent, peerBrowserVersion, callback, constraints) {
  355. if (typeof callback !== 'function') {
  356. return;
  357. }
  358. var beOfferer = true;
  359. var isLocalFirefox = webrtcDetectedBrowser === 'firefox';
  360. // Nightly version does not require MozDontOfferDataChannel for interop
  361. var isLocalFirefoxInterop = webrtcDetectedType === 'moz' && webrtcDetectedVersion > 30;
  362. var isPeerFirefox = peerBrowserAgent === 'firefox';
  363. var isPeerFirefoxInterop = peerBrowserAgent === 'firefox' &&
  364. ((peerBrowserVersion) ? (peerBrowserVersion > 30) : false);
  365. // Resends an updated version of constraints for MozDataChannel to work
  366. // If other userAgent is firefox and user is firefox, remove MozDataChannel
  367. if ((isLocalFirefox && isPeerFirefox) || (isLocalFirefoxInterop)) {
  368. try {
  369. delete constraints.mandatory.MozDontOfferDataChannel;
  370. } catch (error) {
  371. console.error('Failed deleting MozDontOfferDataChannel');
  372. console.error(error);
  373. }
  374. } else if ((isLocalFirefox && !isPeerFirefox)) {
  375. constraints.mandatory.MozDontOfferDataChannel = true;
  376. }
  377. if (!isLocalFirefox) {
  378. // temporary measure to remove Moz* constraints in non Firefox browsers
  379. for (var prop in constraints.mandatory) {
  380. if (constraints.mandatory.hasOwnProperty(prop)) {
  381. if (prop.indexOf('Moz') !== -1) {
  382. delete constraints.mandatory[prop];
  383. }
  384. }
  385. }
  386. }
  387. // Firefox (not interopable) cannot offer DataChannel as it will cause problems to the
  388. // interopability of the media stream
  389. if (isLocalFirefox && !isPeerFirefox && !isLocalFirefoxInterop) {
  390. beOfferer = false;
  391. }
  392. callback(beOfferer, constraints);
  393. };
  394. // Handles the differences for all browsers ice connection state output.
  395. // - Tested outcomes are:
  396. // - Chrome (offerer) : 'checking' > 'completed' > 'completed'
  397. // - Chrome (answerer) : 'checking' > 'connected'
  398. // - Firefox (offerer) : 'checking' > 'connected'
  399. // - Firefox (answerer): 'checking' > 'connected'
  400. checkIceConnectionState = function (peerId, iceConnectionState, callback) {
  401. if (typeof callback !== 'function') {
  402. console.warn('No callback specified in checkIceConnectionState. Aborted.');
  403. return;
  404. }
  405. peerId = (peerId) ? peerId : 'peer';
  406. if (!AdapterJS._iceConnectionFiredStates[peerId] ||
  407. iceConnectionState === AdapterJS._iceConnectionStates.disconnected ||
  408. iceConnectionState === AdapterJS._iceConnectionStates.failed ||
  409. iceConnectionState === AdapterJS._iceConnectionStates.closed) {
  410. AdapterJS._iceConnectionFiredStates[peerId] = [];
  411. }
  412. iceConnectionState = AdapterJS._iceConnectionStates[iceConnectionState];
  413. if (AdapterJS._iceConnectionFiredStates[peerId].indexOf(iceConnectionState) < 0) {
  414. AdapterJS._iceConnectionFiredStates[peerId].push(iceConnectionState);
  415. if (iceConnectionState === AdapterJS._iceConnectionStates.connected) {
  416. setTimeout(function () {
  417. AdapterJS._iceConnectionFiredStates[peerId]
  418. .push(AdapterJS._iceConnectionStates.done);
  419. callback(AdapterJS._iceConnectionStates.done);
  420. }, 1000);
  421. }
  422. callback(iceConnectionState);
  423. }
  424. return;
  425. };
  426. // Firefox:
  427. // - Creates iceServer from the url for Firefox.
  428. // - Create iceServer with stun url.
  429. // - Create iceServer with turn url.
  430. // - Ignore the transport parameter from TURN url for FF version <=27.
  431. // - Return null for createIceServer if transport=tcp.
  432. // - FF 27 and above supports transport parameters in TURN url,
  433. // - So passing in the full url to create iceServer.
  434. // Chrome:
  435. // - Creates iceServer from the url for Chrome M33 and earlier.
  436. // - Create iceServer with stun url.
  437. // - Chrome M28 & above uses below TURN format.
  438. // Plugin:
  439. // - Creates Ice Server for Plugin Browsers
  440. // - If Stun - Create iceServer with stun url.
  441. // - Else - Create iceServer with turn url
  442. // - This is a WebRTC Function
  443. createIceServer = null;
  444. // Firefox:
  445. // - Creates IceServers for Firefox
  446. // - Use .url for FireFox.
  447. // - Multiple Urls support
  448. // Chrome:
  449. // - Creates iceServers from the urls for Chrome M34 and above.
  450. // - .urls is supported since Chrome M34.
  451. // - Multiple Urls support
  452. // Plugin:
  453. // - Creates Ice Servers for Plugin Browsers
  454. // - Multiple Urls support
  455. // - This is a WebRTC Function
  456. createIceServers = null;
  457. //------------------------------------------------------------
  458. //The RTCPeerConnection object.
  459. RTCPeerConnection = null;
  460. // Creates RTCSessionDescription object for Plugin Browsers
  461. RTCSessionDescription = (typeof RTCSessionDescription === 'function') ?
  462. RTCSessionDescription : null;
  463. // Creates RTCIceCandidate object for Plugin Browsers
  464. RTCIceCandidate = (typeof RTCIceCandidate === 'function') ?
  465. RTCIceCandidate : null;
  466. // Get UserMedia (only difference is the prefix).
  467. // Code from Adam Barth.
  468. getUserMedia = null;
  469. // Attach a media stream to an element.
  470. attachMediaStream = null;
  471. // Re-attach a media stream to an element.
  472. reattachMediaStream = null;
  473. // Detected browser agent name. Types are:
  474. // - 'firefox': Firefox browser.
  475. // - 'chrome': Chrome browser.
  476. // - 'opera': Opera browser.
  477. // - 'safari': Safari browser.
  478. // - 'IE' - Internet Explorer browser.
  479. webrtcDetectedBrowser = null;
  480. // Detected browser version.
  481. webrtcDetectedVersion = null;
  482. // Check for browser types and react accordingly
  483. if (navigator.mozGetUserMedia) {
  484. webrtcDetectedBrowser = 'firefox';
  485. webrtcDetectedVersion = parseInt(navigator
  486. .userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
  487. webrtcDetectedType = 'moz';
  488. webrtcDetectedDCSupport = 'SCTP';
  489. RTCPeerConnection = function (pcConfig, pcConstraints) {
  490. AdapterJS.maybeFixConfiguration(pcConfig);
  491. return new mozRTCPeerConnection(pcConfig, pcConstraints);
  492. };
  493. // The RTCSessionDescription object.
  494. RTCSessionDescription = mozRTCSessionDescription;
  495. window.RTCSessionDescription = RTCSessionDescription;
  496. // The RTCIceCandidate object.
  497. RTCIceCandidate = mozRTCIceCandidate;
  498. window.RTCIceCandidate = RTCIceCandidate;
  499. window.getUserMedia = navigator.mozGetUserMedia.bind(navigator);
  500. navigator.getUserMedia = window.getUserMedia;
  501. // Shim for MediaStreamTrack.getSources.
  502. MediaStreamTrack.getSources = function(successCb) {
  503. setTimeout(function() {
  504. var infos = [
  505. { kind: 'audio', id: 'default', label:'', facing:'' },
  506. { kind: 'video', id: 'default', label:'', facing:'' }
  507. ];
  508. successCb(infos);
  509. }, 0);
  510. };
  511. createIceServer = function (url, username, password) {
  512. var iceServer = null;
  513. var url_parts = url.split(':');
  514. if (url_parts[0].indexOf('stun') === 0) {
  515. iceServer = { url : url };
  516. } else if (url_parts[0].indexOf('turn') === 0) {
  517. if (webrtcDetectedVersion < 27) {
  518. var turn_url_parts = url.split('?');
  519. if (turn_url_parts.length === 1 ||
  520. turn_url_parts[1].indexOf('transport=udp') === 0) {
  521. iceServer = {
  522. url : turn_url_parts[0],
  523. credential : password,
  524. username : username
  525. };
  526. }
  527. } else {
  528. iceServer = {
  529. url : url,
  530. credential : password,
  531. username : username
  532. };
  533. }
  534. }
  535. return iceServer;
  536. };
  537. createIceServers = function (urls, username, password) {
  538. var iceServers = [];
  539. for (i = 0; i < urls.length; i++) {
  540. var iceServer = createIceServer(urls[i], username, password);
  541. if (iceServer !== null) {
  542. iceServers.push(iceServer);
  543. }
  544. }
  545. return iceServers;
  546. };
  547. attachMediaStream = function (element, stream) {
  548. element.mozSrcObject = stream;
  549. if (stream !== null)
  550. element.play();
  551. return element;
  552. };
  553. reattachMediaStream = function (to, from) {
  554. to.mozSrcObject = from.mozSrcObject;
  555. to.play();
  556. return to;
  557. };
  558. MediaStreamTrack.getSources = MediaStreamTrack.getSources || function (callback) {
  559. if (!callback) {
  560. throw new TypeError('Failed to execute \'getSources\' on \'MediaStreamTrack\'' +
  561. ': 1 argument required, but only 0 present.');
  562. }
  563. return callback([]);
  564. };
  565. // Fake get{Video,Audio}Tracks
  566. if (!MediaStream.prototype.getVideoTracks) {
  567. MediaStream.prototype.getVideoTracks = function () {
  568. return [];
  569. };
  570. }
  571. if (!MediaStream.prototype.getAudioTracks) {
  572. MediaStream.prototype.getAudioTracks = function () {
  573. return [];
  574. };
  575. }
  576. AdapterJS.maybeThroughWebRTCReady();
  577. } else if (navigator.webkitGetUserMedia) {
  578. webrtcDetectedBrowser = 'chrome';
  579. webrtcDetectedType = 'webkit';
  580. webrtcDetectedVersion = parseInt(navigator
  581. .userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
  582. // check if browser is opera 20+
  583. var checkIfOpera = navigator.userAgent.match(/\bOPR\/(\d+)/);
  584. if (checkIfOpera !== null) {
  585. webrtcDetectedBrowser = 'opera';
  586. webrtcDetectedVersion = parseInt(checkIfOpera[1], 10);
  587. }
  588. // check browser datachannel support
  589. if ((webrtcDetectedBrowser === 'chrome' && webrtcDetectedVersion >= 31) ||
  590. (webrtcDetectedBrowser === 'opera' && webrtcDetectedVersion >= 20)) {
  591. webrtcDetectedDCSupport = 'SCTP';
  592. } else if (webrtcDetectedBrowser === 'chrome' && webrtcDetectedVersion < 30 &&
  593. webrtcDetectedVersion > 24) {
  594. webrtcDetectedDCSupport = 'RTP';
  595. } else {
  596. webrtcDetectedDCSupport = '';
  597. }
  598. createIceServer = function (url, username, password) {
  599. var iceServer = null;
  600. var url_parts = url.split(':');
  601. if (url_parts[0].indexOf('stun') === 0) {
  602. iceServer = { 'url' : url };
  603. } else if (url_parts[0].indexOf('turn') === 0) {
  604. iceServer = {
  605. 'url' : url,
  606. 'credential' : password,
  607. 'username' : username
  608. };
  609. }
  610. return iceServer;
  611. };
  612. createIceServers = function (urls, username, password) {
  613. var iceServers = [];
  614. if (webrtcDetectedVersion >= 34) {
  615. iceServers = {
  616. 'urls' : urls,
  617. 'credential' : password,
  618. 'username' : username
  619. };
  620. } else {
  621. for (i = 0; i < urls.length; i++) {
  622. var iceServer = createIceServer(urls[i], username, password);
  623. if (iceServer !== null) {
  624. iceServers.push(iceServer);
  625. }
  626. }
  627. }
  628. return iceServers;
  629. };
  630. RTCPeerConnection = function (pcConfig, pcConstraints) {
  631. if (webrtcDetectedVersion < 34) {
  632. AdapterJS.maybeFixConfiguration(pcConfig);
  633. }
  634. return new webkitRTCPeerConnection(pcConfig, pcConstraints);
  635. };
  636. window.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  637. navigator.getUserMedia = window.getUserMedia;
  638. attachMediaStream = function (element, stream) {
  639. if (typeof element.srcObject !== 'undefined') {
  640. element.srcObject = stream;
  641. } else if (typeof element.mozSrcObject !== 'undefined') {
  642. element.mozSrcObject = stream;
  643. } else if (typeof element.src !== 'undefined') {
  644. element.src = (stream === null ? '' : URL.createObjectURL(stream));
  645. } else {
  646. console.log('Error attaching stream to element.');
  647. }
  648. return element;
  649. };
  650. reattachMediaStream = function (to, from) {
  651. to.src = from.src;
  652. return to;
  653. };
  654. AdapterJS.maybeThroughWebRTCReady();
  655. } else if (navigator.mediaDevices && navigator.userAgent.match(
  656. /Edge\/(\d+).(\d+)$/)) {
  657. webrtcDetectedBrowser = 'edge';
  658. webrtcDetectedVersion =
  659. parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10);
  660. // the minimum version still supported by adapter.
  661. webrtcMinimumVersion = 12;
  662. getUserMedia = navigator.getUserMedia;
  663. attachMediaStream = function(element, stream) {
  664. element.srcObject = stream;
  665. return element;
  666. };
  667. reattachMediaStream = function(to, from) {
  668. to.srcObject = from.srcObject;
  669. return to;
  670. };
  671. AdapterJS.maybeThroughWebRTCReady();
  672. } else { // TRY TO USE PLUGIN
  673. // IE 9 is not offering an implementation of console.log until you open a console
  674. if (typeof console !== 'object' || typeof console.log !== 'function') {
  675. /* jshint -W020 */
  676. console = {} || console;
  677. // Implemented based on console specs from MDN
  678. // You may override these functions
  679. console.log = function (arg) {};
  680. console.info = function (arg) {};
  681. console.error = function (arg) {};
  682. console.dir = function (arg) {};
  683. console.exception = function (arg) {};
  684. console.trace = function (arg) {};
  685. console.warn = function (arg) {};
  686. console.count = function (arg) {};
  687. console.debug = function (arg) {};
  688. console.count = function (arg) {};
  689. console.time = function (arg) {};
  690. console.timeEnd = function (arg) {};
  691. console.group = function (arg) {};
  692. console.groupCollapsed = function (arg) {};
  693. console.groupEnd = function (arg) {};
  694. /* jshint +W020 */
  695. }
  696. webrtcDetectedType = 'plugin';
  697. webrtcDetectedDCSupport = 'plugin';
  698. AdapterJS.parseWebrtcDetectedBrowser();
  699. isIE = webrtcDetectedBrowser === 'IE';
  700. /* jshint -W035 */
  701. AdapterJS.WebRTCPlugin.WaitForPluginReady = function() {
  702. while (AdapterJS.WebRTCPlugin.pluginState !== AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  703. /* empty because it needs to prevent the function from running. */
  704. }
  705. };
  706. /* jshint +W035 */
  707. AdapterJS.WebRTCPlugin.callWhenPluginReady = function (callback) {
  708. if (AdapterJS.WebRTCPlugin.pluginState === AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  709. // Call immediately if possible
  710. // Once the plugin is set, the code will always take this path
  711. callback();
  712. } else {
  713. // otherwise start a 100ms interval
  714. var checkPluginReadyState = setInterval(function () {
  715. if (AdapterJS.WebRTCPlugin.pluginState === AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  716. clearInterval(checkPluginReadyState);
  717. callback();
  718. }
  719. }, 100);
  720. }
  721. };
  722. AdapterJS.WebRTCPlugin.setLogLevel = function(logLevel) {
  723. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  724. AdapterJS.WebRTCPlugin.plugin.setLogLevel(logLevel);
  725. });
  726. };
  727. AdapterJS.WebRTCPlugin.injectPlugin = function () {
  728. // only inject once the page is ready
  729. if (document.readyState !== 'complete') {
  730. return;
  731. }
  732. // Prevent multiple injections
  733. if (AdapterJS.WebRTCPlugin.pluginState !== AdapterJS.WebRTCPlugin.PLUGIN_STATES.INITIALIZING) {
  734. return;
  735. }
  736. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INJECTING;
  737. if (webrtcDetectedBrowser === 'IE' && webrtcDetectedVersion <= 10) {
  738. var frag = document.createDocumentFragment();
  739. AdapterJS.WebRTCPlugin.plugin = document.createElement('div');
  740. AdapterJS.WebRTCPlugin.plugin.innerHTML = '<object id="' +
  741. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" type="' +
  742. AdapterJS.WebRTCPlugin.pluginInfo.type + '" ' + 'width="1" height="1">' +
  743. '<param name="pluginId" value="' +
  744. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '" /> ' +
  745. '<param name="windowless" value="false" /> ' +
  746. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
  747. '<param name="onload" value="' + AdapterJS.WebRTCPlugin.pluginInfo.onload + '" />' +
  748. '<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />' +
  749. // uncomment to be able to use virtual cams
  750. (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
  751. '</object>';
  752. while (AdapterJS.WebRTCPlugin.plugin.firstChild) {
  753. frag.appendChild(AdapterJS.WebRTCPlugin.plugin.firstChild);
  754. }
  755. document.body.appendChild(frag);
  756. // Need to re-fetch the plugin
  757. AdapterJS.WebRTCPlugin.plugin =
  758. document.getElementById(AdapterJS.WebRTCPlugin.pluginInfo.pluginId);
  759. } else {
  760. // Load Plugin
  761. AdapterJS.WebRTCPlugin.plugin = document.createElement('object');
  762. AdapterJS.WebRTCPlugin.plugin.id =
  763. AdapterJS.WebRTCPlugin.pluginInfo.pluginId;
  764. // IE will only start the plugin if it's ACTUALLY visible
  765. if (isIE) {
  766. AdapterJS.WebRTCPlugin.plugin.width = '1px';
  767. AdapterJS.WebRTCPlugin.plugin.height = '1px';
  768. } else { // The size of the plugin on Safari should be 0x0px
  769. // so that the autorisation prompt is at the top
  770. AdapterJS.WebRTCPlugin.plugin.width = '0px';
  771. AdapterJS.WebRTCPlugin.plugin.height = '0px';
  772. }
  773. AdapterJS.WebRTCPlugin.plugin.type = AdapterJS.WebRTCPlugin.pluginInfo.type;
  774. AdapterJS.WebRTCPlugin.plugin.innerHTML = '<param name="onload" value="' +
  775. AdapterJS.WebRTCPlugin.pluginInfo.onload + '">' +
  776. '<param name="pluginId" value="' +
  777. AdapterJS.WebRTCPlugin.pluginInfo.pluginId + '">' +
  778. '<param name="windowless" value="false" /> ' +
  779. (AdapterJS.options.getAllCams ? '<param name="forceGetAllCams" value="True" />':'') +
  780. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '">' +
  781. '<param name="tag" value="' + AdapterJS.WebRTCPlugin.TAGS.NONE + '" />';
  782. document.body.appendChild(AdapterJS.WebRTCPlugin.plugin);
  783. }
  784. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INJECTED;
  785. };
  786. AdapterJS.WebRTCPlugin.isPluginInstalled =
  787. function (comName, plugName, installedCb, notInstalledCb) {
  788. if (!isIE) {
  789. var pluginArray = navigator.plugins;
  790. for (var i = 0; i < pluginArray.length; i++) {
  791. if (pluginArray[i].name.indexOf(plugName) >= 0) {
  792. installedCb();
  793. return;
  794. }
  795. }
  796. notInstalledCb();
  797. } else {
  798. try {
  799. var axo = new ActiveXObject(comName + '.' + plugName);
  800. } catch (e) {
  801. notInstalledCb();
  802. return;
  803. }
  804. installedCb();
  805. }
  806. };
  807. AdapterJS.WebRTCPlugin.defineWebRTCInterface = function () {
  808. if (AdapterJS.WebRTCPlugin.pluginState ===
  809. AdapterJS.WebRTCPlugin.PLUGIN_STATES.READY) {
  810. console.error("AdapterJS - WebRTC interface has already been defined");
  811. return;
  812. }
  813. AdapterJS.WebRTCPlugin.pluginState = AdapterJS.WebRTCPlugin.PLUGIN_STATES.INITIALIZING;
  814. AdapterJS.isDefined = function (variable) {
  815. return variable !== null && variable !== undefined;
  816. };
  817. createIceServer = function (url, username, password) {
  818. var iceServer = null;
  819. var url_parts = url.split(':');
  820. if (url_parts[0].indexOf('stun') === 0) {
  821. iceServer = {
  822. 'url' : url,
  823. 'hasCredentials' : false
  824. };
  825. } else if (url_parts[0].indexOf('turn') === 0) {
  826. iceServer = {
  827. 'url' : url,
  828. 'hasCredentials' : true,
  829. 'credential' : password,
  830. 'username' : username
  831. };
  832. }
  833. return iceServer;
  834. };
  835. createIceServers = function (urls, username, password) {
  836. var iceServers = [];
  837. for (var i = 0; i < urls.length; ++i) {
  838. iceServers.push(createIceServer(urls[i], username, password));
  839. }
  840. return iceServers;
  841. };
  842. RTCSessionDescription = function (info) {
  843. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  844. return AdapterJS.WebRTCPlugin.plugin.
  845. ConstructSessionDescription(info.type, info.sdp);
  846. };
  847. RTCPeerConnection = function (servers, constraints) {
  848. var iceServers = null;
  849. if (servers) {
  850. iceServers = servers.iceServers;
  851. for (var i = 0; i < iceServers.length; i++) {
  852. if (iceServers[i].urls && !iceServers[i].url) {
  853. iceServers[i].url = iceServers[i].urls;
  854. }
  855. iceServers[i].hasCredentials = AdapterJS.
  856. isDefined(iceServers[i].username) &&
  857. AdapterJS.isDefined(iceServers[i].credential);
  858. }
  859. }
  860. var mandatory = (constraints && constraints.mandatory) ?
  861. constraints.mandatory : null;
  862. var optional = (constraints && constraints.optional) ?
  863. constraints.optional : null;
  864. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  865. return AdapterJS.WebRTCPlugin.plugin.
  866. PeerConnection(AdapterJS.WebRTCPlugin.pageId,
  867. iceServers, mandatory, optional);
  868. };
  869. MediaStreamTrack = {};
  870. MediaStreamTrack.getSources = function (callback) {
  871. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  872. AdapterJS.WebRTCPlugin.plugin.GetSources(callback);
  873. });
  874. };
  875. window.getUserMedia = function (constraints, successCallback, failureCallback) {
  876. constraints.audio = constraints.audio || false;
  877. constraints.video = constraints.video || false;
  878. AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
  879. AdapterJS.WebRTCPlugin.plugin.
  880. getUserMedia(constraints, successCallback, failureCallback);
  881. });
  882. };
  883. window.navigator.getUserMedia = window.getUserMedia;
  884. attachMediaStream = function (element, stream) {
  885. if (!element || !element.parentNode) {
  886. return;
  887. }
  888. var streamId
  889. if (stream === null) {
  890. streamId = '';
  891. }
  892. else {
  893. stream.enableSoundTracks(true); // TODO: remove on 0.12.0
  894. streamId = stream.id;
  895. }
  896. var elementId = element.id.length === 0 ? Math.random().toString(36).slice(2) : element.id;
  897. var nodeName = element.nodeName.toLowerCase();
  898. if (nodeName !== 'object') { // not a plugin <object> tag yet
  899. var tag;
  900. switch(nodeName) {
  901. case 'audio':
  902. tag = AdapterJS.WebRTCPlugin.TAGS.AUDIO;
  903. break;
  904. case 'video':
  905. tag = AdapterJS.WebRTCPlugin.TAGS.VIDEO;
  906. break;
  907. default:
  908. tag = AdapterJS.WebRTCPlugin.TAGS.NONE;
  909. }
  910. var frag = document.createDocumentFragment();
  911. var temp = document.createElement('div');
  912. var classHTML = '';
  913. if (element.className) {
  914. classHTML = 'class="' + element.className + '" ';
  915. } else if (element.attributes && element.attributes['class']) {
  916. classHTML = 'class="' + element.attributes['class'].value + '" ';
  917. }
  918. temp.innerHTML = '<object id="' + elementId + '" ' + classHTML +
  919. 'type="' + AdapterJS.WebRTCPlugin.pluginInfo.type + '">' +
  920. '<param name="pluginId" value="' + elementId + '" /> ' +
  921. '<param name="pageId" value="' + AdapterJS.WebRTCPlugin.pageId + '" /> ' +
  922. '<param name="windowless" value="true" /> ' +
  923. '<param name="streamId" value="' + streamId + '" /> ' +
  924. '<param name="tag" value="' + tag + '" /> ' +
  925. '</object>';
  926. while (temp.firstChild) {
  927. frag.appendChild(temp.firstChild);
  928. }
  929. var height = '';
  930. var width = '';
  931. if (element.getBoundingClientRect) {
  932. var rectObject = element.getBoundingClientRect();
  933. width = rectObject.width + 'px';
  934. height = rectObject.height + 'px';
  935. }
  936. else if (element.width) {
  937. width = element.width;
  938. height = element.height;
  939. } else {
  940. // TODO: What scenario could bring us here?
  941. }
  942. element.parentNode.insertBefore(frag, element);
  943. frag = document.getElementById(elementId);
  944. frag.width = width;
  945. frag.height = height;
  946. element.parentNode.removeChild(element);
  947. } else { // already an <object> tag, just change the stream id
  948. var children = element.children;
  949. for (var i = 0; i !== children.length; ++i) {
  950. if (children[i].name === 'streamId') {
  951. children[i].value = streamId;
  952. break;
  953. }
  954. }
  955. element.setStreamId(streamId);
  956. }
  957. var newElement = document.getElementById(elementId);
  958. newElement.onplaying = (element.onplaying) ? element.onplaying : function (arg) {};
  959. newElement.onclick = (element.onclick) ? element.onclick : function (arg) {};
  960. if (isIE) { // on IE the event needs to be plugged manually
  961. newElement.attachEvent('onplaying', newElement.onplaying);
  962. newElement._TemOnClick = function (id) {
  963. var arg = {
  964. srcElement : document.getElementById(id)
  965. };
  966. newElement.onclick(arg);
  967. };
  968. }
  969. return newElement;
  970. };
  971. reattachMediaStream = function (to, from) {
  972. var stream = null;
  973. var children = from.children;
  974. for (var i = 0; i !== children.length; ++i) {
  975. if (children[i].name === 'streamId') {
  976. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  977. stream = AdapterJS.WebRTCPlugin.plugin
  978. .getStreamWithId(AdapterJS.WebRTCPlugin.pageId, children[i].value);
  979. break;
  980. }
  981. }
  982. if (stream !== null) {
  983. return attachMediaStream(to, stream);
  984. } else {
  985. console.log('Could not find the stream associated with this element');
  986. }
  987. };
  988. RTCIceCandidate = function (candidate) {
  989. if (!candidate.sdpMid) {
  990. candidate.sdpMid = '';
  991. }
  992. AdapterJS.WebRTCPlugin.WaitForPluginReady();
  993. return AdapterJS.WebRTCPlugin.plugin.ConstructIceCandidate(
  994. candidate.sdpMid, candidate.sdpMLineIndex, candidate.candidate
  995. );
  996. };
  997. // inject plugin
  998. AdapterJS.addEvent(document, 'readystatechange', AdapterJS.WebRTCPlugin.injectPlugin);
  999. AdapterJS.WebRTCPlugin.injectPlugin();
  1000. };
  1001. // This function will be called if the plugin is needed (browser different
  1002. // from Chrome or Firefox), but the plugin is not installed.
  1003. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb = AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb ||
  1004. function() {
  1005. AdapterJS.addEvent(document,
  1006. 'readystatechange',
  1007. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv);
  1008. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv();
  1009. };
  1010. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCbPriv = function () {
  1011. if (AdapterJS.options.hidePluginInstallPrompt) {
  1012. return;
  1013. }
  1014. var downloadLink = AdapterJS.WebRTCPlugin.pluginInfo.downloadLink;
  1015. if(downloadLink) { // if download link
  1016. var popupString;
  1017. if (AdapterJS.WebRTCPlugin.pluginInfo.portalLink) { // is portal link
  1018. popupString = 'This website requires you to install the ' +
  1019. ' <a href="' + AdapterJS.WebRTCPlugin.pluginInfo.portalLink +
  1020. '" target="_blank">' + AdapterJS.WebRTCPlugin.pluginInfo.companyName +
  1021. ' WebRTC Plugin</a>' +
  1022. ' to work on this browser.';
  1023. } else { // no portal link, just print a generic explanation
  1024. popupString = AdapterJS.TEXT.PLUGIN.REQUIRE_INSTALLATION;
  1025. }
  1026. AdapterJS.renderNotificationBar(popupString, AdapterJS.TEXT.PLUGIN.BUTTON, downloadLink);
  1027. } else { // no download link, just print a generic explanation
  1028. AdapterJS.renderNotificationBar(AdapterJS.TEXT.PLUGIN.NOT_SUPPORTED);
  1029. }
  1030. };
  1031. // Try to detect the plugin and act accordingly
  1032. AdapterJS.WebRTCPlugin.isPluginInstalled(
  1033. AdapterJS.WebRTCPlugin.pluginInfo.prefix,
  1034. AdapterJS.WebRTCPlugin.pluginInfo.plugName,
  1035. AdapterJS.WebRTCPlugin.defineWebRTCInterface,
  1036. AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb);
  1037. }