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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* global $, JitsiMeetJS, config */
  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 statistics from "./modules/statistics/statistics";
  18. import settings from "./modules/settings/Settings";
  19. import UIEvents from './service/UI/UIEvents';
  20. import conference from './conference';
  21. function buildRoomName () {
  22. let path = window.location.pathname;
  23. let roomName;
  24. // determinde the room node from the url
  25. // TODO: just the roomnode or the whole bare jid?
  26. if (config.getroomnode && typeof config.getroomnode === 'function') {
  27. // custom function might be responsible for doing the pushstate
  28. roomName = config.getroomnode(path);
  29. } else {
  30. /* fall back to default strategy
  31. * this is making assumptions about how the URL->room mapping happens.
  32. * It currently assumes deployment at root, with a rewrite like the
  33. * following one (for nginx):
  34. location ~ ^/([a-zA-Z0-9]+)$ {
  35. rewrite ^/(.*)$ / break;
  36. }
  37. */
  38. if (path.length > 1) {
  39. roomName = path.substr(1).toLowerCase();
  40. } else {
  41. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  42. roomName = word.toLowerCase();
  43. window.history.pushState(
  44. 'VideoChat', `Room: ${word}`, window.location.pathname + word
  45. );
  46. }
  47. }
  48. return roomName;
  49. }
  50. const APP = {
  51. UI,
  52. statistics,
  53. settings,
  54. init () {
  55. this.conference = conference;
  56. this.API = require("./modules/API/API");
  57. this.connectionquality =
  58. require("./modules/connectionquality/connectionquality");
  59. this.desktopsharing =
  60. require("./modules/desktopsharing/desktopsharing");
  61. this.keyboardshortcut =
  62. require("./modules/keyboardshortcut/keyboardshortcut");
  63. this.translation = require("./modules/translation/translation");
  64. this.configFetch = require("./modules/config/HttpConfigFetch");
  65. }
  66. };
  67. function init() {
  68. var isUIReady = APP.UI.start();
  69. if (isUIReady) {
  70. APP.conference.init({roomName: buildRoomName()}).then(function () {
  71. APP.UI.initConference();
  72. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  73. APP.translation.setLanguage(language);
  74. APP.settings.setLanguage(language);
  75. });
  76. APP.desktopsharing.init(JitsiMeetJS.isDesktopSharingEnabled());
  77. APP.statistics.start();
  78. APP.connectionquality.init();
  79. APP.keyboardshortcut.init();
  80. }).catch(function (err) {
  81. console.error(err);
  82. });
  83. }
  84. }
  85. /**
  86. * If we have an HTTP endpoint for getting config.json configured we're going to
  87. * read it and override properties from config.js and interfaceConfig.js.
  88. * If there is no endpoint we'll just continue with initialization.
  89. * Keep in mind that if the endpoint has been configured and we fail to obtain
  90. * the config for any reason then the conference won't start and error message
  91. * will be displayed to the user.
  92. */
  93. function obtainConfigAndInit() {
  94. let roomName = APP.conference.roomName;
  95. if (config.configLocation) {
  96. APP.configFetch.obtainConfig(
  97. config.configLocation, roomName,
  98. // Get config result callback
  99. function(success, error) {
  100. if (success) {
  101. console.log("(TIME) configuration fetched:\t",
  102. window.performance.now());
  103. init();
  104. } else {
  105. // Show obtain config error,
  106. // pass the error object for report
  107. APP.UI.messageHandler.openReportDialog(
  108. null, "dialog.connectError", error);
  109. }
  110. });
  111. } else {
  112. require("./modules/config/BoshAddressChoice").chooseAddress(
  113. config, roomName);
  114. init();
  115. }
  116. }
  117. $(document).ready(function () {
  118. console.log("(TIME) document ready:\t", window.performance.now());
  119. URLProcessor.setConfigParametersFromUrl();
  120. APP.init();
  121. APP.translation.init(settings.getLanguage());
  122. if (APP.API.isEnabled()) {
  123. APP.API.init();
  124. }
  125. obtainConfigAndInit();
  126. });
  127. $(window).bind('beforeunload', function () {
  128. if (APP.API.isEnabled()) {
  129. APP.API.dispose();
  130. }
  131. });
  132. module.exports = APP;