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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* global $, JitsiMeetJS, config, getRoomName */
  2. /* application specific logic */
  3. import "babel-polyfill";
  4. import "jquery";
  5. import "jquery-ui";
  6. import "strophe";
  7. import "strophe-disco";
  8. import "strophe-caps";
  9. import "tooltip";
  10. import "popover";
  11. import "jQuery-Impromptu";
  12. import "autosize";
  13. window.toastr = require("toastr");
  14. import URLProcessor from "./modules/config/URLProcessor";
  15. import RoomnameGenerator from './modules/util/RoomnameGenerator';
  16. import UI from "./modules/UI/UI";
  17. import settings from "./modules/settings/Settings";
  18. import conference from './conference';
  19. import API from './modules/API/API';
  20. import UIEvents from './service/UI/UIEvents';
  21. /**
  22. * Builds and returns the room name.
  23. */
  24. function buildRoomName () {
  25. let roomName = getRoomName();
  26. if(!roomName) {
  27. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  28. roomName = word.toLowerCase();
  29. window.history.pushState(
  30. 'VideoChat', `Room: ${word}`, window.location.pathname + word
  31. );
  32. }
  33. return roomName;
  34. }
  35. const APP = {
  36. // Used by do_external_connect.js if we receive the attach data after
  37. // connect was already executed. status property can be "initialized",
  38. // "ready" or "connecting". We are interested in "ready" status only which
  39. // means that connect was executed but we have to wait for the attach data.
  40. // In status "ready" handler property will be set to a function that will
  41. // finish the connect process when the attach data or error is received.
  42. connect: {
  43. status: "initialized",
  44. handler: null
  45. },
  46. UI,
  47. settings,
  48. conference,
  49. API,
  50. init () {
  51. this.keyboardshortcut =
  52. require("./modules/keyboardshortcut/keyboardshortcut");
  53. this.translation = require("./modules/translation/translation");
  54. this.configFetch = require("./modules/config/HttpConfigFetch");
  55. }
  56. };
  57. function init() {
  58. var isUIReady = APP.UI.start();
  59. if (isUIReady) {
  60. APP.conference.init({roomName: buildRoomName()}).then(function () {
  61. APP.UI.initConference();
  62. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  63. APP.translation.setLanguage(language);
  64. APP.settings.setLanguage(language);
  65. });
  66. APP.keyboardshortcut.init();
  67. }).catch(function (err) {
  68. console.error(err);
  69. });
  70. }
  71. }
  72. /**
  73. * If we have an HTTP endpoint for getting config.json configured we're going to
  74. * read it and override properties from config.js and interfaceConfig.js.
  75. * If there is no endpoint we'll just continue with initialization.
  76. * Keep in mind that if the endpoint has been configured and we fail to obtain
  77. * the config for any reason then the conference won't start and error message
  78. * will be displayed to the user.
  79. */
  80. function obtainConfigAndInit() {
  81. let roomName = APP.conference.roomName;
  82. if (config.configLocation) {
  83. APP.configFetch.obtainConfig(
  84. config.configLocation, roomName,
  85. // Get config result callback
  86. function(success, error) {
  87. if (success) {
  88. console.log("(TIME) configuration fetched:\t",
  89. window.performance.now());
  90. init();
  91. } else {
  92. // Show obtain config error,
  93. // pass the error object for report
  94. APP.UI.messageHandler.openReportDialog(
  95. null, "dialog.connectError", error);
  96. }
  97. });
  98. } else {
  99. require("./modules/config/BoshAddressChoice").chooseAddress(
  100. config, roomName);
  101. init();
  102. }
  103. }
  104. $(document).ready(function () {
  105. console.log("(TIME) document ready:\t", window.performance.now());
  106. URLProcessor.setConfigParametersFromUrl();
  107. APP.init();
  108. APP.translation.init(settings.getLanguage());
  109. APP.API.init();
  110. obtainConfigAndInit();
  111. });
  112. $(window).bind('beforeunload', function () {
  113. APP.API.dispose();
  114. });
  115. module.exports = APP;