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

app.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* global $, config, getRoomName */
  2. /* application specific logic */
  3. import "babel-polyfill";
  4. import "jquery";
  5. import "jquery-contextmenu";
  6. import "jquery-ui";
  7. import "strophe";
  8. import "strophe-disco";
  9. import "strophe-caps";
  10. import "jQuery-Impromptu";
  11. import "autosize";
  12. import 'aui';
  13. import 'aui-experimental';
  14. import 'aui-css';
  15. import 'aui-experimental-css';
  16. window.toastr = require("toastr");
  17. import URLProcessor from "./modules/config/URLProcessor";
  18. import RoomnameGenerator from './modules/util/RoomnameGenerator';
  19. import UI from "./modules/UI/UI";
  20. import settings from "./modules/settings/Settings";
  21. import conference from './conference';
  22. import API from './modules/API/API';
  23. import UIEvents from './service/UI/UIEvents';
  24. import getTokenData from "./modules/TokenData/TokenData";
  25. /**
  26. * Tries to push history state with the following parameters:
  27. * 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
  28. * it.
  29. */
  30. function pushHistoryState(roomName, URL) {
  31. try {
  32. window.history.pushState(
  33. 'VideoChat', `Room: ${roomName}`, URL
  34. );
  35. } catch (e) {
  36. console.warn("Push history state failed with parameters:",
  37. 'VideoChat', `Room: ${roomName}`, URL, e);
  38. return e;
  39. }
  40. return null;
  41. }
  42. /**
  43. * Builds and returns the room name.
  44. */
  45. function buildRoomName () {
  46. let roomName = getRoomName();
  47. if(!roomName) {
  48. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  49. roomName = word.toLowerCase();
  50. let historyURL = window.location.href + word;
  51. //Trying to push state with current URL + roomName
  52. pushHistoryState(word, historyURL);
  53. }
  54. return roomName;
  55. }
  56. const APP = {
  57. // Used by do_external_connect.js if we receive the attach data after
  58. // connect was already executed. status property can be "initialized",
  59. // "ready" or "connecting". We are interested in "ready" status only which
  60. // means that connect was executed but we have to wait for the attach data.
  61. // In status "ready" handler property will be set to a function that will
  62. // finish the connect process when the attach data or error is received.
  63. connect: {
  64. status: "initialized",
  65. handler: null
  66. },
  67. // Used for automated performance tests
  68. connectionTimes: {
  69. "index.loaded": window.indexLoadedTime
  70. },
  71. UI,
  72. settings,
  73. conference,
  74. connection: null,
  75. API,
  76. init () {
  77. this.keyboardshortcut =
  78. require("./modules/keyboardshortcut/keyboardshortcut");
  79. this.translation = require("./modules/translation/translation");
  80. this.configFetch = require("./modules/config/HttpConfigFetch");
  81. this.tokenData = getTokenData();
  82. }
  83. };
  84. /**
  85. * If JWT token data it will be used for local user settings
  86. */
  87. function setTokenData() {
  88. let localUser = APP.tokenData.caller;
  89. if(localUser) {
  90. APP.settings.setEmail((localUser.getEmail() || "").trim(), true);
  91. APP.settings.setAvatarUrl((localUser.getAvatarUrl() || "").trim());
  92. APP.settings.setDisplayName((localUser.getName() || "").trim(), true);
  93. }
  94. }
  95. function init() {
  96. setTokenData();
  97. var isUIReady = APP.UI.start();
  98. if (isUIReady) {
  99. APP.conference.init({roomName: buildRoomName()}).then(function () {
  100. APP.UI.initConference();
  101. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  102. APP.translation.setLanguage(language);
  103. APP.settings.setLanguage(language);
  104. });
  105. APP.keyboardshortcut.init();
  106. }).catch(function (err) {
  107. APP.UI.hideRingOverLay();
  108. APP.API.notifyConferenceLeft(APP.conference.roomName);
  109. console.error(err);
  110. });
  111. }
  112. }
  113. /**
  114. * If we have an HTTP endpoint for getting config.json configured we're going to
  115. * read it and override properties from config.js and interfaceConfig.js.
  116. * If there is no endpoint we'll just continue with initialization.
  117. * Keep in mind that if the endpoint has been configured and we fail to obtain
  118. * the config for any reason then the conference won't start and error message
  119. * will be displayed to the user.
  120. */
  121. function obtainConfigAndInit() {
  122. let roomName = APP.conference.roomName;
  123. if (config.configLocation) {
  124. APP.configFetch.obtainConfig(
  125. config.configLocation, roomName,
  126. // Get config result callback
  127. function(success, error) {
  128. if (success) {
  129. var now = APP.connectionTimes["configuration.fetched"] =
  130. window.performance.now();
  131. console.log("(TIME) configuration fetched:\t", now);
  132. init();
  133. } else {
  134. // Show obtain config error,
  135. // pass the error object for report
  136. APP.UI.messageHandler.openReportDialog(
  137. null, "dialog.connectError", error);
  138. }
  139. });
  140. } else {
  141. require("./modules/config/BoshAddressChoice").chooseAddress(
  142. config, roomName);
  143. init();
  144. }
  145. }
  146. $(document).ready(function () {
  147. var now = APP.connectionTimes["document.ready"] = window.performance.now();
  148. console.log("(TIME) document ready:\t", now);
  149. URLProcessor.setConfigParametersFromUrl();
  150. APP.init();
  151. APP.translation.init(settings.getLanguage());
  152. APP.API.init(APP.tokenData.externalAPISettings);
  153. obtainConfigAndInit();
  154. });
  155. $(window).bind('beforeunload', function () {
  156. APP.API.dispose();
  157. });
  158. module.exports = APP;