2015-12-03 13:11:01 +00:00
|
|
|
/* global $, JitsiMeetJS, config, Promise */
|
2013-12-16 11:22:23 +00:00
|
|
|
/* application specific logic */
|
2014-05-12 09:56:33 +00:00
|
|
|
|
2015-09-10 17:15:56 +00:00
|
|
|
require("jquery");
|
|
|
|
require("jquery-ui");
|
|
|
|
require("strophe");
|
|
|
|
require("strophe-disco");
|
|
|
|
require("strophe-caps");
|
|
|
|
require("tooltip");
|
|
|
|
require("popover");
|
|
|
|
window.toastr = require("toastr");
|
|
|
|
require("jQuery-Impromptu");
|
|
|
|
require("autosize");
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
var CQEvents = require('./service/connectionquality/CQEvents');
|
|
|
|
var UIEvents = require('./service/UI/UIEvents');
|
|
|
|
|
2015-12-02 13:05:29 +00:00
|
|
|
var Commands = {
|
2015-12-02 15:24:57 +00:00
|
|
|
CONNECTION_QUALITY: "connectionQuality",
|
|
|
|
EMAIL: "email"
|
2015-12-02 13:05:29 +00:00
|
|
|
};
|
|
|
|
|
2015-11-30 11:54:54 +00:00
|
|
|
var APP = {
|
2015-01-28 14:35:22 +00:00
|
|
|
init: function () {
|
2015-12-03 13:11:01 +00:00
|
|
|
JitsiMeetJS.init();
|
|
|
|
JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
|
|
|
|
|
|
|
|
this.conference = {
|
|
|
|
localId: undefined,
|
|
|
|
isModerator: false,
|
|
|
|
membersCount: 0,
|
|
|
|
audioMuted: false,
|
|
|
|
videoMuted: false,
|
|
|
|
isLocalId: function (id) {
|
|
|
|
return this.localId === id;
|
|
|
|
},
|
|
|
|
muteAudio: function (mute) {
|
|
|
|
APP.UI.eventEmitter.emit(UIEvents.AUDIO_MUTED, mute);
|
|
|
|
},
|
|
|
|
toggleAudioMuted: function () {
|
|
|
|
this.muteAudio(!this.audioMuted);
|
|
|
|
},
|
|
|
|
muteVideo: function (mute) {
|
|
|
|
APP.UI.eventEmitter.emit(UIEvents.VIDEO_MUTED, mute);
|
|
|
|
},
|
|
|
|
toggleVideoMuted: function () {
|
|
|
|
this.muteVideo(!this.videoMuted);
|
|
|
|
}
|
|
|
|
};
|
2015-11-30 11:54:54 +00:00
|
|
|
|
2015-01-28 14:35:22 +00:00
|
|
|
this.UI = require("./modules/UI/UI");
|
|
|
|
this.API = require("./modules/API/API");
|
2015-09-11 02:42:15 +00:00
|
|
|
this.connectionquality =
|
|
|
|
require("./modules/connectionquality/connectionquality");
|
2015-01-28 14:35:22 +00:00
|
|
|
this.statistics = require("./modules/statistics/statistics");
|
2015-09-11 02:42:15 +00:00
|
|
|
this.desktopsharing =
|
|
|
|
require("./modules/desktopsharing/desktopsharing");
|
|
|
|
this.keyboardshortcut =
|
|
|
|
require("./modules/keyboardshortcut/keyboardshortcut");
|
2015-02-06 15:46:50 +00:00
|
|
|
this.translation = require("./modules/translation/translation");
|
2015-03-09 15:50:13 +00:00
|
|
|
this.settings = require("./modules/settings/Settings");
|
2015-08-21 12:33:05 +00:00
|
|
|
this.configFetch = require("./modules/config/HttpConfigFetch");
|
2015-01-28 14:35:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
|
|
|
|
var ConnectionEvents = JitsiMeetJS.events.connection;
|
|
|
|
var ConnectionErrors = JitsiMeetJS.errors.connection;
|
2015-11-30 11:54:54 +00:00
|
|
|
function connect() {
|
2015-12-03 13:11:01 +00:00
|
|
|
var connection = new JitsiMeetJS.JitsiConnection(null, null, {
|
2015-11-30 11:54:54 +00:00
|
|
|
hosts: config.hosts,
|
|
|
|
bosh: config.bosh,
|
|
|
|
clientNode: config.clientNode
|
|
|
|
});
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
2015-12-03 13:11:01 +00:00
|
|
|
var handlers = {};
|
|
|
|
|
|
|
|
var unsubscribe = function () {
|
|
|
|
Object.keys(handlers).forEach(function (event) {
|
|
|
|
connection.removeEventListener(event, handlers[event]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handlers[ConnectionEvents.CONNECTION_ESTABLISHED] = function () {
|
2015-11-30 11:54:54 +00:00
|
|
|
console.log('CONNECTED');
|
2015-12-03 13:11:01 +00:00
|
|
|
unsubscribe();
|
2015-11-30 11:54:54 +00:00
|
|
|
resolve(connection);
|
|
|
|
};
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
var listenForFailure = function (event) {
|
|
|
|
handlers[event] = function () {
|
|
|
|
// convert arguments to array
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
args.unshift(event);
|
|
|
|
// [event, ...params]
|
|
|
|
console.error('CONNECTION FAILED:', args);
|
|
|
|
|
|
|
|
unsubscribe();
|
|
|
|
reject(args);
|
|
|
|
};
|
2015-11-30 11:54:54 +00:00
|
|
|
};
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
listenForFailure(ConnectionEvents.CONNECTION_FAILED);
|
|
|
|
listenForFailure(ConnectionErrors.PASSWORD_REQUIRED);
|
|
|
|
listenForFailure(ConnectionErrors.CONNECTION_ERROR);
|
|
|
|
listenForFailure(ConnectionErrors.OTHER_ERRORS);
|
2015-11-30 11:54:54 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
// install event listeners
|
|
|
|
Object.keys(handlers).forEach(function (event) {
|
|
|
|
connection.addEventListener(event, handlers[event]);
|
|
|
|
});
|
2015-11-30 11:54:54 +00:00
|
|
|
|
|
|
|
connection.connect();
|
2015-12-03 13:11:01 +00:00
|
|
|
}).catch(function (err) {
|
|
|
|
if (err[0] === ConnectionErrors.PASSWORD_REQUIRED) {
|
|
|
|
// FIXME ask for password and try again
|
|
|
|
return connect();
|
|
|
|
}
|
|
|
|
console.error('FAILED TO CONNECT', err);
|
|
|
|
APP.UI.notifyConnectionFailed(err[1]);
|
2015-11-30 11:54:54 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
throw new Error(err[0]);
|
2015-11-30 11:54:54 +00:00
|
|
|
});
|
|
|
|
}
|
2014-11-06 13:54:47 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
var ConferenceEvents = JitsiMeetJS.events.conference;
|
|
|
|
var ConferenceErrors = JitsiMeetJS.errors.conference;
|
2015-11-30 11:54:54 +00:00
|
|
|
function initConference(connection, roomName) {
|
|
|
|
var room = connection.initJitsiConference(roomName, {
|
|
|
|
openSctp: config.openSctp,
|
|
|
|
disableAudioLevels: config.disableAudioLevels
|
|
|
|
});
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
var users = {};
|
|
|
|
var localTracks = [];
|
2015-11-30 15:24:42 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
APP.conference.localId = room.myUserId();
|
|
|
|
Object.defineProperty(APP.conference, "membersCount", {
|
|
|
|
get: function () {
|
|
|
|
return Object.keys(users).length; // FIXME maybe +1?
|
2015-11-30 11:54:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
room.on(ConferenceEvents.USER_JOINED, function (id) {
|
|
|
|
users[id] = {
|
|
|
|
displayName: undefined,
|
|
|
|
tracks: []
|
|
|
|
};
|
|
|
|
// FIXME email???
|
|
|
|
APP.UI.addUser(id);
|
|
|
|
});
|
|
|
|
room.on(ConferenceEvents.USER_LEFT, function (id) {
|
|
|
|
delete users[id];
|
|
|
|
APP.UI.removeUser(id);
|
|
|
|
});
|
2015-11-30 11:54:54 +00:00
|
|
|
|
2015-11-30 15:24:42 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
room.on(ConferenceEvents.TRACK_MUTE_CHANGED, function (track) {
|
|
|
|
// FIXME handle mute
|
|
|
|
});
|
|
|
|
room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, function (id, lvl) {
|
|
|
|
APP.UI.setAudioLevel(id, lvl);
|
|
|
|
});
|
|
|
|
APP.UI.addListener(UIEvents.AUDIO_MUTED, function (muted) {
|
|
|
|
// FIXME mute or unmute
|
|
|
|
APP.UI.setAudioMuted(muted);
|
|
|
|
APP.conference.audioMuted = muted;
|
|
|
|
});
|
|
|
|
APP.UI.addListener(UIEvents.VIDEO_MUTED, function (muted) {
|
|
|
|
// FIXME mute or unmute
|
|
|
|
APP.UI.setVideoMuted(muted);
|
|
|
|
APP.conference.videoMuted = muted;
|
|
|
|
});
|
2015-11-30 15:24:42 +00:00
|
|
|
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
|
|
|
|
if (config.muteLocalVideoIfNotInLastN) {
|
|
|
|
// TODO mute or unmute if required
|
|
|
|
// mark video on UI
|
|
|
|
// APP.UI.markVideoMuted(true/false);
|
2015-11-30 15:24:42 +00:00
|
|
|
}
|
2015-12-03 13:11:01 +00:00
|
|
|
});
|
|
|
|
room.on(ConferenceEvents.LAST_N_ENDPOINTS_CHANGED, function (ids) {
|
|
|
|
APP.UI.handleLastNEndpoints(ids);
|
|
|
|
});
|
|
|
|
room.on(ConferenceEvents.ACTIVE_SPEAKER_CHANGED, function (id) {
|
|
|
|
APP.UI.markDominantSpiker(id);
|
|
|
|
});
|
2015-11-30 15:24:42 +00:00
|
|
|
|
2015-12-01 10:05:55 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
|
|
|
|
APP.UI.markVideoInterrupted(true);
|
|
|
|
});
|
|
|
|
room.on(ConferenceEvents.CONNECTION_RESTORED, function () {
|
|
|
|
APP.UI.markVideoInterrupted(false);
|
|
|
|
});
|
2015-12-01 10:05:55 +00:00
|
|
|
|
2015-11-30 15:24:42 +00:00
|
|
|
|
2015-12-02 13:05:29 +00:00
|
|
|
APP.connectionquality.addListener(
|
|
|
|
CQEvents.LOCALSTATS_UPDATED,
|
|
|
|
function (percent, stats) {
|
|
|
|
APP.UI.updateLocalStats(percent, stats);
|
|
|
|
|
|
|
|
// send local stats to other users
|
|
|
|
room.sendCommand(Commands.CONNECTION_QUALITY, {
|
|
|
|
value: APP.connectionquality.convertToMUCStats(stats),
|
|
|
|
attributes: {
|
|
|
|
id: room.myUserId()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 13:11:01 +00:00
|
|
|
APP.connectionquality.addListener(CQEvents.STOP, function () {
|
|
|
|
APP.UI.hideStats();
|
|
|
|
room.removeCommand(Commands.CONNECTION_QUALITY);
|
|
|
|
});
|
2015-12-02 13:05:29 +00:00
|
|
|
// listen to remote stats
|
|
|
|
room.addCommandListener(Commands.CONNECTION_QUALITY, function (data) {
|
|
|
|
APP.connectionquality.updateRemoteStats(data.attributes.id, data.value);
|
|
|
|
});
|
|
|
|
APP.connectionquality.addListener(
|
|
|
|
CQEvents.REMOTESTATS_UPDATED,
|
|
|
|
function (id, percent, stats) {
|
|
|
|
APP.UI.updateRemoteStats(id, percent, stats);
|
|
|
|
}
|
|
|
|
);
|
2015-11-30 15:24:42 +00:00
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
|
|
|
|
// share email with other users
|
2015-12-02 15:24:57 +00:00
|
|
|
function sendEmail(email) {
|
|
|
|
room.sendCommand(Commands.EMAIL, {
|
|
|
|
value: email,
|
|
|
|
attributes: {
|
|
|
|
id: room.myUserId()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
var email = APP.settings.getEmail();
|
|
|
|
email && sendEmail(email);
|
2015-12-02 15:24:57 +00:00
|
|
|
APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
|
|
|
|
APP.settings.setEmail(email);
|
2015-12-03 13:11:01 +00:00
|
|
|
APP.UI.setUserAvatar(room.myUserId(), email);
|
2015-12-02 15:24:57 +00:00
|
|
|
sendEmail(email);
|
|
|
|
});
|
|
|
|
room.addCommandListener(Commands.EMAIL, function (data) {
|
|
|
|
APP.UI.setUserAvatar(data.attributes.id, data.value);
|
|
|
|
});
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
|
|
|
|
room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, function (id, displayName) {
|
|
|
|
APP.UI.changeDisplayName(id, displayName);
|
|
|
|
});
|
|
|
|
APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
|
|
|
|
APP.settings.setDisplayName(nickname);
|
|
|
|
room.setDisplayName(nickname);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
|
|
|
|
room.sendTextMessage(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
|
|
|
|
// FIXME handle
|
|
|
|
});
|
|
|
|
room.on(ConferenceErrors.CONNECTION_ERROR, function () {
|
|
|
|
// FIXME handle
|
|
|
|
});
|
|
|
|
|
|
|
|
APP.UI.addListener(
|
|
|
|
UIEvents.START_MUTED_CHANGED,
|
|
|
|
function (startAudioMuted, startVideoMuted) {
|
|
|
|
// FIXME start muted
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-11-30 15:24:42 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
room.on(
|
|
|
|
ConferenceEvents.CONFERENCE_JOINED,
|
|
|
|
function () {
|
2015-12-03 13:11:01 +00:00
|
|
|
resolve();
|
2015-12-01 12:53:01 +00:00
|
|
|
}
|
|
|
|
);
|
2015-11-30 15:24:42 +00:00
|
|
|
APP.UI.closeAuthenticationDialog();
|
|
|
|
if (config.useNicks) {
|
|
|
|
// FIXME check this
|
|
|
|
var nick = APP.UI.askForNickname();
|
|
|
|
}
|
|
|
|
room.join();
|
2015-12-03 13:11:01 +00:00
|
|
|
}).catch(function (err) {
|
|
|
|
if (err[0] === ConferenceErrors.PASSWORD_REQUIRED) {
|
|
|
|
// FIXME ask for password and try again
|
|
|
|
return initConference(connection, roomName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME else notify that we cannot conenct to the room
|
|
|
|
|
|
|
|
throw new Error(err[0]);
|
2015-11-30 15:24:42 +00:00
|
|
|
});
|
2015-11-30 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
connect().then(function (connection) {
|
2015-12-01 10:05:55 +00:00
|
|
|
return initConference(connection, APP.UI.generateRoomName());
|
2015-12-03 13:11:01 +00:00
|
|
|
}).then(function () {
|
2015-12-01 12:53:01 +00:00
|
|
|
APP.UI.start();
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
APP.UI.initConference();
|
2015-12-01 12:53:01 +00:00
|
|
|
|
2015-12-01 13:41:58 +00:00
|
|
|
APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
|
|
|
|
APP.translation.setLanguage(language);
|
|
|
|
APP.settings.setLanguage(language);
|
|
|
|
});
|
|
|
|
|
2015-11-30 11:54:54 +00:00
|
|
|
APP.desktopsharing.init();
|
|
|
|
APP.statistics.start();
|
|
|
|
APP.connectionquality.init();
|
|
|
|
APP.keyboardshortcut.init();
|
|
|
|
});
|
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-10-20 15:41:15 +00:00
|
|
|
var roomName = APP.UI.getRoomNode();
|
|
|
|
|
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) {
|
2015-10-06 21:36:41 +00:00
|
|
|
console.log("(TIME) configuration fetched:\t",
|
|
|
|
window.performance.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 () {
|
2015-10-06 21:36:41 +00:00
|
|
|
console.log("(TIME) document ready:\t", window.performance.now());
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-08-21 12:33:05 +00:00
|
|
|
var URLProcessor = require("./modules/config/URLProcessor");
|
2015-07-22 18:34:44 +00:00
|
|
|
URLProcessor.setConfigParametersFromUrl();
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.init();
|
2014-08-21 16:42:54 +00:00
|
|
|
|
2015-02-06 15:46:50 +00:00
|
|
|
APP.translation.init();
|
|
|
|
|
2015-12-03 13:11:01 +00:00
|
|
|
if (APP.API.isEnabled()) {
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.API.init();
|
2015-11-30 11:54:54 +00:00
|
|
|
}
|
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 () {
|
2015-12-03 13:11:01 +00:00
|
|
|
if (APP.API.isEnabled()) {
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.API.dispose();
|
2015-12-03 13:11:01 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
});
|
|
|
|
|
2015-01-28 14:35:22 +00:00
|
|
|
module.exports = APP;
|