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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { loadScript } from '../../base/util';
  2. import {
  3. setConfigParametersFromUrl
  4. } from '../../../../modules/config/URLProcessor';
  5. import JitsiMeetJS from './_';
  6. declare var APP: Object;
  7. const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
  8. /**
  9. * Determines whether a specific JitsiConnectionErrors instance indicates a
  10. * fatal JitsiConnection error.
  11. *
  12. * FIXME Figure out the category of errors defined by the fucntion and describe
  13. * that category. I've currently named the category fatal because it appears to
  14. * be used in the cases of unrecoverable errors that necessitate a reload.
  15. *
  16. * @param {string} error - The JitsiConnectionErrors instance to
  17. * categorize/classify.
  18. * @returns {boolean} True if the specified JitsiConnectionErrors instance
  19. * indicates a fatal JitsiConnection error; otherwise, false.
  20. */
  21. export function isFatalJitsiConnectionError(error: string) {
  22. return (
  23. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  24. || error === JitsiConnectionErrors.OTHER_ERROR
  25. || error === JitsiConnectionErrors.SERVER_ERROR);
  26. }
  27. /**
  28. * Loads config.js file from remote server.
  29. *
  30. * @param {string} host - Host where config.js is hosted.
  31. * @param {string} path='/config.js' - Relative pah to config.js file.
  32. * @returns {Promise<Object>}
  33. */
  34. export function loadConfig(host: string, path: string = '/config.js') {
  35. // Returns config.js file from global scope. We can't use the version that's
  36. // being used for the React Native app because the old/current Web app uses
  37. // config from the global scope.
  38. if (typeof APP !== 'undefined') {
  39. // FIXME The following call to setConfigParametersFromUrl is bad design
  40. // but URLProcessor still deals with the global variables config,
  41. // interfaceConfig, and loggingConfig and loadConfig. As the latter will
  42. // surely change in the future, so will the former then.
  43. setConfigParametersFromUrl();
  44. return Promise.resolve(window.config);
  45. }
  46. return loadScript(new URL(path, host).toString())
  47. .then(() => {
  48. const config = window.config;
  49. // We don't want to pollute global scope.
  50. window.config = undefined;
  51. if (typeof config !== 'object') {
  52. throw new Error('window.config is not an object');
  53. }
  54. return config;
  55. })
  56. .catch(err => {
  57. console.error(`Failed to load ${path} from ${host}`, err);
  58. throw err;
  59. });
  60. }
  61. /**
  62. * Creates a JitsiLocalTrack model from the given device id.
  63. *
  64. * @param {string} type - The media type of track being created. Expected values
  65. * are "video" or "audio".
  66. * @param {string} deviceId - The id of the target media source.
  67. * @returns {Promise<JitsiLocalTrack>}
  68. */
  69. export function createLocalTrack(type, deviceId) {
  70. return JitsiMeetJS.createLocalTracks({
  71. cameraDeviceId: deviceId,
  72. devices: [ type ],
  73. // eslint-disable-next-line camelcase
  74. firefox_fake_device:
  75. window.config && window.config.firefox_fake_device,
  76. micDeviceId: deviceId
  77. })
  78. .then(([ jitsiLocalTrack ]) => jitsiLocalTrack);
  79. }