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

app.js 5.1KB

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