do not use NicknameHandler

This commit is contained in:
isymchych 2015-12-01 14:53:01 +02:00
parent 4152106a06
commit c50151d85d
9 changed files with 52 additions and 91 deletions

26
app.js
View File

@ -36,14 +36,19 @@ function createConference(connection, room) {
setNickname: function (nickname) { setNickname: function (nickname) {
// FIXME check if room is available etc. // FIXME check if room is available etc.
APP.settings.setDisplayName(nickname);
room.setDisplayName(nickname); room.setDisplayName(nickname);
}, },
sendMessage: function (message) {
room.sendTextMessage(message);
},
isModerator: function () { isModerator: function () {
return false; return false;
}, },
myJid: function () { localId: function () {
return room.myUserId(); return room.myUserId();
} }
}; };
@ -54,6 +59,7 @@ var APP = {
init: function () { init: function () {
this.JitsiMeetJS.init(); this.JitsiMeetJS.init();
this.JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
this.conference = null; this.conference = null;
this.UI = require("./modules/UI/UI"); this.UI = require("./modules/UI/UI");
@ -222,6 +228,13 @@ function initConference(connection, roomName) {
reject(); reject();
} }
); );
room.on(
ConferenceErrors.CONNECTION_ERROR,
function () {
// FIXME handle
reject();
}
);
APP.UI.closeAuthenticationDialog(); APP.UI.closeAuthenticationDialog();
if (config.useNicks) { if (config.useNicks) {
// FIXME check this // FIXME check this
@ -237,13 +250,19 @@ function init() {
}).then(function (conference) { }).then(function (conference) {
APP.conference = conference; APP.conference = conference;
APP.UI.initConference(); APP.UI.start();
// FIXME find own jid
APP.UI.initConference("asdfasdf");
//NicknameHandler emits this event
APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) { APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
APP.conference.setNickname(nickname); APP.conference.setNickname(nickname);
}); });
APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
APP.conference.sendMessage(message);
});
APP.desktopsharing.init(); APP.desktopsharing.init();
APP.statistics.start(); APP.statistics.start();
APP.connectionquality.init(); APP.connectionquality.init();
@ -301,7 +320,6 @@ $(document).ready(function () {
APP.API.init(); APP.API.init();
} }
APP.UI.start();
obtainConfigAndInit(); obtainConfigAndInit();
}); });

View File

