2016-10-03 16:12:04 +00:00
|
|
|
/* global $, config, getRoomName */
|
2013-12-16 11:22:23 +00:00
|
|
|
/* application specific logic */
|
2014-05-12 09:56:33 +00:00
|
|
|
|
2015-12-04 13:46:25 +00:00
|
|
|
import "babel-polyfill";
|
2015-12-04 14:57:28 +00:00
|
|
|
import "jquery";
|
2016-05-07 01:50:37 +00:00
|
|
|
import "jquery-contextmenu";
|
2015-12-04 14:57:28 +00:00
|
|
|
import "jquery-ui";
|
|
|
|
import "strophe";
|
|
|
|
import "strophe-disco";
|
|
|
|
import "strophe-caps";
|
|
|
|
import "jQuery-Impromptu";
|
|
|
|
import "autosize";
|
2016-09-16 03:22:56 +00:00
|
|
|
|
|
|
|
import 'aui';
|
|
|
|
import 'aui-experimental';
|
|
|
|
import 'aui-css';
|
|
|
|
import 'aui-experimental-css';
|
|
|
|
|
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-10-21 14:46:09 +00:00
|
|
|
import ConferenceUrl from './modules/URL/ConferenceUrl';
|
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';
|
2016-11-04 22:35:13 +00:00
|
|
|
import getTokenData from "./modules/tokendata/TokenData";
|
2016-10-31 22:16:30 +00:00
|
|
|
import translation from "./modules/translation/translation";
|
2015-12-29 22:30:50 +00:00
|
|
|
|
2016-06-03 12:45:57 +00:00
|
|
|
/**
|
|
|
|
* Tries to push history state with the following parameters:
|
|
|
|
* 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
function pushHistoryState(roomName, URL) {
|
|
|
|
try {
|
|
|
|
window.history.pushState(
|
|
|
|
'VideoChat', `Room: ${roomName}`, URL
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Push history state failed with parameters:",
|
|
|
|
'VideoChat', `Room: ${roomName}`, URL, e);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-10-13 17:42:59 +00:00
|
|
|
/**
|
|
|
|
* Replaces current history state(replaces the URL displayed by the browser).
|
|
|
|
* @param {string} newUrl the URL string which is to be displayed by the browser
|
|
|
|
* to the user.
|
|
|
|
*/
|
|
|
|
function replaceHistoryState (newUrl) {
|
|
|
|
if (window.history
|
|
|
|
&& typeof window.history.replaceState === 'function') {
|
|
|
|
window.history.replaceState({}, document.title, newUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
/**
|
|
|
|
* Builds and returns the room name.
|
|
|
|
*/
|
2015-12-04 14:57:28 +00:00
|
|
|
function buildRoomName () {
|
2016-03-28 21:19:32 +00:00
|
|
|
let roomName = getRoomName();
|
2015-12-04 14:57:28 +00:00
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
if(!roomName) {
|
|
|
|
let word = RoomnameGenerator.generateRoomWithoutSeparator();
|
|
|
|
roomName = word.toLowerCase();
|
2016-06-03 18:00:09 +00:00
|
|
|
let historyURL = window.location.href + word;
|
|
|
|
//Trying to push state with current URL + roomName
|
|
|
|
pushHistoryState(word, historyURL);
|
2015-12-04 14:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return roomName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const APP = {
|
2016-03-28 21:19:32 +00:00
|
|
|
// Used by do_external_connect.js if we receive the attach data after
|
|
|
|
// connect was already executed. status property can be "initialized",
|
|
|
|
// "ready" or "connecting". We are interested in "ready" status only which
|
|
|
|
// means that connect was executed but we have to wait for the attach data.
|
|
|
|
// In status "ready" handler property will be set to a function that will
|
|
|
|
// finish the connect process when the attach data or error is received.
|
|
|
|
connect: {
|
|
|
|
status: "initialized",
|
|
|
|
handler: null
|
|
|
|
},
|
2016-04-01 19:44:25 +00:00
|
|
|
// Used for automated performance tests
|
2016-04-11 15:01:23 +00:00
|
|
|
connectionTimes: {
|
2016-04-01 19:44:25 +00:00
|
|
|
"index.loaded": window.indexLoadedTime
|
|
|
|
},
|
2015-12-29 12:41:43 +00:00
|
|
|
UI,
|
|
|
|
settings,
|
2016-01-14 15:05:54 +00:00
|
|
|
conference,
|
2016-10-31 22:16:30 +00:00
|
|
|
translation,
|
2016-10-21 14:46:09 +00:00
|
|
|
/**
|
|
|
|
* After the APP has been initialized provides utility methods for dealing
|
|
|
|
* with the conference room URL(address).
|
|
|
|
* @type ConferenceUrl
|
|
|
|
*/
|
|
|
|
ConferenceUrl : null,
|
2016-04-01 19:44:25 +00:00
|
|
|
connection: null,
|
2016-01-14 15:05:54 +00:00
|
|
|
API,
|
2015-12-04 14:57:28 +00:00
|
|
|
init () {
|
2015-09-11 02:42:15 +00:00
|
|
|
this.keyboardshortcut =
|
|
|
|
require("./modules/keyboardshortcut/keyboardshortcut");
|
2015-08-21 12:33:05 +00:00
|
|
|
this.configFetch = require("./modules/config/HttpConfigFetch");
|
2016-06-13 21:11:44 +00:00
|
|
|
this.tokenData = getTokenData();
|
2015-01-28 14:35:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-13 21:11:44 +00:00
|
|
|
/**
|
|
|
|
* If JWT token data it will be used for local user settings
|
|
|
|
*/
|
|
|
|
function setTokenData() {
|
|
|
|
let localUser = APP.tokenData.caller;
|
|
|
|
if(localUser) {
|
2016-08-30 19:10:20 +00:00
|
|
|
APP.settings.setEmail((localUser.getEmail() || "").trim(), true);
|
2016-06-13 21:11:44 +00:00
|
|
|
APP.settings.setAvatarUrl((localUser.getAvatarUrl() || "").trim());
|
2016-08-30 19:10:20 +00:00
|
|
|
APP.settings.setDisplayName((localUser.getName() || "").trim(), true);
|
2016-06-13 21:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-30 11:54:54 +00:00
|
|
|
function init() {
|
2016-06-13 21:11:44 +00:00
|
|
|
setTokenData();
|
2016-10-13 17:42:59 +00:00
|
|
|
// Initialize the conference URL handler
|
2016-10-21 14:46:09 +00:00
|
|
|
APP.ConferenceUrl = new ConferenceUrl(window.location);
|
2016-10-13 17:42:59 +00:00
|
|
|
// Clean up the URL displayed by the browser
|
2016-10-21 14:46:09 +00:00
|
|
|
replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
|
2016-01-11 20:26:04 +00:00
|
|
|
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
|
|
|
|
2016-01-11 20:26:04 +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
|
|
|
|
2016-01-11 20:26:04 +00:00
|
|
|
APP.keyboardshortcut.init();
|
|
|
|
}).catch(function (err) {
|
2016-06-13 21:11:44 +00:00
|
|
|
APP.UI.hideRingOverLay();
|
2016-06-17 20:35:40 +00:00
|
|
|
APP.API.notifyConferenceLeft(APP.conference.roomName);
|
2016-01-11 20:26:04 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 12:33:05 +00:00
|
|
|
/**
|
2015-10-20 15:41:15 +00:00
|
|
|
* If we have an HTTP endpoint for getting config.json configured we're going to
|
2015-08-21 12:33:05 +00:00
|
|
|
* 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;
|
2015-10-20 15:41:15 +00:00
|
|
|
|
2015-08-21 12:33:05 +00:00
|
|
|
if (config.configLocation) {
|
|
|
|
APP.configFetch.obtainConfig(
|
2015-10-20 15:41:15 +00:00
|
|
|
config.configLocation, roomName,
|
2015-08-21 12:33:05 +00:00
|
|
|
// Get config result callback
|
|
|
|
function(success, error) {
|
|
|
|
if (success) {
|
2016-04-11 15:01:23 +00:00
|
|
|
var now = APP.connectionTimes["configuration.fetched"] =
|
2016-04-01 19:44:25 +00:00
|
|
|
window.performance.now();
|
|
|
|
console.log("(TIME) configuration fetched:\t", now);
|
2015-08-21 12:33:05 +00:00
|
|
|
init();
|
|
|
|
} else {
|
|
|
|
// Show obtain config error,
|
|
|
|
// pass the error object for report
|
|
|
|
APP.UI.messageHandler.openReportDialog(
|
|
|
|
null, "dialog.connectError", error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2015-10-20 15:41:15 +00:00
|
|
|
require("./modules/config/BoshAddressChoice").chooseAddress(
|
|
|
|
config, roomName);
|
|
|
|
|
2015-08-21 12:33:05 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 11:31:32 +00:00
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
$(document).ready(function () {
|
2016-04-11 15:01:23 +00:00
|
|
|
var now = APP.connectionTimes["document.ready"] = window.performance.now();
|
2016-04-01 19:44:25 +00:00
|
|
|
console.log("(TIME) document ready:\t", now);
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-07-22 18:34:44 +00:00
|
|
|
URLProcessor.setConfigParametersFromUrl();
|
2016-11-23 21:46:46 +00:00
|
|
|
|
|
|
|
// TODO The execution of the mobile app starts from react/index.native.js.
|
|
|
|
// Similarly, the execution of the Web app should start from
|
|
|
|
// react/index.web.js for the sake of consistency and ease of understanding.
|
|
|
|
// Temporarily though because we are at the beginning of introducing React
|
|
|
|
// into the Web app, allow the execution of the Web app to start from app.js
|
|
|
|
// in order to reduce the complexity of the beginning step.
|
|
|
|
require('./react');
|
|
|
|
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.init();
|
2014-08-21 16:42:54 +00:00
|
|
|
|
2015-12-29 12:41:43 +00:00
|
|
|
APP.translation.init(settings.getLanguage());
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2016-06-13 21:11:44 +00:00
|
|
|
APP.API.init(APP.tokenData.externalAPISettings);
|
2015-01-28 14:35:22 +00:00
|
|
|
|
2015-11-30 11:54:54 +00:00
|
|
|
obtainConfigAndInit();
|
2013-12-16 11:22:23 +00:00
|
|
|
});
|
|
|
|
|
2013-12-30 08:31:08 +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;
|