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.

ScreenObtainer.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /* global chrome, $, alert */
  2. import JitsiTrackError from '../../JitsiTrackError';
  3. import * as JitsiTrackErrors from '../../JitsiTrackErrors';
  4. import RTCBrowserType from './RTCBrowserType';
  5. const logger = require('jitsi-meet-logger').getLogger(__filename);
  6. const GlobalOnErrorHandler = require('../util/GlobalOnErrorHandler');
  7. /**
  8. * Indicates whether the Chrome desktop sharing extension is installed.
  9. * @type {boolean}
  10. */
  11. let chromeExtInstalled = false;
  12. /**
  13. * Indicates whether an update of the Chrome desktop sharing extension is
  14. * required.
  15. * @type {boolean}
  16. */
  17. let chromeExtUpdateRequired = false;
  18. /**
  19. * Whether the jidesha extension for firefox is installed for the domain on
  20. * which we are running. Null designates an unknown value.
  21. * @type {null}
  22. */
  23. let firefoxExtInstalled = null;
  24. /**
  25. * If set to true, detection of an installed firefox extension will be started
  26. * again the next time obtainScreenOnFirefox is called (e.g. next time the
  27. * user tries to enable screen sharing).
  28. */
  29. let reDetectFirefoxExtension = false;
  30. let gumFunction = null;
  31. /**
  32. * The error returned by chrome when trying to start inline installation from
  33. * popup.
  34. */
  35. const CHROME_EXTENSION_POPUP_ERROR
  36. = 'Inline installs can not be initiated from pop-up windows.';
  37. /**
  38. * The error returned by chrome when trying to start inline installation from
  39. * iframe.
  40. */
  41. const CHROME_EXTENSION_IFRAME_ERROR
  42. = 'Chrome Web Store installations can only be started by the top frame.';
  43. /**
  44. * The error message returned by chrome when the extension is installed.
  45. */
  46. const CHROME_NO_EXTENSION_ERROR_MSG // eslint-disable-line no-unused-vars
  47. = 'Could not establish connection. Receiving end does not exist.';
  48. /**
  49. * The error message returned by chrome when the extension install action needs
  50. * to be initiated by a user gesture.
  51. * @type {string}
  52. */
  53. const CHROME_USER_GESTURE_REQ_ERROR
  54. = 'Chrome Web Store installations can only be initated by a user gesture.';
  55. /**
  56. * Handles obtaining a stream from a screen capture on different browsers.
  57. */
  58. const ScreenObtainer = {
  59. obtainStream: null,
  60. /**
  61. * Initializes the function used to obtain a screen capture
  62. * (this.obtainStream).
  63. *
  64. * @param {object} options
  65. * @param {boolean} [options.disableDesktopSharing]
  66. * @param {boolean} [options.desktopSharingChromeDisabled]
  67. * @param {boolean} [options.desktopSharingChromeExtId]
  68. * @param {boolean} [options.desktopSharingFirefoxDisabled]
  69. * @param {boolean} [options.desktopSharingFirefoxExtId] (deprecated)
  70. * @param {Function} gum GUM method
  71. */
  72. init(options = {
  73. disableDesktopSharing: false,
  74. desktopSharingChromeDisabled: false,
  75. desktopSharingChromeExtId: null,
  76. desktopSharingFirefoxDisabled: false,
  77. desktopSharingFirefoxExtId: null
  78. }, gum) {
  79. // eslint-disable-next-line no-param-reassign
  80. this.options = options = options || {};
  81. gumFunction = gum;
  82. this.obtainStream
  83. = this.options.disableDesktopSharing
  84. ? null : this._createObtainStreamMethod(options);
  85. if (!this.obtainStream) {
  86. logger.info('Desktop sharing disabled');
  87. }
  88. },
  89. /**
  90. * Returns a method which will be used to obtain the screen sharing stream
  91. * (based on the browser type).
  92. *
  93. * @param {object} options passed from {@link init} - check description
  94. * there
  95. * @returns {Function}
  96. * @private
  97. */
  98. _createObtainStreamMethod(options) {
  99. if (RTCBrowserType.isNWJS()) {
  100. return (_, onSuccess, onFailure) => {
  101. window.JitsiMeetNW.obtainDesktopStream(
  102. onSuccess,
  103. (error, constraints) => {
  104. let jitsiError;
  105. // FIXME:
  106. // This is very very dirty fix for recognising that the
  107. // user have clicked the cancel button from the Desktop
  108. // sharing pick window. The proper solution would be to
  109. // detect this in the NWJS application by checking the
  110. // streamId === "". Even better solution would be to
  111. // stop calling GUM from the NWJS app and just pass the
  112. // streamId to lib-jitsi-meet. This way the desktop
  113. // sharing implementation for NWJS and chrome extension
  114. // will be the same and lib-jitsi-meet will be able to
  115. // control the constraints, check the streamId, etc.
  116. //
  117. // I cannot find documentation about "InvalidStateError"
  118. // but this is what we are receiving from GUM when the
  119. // streamId for the desktop sharing is "".
  120. if (error && error.name === 'InvalidStateError') {
  121. jitsiError = new JitsiTrackError(
  122. JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED
  123. );
  124. } else {
  125. jitsiError = new JitsiTrackError(
  126. error, constraints, [ 'desktop' ]);
  127. }
  128. (typeof onFailure === 'function')
  129. && onFailure(jitsiError);
  130. });
  131. };
  132. } else if (RTCBrowserType.isElectron()) {
  133. return this.obtainScreenOnElectron;
  134. } else if (RTCBrowserType.isTemasysPluginUsed()) {
  135. // XXX Don't require Temasys unless it's to be used because it
  136. // doesn't run on React Native, for example.
  137. const plugin
  138. = require('./adapter.screenshare').WebRTCPlugin.plugin;
  139. if (!plugin.HasScreensharingFeature) {
  140. logger.warn(
  141. 'Screensharing not supported by this plugin version');
  142. return null;
  143. } else if (!plugin.isScreensharingAvailable) {
  144. logger.warn(
  145. 'Screensharing not available with Temasys plugin on'
  146. + ' this site');
  147. return null;
  148. }
  149. logger.info('Using Temasys plugin for desktop sharing');
  150. return obtainWebRTCScreen;
  151. } else if (RTCBrowserType.isChrome()) {
  152. if (RTCBrowserType.getChromeVersion() < 34) {
  153. logger.info('Chrome extension not supported until ver 34');
  154. return null;
  155. } else if (options.desktopSharingChromeDisabled
  156. || options.desktopSharingChromeMethod === false
  157. || !options.desktopSharingChromeExtId) {
  158. // TODO: desktopSharingChromeMethod is deprecated, remove.
  159. return null;
  160. }
  161. logger.info('Using Chrome extension for desktop sharing');
  162. initChromeExtension(options);
  163. return this.obtainScreenFromExtension;
  164. } else if (RTCBrowserType.isFirefox()) {
  165. if (options.desktopSharingFirefoxDisabled) {
  166. return null;
  167. } else if (window.location.protocol === 'http:') {
  168. logger.log('Screen sharing is not supported over HTTP. '
  169. + 'Use of HTTPS is required.');
  170. return null;
  171. }
  172. initFirefoxExtensionDetection(options);
  173. return this.obtainScreenOnFirefox;
  174. }
  175. logger.warn(
  176. 'Screen sharing not supported by the current browser: ',
  177. RTCBrowserType.getBrowserType(),
  178. RTCBrowserType.getBrowserName());
  179. return null;
  180. },
  181. /**
  182. * Checks whether obtaining a screen capture is supported in the current
  183. * environment.
  184. * @returns {boolean}
  185. */
  186. isSupported() {
  187. return this.obtainStream !== null;
  188. },
  189. /**
  190. * Obtains a screen capture stream on Firefox.
  191. * @param callback
  192. * @param errorCallback
  193. */
  194. obtainScreenOnFirefox(options, callback, errorCallback) {
  195. let extensionRequired = false;
  196. const { desktopSharingFirefoxMaxVersionExtRequired } = this.options;
  197. if (desktopSharingFirefoxMaxVersionExtRequired === -1
  198. || (desktopSharingFirefoxMaxVersionExtRequired >= 0
  199. && RTCBrowserType.getFirefoxVersion()
  200. <= desktopSharingFirefoxMaxVersionExtRequired)) {
  201. extensionRequired = true;
  202. logger.log(
  203. `Jidesha extension required on firefox version ${
  204. RTCBrowserType.getFirefoxVersion()}`);
  205. }
  206. if (!extensionRequired || firefoxExtInstalled === true) {
  207. obtainWebRTCScreen(options, callback, errorCallback);
  208. return;
  209. }
  210. if (reDetectFirefoxExtension) {
  211. reDetectFirefoxExtension = false;
  212. initFirefoxExtensionDetection(this.options);
  213. }
  214. // Give it some (more) time to initialize, and assume lack of
  215. // extension if it hasn't.
  216. if (firefoxExtInstalled === null) {
  217. window.setTimeout(
  218. () => {
  219. if (firefoxExtInstalled === null) {
  220. firefoxExtInstalled = false;
  221. }
  222. this.obtainScreenOnFirefox(callback, errorCallback);
  223. },
  224. 300);
  225. logger.log(
  226. 'Waiting for detection of jidesha on firefox to finish.');
  227. return;
  228. }
  229. // We need an extension and it isn't installed.
  230. // Make sure we check for the extension when the user clicks again.
  231. firefoxExtInstalled = null;
  232. reDetectFirefoxExtension = true;
  233. // Make sure desktopsharing knows that we failed, so that it doesn't get
  234. // stuck in 'switching' mode.
  235. errorCallback(
  236. new JitsiTrackError(JitsiTrackErrors.FIREFOX_EXTENSION_NEEDED));
  237. },
  238. /**
  239. * Obtains a screen capture stream on Electron.
  240. *
  241. * @param {Object} [options] - Screen sharing options.
  242. * @param {Array<string>} [options.desktopSharingSources] - Array with the
  243. * sources that have to be displayed in the desktop picker window ('screen',
  244. * 'window', etc.).
  245. * @param onSuccess - Success callback.
  246. * @param onFailure - Failure callback.
  247. */
  248. obtainScreenOnElectron(options = {}, onSuccess, onFailure) {
  249. if (window.JitsiMeetScreenObtainer
  250. && window.JitsiMeetScreenObtainer.openDesktopPicker) {
  251. window.JitsiMeetScreenObtainer.openDesktopPicker(
  252. {
  253. desktopSharingSources:
  254. options.desktopSharingSources
  255. || this.options.desktopSharingChromeSources
  256. },
  257. (streamId, streamType) =>
  258. onGetStreamResponse(
  259. {
  260. streamId,
  261. streamType
  262. },
  263. onSuccess,
  264. onFailure
  265. ),
  266. err => onFailure(new JitsiTrackError(
  267. JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_ERROR,
  268. err
  269. ))
  270. );
  271. } else {
  272. onFailure(new JitsiTrackError(
  273. JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_NOT_FOUND));
  274. }
  275. },
  276. /**
  277. * Asks Chrome extension to call chooseDesktopMedia and gets chrome
  278. * 'desktop' stream for returned stream token.
  279. */
  280. obtainScreenFromExtension(options, streamCallback, failCallback) {
  281. const {
  282. desktopSharingChromeExtId,
  283. desktopSharingChromeSources
  284. } = this.options;
  285. const gumOptions = {
  286. desktopSharingChromeExtId,
  287. desktopSharingChromeSources:
  288. options.desktopSharingSources
  289. || desktopSharingChromeSources
  290. };
  291. if (chromeExtInstalled) {
  292. doGetStreamFromExtension(
  293. gumOptions,
  294. streamCallback,
  295. failCallback);
  296. } else {
  297. if (chromeExtUpdateRequired) {
  298. /* eslint-disable no-alert */
  299. alert(
  300. 'Jitsi Desktop Streamer requires update. '
  301. + 'Changes will take effect after next Chrome restart.');
  302. /* eslint-enable no-alert */
  303. }
  304. try {
  305. chrome.webstore.install(
  306. getWebStoreInstallUrl(this.options),
  307. arg => {
  308. logger.log('Extension installed successfully', arg);
  309. chromeExtInstalled = true;
  310. // We need to give a moment to the endpoint to become
  311. // available.
  312. waitForExtensionAfterInstall(this.options, 200, 10)
  313. .then(() => {
  314. doGetStreamFromExtension(
  315. gumOptions,
  316. streamCallback,
  317. failCallback);
  318. })
  319. .catch(() => {
  320. this.handleExtensionInstallationError(options,
  321. streamCallback, failCallback);
  322. });
  323. },
  324. this.handleExtensionInstallationError.bind(this,
  325. options, streamCallback, failCallback)
  326. );
  327. } catch (e) {
  328. this.handleExtensionInstallationError(options, streamCallback,
  329. failCallback, e);
  330. }
  331. }
  332. },
  333. /* eslint-disable max-params */
  334. handleExtensionInstallationError(options, streamCallback, failCallback, e) {
  335. const webStoreInstallUrl = getWebStoreInstallUrl(this.options);
  336. if ((CHROME_EXTENSION_POPUP_ERROR === e
  337. || CHROME_EXTENSION_IFRAME_ERROR === e)
  338. && options.interval > 0
  339. && typeof options.checkAgain === 'function'
  340. && typeof options.listener === 'function') {
  341. options.listener('waitingForExtension', webStoreInstallUrl);
  342. this.checkForChromeExtensionOnInterval(options, streamCallback,
  343. failCallback, e);
  344. return;
  345. }
  346. const msg
  347. = `Failed to install the extension from ${webStoreInstallUrl}`;
  348. logger.log(msg, e);
  349. const error
  350. = e === CHROME_USER_GESTURE_REQ_ERROR
  351. ? JitsiTrackErrors.CHROME_EXTENSION_USER_GESTURE_REQUIRED
  352. : JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR;
  353. failCallback(new JitsiTrackError(error, msg));
  354. },
  355. /* eslint-enable max-params */
  356. checkForChromeExtensionOnInterval(options, streamCallback, failCallback) {
  357. if (options.checkAgain() === false) {
  358. failCallback(new JitsiTrackError(
  359. JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR));
  360. return;
  361. }
  362. waitForExtensionAfterInstall(this.options, options.interval, 1)
  363. .then(() => {
  364. chromeExtInstalled = true;
  365. options.listener('extensionFound');
  366. this.obtainScreenFromExtension(options,
  367. streamCallback, failCallback);
  368. })
  369. .catch(() => {
  370. this.checkForChromeExtensionOnInterval(options,
  371. streamCallback, failCallback);
  372. });
  373. }
  374. };
  375. /**
  376. * Obtains a desktop stream using getUserMedia.
  377. * For this to work on Chrome, the
  378. * 'chrome://flags/#enable-usermedia-screen-capture' flag must be enabled.
  379. *
  380. * On firefox, the document's domain must be white-listed in the
  381. * 'media.getusermedia.screensharing.allowed_domains' preference in
  382. * 'about:config'.
  383. */
  384. function obtainWebRTCScreen(options, streamCallback, failCallback) {
  385. gumFunction(
  386. [ 'screen' ],
  387. stream => streamCallback({ stream }),
  388. failCallback
  389. );
  390. }
  391. /**
  392. * Constructs inline install URL for Chrome desktop streaming extension.
  393. * The 'chromeExtensionId' must be defined in options parameter.
  394. * @param options supports "desktopSharingChromeExtId"
  395. * @returns {string}
  396. */
  397. function getWebStoreInstallUrl(options) {
  398. return (
  399. `https://chrome.google.com/webstore/detail/${
  400. options.desktopSharingChromeExtId}`);
  401. }
  402. /**
  403. * Checks whether an update of the Chrome extension is required.
  404. * @param minVersion minimal required version
  405. * @param extVersion current extension version
  406. * @returns {boolean}
  407. */
  408. function isUpdateRequired(minVersion, extVersion) {
  409. try {
  410. const s1 = minVersion.split('.');
  411. const s2 = extVersion.split('.');
  412. const len = Math.max(s1.length, s2.length);
  413. for (let i = 0; i < len; i++) {
  414. let n1 = 0,
  415. n2 = 0;
  416. if (i < s1.length) {
  417. n1 = parseInt(s1[i], 10);
  418. }
  419. if (i < s2.length) {
  420. n2 = parseInt(s2[i], 10);
  421. }
  422. if (isNaN(n1) || isNaN(n2)) {
  423. return true;
  424. } else if (n1 !== n2) {
  425. return n1 > n2;
  426. }
  427. }
  428. // will happen if both versions have identical numbers in
  429. // their components (even if one of them is longer, has more components)
  430. return false;
  431. } catch (e) {
  432. GlobalOnErrorHandler.callErrorHandler(e);
  433. logger.error('Failed to parse extension version', e);
  434. return true;
  435. }
  436. }
  437. /**
  438. *
  439. * @param callback
  440. * @param options
  441. */
  442. function checkChromeExtInstalled(callback, options) {
  443. if (typeof chrome === 'undefined' || !chrome || !chrome.runtime) {
  444. // No API, so no extension for sure
  445. callback(false, false);
  446. return;
  447. }
  448. chrome.runtime.sendMessage(
  449. options.desktopSharingChromeExtId,
  450. { getVersion: true },
  451. response => {
  452. if (!response || !response.version) {
  453. // Communication failure - assume that no endpoint exists
  454. logger.warn(
  455. 'Extension not installed?: ', chrome.runtime.lastError);
  456. callback(false, false);
  457. return;
  458. }
  459. // Check installed extension version
  460. const extVersion = response.version;
  461. logger.log(`Extension version is: ${extVersion}`);
  462. const updateRequired
  463. = isUpdateRequired(
  464. options.desktopSharingChromeMinExtVersion,
  465. extVersion);
  466. callback(!updateRequired, updateRequired);
  467. }
  468. );
  469. }
  470. /**
  471. *
  472. * @param options
  473. * @param streamCallback
  474. * @param failCallback
  475. */
  476. function doGetStreamFromExtension(options, streamCallback, failCallback) {
  477. // Sends 'getStream' msg to the extension.
  478. // Extension id must be defined in the config.
  479. chrome.runtime.sendMessage(
  480. options.desktopSharingChromeExtId,
  481. {
  482. getStream: true,
  483. sources: options.desktopSharingChromeSources
  484. },
  485. response => {
  486. if (!response) {
  487. // possibly re-wraping error message to make code consistent
  488. const lastError = chrome.runtime.lastError;
  489. failCallback(lastError instanceof Error
  490. ? lastError
  491. : new JitsiTrackError(
  492. JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR,
  493. lastError));
  494. return;
  495. }
  496. logger.log('Response from extension: ', response);
  497. onGetStreamResponse(response, streamCallback, failCallback);
  498. }
  499. );
  500. }
  501. /**
  502. * Initializes <link rel=chrome-webstore-item /> with extension id set in
  503. * config.js to support inline installs. Host site must be selected as main
  504. * website of published extension.
  505. * @param options supports "desktopSharingChromeExtId"
  506. */
  507. function initInlineInstalls(options) {
  508. if ($('link[rel=chrome-webstore-item]').length === 0) {
  509. $('head').append('<link rel="chrome-webstore-item">');
  510. }
  511. $('link[rel=chrome-webstore-item]').attr('href',
  512. getWebStoreInstallUrl(options));
  513. }
  514. /**
  515. *
  516. * @param options
  517. */
  518. function initChromeExtension(options) {
  519. // Initialize Chrome extension inline installs
  520. initInlineInstalls(options);
  521. // Check if extension is installed
  522. checkChromeExtInstalled((installed, updateRequired) => {
  523. chromeExtInstalled = installed;
  524. chromeExtUpdateRequired = updateRequired;
  525. logger.info(
  526. `Chrome extension installed: ${chromeExtInstalled
  527. } updateRequired: ${chromeExtUpdateRequired}`);
  528. }, options);
  529. }
  530. /**
  531. * Checks "retries" times on every "waitInterval"ms whether the ext is alive.
  532. * @param {Object} options the options passed to ScreanObtainer.obtainStream
  533. * @param {int} waitInterval the number of ms between retries
  534. * @param {int} retries the number of retries
  535. * @returns {Promise} returns promise that will be resolved when the extension
  536. * is alive and rejected if the extension is not alive even after "retries"
  537. * checks
  538. */
  539. function waitForExtensionAfterInstall(options, waitInterval, retries) {
  540. if (retries === 0) {
  541. return Promise.reject();
  542. }
  543. return new Promise((resolve, reject) => {
  544. let currentRetries = retries;
  545. const interval = window.setInterval(() => {
  546. checkChromeExtInstalled(installed => {
  547. if (installed) {
  548. window.clearInterval(interval);
  549. resolve();
  550. } else {
  551. currentRetries--;
  552. if (currentRetries === 0) {
  553. reject();
  554. window.clearInterval(interval);
  555. }
  556. }
  557. }, options);
  558. }, waitInterval);
  559. });
  560. }
  561. /**
  562. * Handles response from external application / extension and calls GUM to
  563. * receive the desktop streams or reports error.
  564. * @param {object} response
  565. * @param {string} response.streamId - the streamId for the desktop stream
  566. * @param {string} response.error - error to be reported.
  567. * @param {Function} onSuccess - callback for success.
  568. * @param {Function} onFailure - callback for failure.
  569. */
  570. function onGetStreamResponse(
  571. { streamId, streamType, error },
  572. onSuccess,
  573. onFailure) {
  574. if (streamId) {
  575. gumFunction(
  576. [ 'desktop' ],
  577. stream => onSuccess({
  578. stream,
  579. sourceId: streamId,
  580. sourceType: streamType
  581. }),
  582. onFailure,
  583. { desktopStream: streamId });
  584. } else {
  585. // As noted in Chrome Desktop Capture API:
  586. // If user didn't select any source (i.e. canceled the prompt)
  587. // then the callback is called with an empty streamId.
  588. if (streamId === '') {
  589. onFailure(new JitsiTrackError(
  590. JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED));
  591. return;
  592. }
  593. onFailure(new JitsiTrackError(
  594. JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR,
  595. error));
  596. }
  597. }
  598. /**
  599. * Starts the detection of an installed jidesha extension for firefox.
  600. * @param options supports "desktopSharingFirefoxDisabled",
  601. * "desktopSharingFirefoxExtId"
  602. */
  603. function initFirefoxExtensionDetection(options) {
  604. if (options.desktopSharingFirefoxDisabled) {
  605. return;
  606. }
  607. if (firefoxExtInstalled === false || firefoxExtInstalled === true) {
  608. return;
  609. }
  610. if (!options.desktopSharingFirefoxExtId) {
  611. firefoxExtInstalled = false;
  612. return;
  613. }
  614. const img = document.createElement('img');
  615. img.onload = () => {
  616. logger.log('Detected firefox screen sharing extension.');
  617. firefoxExtInstalled = true;
  618. };
  619. img.onerror = () => {
  620. logger.log('Detected lack of firefox screen sharing extension.');
  621. firefoxExtInstalled = false;
  622. };
  623. // The jidesha extension exposes an empty image file under the url:
  624. // "chrome://EXT_ID/content/DOMAIN.png"
  625. // Where EXT_ID is the ID of the extension with "@" replaced by ".", and
  626. // DOMAIN is a domain whitelisted by the extension.
  627. const src
  628. = `chrome://${options.desktopSharingFirefoxExtId.replace('@', '.')
  629. }/content/${document.location.hostname}.png`;
  630. img.setAttribute('src', src);
  631. }
  632. export default ScreenObtainer;