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.

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