You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. import URLProcessor from "./modules/config/URLProcessor";
  20. import RoomnameGenerator from './modules/util/RoomnameGenerator';
  21. import UI from "./modules/UI/UI";
  22. import settings from "./modules/settings/Settings";
  23. import conference from './conference';
  24. import ConferenceUrl from './modules/URL/ConferenceUrl';
  25. import API from './modules/API/API';
  26. import UIEvents from './service/UI/UIEvents';
  27. import getTokenData from "./modules/tokendata/TokenData";
  28. import translation from "./modules/translation/translation";
  29. /**
  30. * Tries to push history state with the following parameters:
  31. * 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
  32. * it.
  33. */
  34. function pushHistoryState(roomName, URL) {
  35. try {
  36. window.history.pushState(
  37. 'VideoChat', `Room: ${roomName}`, URL
  38. );
  39. } catch (e) {
  40. logger.warn("Push history state failed with parameters:",
  41. 'VideoChat', `Room: ${roomName}`, URL, e);
  42. return e;
  43. }
  44. return null;
  45. }
  46. /**
  47. * Replaces current history state(replaces the URL displayed by the browser).
  48. * @param {string} newUrl the URL string which is to be displayed by the browser
  49. * to the user.
  50. */
  51. function replaceHistoryState (newUrl) {
  52. if (window.history
  53. && typeof window.history.replaceState === 'function') {
  54. window.history.replaceState({}, document.title, newUrl);
  55. }
  56. }
  57. /**
  58. * Builds and returns the room name.
  59. */
  60. function buildRoomName () {
  61. let roomName = getRoomName();
  62. if(!roomName) {
  63. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  64. roomName = word.toLowerCase();
  65. let historyURL = window.location.href + word;
  66. //Trying to push state with current URL + roomName
  67. pushHistoryState(word, historyURL);
  68. }
  69. return roomName;
  70. }
  71. /**
  72. * Adjusts the logging levels.
  73. * @private
  74. */
  75. function configureLoggingLevels () {
  76. // NOTE The library Logger is separated from the app loggers, so the levels
  77. // have to be set in two places
  78. // Set default logging level
  79. const defaultLogLevel
  80. = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
  81. Logger.setLogLevel(defaultLogLevel);
  82. JitsiMeetJS.setLogLevel(defaultLogLevel);
  83. // NOTE console was used on purpose here to go around the logging
  84. // and always print the default logging level to the console
  85. console.info("Default logging level set to: " + defaultLogLevel);
  86. // Set log level for each logger
  87. if (loggingConfig) {
  88. Object.keys(loggingConfig).forEach(function(loggerName) {
  89. if ('defaultLogLevel' !== loggerName) {
  90. const level = loggingConfig[loggerName];
  91. Logger.setLogLevelById(level, loggerName);
  92. JitsiMeetJS.setLogLevelById(level, loggerName);
  93. }
  94. });
  95. }
  96. }
  97. const APP = {
  98. // Used by do_external_connect.js if we receive the attach data after
  99. // connect was already executed. status property can be "initialized",
  100. // "ready" or "connecting". We are interested in "ready" status only which
  101. // means that connect was executed but we have to wait for the attach data.
  102. // In status "ready" handler property will be set to a function that will
  103. // finish the connect process when the attach data or error is received.
  104. connect: {
  105. status: "initialized",
  106. handler: null
  107. },
  108. // Used for automated performance tests
  109. connectionTimes: {
  110. "index.loaded": window.indexLoadedTime
  111. },
  112. UI,
  113. settings,
  114. conference,
  115. translation,
  116. /**
  117. * After the APP has been initialized provides utility methods for dealing
  118. * with the conference room URL(address).
  119. * @type ConferenceUrl
  120. */
  121. ConferenceUrl : null,
  122. connection: null,
  123. API,
  124. init () {
  125. configureLoggingLevels();
  126. this.keyboardshortcut =
  127. require("./modules/keyboardshortcut/keyboardshortcut");
  128. this.configFetch = require("./modules/config/HttpConfigFetch");
  129. this.tokenData = getTokenData();
  130. }
  131. };
  132. /**
  133. * If JWT token data it will be used for local user settings
  134. */
  135. function setTokenData() {
  136. let localUser = APP.tokenData.caller;
  137. if(localUser) {
  138. APP.settings.setEmail((localUser.getEmail() || "").trim(), true);
  139. APP.settings.setAvatarUrl((localUser.getAvatarUrl() || "").trim());
  140. APP.settings.setDisplayName((localUser.getName() || "").trim(), true);
  141. }
  142. }
  143. function init() {
  144. setTokenData();
  145. // Initialize the conference URL handler
  146. APP.ConferenceUrl = new ConferenceUrl(window.location);
  147. // Clean up the URL displayed by the browser
  148. replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
  149. var isUIReady = APP.UI.start();
  150. if (isUIReady) {
  151. APP.conference.init({roomName: buildRoomName()}).then(function () {
  152. APP.UI.initConference();
  153. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  154. APP.translation.setLanguage(language);
  155. APP.settings.setLanguage(language);
  156. });
  157. APP.keyboardshortcut.init();
  158. }).catch(function (err) {
  159. APP.UI.hideRingOverLay();
  160. APP.API.notifyConferenceLeft(APP.conference.roomName);
  161. logger.error(err);
  162. });
  163. }
  164. }
  165. /**
  166. * If we have an HTTP endpoint for getting config.json configured we're going to
  167. * read it and override properties from config.js and interfaceConfig.js.
  168. * If there is no endpoint we'll just continue with initialization.
  169. * Keep in mind that if the endpoint has been configured and we fail to obtain
  170. * the config for any reason then the conference won't start and error message
  171. * will be displayed to the user.
  172. */
  173. function obtainConfigAndInit() {
  174. let roomName = APP.conference.roomName;
  175. if (config.configLocation) {
  176. APP.configFetch.obtainConfig(
  177. config.configLocation, roomName,
  178. // Get config result callback
  179. function(success, error) {
  180. if (success) {
  181. var now = APP.connectionTimes["configuration.fetched"] =
  182. window.performance.now();
  183. logger.log("(TIME) configuration fetched:\t", now);
  184. init();
  185. } else {
  186. // Show obtain config error,
  187. // pass the error object for report
  188. APP.UI.messageHandler.openReportDialog(
  189. null, "dialog.connectError", error);
  190. }
  191. });
  192. } else {
  193. require("./modules/config/BoshAddressChoice").chooseAddress(
  194. config, roomName);
  195. init();
  196. }
  197. }
  198. $(document).ready(function () {
  199. var now = APP.connectionTimes["document.ready"] = window.performance.now();
  200. logger.log("(TIME) document ready:\t", now);
  201. URLProcessor.setConfigParametersFromUrl();
  202. APP.init();
  203. APP.translation.init(settings.getLanguage());
  204. APP.API.init(APP.tokenData.externalAPISettings);
  205. obtainConfigAndInit();
  206. });
  207. $(window).bind('beforeunload', function () {
  208. APP.API.dispose();
  209. });
  210. module.exports = APP;