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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 { generateRoomWithoutSeparator } 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 = 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. // Create the LogCollector and register it as the global log transport.
  148. // It is done early to capture as much logs as possible. Captured logs
  149. // will be cached, before the JitsiMeetLogStorage gets ready (statistics
  150. // module is initialized).
  151. if (!this.logCollector && !loggingConfig.disableLogCollector) {
  152. this.logCollector = new LogCollector(new JitsiMeetLogStorage());
  153. Logger.addGlobalTransport(this.logCollector);
  154. JitsiMeetJS.addGlobalLogTransport(this.logCollector);
  155. }
  156. }
  157. };
  158. /**
  159. * If JWT token data it will be used for local user settings
  160. */
  161. function setTokenData() {
  162. let localUser = APP.tokenData.caller;
  163. if(localUser) {
  164. APP.settings.setEmail((localUser.getEmail() || "").trim(), true);
  165. APP.settings.setAvatarUrl((localUser.getAvatarUrl() || "").trim());
  166. APP.settings.setDisplayName((localUser.getName() || "").trim(), true);
  167. }
  168. }
  169. function init() {
  170. setTokenData();
  171. // Initialize the conference URL handler
  172. APP.ConferenceUrl = new ConferenceUrl(window.location);
  173. // Clean up the URL displayed by the browser
  174. replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
  175. // TODO The execution of the mobile app starts from react/index.native.js.
  176. // Similarly, the execution of the Web app should start from
  177. // react/index.web.js for the sake of consistency and ease of understanding.
  178. // Temporarily though because we are at the beginning of introducing React
  179. // into the Web app, allow the execution of the Web app to start from app.js
  180. // in order to reduce the complexity of the beginning step.
  181. require('./react');
  182. const isUIReady = APP.UI.start();
  183. if (isUIReady) {
  184. APP.conference.init({roomName: buildRoomName()}).then(() => {
  185. if (APP.logCollector) {
  186. // Start the LogCollector's periodic "store logs" task only if
  187. // we're in the conference and not on the welcome page. This is
  188. // determined by the value of "isUIReady" const above.
  189. APP.logCollector.start();
  190. APP.logCollectorStarted = true;
  191. // Make an attempt to flush in case a lot of logs have been
  192. // cached, before the collector was started.
  193. APP.logCollector.flush();
  194. // This event listener will flush the logs, before
  195. // the statistics module (CallStats) is stopped.
  196. //
  197. // NOTE The LogCollector is not stopped, because this event can
  198. // be triggered multiple times during single conference
  199. // (whenever statistics module is stopped). That includes
  200. // the case when Jicofo terminates the single person left in the
  201. // room. It will then restart the media session when someone
  202. // eventually join the room which will start the stats again.
  203. APP.conference.addConferenceListener(
  204. ConferenceEvents.BEFORE_STATISTICS_DISPOSED,
  205. () => {
  206. if (APP.logCollector) {
  207. APP.logCollector.flush();
  208. }
  209. }
  210. );
  211. }
  212. APP.UI.initConference();
  213. APP.UI.addListener(UIEvents.LANG_CHANGED, language => {
  214. APP.translation.setLanguage(language);
  215. APP.settings.setLanguage(language);
  216. });
  217. APP.keyboardshortcut.init();
  218. }).catch(err => {
  219. APP.UI.hideRingOverLay();
  220. APP.API.notifyConferenceLeft(APP.conference.roomName);
  221. logger.error(err);
  222. });
  223. }
  224. }
  225. /**
  226. * If we have an HTTP endpoint for getting config.json configured we're going to
  227. * read it and override properties from config.js and interfaceConfig.js.
  228. * If there is no endpoint we'll just continue with initialization.
  229. * Keep in mind that if the endpoint has been configured and we fail to obtain
  230. * the config for any reason then the conference won't start and error message
  231. * will be displayed to the user.
  232. */
  233. function obtainConfigAndInit() {
  234. let roomName = APP.conference.roomName;
  235. if (config.configLocation) {
  236. APP.configFetch.obtainConfig(
  237. config.configLocation, roomName,
  238. // Get config result callback
  239. function(success, error) {
  240. if (success) {
  241. var now = APP.connectionTimes["configuration.fetched"] =
  242. window.performance.now();
  243. logger.log("(TIME) configuration fetched:\t", now);
  244. init();
  245. } else {
  246. // Show obtain config error,
  247. // pass the error object for report
  248. APP.UI.messageHandler.openReportDialog(
  249. null, "dialog.connectError", error);
  250. }
  251. });
  252. } else {
  253. require("./modules/config/BoshAddressChoice").chooseAddress(
  254. config, roomName);
  255. init();
  256. }
  257. }
  258. $(document).ready(function () {
  259. var now = APP.connectionTimes["document.ready"] = window.performance.now();
  260. logger.log("(TIME) document ready:\t", now);
  261. URLProcessor.setConfigParametersFromUrl();
  262. APP.init();
  263. APP.translation.init(settings.getLanguage());
  264. APP.API.init(APP.tokenData.externalAPISettings);
  265. obtainConfigAndInit();
  266. });
  267. $(window).bind('beforeunload', function () {
  268. // Stop the LogCollector
  269. if (APP.logCollectorStarted) {
  270. APP.logCollector.stop();
  271. APP.logCollectorStarted = false;
  272. }
  273. APP.API.dispose();
  274. });
  275. module.exports = APP;