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

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