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

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