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.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import JitsiMeetJS from '../lib-jitsi-meet';
  2. import Platform from '../react/Platform';
  3. import { isMobileBrowser } from './utils';
  4. const { browser } = JitsiMeetJS.util;
  5. const DEFAULT_OPTIMAL_BROWSERS = [
  6. 'chrome',
  7. 'electron',
  8. 'firefox',
  9. 'nwjs',
  10. 'safari'
  11. ];
  12. const DEFAULT_UNSUPPORTED_BROWSERS: string[] = [];
  13. const browserNameToCheck = {
  14. chrome: browser.isChrome.bind(browser),
  15. chromium: browser.isChromiumBased.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. /**
  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 OS is Mac.
  35. *
  36. * @returns {boolean}
  37. */
  38. export function isMacOS() {
  39. return Platform.OS === 'macos';
  40. }
  41. /**
  42. * Returns whether or not the current OS is Windows.
  43. *
  44. * @returns {boolean}
  45. */
  46. export function isWindows() {
  47. return Platform.OS === 'windows';
  48. }
  49. /**
  50. * Returns whether or not the current browser or the list of passed in browsers
  51. * is considered suboptimal. Suboptimal means it is a supported browser but has
  52. * not been explicitly listed as being optimal, possibly due to functionality
  53. * issues.
  54. *
  55. * @param {Array<string>} [browsers] - A list of browser names to check. Will
  56. * default to a whitelist.
  57. * @returns {boolean}
  58. */
  59. export function isSuboptimalBrowser() {
  60. const optimalBrowsers
  61. = interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS;
  62. return !_isCurrentBrowserInList(optimalBrowsers) && isSupportedBrowser();
  63. }
  64. /**
  65. * Returns whether or not the current browser should allow the app to display.
  66. * A supported browser is assumed to be able to support WebRtc.
  67. *
  68. * @returns {boolean}
  69. */
  70. export function isSupportedBrowser() {
  71. if (navigator.product === 'ReactNative') {
  72. return false;
  73. }
  74. // Blacklists apply to desktop browsers only right now.
  75. if (!isMobileBrowser() && _isCurrentBrowserInList(
  76. interfaceConfig.UNSUPPORTED_BROWSERS || DEFAULT_UNSUPPORTED_BROWSERS
  77. )) {
  78. return false;
  79. }
  80. return isMobileBrowser() ? isSupportedMobileBrowser() : JitsiMeetJS.isWebRtcSupported();
  81. }
  82. /**
  83. * Returns whether or not the current environment is a supported
  84. * browser on a mobile device.
  85. *
  86. * @returns {boolean}
  87. */
  88. export function isSupportedMobileBrowser() {
  89. return (Platform.OS === 'android' && browser.isSupportedAndroidBrowser())
  90. || (Platform.OS === 'ios' && browser.isSupportedIOSBrowser());
  91. }
  92. /**
  93. * Runs various browser checks to know if the current browser is found within
  94. * the list.
  95. *
  96. * @param {Array<string>} list - Browser names to check. The names should be
  97. * keys in {@link browserNameToCheck}.
  98. * @private
  99. * @returns {boolean}
  100. */
  101. function _isCurrentBrowserInList(list: string[]) {
  102. return Boolean(list.find(browserName => {
  103. const checkFunction = browserNameToCheck[browserName as keyof typeof browserNameToCheck];
  104. return checkFunction ? checkFunction.call(browser) : false;
  105. }));
  106. }