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

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