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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* global APP, config */
  2. import HttpConfigFetch from '../../../modules/config/HttpConfigFetch';
  3. import ConferenceUrl from '../../../modules/URL/ConferenceUrl';
  4. import BoshAddressChoice from '../../../modules/config/BoshAddressChoice';
  5. const logger = require('jitsi-meet-logger').getLogger(__filename);
  6. /**
  7. * If we have an HTTP endpoint for getting config.json configured
  8. * we're going to read it and override properties from config.js and
  9. * interfaceConfig.js. If there is no endpoint we'll just
  10. * continue with initialization.
  11. * Keep in mind that if the endpoint has been configured and we fail
  12. * to obtain the config for any reason then the conference won't
  13. * start and error message will be displayed to the user.
  14. *
  15. * @returns {Function}
  16. */
  17. export function obtainConfigAndInit() {
  18. // Skip initialization if conference is already initialized
  19. if (!APP.ConferenceUrl) {
  20. const room = APP.conference.roomName;
  21. if (config.configLocation) {
  22. const location = config.configLocation;
  23. obtainConfig(location, room)
  24. .then(_obtainConfigHandler)
  25. .then(_initConference)
  26. .catch(err => {
  27. // Show obtain config error,
  28. // pass the error object for report
  29. APP.UI.messageHandler.openReportDialog(
  30. null, 'dialog.connectError', err);
  31. });
  32. } else {
  33. BoshAddressChoice.chooseAddress(config, room);
  34. _initConference();
  35. }
  36. }
  37. }
  38. /**
  39. * Obtain config handler.
  40. *
  41. * @returns {Promise}
  42. * @private
  43. */
  44. function _obtainConfigHandler() {
  45. const now = window.performance.now();
  46. APP.connectionTimes['configuration.fetched'] = now;
  47. logger.log('(TIME) configuration fetched:\t', now);
  48. return Promise.resolve();
  49. }
  50. /**
  51. * Initialization of the app.
  52. *
  53. * @returns {void}
  54. * @private
  55. */
  56. function _initConference() {
  57. setTokenData();
  58. // Initialize the conference URL handler
  59. APP.ConferenceUrl = new ConferenceUrl(window.location);
  60. }
  61. /**
  62. * Promise wrapper on obtain config method.
  63. * When HttpConfigFetch will be moved to React app
  64. * it's better to use load config instead.
  65. *
  66. * @param {string} location - URL of the domain.
  67. * @param {string} room - Room name.
  68. * @returns {Promise}
  69. */
  70. export function obtainConfig(location, room) {
  71. return new Promise((resolve, reject) => {
  72. HttpConfigFetch.obtainConfig(location, room, (success, error) => {
  73. if (success) {
  74. resolve();
  75. } else {
  76. reject(error);
  77. }
  78. });
  79. });
  80. }
  81. /**
  82. * If JWT token data it will be used for local user settings.
  83. *
  84. * @returns {void}
  85. */
  86. export function setTokenData() {
  87. const localUser = APP.tokenData.caller;
  88. if (localUser) {
  89. const email = localUser.getEmail();
  90. const avatarUrl = localUser.getAvatarUrl();
  91. const name = localUser.getName();
  92. APP.settings.setEmail((email || '').trim(), true);
  93. APP.settings.setAvatarUrl((avatarUrl || '').trim());
  94. APP.settings.setDisplayName((name || '').trim(), true);
  95. }
  96. }