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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 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. 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. settings,
  53. conference,
  54. API,
  55. init () {
  56. this.desktopsharing =
  57. require("./modules/desktopsharing/desktopsharing");
  58. this.keyboardshortcut =
  59. require("./modules/keyboardshortcut/keyboardshortcut");
  60. this.translation = require("./modules/translation/translation");
  61. this.configFetch = require("./modules/config/HttpConfigFetch");
  62. }
  63. };
  64. function init() {
  65. var isUIReady = APP.UI.start();
  66. if (isUIReady) {
  67. APP.conference.init({roomName: buildRoomName()}).then(function () {
  68. APP.UI.initConference();
  69. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  70. APP.translation.setLanguage(language);
  71. APP.settings.setLanguage(language);
  72. });
  73. APP.desktopsharing.init(JitsiMeetJS.isDesktopSharingEnabled());
  74. APP.keyboardshortcut.init();
  75. }).catch(function (err) {
  76. console.error(err);
  77. });
  78. }
  79. }
  80. /**
  81. * If we have an HTTP endpoint for getting config.json configured we're going to
  82. * read it and override properties from config.js and interfaceConfig.js.
  83. * If there is no endpoint we'll just continue with initialization.
  84. * Keep in mind that if the endpoint has been configured and we fail to obtain
  85. * the config for any reason then the conference won't start and error message
  86. * will be displayed to the user.
  87. */
  88. function obtainConfigAndInit() {
  89. let roomName = APP.conference.roomName;
  90. if (config.configLocation) {
  91. APP.configFetch.obtainConfig(
  92. config.configLocation, roomName,
  93. // Get config result callback
  94. function(success, error) {
  95. if (success) {
  96. console.log("(TIME) configuration fetched:\t",
  97. window.performance.now());
  98. init();
  99. } else {
  100. // Show obtain config error,
  101. // pass the error object for report
  102. APP.UI.messageHandler.openReportDialog(
  103. null, "dialog.connectError", error);
  104. }
  105. });
  106. } else {
  107. require("./modules/config/BoshAddressChoice").chooseAddress(
  108. config, roomName);
  109. init();
  110. }
  111. }
  112. $(document).ready(function () {
  113. console.log("(TIME) document ready:\t", window.performance.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;