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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ var SettingsMenu = {
}
});
if (APP.xmpp.isModerator()) {
if (APP.conference.isModerator()) {
startMutedSelector.css("display", "block");
}
else {
@ -47,7 +47,7 @@ var SettingsMenu = {
},
onRoleChanged: function () {
if(APP.xmpp.isModerator()) {
if(APP.conference.isModerator()) {
$("#startMutedOptions").css("display", "block");
}
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 */
var SmallVideo = require("./SmallVideo");
var ConnectionIndicator = require("./ConnectionIndicator");
var NicknameHandler = require("../util/NicknameHandler");
var UIUtil = require("../util/UIUtil");
var UIEvents = require("../../../service/UI/UIEvents");
var LargeVideo = require("./LargeVideo");
var RTCBrowserType = require("../../RTC/RTCBrowserType");
function LocalVideo(VideoLayout) {
function LocalVideo(VideoLayout, emitter) {
this.videoSpanId = "localVideoContainer";
this.container = $("#localVideoContainer").get(0);
this.bindHoverHandler();
@ -14,6 +14,7 @@ function LocalVideo(VideoLayout) {
this.flipX = true;
this.isLocal = true;
this.peerJid = null;
this.emitter = emitter;
}
LocalVideo.prototype = Object.create(SmallVideo.prototype);
@ -117,11 +118,13 @@ LocalVideo.prototype.setDisplayName = function(displayName, key) {
editDisplayName.one("focusout", function (e) {
self.VideoLayout.inputDisplayNameHandler(this.value);
$('#editDisplayName').hide();
});
editDisplayName.on('keydown', function (e) {
if (e.keyCode === 13) {
e.preventDefault();
$('#editDisplayName').hide();
self.VideoLayout.inputDisplayNameHandler(this.value);
}
});
@ -130,25 +133,7 @@ LocalVideo.prototype.setDisplayName = function(displayName, key) {
};
LocalVideo.prototype.inputDisplayNameHandler = function (name) {
name = 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();
this.emitter.emit(UIEvents.NICKNAME_CHANGED, UIUtil.escapeHtml(name));
};
LocalVideo.prototype.createConnectionIndicator = function() {

View File

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

View File

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

View File

@ -3,6 +3,10 @@ var UIEvents = {
SELECTED_ENDPOINT: "UI.selected_endpoint",
PINNED_ENDPOINT: "UI.pinned_endpoint",
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)
* is hidden (toggled) or shown (un-toggled).