您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

route.js 3.3KB

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