Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

app.js 4.8KB

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