您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* @flow */
  2. import { setConfigFromURLParams } from '../../base/config';
  3. import { loadScript } from '../../base/util';
  4. import JitsiMeetJS from './_';
  5. declare var APP: Object;
  6. const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
  7. /**
  8. * Creates a JitsiLocalTrack model from the given device id.
  9. *
  10. * @param {string} type - The media type of track being created. Expected values
  11. * are "video" or "audio".
  12. * @param {string} deviceId - The id of the target media source.
  13. * @returns {Promise<JitsiLocalTrack>}
  14. */
  15. export function createLocalTrack(type: string, deviceId: string) {
  16. return (
  17. JitsiMeetJS.createLocalTracks({
  18. cameraDeviceId: deviceId,
  19. devices: [ type ],
  20. // eslint-disable-next-line camelcase
  21. firefox_fake_device:
  22. window.config && window.config.firefox_fake_device,
  23. micDeviceId: deviceId
  24. })
  25. .then(([ jitsiLocalTrack ]) => jitsiLocalTrack));
  26. }
  27. /**
  28. * Determines whether a specific JitsiConnectionErrors instance indicates a
  29. * fatal JitsiConnection error.
  30. *
  31. * FIXME Figure out the category of errors defined by the fucntion and describe
  32. * that category. I've currently named the category fatal because it appears to
  33. * be used in the cases of unrecoverable errors that necessitate a reload.
  34. *
  35. * @param {Object|string} error - The JitsiConnectionErrors instance to
  36. * categorize/classify or an Error-like object.
  37. * @returns {boolean} True if the specified JitsiConnectionErrors instance
  38. * indicates a fatal JitsiConnection error; otherwise, false.
  39. */
  40. export function isFatalJitsiConnectionError(error: Object | string) {
  41. if (typeof error !== 'string') {
  42. error = error.name; // eslint-disable-line no-param-reassign
  43. }
  44. return (
  45. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  46. || error === JitsiConnectionErrors.OTHER_ERROR
  47. || error === JitsiConnectionErrors.SERVER_ERROR);
  48. }
  49. /**
  50. * Loads config.js from a specific remote server.
  51. *
  52. * @param {string} url - The URL to load.
  53. * @returns {Promise<Object>}
  54. */
  55. export function loadConfig(url: string) {
  56. let promise;
  57. if (typeof APP === 'undefined') {
  58. promise
  59. = loadScript(url)
  60. .then(() => {
  61. const { config } = window;
  62. // We don't want to pollute the global scope.
  63. window.config = undefined;
  64. if (typeof config !== 'object') {
  65. throw new Error('window.config is not an object');
  66. }
  67. return config;
  68. })
  69. .catch(err => {
  70. console.error(`Failed to load config from ${url}`, err);
  71. throw err;
  72. });
  73. } else {
  74. // Return "the config.js file" from the global scope - that is how the
  75. // Web app on both the client and the server was implemented before the
  76. // React Native app was even conceived.
  77. promise = Promise.resolve(window.config);
  78. }
  79. // FIXME It's neither here nor there at the time of this writing where
  80. // config, interfaceConfig, and loggingConfig should be overwritten by URL
  81. // params.
  82. promise = promise.then(value => {
  83. setConfigFromURLParams();
  84. return value;
  85. });
  86. return promise;
  87. }
  88. /**
  89. * Evaluates whether analytics is enabled or not based on
  90. * the redux {@code store}.
  91. *
  92. * @param {Store} store - The redux store in which the specified {@code action}
  93. * is being dispatched.
  94. * @returns {boolean} True if analytics is enabled, false otherwise.
  95. */
  96. export function isAnalyticsEnabled({ getState }: { getState: Function }) {
  97. const {
  98. analyticsScriptUrls,
  99. disableThirdPartyRequests
  100. } = getState()['features/base/config'];
  101. const scriptURLs = Array.isArray(analyticsScriptUrls)
  102. ? analyticsScriptUrls : [];
  103. return Boolean(scriptURLs.length) && !disableThirdPartyRequests;
  104. }