Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

environment.ts 3.4KB

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