Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

app.js 11KB

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