diff --git a/app.js b/app.js index 7580cf198..26aa7c851 100644 --- a/app.js +++ b/app.js @@ -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(); }); diff --git a/modules/UI/UI.js b/modules/UI/UI.js index c248639fa..1ead4fd8d 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -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(); }; diff --git a/modules/UI/side_pannels/chat/Chat.js b/modules/UI/side_pannels/chat/Chat.js index ccf63373f..f5a82cc51 100644 --- a/modules/UI/side_pannels/chat/Chat.js +++ b/modules/UI/side_pannels/chat/Chat.js @@ -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); } } }); diff --git a/modules/UI/side_pannels/settings/SettingsMenu.js b/modules/UI/side_pannels/settings/SettingsMenu.js index 6012b4b42..c502e02d7 100644 --- a/modules/UI/side_pannels/settings/SettingsMenu.js +++ b/modules/UI/side_pannels/settings/SettingsMenu.js @@ -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 { diff --git a/modules/UI/util/NicknameHandler.js b/modules/UI/util/NicknameHandler.js deleted file mode 100644 index fa0c667a9..000000000 --- a/modules/UI/util/NicknameHandler.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/modules/UI/videolayout/LocalVideo.js b/modules/UI/videolayout/LocalVideo.js index 51fa47d26..dfc97bb6e 100644 --- a/modules/UI/videolayout/LocalVideo.js +++ b/modules/UI/videolayout/LocalVideo.js @@ -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() { diff --git a/modules/UI/videolayout/VideoLayout.js b/modules/UI/videolayout/VideoLayout.js index 12869f059..ae12d18e7 100644 --- a/modules/UI/videolayout/VideoLayout.js +++ b/modules/UI/videolayout/VideoLayout.js @@ -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 { diff --git a/modules/settings/Settings.js b/modules/settings/Settings.js index 204dbbf34..b038bfc06 100644 --- a/modules/settings/Settings.js +++ b/modules/settings/Settings.js @@ -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; diff --git a/service/UI/UIEvents.js b/service/UI/UIEvents.js index e0b31eae5..3cf53e5fc 100644 --- a/service/UI/UIEvents.js +++ b/service/UI/UIEvents.js @@ -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).