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.

functions.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 {string} error - The JitsiConnectionErrors instance to
  36. * categorize/classify.
  37. * @returns {boolean} True if the specified JitsiConnectionErrors instance
  38. * indicates a fatal JitsiConnection error; otherwise, false.
  39. */
  40. export function isFatalJitsiConnectionError(error: string) {
  41. return (
  42. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  43. || error === JitsiConnectionErrors.OTHER_ERROR
  44. || error === JitsiConnectionErrors.SERVER_ERROR);
  45. }
  46. /**
  47. * Loads config.js from a specific remote server.
  48. *
  49. * @param {string} url - The URL to load.
  50. * @returns {Promise<Object>}
  51. */
  52. export function loadConfig(url: string) {
  53. let promise;
  54. if (typeof APP === 'undefined') {
  55. promise
  56. = loadScript(url)
  57. .then(() => {
  58. const { config } = window;
  59. // We don't want to pollute the global scope.
  60. window.config = undefined;
  61. if (typeof config !== 'object') {
  62. throw new Error('window.config is not an object');
  63. }
  64. return config;
  65. })
  66. .catch(err => {
  67. console.error(`Failed to load config from ${url}`, err);
  68. throw err;
  69. });
  70. } else {
  71. // Return "the config.js file" from the global scope - that is how the
  72. // Web app on both the client and the server was implemented before the
  73. // React Native app was even conceived.
  74. promise = Promise.resolve(window.config);
  75. }
  76. // FIXME It's neither here nor there at the time of this writing where
  77. // config, interfaceConfig, and loggingConfig should be overwritten by URL
  78. // params.
  79. promise = promise.then(value => {
  80. setConfigFromURLParams();
  81. return value;
  82. });
  83. return promise;
  84. }
  85. /**
  86. * Evaluates whether analytics is enabled or not based on
  87. * the redux {@code store}.
  88. *
  89. * @param {Store} store - The redux store in which the specified {@code action}
  90. * is being dispatched.
  91. * @returns {boolean} True if analytics is enabled, false otherwise.
  92. */
  93. export function isAnalyticsEnabled({ getState }: { getState: Function }) {
  94. const {
  95. analyticsScriptUrls,
  96. disableThirdPartyRequests
  97. } = getState()['features/base/config'];
  98. const scriptURLs = Array.isArray(analyticsScriptUrls)
  99. ? analyticsScriptUrls : [];
  100. return Boolean(scriptURLs.length) && !disableThirdPartyRequests;
  101. }