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.

route.js 3.5KB

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