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

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