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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 OS is Mac.
  37. *
  38. * @returns {boolean}
  39. */
  40. export function isMacOS() {
  41. return Platform.OS === 'macos';
  42. }
  43. /**
  44. * Returns whether or not the current browser or the list of passed in browsers
  45. * is considered suboptimal. Suboptimal means it is a supported browser but has
  46. * not been explicitly listed as being optimal, possibly due to functionality
  47. * issues.
  48. *
  49. * @param {Array<string>} [browsers] - A list of browser names to check. Will
  50. * default to a whitelist.
  51. * @returns {boolean}
  52. */
  53. export function isSuboptimalBrowser() {
  54. const optimalBrowsers
  55. = interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS;
  56. return !_isCurrentBrowserInList(optimalBrowsers) && isSupportedBrowser();
  57. }
  58. /**
  59. * Returns whether or not the current browser should allow the app to display.
  60. * A supported browser is assumed to be able to support WebRtc.
  61. *
  62. * @returns {boolean}
  63. */
  64. export function isSupportedBrowser() {
  65. if (navigator.product === 'ReactNative') {
  66. return false;
  67. }
  68. // Blacklists apply to desktop browsers only right now.
  69. if (!isMobileBrowser() && _isCurrentBrowserInList(
  70. interfaceConfig.UNSUPPORTED_BROWSERS || DEFAULT_UNSUPPORTED_BROWSERS
  71. )) {
  72. return false;
  73. }
  74. // We are intentionally allow mobile browsers because:
  75. // - the WelcomePage is mobile ready;
  76. // - if the URL points to a conference then deep-linking will take
  77. // care of it.
  78. return isMobileBrowser() || JitsiMeetJS.isWebRtcSupported();
  79. }
  80. /**
  81. * Returns whether or not the current environment is a supported
  82. * browser on a mobile device.
  83. *
  84. * @returns {boolean}
  85. */
  86. export function isSupportedMobileBrowser() {
  87. return (Platform.OS === 'android' && browser.isChromiumBased())
  88. || (Platform.OS === 'android' && browser.isFirefox())
  89. || (Platform.OS === 'ios' && browser.isWebKitBased());
  90. }
  91. /**
  92. * Runs various browser checks to know if the current browser is found within
  93. * the list.
  94. *
  95. * @param {Array<string>} list - Browser names to check. The names should be
  96. * keys in {@link browserNameToCheck}.
  97. * @private
  98. * @returns {boolean}
  99. */
  100. function _isCurrentBrowserInList(list) {
  101. return Boolean(list.find(browserName => {
  102. const checkFunction = browserNameToCheck[browserName];
  103. return checkFunction ? checkFunction.call(browser) : false;
  104. }));
  105. }