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 6.3KB

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