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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 file from remote server.
  48. *
  49. * @param {string} host - Host where config.js is hosted.
  50. * @param {string} path='/config.js' - Relative pah to config.js file.
  51. * @returns {Promise<Object>}
  52. */
  53. export function loadConfig(host: string, path: string = '/config.js') {
  54. let promise;
  55. if (typeof APP === 'undefined') {
  56. promise
  57. = loadScript(new URL(path, host).toString())
  58. .then(() => {
  59. const { config } = window;
  60. // We don't want to pollute global scope.
  61. window.config = undefined;
  62. if (typeof config !== 'object') {
  63. throw new Error('window.config is not an object');
  64. }
  65. return config;
  66. })
  67. .catch(err => {
  68. console.error(`Failed to load ${path} from ${host}`, err);
  69. throw err;
  70. });
  71. } else {
  72. // Return config.js file from global scope. We can't use the version
  73. // that's being used for the React Native app because the old/current
  74. // Web app uses config from the global scope.
  75. promise = Promise.resolve(window.config);
  76. }
  77. // FIXME It's neither here nor there at the time of this writing where
  78. // config, interfaceConfig, and loggingConfig should be overwritten by URL
  79. // params.
  80. promise = promise.then(value => {
  81. setConfigFromURLParams();
  82. return value;
  83. });
  84. return promise;
  85. }