jiti-meet/app.js

144 lines
4.2 KiB
JavaScript
Raw Normal View History

2015-12-31 15:23:23 +00:00
/* global $, JitsiMeetJS, config */
2013-12-16 11:22:23 +00:00
/* application specific logic */
2015-12-04 13:46:25 +00:00
import "babel-polyfill";
2015-12-04 14:57:28 +00:00
import "jquery";
import "jquery-ui";
import "strophe";
import "strophe-disco";
import "strophe-caps";
import "tooltip";
import "popover";
import "jQuery-Impromptu";
import "autosize";
2015-09-10 17:15:56 +00:00
window.toastr = require("toastr");
2015-12-14 12:26:50 +00:00
import URLProcessor from "./modules/config/URLProcessor";
2015-12-04 14:57:28 +00:00
import RoomnameGenerator from './modules/util/RoomnameGenerator';
2015-12-17 15:31:11 +00:00
2015-12-29 12:41:43 +00:00
import UI from "./modules/UI/UI";
import settings from "./modules/settings/Settings";
2016-01-06 22:39:13 +00:00
import conference from './conference';
2016-01-14 15:05:54 +00:00
import API from './modules/API/API';
2015-12-29 22:30:50 +00:00
2016-01-14 15:05:54 +00:00
import UIEvents from './service/UI/UIEvents';
2015-12-29 22:30:50 +00:00
2015-12-04 14:57:28 +00:00
function buildRoomName () {
let path = window.location.pathname;
let roomName;
// determinde the room node from the url
// TODO: just the roomnode or the whole bare jid?
if (config.getroomnode && typeof config.getroomnode === 'function') {
// custom function might be responsible for doing the pushstate
roomName = config.getroomnode(path);
} else {
/* fall back to default strategy
* this is making assumptions about how the URL->room mapping happens.
* It currently assumes deployment at root, with a rewrite like the
* following one (for nginx):
location ~ ^/([a-zA-Z0-9]+)$ {
rewrite ^/(.*)$ / break;
}
2015-12-17 15:31:11 +00:00
*/
2015-12-04 14:57:28 +00:00
if (path.length > 1) {
roomName = path.substr(1).toLowerCase();
} else {
let word = RoomnameGenerator.generateRoomWithoutSeparator();
roomName = word.toLowerCase();
window.history.pushState(
2015-12-07 16:26:25 +00:00
'VideoChat', `Room: ${word}`, window.location.pathname + word
2015-12-04 14:57:28 +00:00
);
}
}
return roomName;
}
const APP = {
2015-12-29 12:41:43 +00:00
UI,
settings,
2016-01-14 15:05:54 +00:00
conference,
API,
2015-12-04 14:57:28 +00:00
init () {
this.keyboardshortcut =
require("./modules/keyboardshortcut/keyboardshortcut");
this.translation = require("./modules/translation/translation");
this.configFetch = require("./modules/config/HttpConfigFetch");
}
};
2015-11-30 11:54:54 +00:00
function init() {
var isUIReady = APP.UI.start();
if (isUIReady) {
APP.conference.init({roomName: buildRoomName()}).then(function () {
APP.UI.initConference();
2015-12-01 12:53:01 +00:00
APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
APP.translation.setLanguage(language);
APP.settings.setLanguage(language);
});
2015-12-01 13:41:58 +00:00
APP.keyboardshortcut.init();
}).catch(function (err) {
console.error(err);
});
}
2013-12-16 11:22:23 +00:00
}
/**
* If we have an HTTP endpoint for getting config.json configured we're going to
* read it and override properties from config.js and interfaceConfig.js.
* If there is no endpoint we'll just continue with initialization.
* Keep in mind that if the endpoint has been configured and we fail to obtain
* the config for any reason then the conference won't start and error message
* will be displayed to the user.
*/
function obtainConfigAndInit() {
2015-12-04 14:57:28 +00:00
let roomName = APP.conference.roomName;
if (config.configLocation) {
APP.configFetch.obtainConfig(
config.configLocation, roomName,
// Get config result callback
function(success, error) {
if (success) {
console.log("(TIME) configuration fetched:\t",
window.performance.now());
init();
} else {
// Show obtain config error,
// pass the error object for report
APP.UI.messageHandler.openReportDialog(
null, "dialog.connectError", error);
}
});
} else {
require("./modules/config/BoshAddressChoice").chooseAddress(
config, roomName);
init();
}
}
2013-12-16 11:22:23 +00:00
$(document).ready(function () {
console.log("(TIME) document ready:\t", window.performance.now());
2015-01-07 14:54:03 +00:00
URLProcessor.setConfigParametersFromUrl();
APP.init();
2014-08-21 16:42:54 +00:00
2015-12-29 12:41:43 +00:00
APP.translation.init(settings.getLanguage());
2016-01-14 15:05:54 +00:00
APP.API.init();
2015-11-30 11:54:54 +00:00
obtainConfigAndInit();
2013-12-16 11:22:23 +00:00
});
$(window).bind('beforeunload', function () {
2016-01-14 15:05:54 +00:00
APP.API.dispose();
2013-12-16 11:22:23 +00:00
});
2015-12-14 12:26:50 +00:00
module.exports = APP;