Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

environment.js 3.5KB

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