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

route.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/react';
  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 from which the config is to be
  36. * obtained.
  37. * @param {string} room - Room name.
  38. * @private
  39. * @returns {Promise}
  40. */
  41. function _obtainConfig(location, room) {
  42. return new Promise((resolve, reject) => {
  43. HttpConfigFetch.obtainConfig(location, room, (success, error) => {
  44. if (success) {
  45. resolve();
  46. } else {
  47. reject(error);
  48. }
  49. });
  50. });
  51. }
  52. /**
  53. * If we have an HTTP endpoint for getting config.json configured we're going to
  54. * read it and override properties from config.js and interfaceConfig.js. If
  55. * there is no endpoint we'll just continue with initialization. Keep in mind
  56. * that if the endpoint has been configured and we fail to obtain the config for
  57. * any reason then the conference won't start and error message will be
  58. * displayed to the user.
  59. *
  60. * @private
  61. * @returns {void}
  62. */
  63. function _obtainConfigAndInit() {
  64. // Skip initialization if conference is initialized already.
  65. if (typeof APP !== 'undefined' && !APP.ConferenceUrl) {
  66. const location = config.configLocation;
  67. const room = APP.conference.roomName;
  68. if (location) {
  69. _obtainConfig(location, room)
  70. .then(() => {
  71. _obtainConfigHandler();
  72. _initConference();
  73. })
  74. .catch(err => {
  75. // Show obtain config error.
  76. APP.UI.messageHandler.openReportDialog(
  77. null, 'dialog.connectError', err);
  78. });
  79. } else {
  80. BoshAddressChoice.chooseAddress(config, room);
  81. _initConference();
  82. }
  83. }
  84. }
  85. /**
  86. * Obtain config handler.
  87. *
  88. * @private
  89. * @returns {Promise}
  90. */
  91. function _obtainConfigHandler() {
  92. const now = window.performance.now();
  93. APP.connectionTimes['configuration.fetched'] = now;
  94. logger.log('(TIME) configuration fetched:\t', now);
  95. }
  96. /**
  97. * If JWT token data it will be used for local user settings.
  98. *
  99. * @private
  100. * @returns {void}
  101. */
  102. function _setTokenData() {
  103. const localUser = APP.tokenData.caller;
  104. if (localUser) {
  105. const email = localUser.getEmail();
  106. const avatarUrl = localUser.getAvatarUrl();
  107. const name = localUser.getName();
  108. APP.settings.setEmail((email || '').trim(), true);
  109. APP.settings.setAvatarUrl((avatarUrl || '').trim());
  110. APP.settings.setDisplayName((name || '').trim(), true);
  111. }
  112. }