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.

functions.js 3.1KB

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