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 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { loadScript } from '../../base/util';
  2. import JitsiMeetJS from './_';
  3. declare var APP: Object;
  4. const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
  5. /**
  6. * Determines whether a specific JitsiConnectionErrors instance indicates a
  7. * fatal JitsiConnection error.
  8. *
  9. * FIXME Figure out the category of errors defined by the fucntion and describe
  10. * that category. I've currently named the category fatal because it appears to
  11. * be used in the cases of unrecoverable errors that necessitate a reload.
  12. *
  13. * @param {string} error - The JitsiConnectionErrors instance to
  14. * categorize/classify.
  15. * @returns {boolean} True if the specified JitsiConnectionErrors instance
  16. * indicates a fatal JitsiConnection error; otherwise, false.
  17. */
  18. export function isFatalJitsiConnectionError(error: string) {
  19. return (
  20. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  21. || error === JitsiConnectionErrors.OTHER_ERROR
  22. || error === JitsiConnectionErrors.SERVER_ERROR);
  23. }
  24. /**
  25. * Loads config.js file from remote server.
  26. *
  27. * @param {string} host - Host where config.js is hosted.
  28. * @param {string} path='/config.js' - Relative pah to config.js file.
  29. * @returns {Promise<Object>}
  30. */
  31. export function loadConfig(host: string, path: string = '/config.js') {
  32. // Returns config.js file from global scope. We can't use the version that's
  33. // being used for the React Native app because the old/current Web app uses
  34. // config from the global scope.
  35. if (typeof APP !== 'undefined') {
  36. return Promise.resolve(window.config);
  37. }
  38. return loadScript(new URL(path, host).toString())
  39. .then(() => {
  40. const config = window.config;
  41. // We don't want to pollute global scope.
  42. window.config = undefined;
  43. if (typeof config !== 'object') {
  44. throw new Error('window.config is not an object');
  45. }
  46. return config;
  47. })
  48. .catch(err => {
  49. console.error(`Failed to load ${path} from ${host}`, err);
  50. throw err;
  51. });
  52. }