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

app.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* global $, config, getRoomName, loggingConfig, JitsiMeetJS */
  2. /* application specific logic */
  3. const logger = require("jitsi-meet-logger").getLogger(__filename);
  4. import "babel-polyfill";
  5. import "jquery";
  6. import "jquery-contextmenu";
  7. import "jquery-ui";
  8. import "strophe";
  9. import "strophe-disco";
  10. import "strophe-caps";
  11. import "jQuery-Impromptu";
  12. import "autosize";
  13. import 'aui';
  14. import 'aui-experimental';
  15. import 'aui-css';
  16. import 'aui-experimental-css';
  17. window.toastr = require("toastr");
  18. const Logger = require("jitsi-meet-logger");
  19. const LogCollector = Logger.LogCollector;
  20. import JitsiMeetLogStorage from "./modules/util/JitsiMeetLogStorage";
  21. import URLProcessor from "./modules/config/URLProcessor";
  22. import RoomnameGenerator from './modules/util/RoomnameGenerator';
  23. import UI from "./modules/UI/UI";
  24. import settings from "./modules/settings/Settings";
  25. import conference from './conference';
  26. import ConferenceUrl from './modules/URL/ConferenceUrl';
  27. import API from './modules/API/API';
  28. import UIEvents from './service/UI/UIEvents';
  29. import getTokenData from "./modules/tokendata/TokenData";
  30. import translation from "./modules/translation/translation";
  31. const ConferenceEvents = JitsiMeetJS.events.conference;
  32. /**
  33. * Tries to push history state with the following parameters:
  34. * 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
  35. * it.
  36. */
  37. function pushHistoryState(roomName, URL) {
  38. try {
  39. window.history.pushState(
  40. 'VideoChat', `Room: ${roomName}`, URL
  41. );
  42. } catch (e) {
  43. logger.warn("Push history state failed with parameters:",
  44. 'VideoChat', `Room: ${roomName}`, URL, e);
  45. return e;
  46. }
  47. return null;
  48. }
  49. /**
  50. * Replaces current history state(replaces the URL displayed by the browser).
  51. * @param {string} newUrl the URL string which is to be displayed by the browser
  52. * to the user.
  53. */
  54. function replaceHistoryState (newUrl) {
  55. if (window.history
  56. && typeof window.history.replaceState === 'function') {
  57. window.history.replaceState({}, document.title, newUrl);
  58. }
  59. }
  60. /**
  61. * Builds and returns the room name.
  62. */
  63. function buildRoomName () {
  64. let roomName = getRoomName();
  65. if(!roomName) {
  66. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  67. roomName = word.toLowerCase();
  68. let historyURL = window.location.href + word;
  69. //Trying to push state with current URL + roomName
  70. pushHistoryState(word, historyURL);
  71. }
  72. return roomName;
  73. }
  74. /**
  75. * Adjusts the logging levels.
  76. * @private
  77. */
  78. function configureLoggingLevels () {
  79. // NOTE The library Logger is separated from the app loggers, so the levels
  80. // have to be set in two places
  81. // Set default logging level
  82. const defaultLogLevel
  83. = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
  84. Logger.setLogLevel(defaultLogLevel);
  85. JitsiMeetJS.setLogLevel(defaultLogLevel);
  86. // NOTE console was used on purpose here to go around the logging
  87. // and always print the default logging level to the console
  88. console.info("Default logging level set to: " + defaultLogLevel);
  89. // Set log level for each logger
  90. if (loggingConfig) {
  91. Object.keys(loggingConfig).forEach(function(loggerName) {
  92. if ('defaultLogLevel' !== loggerName) {
  93. const level = loggingConfig[loggerName];
  94. Logger.setLogLevelById(level, loggerName);
  95. JitsiMeetJS.setLogLevelById(level, loggerName);
  96. }
  97. });
  98. }
  99. }
  100. const APP = {
  101. // Used by do_external_connect.js if we receive the attach data after
  102. // connect was already executed. status property can be "initialized",
  103. // "ready" or "connecting". We are interested in "ready" status only which
  104. // means that connect was executed but we have to wait for the attach data.
  105. // In status "ready" handler property will be set to a function that will
  106. // finish the connect process when the attach data or error is received.
  107. connect: {
  108. status: "initialized",
  109. handler: null
  110. },
  111. // Used for automated performance tests
  112. connectionTimes: {
  113. "index.loaded": window.indexLoadedTime
  114. },
  115. UI,
  116. settings,
  117. conference,
  118. translation,
  119. /**
  120. * The log collector which captures JS console logs for this app.
  121. * @type {LogCollector}
  122. */
  123. logCollector: null,
  124. /**
  125. * Indicates if the log collector has been started (it will not be started
  126. * if the welcome page is displayed).
  127. */
  128. logCollectorStarted : false,
  129. /**
  130. * After the APP has been initialized provides utility methods for dealing
  131. * with the conference room URL(address).
  132. * @type ConferenceUrl
  133. */
  134. ConferenceUrl : null,
  135. connection: null,
  136. API,
  137. init () {
  138. this.initLogging();
  139. this.keyboardshortcut =
  140. require("./modules/keyboardshortcut/keyboardshortcut");
  141. this.configFetch = require("./modules/config/HttpConfigFetch");
  142. this.tokenData = getTokenData();
  143. },
  144. initLogging () {
  145. // Adjust logging level
  146. configureLoggingLevels();
  147. // Start the LogCollector and register it as the global log transport
  148. if (!this.logCollector && !loggingConfig.disableLogCollector) {
  149. this.logCollector = new LogCollector(new JitsiMeetLogStorage());
  150. Logger.addGlobalTransport(this.logCollector);
  151. JitsiMeetJS.addGlobalLogTransport(this.logCollector);
  152. }
  153. }
  154. };
  155. /**
  156. * If JWT token data it will be used for local user settings
  157. */
  158. function setTokenData() {
  159. let localUser = APP.tokenData.caller;
  160. if(localUser) {
  161. APP.settings.setEmail((localUser.getEmail() || "").trim(), true);
  162. APP.settings.setAvatarUrl((localUser.getAvatarUrl() || "").trim());
  163. APP.settings.setDisplayName((localUser.getName() || "").trim(), true);
  164. }
  165. }
  166. function init() {
  167. setTokenData();
  168. // Initialize the conference URL handler
  169. APP.ConferenceUrl = new ConferenceUrl(window.location);
  170. // Clean up the URL displayed by the browser
  171. replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
  172. var isUIReady = APP.UI.start();
  173. if (isUIReady) {
  174. // Start the LogCollector's periodic "store logs" task only if we're in
  175. // the conference and not on the welcome page.
  176. if (APP.logCollector) {
  177. APP.logCollector.start();
  178. APP.logCollectorStarted = true;
  179. }
  180. APP.conference.init({roomName: buildRoomName()}).then(function () {
  181. // Will flush the logs, before the stats are disposed
  182. if (APP.logCollector) {
  183. APP.conference.addConferenceListener(
  184. ConferenceEvents.BEFORE_STATISTICS_DISPOSED,
  185. () => {
  186. if (APP.logCollector) {
  187. APP.logCollector.flush();
  188. }
  189. }
  190. );
  191. }
  192. APP.UI.initConference();
  193. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  194. APP.translation.setLanguage(language);
  195. APP.settings.setLanguage(language);
  196. });
  197. APP.keyboardshortcut.init();
  198. }).catch(function (err) {
  199. APP.UI.hideRingOverLay();
  200. APP.API.notifyConferenceLeft(APP.conference.roomName);
  201. logger.error(err);
  202. });
  203. }
  204. }
  205. /**
  206. * If we have an HTTP endpoint for getting config.json configured we're going to
  207. * read it and override properties from config.js and interfaceConfig.js.
  208. * If there is no endpoint we'll just continue with initialization.
  209. * Keep in mind that if the endpoint has been configured and we fail to obtain
  210. * the config for any reason then the conference won't start and error message
  211. * will be displayed to the user.
  212. */
  213. function obtainConfigAndInit() {
  214. let roomName = APP.conference.roomName;
  215. if (config.configLocation) {
  216. APP.configFetch.obtainConfig(
  217. config.configLocation, roomName,
  218. // Get config result callback
  219. function(success, error) {
  220. if (success) {
  221. var now = APP.connectionTimes["configuration.fetched"] =
  222. window.performance.now();
  223. logger.log("(TIME) configuration fetched:\t", now);
  224. init();
  225. } else {
  226. // Show obtain config error,
  227. // pass the error object for report
  228. APP.UI.messageHandler.openReportDialog(
  229. null, "dialog.connectError", error);
  230. }
  231. });
  232. } else {
  233. require("./modules/config/BoshAddressChoice").chooseAddress(
  234. config, roomName);
  235. init();
  236. }
  237. }
  238. $(document).ready(function () {
  239. var now = APP.connectionTimes["document.ready"] = window.performance.now();
  240. logger.log("(TIME) document ready:\t", now);
  241. URLProcessor.setConfigParametersFromUrl();
  242. APP.init();
  243. APP.translation.init(settings.getLanguage());
  244. APP.API.init(APP.tokenData.externalAPISettings);
  245. obtainConfigAndInit();
  246. });
  247. $(window).bind('beforeunload', function () {
  248. // Stop the LogCollector
  249. if (APP.logCollectorStarted) {
  250. APP.logCollector.stop();
  251. APP.logCollectorStarted = false;
  252. }
  253. APP.API.dispose();
  254. });
  255. module.exports = APP;