do not use XMPP or RTC modules in UI

pull/421/head
isymchych 9 years ago
parent 59f98205c7
commit 4ef57ceada
  1. 1
      .jshintignore
  2. 78
      app.js
  3. 269
      modules/UI/UI.js

@ -2,6 +2,7 @@ node_modules
libs libs
debian debian
analytics.js analytics.js
lib-jitsi-meet.js
modules/xmpp/strophe.emuc.js modules/xmpp/strophe.emuc.js
modules/UI/prezi/Prezi.js modules/UI/prezi/Prezi.js

@ -32,13 +32,19 @@ function createConference(connection, room) {
toggleVideoMuted: function () { toggleVideoMuted: function () {
APP.UI.setVideoMuted(muted); APP.UI.setVideoMuted(muted);
},
setNickname: function (nickname) {
// FIXME check if room is available etc.
room.setDisplayName(nickname);
} }
}; };
} }
var APP = { var APP = {
JitsiMeetJS: JitsiMeetJS,
init: function () { init: function () {
this.JitsiMeetJS = JitsiMeetJS;
this.JitsiMeetJS.init(); this.JitsiMeetJS.init();
this.conference = null; this.conference = null;
@ -113,12 +119,15 @@ function connect() {
} }
var ConferenceEvents = APP.JitsiMeetJS.events.conference; var ConferenceEvents = APP.JitsiMeetJS.events.conference;
var ConferenceErrors = APP.JitsiMeetJS.errors.conference;
function initConference(connection, roomName) { function initConference(connection, roomName) {
var room = connection.initJitsiConference(roomName, { var room = connection.initJitsiConference(roomName, {
openSctp: config.openSctp, openSctp: config.openSctp,
disableAudioLevels: config.disableAudioLevels disableAudioLevels: config.disableAudioLevels
}); });
var conf = createConference(connection, room);
room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) { room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
if (config.muteLocalVideoIfNotInLastN) { if (config.muteLocalVideoIfNotInLastN) {
// TODO mute or unmute if required // TODO mute or unmute if required
@ -140,7 +149,64 @@ function initConference(connection, roomName) {
} }
); );
return initConference(connection, room); room.on(
ConferenceEvents.DISPLAY_NAME_CHANGED,
function (id, displayName) {
UI.changeDisplayName(id, displayName);
}
);
room.on(
ConferenceEvents.USER_JOINED,
function (id) {
// FIXME ????
UI.addUser();
}
);
room.on(
ConferenceEvents.USER_LEFT,
function (id) {
UI.removeUser(id);
}
);
room.on(
ConferenceEvents.TRACK_MUTE_CHANGED,
function (track) {
// FIXME handle mute
}
);
room.on(
ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
function (id, lvl) {
UI.setAudioLevel(id, lvl);
}
);
return new Promise(function (resolve, reject) {
room.on(
ConferenceEvents.CONFERENCE_JOINED,
function () {
resolve(conf);
}
);
room.on(
ConferenceErrors.PASSWORD_REQUIRED,
function () {
// FIXME handle
reject();
}
);
APP.UI.closeAuthenticationDialog();
if (config.useNicks) {
// FIXME check this
var nick = APP.UI.askForNickname();
}
room.join();
});
} }
function init() { function init() {
@ -148,6 +214,14 @@ function init() {
return initConference(connection, UI.generateRoomName()); return initConference(connection, UI.generateRoomName());
}).then(function (conference) { }).then(function (conference) {
APP.conference = conference; APP.conference = conference;
APP.UI.initConference();
//NicknameHandler emits this event
APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
APP.conference.setNickname(nickname);
});
APP.desktopsharing.init(); APP.desktopsharing.init();
APP.statistics.start(); APP.statistics.start();
APP.connectionquality.init(); APP.connectionquality.init();

@ -26,7 +26,6 @@ var JitsiPopover = require("./util/JitsiPopover");
var CQEvents = require("../../service/connectionquality/CQEvents"); var CQEvents = require("../../service/connectionquality/CQEvents");
var DesktopSharingEventTypes var DesktopSharingEventTypes
= require("../../service/desktopsharing/DesktopSharingEventTypes"); = require("../../service/desktopsharing/DesktopSharingEventTypes");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var StatisticsEvents = require("../../service/statistics/Events"); var StatisticsEvents = require("../../service/statistics/Events");
var UIEvents = require("../../service/UI/UIEvents"); var UIEvents = require("../../service/UI/UIEvents");
var MemberEvents = require("../../service/members/Events"); var MemberEvents = require("../../service/members/Events");
@ -101,25 +100,14 @@ function setupToolbars() {
BottomToolbar.init(eventEmitter); BottomToolbar.init(eventEmitter);
} }
function onDisposeConference(unload) { UI.notifyGracefulShudown = function () {
Toolbar.showAuthenticateButton(false);
}
function onDisplayNameChanged(jid, displayName) {
ContactList.onDisplayNameChange(jid, displayName);
SettingsMenu.onDisplayNameChange(jid, displayName);
VideoLayout.onDisplayNameChanged(jid, displayName);
}
function registerListeners() {
APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
APP.xmpp.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
messageHandler.openMessageDialog( messageHandler.openMessageDialog(
'dialog.serviceUnavailable', 'dialog.serviceUnavailable',
'dialog.gracefulShutdown' 'dialog.gracefulShutdown'
); );
}); };
APP.xmpp.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
UI.notifyReservationError = function (code, msg) {
var title = APP.translation.generateTranslationHTML( var title = APP.translation.generateTranslationHTML(
"dialog.reservationError"); "dialog.reservationError");
var message = APP.translation.generateTranslationHTML( var message = APP.translation.generateTranslationHTML(
@ -132,98 +120,54 @@ function registerListeners() {
return false; return false;
} }
); );
}); };
APP.xmpp.addListener(XMPPEvents.KICKED, function () {
messageHandler.openMessageDialog("dialog.sessTerminated",
"dialog.kickMessage");
});
APP.xmpp.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
//FIXME: use Session Terminated from translation, but
// 'reason' text comes from XMPP packet and is not translated
var title = APP.translation.generateTranslationHTML("dialog.sessTerminated");
messageHandler.openDialog(
title, reason, true, {},
function (event, value, message, formVals) {
return false;
}
);
});
APP.xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
messageHandler.showError("dialog.error",
"dialog.bridgeUnavailable");
});
APP.xmpp.addListener(XMPPEvents.USER_ID_CHANGED, function (from, id) {
Avatar.setUserAvatar(from, id);
});
APP.xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
APP.xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
APP.xmpp.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, onLocalRoleChanged);
APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, onMucMemberJoined);
APP.xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
APP.xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
APP.xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, onMucMemberLeft);
APP.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordRequired);
APP.xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
APP.xmpp.addListener(XMPPEvents.AUTHENTICATION_REQUIRED,
onAuthenticationRequired);
APP.xmpp.addListener(XMPPEvents.PARTICIPANT_VIDEO_TYPE_CHANGED,
onPeerVideoTypeChanged);
APP.xmpp.addListener(XMPPEvents.DEVICE_AVAILABLE,
function (resource, devices) {
VideoLayout.setDeviceAvailabilityIcons(resource, devices);
});
APP.xmpp.addListener(XMPPEvents.PARTICIPANT_AUDIO_MUTED, UI.notifyKicked = function () {
VideoLayout.onAudioMute); messageHandler.openMessageDialog("dialog.sessTerminated", "dialog.kickMessage");
APP.xmpp.addListener(XMPPEvents.PARTICIPANT_VIDEO_MUTED, };
VideoLayout.onVideoMute);
APP.members.addListener(MemberEvents.DTMF_SUPPORT_CHANGED,
onDtmfSupportChanged);
APP.xmpp.addListener(XMPPEvents.START_MUTED_SETTING_CHANGED, function (audio, video) {
SettingsMenu.setStartMuted(audio, video);
});
APP.xmpp.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function (session, error) { UI.notifyBridgeDown = function () {
UI.messageHandler.showError("dialog.sorry", messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
"dialog.internalError"); };
});
APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) { UI.changeDisplayName = function (jid, displayName) {
// FIXME: re-use LoginDialog which supports retries ContactList.onDisplayNameChange(jid, displayName);
if (config.token) { SettingsMenu.onDisplayNameChange(jid, displayName);
messageHandler.showError("dialog.error", "dialog.tokenAuthFailed"); VideoLayout.onDisplayNameChanged(jid, displayName);
} else { };
UI.showLoginPopup(callback);
}
});
APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) { UI.initConference = function () {
UI.messageHandler.notify( // FIXME find own jid
null, "notify.focus", var jid = "asdfasdf";
'disconnected', "notify.focusFail",
{component: focusComponent, ms: retrySec});
});
APP.xmpp.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) { Toolbar.updateRoomUrl(window.location.href);
UI.messageHandler.openReportDialog(null, var meHTML = APP.translation.generateTranslationHTML("me");
"dialog.connectError", pres); $("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
});
APP.xmpp.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
UI.messageHandler.openReportDialog(null,
"dialog.connectError", pres);
});
APP.xmpp.addListener(XMPPEvents.READY_TO_JOIN, function () { var settings = Settings.getSettings();
var roomName = UI.generateRoomName();
APP.xmpp.allocateConferenceFocus(roomName, UI.checkForNicknameAndJoin);
});
//NicknameHandler emits this event // Make sure we configure our avatar id, before creating avatar for us
UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) { Avatar.setUserAvatar(jid, settings.email || settings.uid);
APP.xmpp.addToPresence("displayName", nickname);
}); // Add myself to the contact list.
ContactList.addContact(jid);
// Once we've joined the muc show the toolbar
ToolbarToggler.showToolbar();
var displayName =
config.displayJids ? Strophe.getResourceFromJid(jid) : settings.displayName;
if (displayName) {
UI.changeDisplayName('localVideoContainer', displayName);
}
VideoLayout.mucJoined();
Toolbar.checkAutoEnableDesktopSharing();
};
function registerListeners() {
UI.addListener(UIEvents.LARGEVIDEO_INIT, function () { UI.addListener(UIEvents.LARGEVIDEO_INIT, function () {
AudioLevels.init(); AudioLevels.init();
}); });
@ -231,15 +175,6 @@ function registerListeners() {
UI.addListener(UIEvents.FILM_STRIP_TOGGLED, function (isToggled) { UI.addListener(UIEvents.FILM_STRIP_TOGGLED, function (isToggled) {
VideoLayout.onFilmStripToggled(isToggled); VideoLayout.onFilmStripToggled(isToggled);
}); });
if (!interfaceConfig.filmStripOnly) {
APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
// Listens for video interruption events.
APP.xmpp.addListener(XMPPEvents.CONNECTION_INTERRUPTED, VideoLayout.onVideoInterrupted);
// Listens for video restores events.
APP.xmpp.addListener(XMPPEvents.CONNECTION_RESTORED, VideoLayout.onVideoRestored);
}
} }
function onResize() { function onResize() {
@ -296,7 +231,8 @@ UI.start = function () {
$('#notice').css({display: 'block'}); $('#notice').css({display: 'block'});
} }
$("#downloadlog").click(function (event) { $("#downloadlog").click(function (event) {
dump(event.target); // dump(event.target);
// FIXME integrate logs
}); });
Feedback.init(); Feedback.init();
} }
@ -388,55 +324,10 @@ function updateChatConversation(from, displayName, message, myjid, stamp) {
return Chat.updateChatConversation(from, displayName, message, myjid, stamp); return Chat.updateChatConversation(from, displayName, message, myjid, stamp);
} }
function onMucJoined(jid, info) {
Toolbar.updateRoomUrl(window.location.href);
var meHTML = APP.translation.generateTranslationHTML("me");
$("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
var settings = Settings.getSettings();
// Make sure we configure our avatar id, before creating avatar for us
Avatar.setUserAvatar(jid, settings.email || settings.uid);
// Add myself to the contact list.
ContactList.addContact(jid);
// Once we've joined the muc show the toolbar
ToolbarToggler.showToolbar();
var displayName =
config.displayJids ? Strophe.getResourceFromJid(jid) : info.displayName;
if (displayName)
onDisplayNameChanged('localVideoContainer', displayName);
VideoLayout.mucJoined();
Toolbar.checkAutoEnableDesktopSharing();
}
function initEtherpad(name) { function initEtherpad(name) {
Etherpad.init(name); Etherpad.init(name);
} }
function onMucMemberLeft(jid) {
console.log('left.muc', jid);
var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
'>.displayname').html();
messageHandler.notify(displayName,'notify.somebody',
'disconnected',
'notify.disconnected');
if (!config.startAudioMuted ||
config.startAudioMuted > APP.members.size()) {
UIUtil.playSoundNotification('userLeft');
}
ContactList.removeContact(jid);
VideoLayout.participantLeft(jid);
}
function onLocalRoleChanged(jid, info, pres, isModerator) { function onLocalRoleChanged(jid, info, pres, isModerator) {
console.info("My role changed, new role: " + info.role); console.info("My role changed, new role: " + info.role);
onModeratorStatusChanged(isModerator); onModeratorStatusChanged(isModerator);
@ -462,7 +353,7 @@ function onModeratorStatusChanged(isModerator) {
//Object.keys(connection.emuc.members).length >= 3); //Object.keys(connection.emuc.members).length >= 3);
} }
function onPasswordRequired(callback) { UI.notifyPasswordRequired = function (callback) {
// password is required // password is required
Toolbar.lockLockButton(); Toolbar.lockLockButton();
var message = '<h2 data-i18n="dialog.passwordRequired">'; var message = '<h2 data-i18n="dialog.passwordRequired">';
@ -490,7 +381,7 @@ function onPasswordRequired(callback) {
}, },
':input:first' ':input:first'
); );
} };
/** /**
* The dialpad button is shown iff there is at least one member that supports * The dialpad button is shown iff there is at least one member that supports
@ -501,7 +392,7 @@ function onDtmfSupportChanged(dtmfSupport) {
//Toolbar.showDialPadButton(dtmfSupport); //Toolbar.showDialPadButton(dtmfSupport);
} }
function onMucMemberJoined(jid, id, displayName) { UI.addUser = function (jid, id, displayName) {
messageHandler.notify(displayName,'notify.somebody', messageHandler.notify(displayName,'notify.somebody',
'connected', 'connected',
'notify.connected'); 'notify.connected');
@ -515,7 +406,24 @@ function onMucMemberJoined(jid, id, displayName) {
// Add Peer's container // Add Peer's container
VideoLayout.ensurePeerContainerExists(jid); VideoLayout.ensurePeerContainerExists(jid);
} };
UI.removeUser = function (jid) {
console.log('left.muc', jid);
var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
'>.displayname').html();
messageHandler.notify(displayName,'notify.somebody',
'disconnected',
'notify.disconnected');
if (!config.startAudioMuted ||
config.startAudioMuted > APP.members.size()) {
UIUtil.playSoundNotification('userLeft');
}
ContactList.removeContact(jid);
VideoLayout.participantLeft(jid);
};
function onMucPresenceStatus(jid, info) { function onMucPresenceStatus(jid, info) {
VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status); VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
@ -544,12 +452,13 @@ function onMucRoleChanged(role, displayName) {
} }
} }
function onAuthenticationRequired(intervalCallback) { UI.notifyAuthRequired = function (intervalCallback) {
Authentication.openAuthenticationDialog( Authentication.openAuthenticationDialog(
roomName, intervalCallback, function () { roomName, intervalCallback, function () {
Toolbar.authenticateClicked(); Toolbar.authenticateClicked();
}); }
} );
};
UI.toggleSmileys = function () { UI.toggleSmileys = function () {
@ -655,36 +564,14 @@ UI.showLoginPopup = function(callback) {
); );
}; };
UI.checkForNicknameAndJoin = function () { UI.closeAuthenticationDialog = function () {
Authentication.closeAuthenticationDialog(); Authentication.closeAuthenticationDialog();
Authentication.stopInterval(); Authentication.stopInterval();
};
var nick = null; UI.askForNickname = function () {
if (config.useNicks) { return window.prompt('Your nickname (optional)');
nick = window.prompt('Your nickname (optional)'); };
}
APP.xmpp.joinRoom(roomName, config.useNicks, nick);
};
function dump(elem, filename) {
elem = elem.parentNode;
elem.download = filename || 'meetlog.json';
elem.href = 'data:application/json;charset=utf-8,\n';
var data = APP.xmpp.getJingleLog();
var metadata = {};
metadata.time = new Date();
metadata.url = window.location.href;
metadata.ua = navigator.userAgent;
var log = APP.xmpp.getXmppLog();
if (log) {
metadata.xmpp = log;
}
data.metadata = metadata;
elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
return false;
}
UI.getRoomName = function () { UI.getRoomName = function () {
return roomName; return roomName;
@ -798,4 +685,8 @@ UI.updateRemoteStats = function (jid, percent, stats) {
VideoLayout.updateConnectionStats(jid, percent, stats); VideoLayout.updateConnectionStats(jid, percent, stats);
}; };
UI.showAuthenticateButton = function (show) {
Toolbar.showAuthenticateButton(show);
};
module.exports = UI; module.exports = UI;

Loading…
Cancel
Save