@ -21,7 +21,6 @@ UI.messageHandler = require("./util/MessageHandler");
var messageHandler = UI.messageHandler; var messageHandler = UI.messageHandler;
var Authentication = require("./authentication/Authentication"); var Authentication = require("./authentication/Authentication");
var UIUtil = require("./util/UIUtil"); var UIUtil = require("./util/UIUtil");
var NicknameHandler = require("./util/NicknameHandler");
var JitsiPopover = require("./util/JitsiPopover"); var JitsiPopover = require("./util/JitsiPopover");
var CQEvents = require("../../service/connectionquality/CQEvents"); var CQEvents = require("../../service/connectionquality/CQEvents");
var DesktopSharingEventTypes var DesktopSharingEventTypes
@ -59,7 +58,7 @@ function promptDisplayName() {
if (v == "ok") { if (v == "ok") {
var displayName = f.displayName; var displayName = f.displayName;
if (displayName) { if (displayName) {
VideoLayout.inputDisplayNameHandler(displayName); UI.inputDisplayNameHandler(displayName);
return true; return true;
} }
} }
@ -88,7 +87,7 @@ function setupPrezi() {
} }
function setupChat() { function setupChat() {
Chat.init(); Chat.init(eventEmitter);
$("#toggle_smileys").click(function() { $("#toggle_smileys").click(function() {
Chat.toggleSmileys(); Chat.toggleSmileys();
}); });
@ -136,13 +135,11 @@ UI.changeDisplayName = function (jid, displayName) {
VideoLayout.onDisplayNameChanged(jid, displayName); VideoLayout.onDisplayNameChanged(jid, displayName);
}; };
UI.initConference = function () { UI.initConference = function (jid) {
// FIXME find own jid
var jid = "asdfasdf";
Toolbar.updateRoomUrl(window.location.href); Toolbar.updateRoomUrl(window.location.href);
var meHTML = APP.translation.generateTranslationHTML("me"); var meHTML = APP.translation.generateTranslationHTML("me");
$("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")"); var localId = APP.conference.localId();
$("#localNick").html(localId + " (" + meHTML + ")");
var settings = Settings.getSettings(); var settings = Settings.getSettings();
@ -155,8 +152,7 @@ UI.initConference = function () {
// Once we've joined the muc show the toolbar // Once we've joined the muc show the toolbar
ToolbarToggler.showToolbar(); ToolbarToggler.showToolbar();
var displayName = var displayName = config.displayJids ? localId : settings.displayName;
config.displayJids ? Strophe.getResourceFromJid(jid) : settings.displayName;
if (displayName) { if (displayName) {
UI.changeDisplayName('localVideoContainer', displayName); UI.changeDisplayName('localVideoContainer', displayName);
@ -211,11 +207,9 @@ UI.start = function () {
// Set the defaults for prompt dialogs. // Set the defaults for prompt dialogs.
$.prompt.setDefaults({persistent: false}); $.prompt.setDefaults({persistent: false});
registerListeners(); registerListeners();
VideoLayout.init(eventEmitter); VideoLayout.init(eventEmitter);
NicknameHandler.init(eventEmitter);
bindEvents(); bindEvents();
setupPrezi(); setupPrezi();
@ -251,13 +245,8 @@ UI.start = function () {
document.title = interfaceConfig.APP_NAME; document.title = interfaceConfig.APP_NAME;
if(config.requireDisplayName) { if(config.requireDisplayName) {
var currentSettings = Settings.getSettings(); if (APP.settings.getDisplayName()) {
if (!currentSettings.displayName) {
promptDisplayName(); promptDisplayName();
} }
} }
@ -667,8 +656,6 @@ UI.setAudioLevel = function (targetJid, lvl) {
); );
}; };
UI.showToolbar = ToolbarToggler.showToolbar;
UI.updateDesktopSharingButtons = function () { UI.updateDesktopSharingButtons = function () {
Toolbar.changeDesktopSharingButtonState(); Toolbar.changeDesktopSharingButtonState();
}; };

View File

@ -1,9 +1,8 @@
/* global APP, $, Util, nickname:true */ /* global APP, $ */
var Replacement = require("./Replacement"); var Replacement = require("./Replacement");
var CommandsProcessor = require("./Commands"); var CommandsProcessor = require("./Commands");
var ToolbarToggler = require("../../toolbars/ToolbarToggler"); var ToolbarToggler = require("../../toolbars/ToolbarToggler");
var smileys = require("./smileys.json").smileys; var smileys = require("./smileys.json").smileys;
var NicknameHandler = require("../../util/NicknameHandler");
var UIUtil = require("../../util/UIUtil"); var UIUtil = require("../../util/UIUtil");
var UIEvents = require("../../../../service/UI/UIEvents"); var UIEvents = require("../../../../service/UI/UIEvents");
@ -169,22 +168,18 @@ var Chat = (function (my) {
/** /**
* Initializes chat related interface. * Initializes chat related interface.
*/ */
my.init = function () { my.init = function (eventEmitter) {
if(NicknameHandler.getNickname()) if (APP.settings.getDisplayName()) {
Chat.setChatConversationMode(true); Chat.setChatConversationMode(true);
NicknameHandler.addListener(UIEvents.NICKNAME_CHANGED, }
function (nickname) {
Chat.setChatConversationMode(true);
});
$('#nickinput').keydown(function (event) { $('#nickinput').keydown(function (event) {
if (event.keyCode === 13) { if (event.keyCode === 13) {
event.preventDefault(); event.preventDefault();
var val = UIUtil.escapeHtml(this.value); var val = UIUtil.escapeHtml(this.value);
this.value = ''; this.value = '';
if (!NicknameHandler.getNickname()) { if (APP.settings.getDisplayName()) {
NicknameHandler.setNickname(val); eventEmitter.emit(UIEvents.NICKNAME_CHANGED, val);
return; return;
} }
} }
@ -203,8 +198,7 @@ var Chat = (function (my) {
} }
else { else {
var message = UIUtil.escapeHtml(value); var message = UIUtil.escapeHtml(value);
APP.xmpp.sendChatMessage(message, eventEmitter.emit(UIEvents.MESSAGE_CREATED, message);
NicknameHandler.getNickname());
} }
} }
}); });

View File

@ -34,7 +34,7 @@ var SettingsMenu = {
} }
}); });
if (APP.xmpp.isModerator()) { if (APP.conference.isModerator()) {
startMutedSelector.css("display", "block"); startMutedSelector.css("display", "block");
} }
else { else {
@ -47,7 +47,7 @@ var SettingsMenu = {
}, },
onRoleChanged: function () { onRoleChanged: function () {
if(APP.xmpp.isModerator()) { if(APP.conference.isModerator()) {
$("#startMutedOptions").css("display", "block"); $("#startMutedOptions").css("display", "block");
} }
else { else {

View File

@ -1,30 +0,0 @@
var UIEvents = require("../../../service/UI/UIEvents");
var nickname = null;
var eventEmitter = null;
var NicknameHandler = {
init: function (emitter) {
eventEmitter = emitter;
var storedDisplayName = window.localStorage.displayname;
if (storedDisplayName) {
nickname = storedDisplayName;
}
},
setNickname: function (newNickname) {
if (!newNickname || nickname === newNickname)
return;
nickname = newNickname;
window.localStorage.displayname = nickname;
eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newNickname);
},
getNickname: function () {
return nickname;
},
addListener: function (type, listener) {
eventEmitter.on(type, listener);
}
};
module.exports = NicknameHandler;

View File

@ -1,12 +1,12 @@
/* global $, interfaceConfig, APP */ /* global $, interfaceConfig, APP */
var SmallVideo = require("./SmallVideo"); var SmallVideo = require("./SmallVideo");
var ConnectionIndicator = require("./ConnectionIndicator"); var ConnectionIndicator = require("./ConnectionIndicator");
var NicknameHandler = require("../util/NicknameHandler");
var UIUtil = require("../util/UIUtil"); var UIUtil = require("../util/UIUtil");
var UIEvents = require("../../../service/UI/UIEvents");
var LargeVideo = require("./LargeVideo"); var LargeVideo = require("./LargeVideo");
var RTCBrowserType = require("../../RTC/RTCBrowserType"); var RTCBrowserType = require("../../RTC/RTCBrowserType");
function LocalVideo(VideoLayout) { function LocalVideo(VideoLayout, emitter) {
this.videoSpanId = "localVideoContainer"; this.videoSpanId = "localVideoContainer";
this.container = $("#localVideoContainer").get(0); this.container = $("#localVideoContainer").get(0);
this.bindHoverHandler(); this.bindHoverHandler();
@ -14,6 +14,7 @@ function LocalVideo(VideoLayout) {
this.flipX = true; this.flipX = true;
this.isLocal = true; this.isLocal = true;
this.peerJid = null; this.peerJid = null;
this.emitter = emitter;
} }
LocalVideo.prototype = Object.create(SmallVideo.prototype); LocalVideo.prototype = Object.create(SmallVideo.prototype);
@ -117,11 +118,13 @@ LocalVideo.prototype.setDisplayName = function(displayName, key) {
editDisplayName.one("focusout", function (e) { editDisplayName.one("focusout", function (e) {
self.VideoLayout.inputDisplayNameHandler(this.value); self.VideoLayout.inputDisplayNameHandler(this.value);
$('#editDisplayName').hide();
}); });
editDisplayName.on('keydown', function (e) { editDisplayName.on('keydown', function (e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
e.preventDefault(); e.preventDefault();
$('#editDisplayName').hide();
self.VideoLayout.inputDisplayNameHandler(this.value); self.VideoLayout.inputDisplayNameHandler(this.value);
} }
}); });
@ -130,25 +133,7 @@ LocalVideo.prototype.setDisplayName = function(displayName, key) {
}; };
LocalVideo.prototype.inputDisplayNameHandler = function (name) { LocalVideo.prototype.inputDisplayNameHandler = function (name) {
name = UIUtil.escapeHtml(name); this.emitter.emit(UIEvents.NICKNAME_CHANGED, UIUtil.escapeHtml(name));
NicknameHandler.setNickname(name);
var localDisplayName = $('#localDisplayName');
if (!localDisplayName.is(":visible")) {
if (NicknameHandler.getNickname()) {
var meHTML = APP.translation.generateTranslationHTML("me");
localDisplayName.html(NicknameHandler.getNickname() + " (" +
meHTML + ")");
} else {
var defaultHTML = APP.translation.generateTranslationHTML(
interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
localDisplayName .html(defaultHTML);
}
localDisplayName.show();
}
$('#editDisplayName').hide();
}; };
LocalVideo.prototype.createConnectionIndicator = function() { LocalVideo.prototype.createConnectionIndicator = function() {

View File

@ -36,7 +36,7 @@ var focusedVideoResourceJid = null;
var VideoLayout = (function (my) { var VideoLayout = (function (my) {
my.init = function (emitter) { my.init = function (emitter) {
eventEmitter = emitter; eventEmitter = emitter;
localVideoThumbnail = new LocalVideo(VideoLayout); localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
if (interfaceConfig.filmStripOnly) { if (interfaceConfig.filmStripOnly) {
LargeVideo.disable(); LargeVideo.disable();
} else { } else {

View File

@ -57,6 +57,9 @@ var Settings = {
* @returns {string} the display name we just set * @returns {string} the display name we just set
*/ */
setDisplayName: function (newDisplayName) { setDisplayName: function (newDisplayName) {
if (displayName === newDisplayName) {
return displayName;
}
displayName = newDisplayName; displayName = newDisplayName;
window.localStorage.displayname = displayName; window.localStorage.displayname = displayName;
return displayName; return displayName;

View File

@ -3,6 +3,10 @@ var UIEvents = {
SELECTED_ENDPOINT: "UI.selected_endpoint", SELECTED_ENDPOINT: "UI.selected_endpoint",
PINNED_ENDPOINT: "UI.pinned_endpoint", PINNED_ENDPOINT: "UI.pinned_endpoint",
LARGEVIDEO_INIT: "UI.largevideo_init", LARGEVIDEO_INIT: "UI.largevideo_init",
/**
* Notifies that local user created text message.
*/
MESSAGE_CREATED: "UI.message_created",
/** /**
* Notifies interested parties when the film strip (remote video's panel) * Notifies interested parties when the film strip (remote video's panel)
* is hidden (toggled) or shown (un-toggled). * is hidden (toggled) or shown (un-toggled).