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

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