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.

environment.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // @flow
  2. import JitsiMeetJS from '../lib-jitsi-meet';
  3. import { isMobileBrowser } from './utils';
  4. const { browser } = JitsiMeetJS.util;
  5. const DEFAULT_OPTIMAL_BROWSERS = [
  6. 'chrome',
  7. 'electron',
  8. 'firefox',
  9. 'nwjs'
  10. ];
  11. const DEFAULT_UNSUPPORTED_BROWSERS = [];
  12. const browserNameToCheck = {
  13. chrome: browser.isChrome.bind(browser),
  14. chromium: browser.isChromiumBased.bind(browser),
  15. electron: browser.isElectron.bind(browser),
  16. firefox: browser.isFirefox.bind(browser),
  17. nwjs: browser.isNWJS.bind(browser),
  18. opera: browser.isOpera.bind(browser),
  19. safari: browser.isSafari.bind(browser)
  20. };
  21. declare var interfaceConfig: Object;
  22. /**
  23. * Returns whether or not jitsi is optimized and targeted for the provided
  24. * browser name.
  25. *
  26. * @param {string} browserName - The name of the browser to check.
  27. * @returns {boolean}
  28. */
  29. export function isBrowsersOptimal(browserName: string) {
  30. return (interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS)
  31. .includes(browserName);
  32. }
  33. /**
  34. * Returns whether or not the current browser or the list of passed in browsers
  35. * is considered suboptimal. Suboptimal means it is a supported browser but has
  36. * not been explicitly listed as being optimal, possibly due to functionality
  37. * issues.
  38. *
  39. * @param {Array<string>} [browsers] - A list of browser names to check. Will
  40. * default to a whitelist.
  41. * @returns {boolean}
  42. */
  43. export function isSuboptimalBrowser() {
  44. const optimalBrowsers
  45. = interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS;
  46. return !_isCurrentBrowserInList(optimalBrowsers) && isSupportedBrowser();
  47. }
  48. /**
  49. * Returns whether or not the current browser should allow the app to display.
  50. * A supported browser is assumed to be able to support WebRtc.
  51. *
  52. * @returns {boolean}
  53. */
  54. export function isSupportedBrowser() {
  55. if (navigator.product === 'ReactNative') {
  56. return false;
  57. }
  58. // Blacklists apply to desktop browsers only right now.
  59. if (!isMobileBrowser() && _isCurrentBrowserInList(
  60. interfaceConfig.UNSUPPORTED_BROWSERS || DEFAULT_UNSUPPORTED_BROWSERS
  61. )) {
  62. return false;
  63. }
  64. // We are intentionally allow mobile browsers because:
  65. // - the WelcomePage is mobile ready;
  66. // - if the URL points to a conference then deep-linking will take
  67. // care of it.
  68. return isMobileBrowser() || JitsiMeetJS.isWebRtcSupported();
  69. }
  70. /**
  71. * Runs various browser checks to know if the current browser is found within
  72. * the list.
  73. *
  74. * @param {Array<string>} list - Browser names to check. The names should be
  75. * keys in {@link browserNameToCheck}.
  76. * @private
  77. * @returns {boolean}
  78. */
  79. function _isCurrentBrowserInList(list) {
  80. return Boolean(list.find(browserName => {
  81. const checkFunction = browserNameToCheck[browserName];
  82. return checkFunction ? checkFunction.call(browser) : false;
  83. }));
  84. }