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.3KB

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