Removes nickname global variable.

This commit is contained in:
hristoterezov 2015-01-22 18:02:37 +02:00
parent 1e9a463245
commit 4c661ffca6
10 changed files with 435 additions and 69 deletions

1
app.js
View File

@ -1,6 +1,5 @@
/* jshint -W117 */ /* jshint -W117 */
/* application specific logic */ /* application specific logic */
var nickname = null;
function init() { function init() {

View File

@ -23,15 +23,16 @@
<script src="service/RTC/StreamEventTypes.js?v=2"></script> <script src="service/RTC/StreamEventTypes.js?v=2"></script>
<script src="service/RTC/MediaStreamTypes.js?v=1"></script> <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
<script src="service/xmpp/XMPPEvents.js?v=1"></script> <script src="service/xmpp/XMPPEvents.js?v=1"></script>
<script src="service/UI/UIEvents.js?v=1"></script>
<script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script> <script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script>
<script src="libs/modules/simulcast.bundle.js?v=5"></script> <script src="libs/modules/simulcast.bundle.js?v=5"></script>
<script src="libs/modules/connectionquality.bundle.js?v=2"></script> <script src="libs/modules/connectionquality.bundle.js?v=2"></script>
<script src="libs/modules/UI.bundle.js?v=8"></script> <script src="libs/modules/UI.bundle.js?v=9"></script>
<script src="libs/modules/statistics.bundle.js?v=4"></script> <script src="libs/modules/statistics.bundle.js?v=4"></script>
<script src="libs/modules/RTC.bundle.js?v=6"></script> <script src="libs/modules/RTC.bundle.js?v=6"></script>
<script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing --> <script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing -->
<script src="util.js?v=7"></script><!-- utility functions --> <script src="util.js?v=7"></script><!-- utility functions -->
<script src="libs/modules/xmpp.bundle.js?v=4"></script> <script src="libs/modules/xmpp.bundle.js?v=5"></script>
<script src="app.js?v=29"></script><!-- application logic --> <script src="app.js?v=29"></script><!-- application logic -->
<script src="libs/modules/API.bundle.js?v=1"></script> <script src="libs/modules/API.bundle.js?v=1"></script>

View File

@ -11,7 +11,7 @@ var ToolbarToggler = require("./toolbars/ToolbarToggler");
var BottomToolbar = require("./toolbars/BottomToolbar"); var BottomToolbar = require("./toolbars/BottomToolbar");
var ContactList = require("./side_pannels/contactlist/ContactList"); var ContactList = require("./side_pannels/contactlist/ContactList");
var Avatar = require("./avatar/Avatar"); var Avatar = require("./avatar/Avatar");
//var EventEmitter = require("events"); var EventEmitter = require("events");
var SettingsMenu = require("./side_pannels/settings/SettingsMenu"); var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
var Settings = require("./side_pannels/settings/Settings"); var Settings = require("./side_pannels/settings/Settings");
var PanelToggler = require("./side_pannels/SidePanelToggler"); var PanelToggler = require("./side_pannels/SidePanelToggler");
@ -20,8 +20,9 @@ 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 eventEmitter = new EventEmitter(); var eventEmitter = new EventEmitter();
var roomName = null; var roomName = null;
@ -211,13 +212,15 @@ UI.start = function () {
// Set the defaults for prompt dialogs. // Set the defaults for prompt dialogs.
jQuery.prompt.setDefaults({persistent: false}); jQuery.prompt.setDefaults({persistent: false});
// KeyboardShortcut.init();
NicknameHandler.init(eventEmitter);
registerListeners(); registerListeners();
bindEvents(); bindEvents();
setupPrezi(); setupPrezi();
setupToolbars(); setupToolbars();
setupChat(); setupChat();
document.title = interfaceConfig.APP_NAME; document.title = interfaceConfig.APP_NAME;
$("#downloadlog").click(function (event) { $("#downloadlog").click(function (event) {
@ -591,7 +594,7 @@ UI.checkForNicknameAndJoin = function () {
if (config.useNicks) { if (config.useNicks) {
nick = window.prompt('Your nickname (optional)'); nick = window.prompt('Your nickname (optional)');
} }
xmpp.joinRooom(roomName, config.useNicks, nick); xmpp.joinRoom(roomName, config.useNicks, nick);
} }
@ -685,10 +688,14 @@ UI.onLastNChanged = function (oldValue, newValue) {
} }
} }
UI.addListener = function (type, listener) {
eventEmitter.on(type, listener);
}
module.exports = UI; module.exports = UI;
},{"./audio_levels/AudioLevels.js":2,"./authentication/Authentication":4,"./avatar/Avatar":5,"./etherpad/Etherpad.js":6,"./prezi/Prezi.js":7,"./side_pannels/SidePanelToggler":8,"./side_pannels/chat/Chat.js":9,"./side_pannels/contactlist/ContactList":13,"./side_pannels/settings/Settings":14,"./side_pannels/settings/SettingsMenu":15,"./toolbars/BottomToolbar":16,"./toolbars/Toolbar":17,"./toolbars/ToolbarToggler":18,"./util/MessageHandler":20,"./util/UIUtil":21,"./videolayout/VideoLayout.js":23,"./welcome_page/RoomnameGenerator":24,"./welcome_page/WelcomePage":25}],2:[function(require,module,exports){ },{"./audio_levels/AudioLevels.js":2,"./authentication/Authentication":4,"./avatar/Avatar":5,"./etherpad/Etherpad.js":6,"./prezi/Prezi.js":7,"./side_pannels/SidePanelToggler":8,"./side_pannels/chat/Chat.js":9,"./side_pannels/contactlist/ContactList":13,"./side_pannels/settings/Settings":14,"./side_pannels/settings/SettingsMenu":15,"./toolbars/BottomToolbar":16,"./toolbars/Toolbar":17,"./toolbars/ToolbarToggler":18,"./util/MessageHandler":20,"./util/NicknameHandler":21,"./util/UIUtil":22,"./videolayout/VideoLayout.js":24,"./welcome_page/RoomnameGenerator":25,"./welcome_page/WelcomePage":26,"events":27}],2:[function(require,module,exports){
var CanvasUtil = require("./CanvasUtils"); var CanvasUtil = require("./CanvasUtils");
/** /**
@ -1305,7 +1312,7 @@ var Avatar = {
module.exports = Avatar; module.exports = Avatar;
},{"../side_pannels/settings/Settings":14,"../videolayout/VideoLayout":23}],6:[function(require,module,exports){ },{"../side_pannels/settings/Settings":14,"../videolayout/VideoLayout":24}],6:[function(require,module,exports){
/* global $, config, dockToolbar, /* global $, config, dockToolbar,
setLargeVideoVisible, Util */ setLargeVideoVisible, Util */
@ -1501,7 +1508,7 @@ var Etherpad = {
module.exports = Etherpad; module.exports = Etherpad;
},{"../prezi/Prezi":7,"../util/UIUtil":21,"../videolayout/VideoLayout":23}],7:[function(require,module,exports){ },{"../prezi/Prezi":7,"../util/UIUtil":22,"../videolayout/VideoLayout":24}],7:[function(require,module,exports){
var ToolbarToggler = require("../toolbars/ToolbarToggler"); var ToolbarToggler = require("../toolbars/ToolbarToggler");
var UIUtil = require("../util/UIUtil"); var UIUtil = require("../util/UIUtil");
var VideoLayout = require("../videolayout/VideoLayout"); var VideoLayout = require("../videolayout/VideoLayout");
@ -1853,7 +1860,7 @@ $(window).resize(function () {
module.exports = Prezi; module.exports = Prezi;
},{"../toolbars/ToolbarToggler":18,"../util/MessageHandler":20,"../util/UIUtil":21,"../videolayout/VideoLayout":23}],8:[function(require,module,exports){ },{"../toolbars/ToolbarToggler":18,"../util/MessageHandler":20,"../util/UIUtil":22,"../videolayout/VideoLayout":24}],8:[function(require,module,exports){
var Chat = require("./chat/Chat"); var Chat = require("./chat/Chat");
var ContactList = require("./contactlist/ContactList"); var ContactList = require("./contactlist/ContactList");
var Settings = require("./settings/Settings"); var Settings = require("./settings/Settings");
@ -2110,12 +2117,13 @@ var PanelToggler = (function(my) {
}(PanelToggler || {})); }(PanelToggler || {}));
module.exports = PanelToggler; module.exports = PanelToggler;
},{"../toolbars/ToolbarToggler":18,"../util/UIUtil":21,"../videolayout/VideoLayout":23,"./chat/Chat":9,"./contactlist/ContactList":13,"./settings/Settings":14,"./settings/SettingsMenu":15}],9:[function(require,module,exports){ },{"../toolbars/ToolbarToggler":18,"../util/UIUtil":22,"../videolayout/VideoLayout":24,"./chat/Chat":9,"./contactlist/ContactList":13,"./settings/Settings":14,"./settings/SettingsMenu":15}],9:[function(require,module,exports){
/* global $, Util, nickname:true, showToolbar */ /* global $, Util, nickname:true, showToolbar */
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 notificationInterval = false; var notificationInterval = false;
var unreadMessages = 0; var unreadMessages = 0;
@ -2281,25 +2289,20 @@ var Chat = (function (my) {
* Initializes chat related interface. * Initializes chat related interface.
*/ */
my.init = function () { my.init = function () {
var storedDisplayName = window.localStorage.displayname; if(NicknameHandler.getNickname())
if (storedDisplayName) {
nickname = storedDisplayName;
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 = Util.escapeHtml(this.value); var val = Util.escapeHtml(this.value);
this.value = ''; this.value = '';
if (!nickname) { if (!NicknameHandler.getNickname()) {
nickname = val; NicknameHandler.setNickname(val);
window.localStorage.displayname = nickname;
xmpp.addToPresence("displayName", nickname);
Chat.setChatConversationMode(true);
return; return;
} }
@ -2320,7 +2323,7 @@ var Chat = (function (my) {
else else
{ {
var message = Util.escapeHtml(value); var message = Util.escapeHtml(value);
xmpp.sendChatMessage(message, nickname); xmpp.sendChatMessage(message, NicknameHandler.getNickname());
} }
} }
}); });
@ -2470,7 +2473,7 @@ var Chat = (function (my) {
return my; return my;
}(Chat || {})); }(Chat || {}));
module.exports = Chat; module.exports = Chat;
},{"../../toolbars/ToolbarToggler":18,"../SidePanelToggler":8,"./Commands":10,"./Replacement":11,"./smileys.json":12}],10:[function(require,module,exports){ },{"../../toolbars/ToolbarToggler":18,"../../util/NicknameHandler":21,"../SidePanelToggler":8,"./Commands":10,"./Replacement":11,"./smileys.json":12}],10:[function(require,module,exports){
/** /**
* List with supported commands. The keys are the names of the commands and * List with supported commands. The keys are the names of the commands and
* the value is the function that processes the message. * the value is the function that processes the message.
@ -3531,7 +3534,7 @@ var Toolbar = (function (my) {
}(Toolbar || {})); }(Toolbar || {}));
module.exports = Toolbar; module.exports = Toolbar;
},{"../authentication/Authentication":4,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/SidePanelToggler":8,"../util/MessageHandler":20,"../util/UIUtil":21,"./BottomToolbar":16}],18:[function(require,module,exports){ },{"../authentication/Authentication":4,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/SidePanelToggler":8,"../util/MessageHandler":20,"../util/UIUtil":22,"./BottomToolbar":16}],18:[function(require,module,exports){
/* global $, interfaceConfig, Moderator, DesktopStreaming.showDesktopSharingButton */ /* global $, interfaceConfig, Moderator, DesktopStreaming.showDesktopSharingButton */
var toolbarTimeoutObject, var toolbarTimeoutObject,
@ -3940,6 +3943,35 @@ module.exports = messageHandler;
},{}],21:[function(require,module,exports){ },{}],21:[function(require,module,exports){
var nickname = null;
var eventEmitter = null;
var NickanameHandler = {
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 = NickanameHandler;
},{}],22:[function(require,module,exports){
/** /**
* Created by hristo on 12/22/14. * Created by hristo on 12/22/14.
*/ */
@ -3963,7 +3995,7 @@ module.exports = {
}; };
},{"../side_pannels/SidePanelToggler":8}],22:[function(require,module,exports){ },{"../side_pannels/SidePanelToggler":8}],23:[function(require,module,exports){
var JitsiPopover = require("../util/JitsiPopover"); var JitsiPopover = require("../util/JitsiPopover");
/** /**
@ -4374,13 +4406,14 @@ ConnectionIndicator.prototype.hideIndicator = function () {
}; };
module.exports = ConnectionIndicator; module.exports = ConnectionIndicator;
},{"../util/JitsiPopover":19}],23:[function(require,module,exports){ },{"../util/JitsiPopover":19}],24:[function(require,module,exports){
var AudioLevels = require("../audio_levels/AudioLevels"); var AudioLevels = require("../audio_levels/AudioLevels");
var Avatar = require("../avatar/Avatar"); var Avatar = require("../avatar/Avatar");
var Chat = require("../side_pannels/chat/Chat"); var Chat = require("../side_pannels/chat/Chat");
var ContactList = require("../side_pannels/contactlist/ContactList"); var ContactList = require("../side_pannels/contactlist/ContactList");
var UIUtil = require("../util/UIUtil"); var UIUtil = require("../util/UIUtil");
var ConnectionIndicator = require("./ConnectionIndicator"); var ConnectionIndicator = require("./ConnectionIndicator");
var NicknameHandler = require("../util/NicknameHandler");
var currentDominantSpeaker = null; var currentDominantSpeaker = null;
var lastNCount = config.channelLastN; var lastNCount = config.channelLastN;
@ -5635,17 +5668,11 @@ var VideoLayout = (function (my) {
}; };
my.inputDisplayNameHandler = function (name) { my.inputDisplayNameHandler = function (name) {
if (name && nickname !== name) { NicknameHandler.setNickname(name);
nickname = name;
window.localStorage.displayname = nickname;
xmpp.addToPresence("displayName", nickname);
Chat.setChatConversationMode(true);
}
if (!$('#localDisplayName').is(":visible")) { if (!$('#localDisplayName').is(":visible")) {
if (nickname) if (NicknameHandler.getNickname())
$('#localDisplayName').text(nickname + " (me)"); $('#localDisplayName').text(NicknameHandler.getNickname() + " (me)");
else else
$('#localDisplayName') $('#localDisplayName')
.text(interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME); .text(interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
@ -6141,7 +6168,7 @@ var VideoLayout = (function (my) {
var name = null; var name = null;
if (jid === 'localVideoContainer' if (jid === 'localVideoContainer'
|| jid === xmpp.myJid()) { || jid === xmpp.myJid()) {
name = nickname; name = NicknameHandler.getNickname();
setDisplayName('localVideoContainer', setDisplayName('localVideoContainer',
displayName); displayName);
} else { } else {
@ -6576,7 +6603,7 @@ var VideoLayout = (function (my) {
}(VideoLayout || {})); }(VideoLayout || {}));
module.exports = VideoLayout; module.exports = VideoLayout;
},{"../audio_levels/AudioLevels":2,"../avatar/Avatar":5,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/chat/Chat":9,"../side_pannels/contactlist/ContactList":13,"../util/UIUtil":21,"./ConnectionIndicator":22}],24:[function(require,module,exports){ },{"../audio_levels/AudioLevels":2,"../avatar/Avatar":5,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/chat/Chat":9,"../side_pannels/contactlist/ContactList":13,"../util/NicknameHandler":21,"../util/UIUtil":22,"./ConnectionIndicator":23}],25:[function(require,module,exports){
//var nouns = [ //var nouns = [
//]; //];
var pluralNouns = [ var pluralNouns = [
@ -6757,7 +6784,7 @@ var RoomNameGenerator = {
module.exports = RoomNameGenerator; module.exports = RoomNameGenerator;
},{}],25:[function(require,module,exports){ },{}],26:[function(require,module,exports){
var animateTimeout, updateTimeout; var animateTimeout, updateTimeout;
var RoomNameGenerator = require("./RoomnameGenerator"); var RoomNameGenerator = require("./RoomnameGenerator");
@ -6861,5 +6888,308 @@ function setupWelcomePage()
} }
module.exports = setupWelcomePage; module.exports = setupWelcomePage;
},{"./RoomnameGenerator":24}]},{},[1])(1) },{"./RoomnameGenerator":25}],27:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
}
throw TypeError('Uncaught, unspecified "error" event.');
}
}
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
handler.apply(this, args);
}
} else if (isObject(handler)) {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
var m;
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
},{}]},{},[1])(1)
}); });

View File

@ -4495,6 +4495,9 @@ function initStrophePlugins()
function registerListeners() { function registerListeners() {
RTC.addStreamListener(maybeDoJoin, RTC.addStreamListener(maybeDoJoin,
StreamEventTypes.EVENT_TYPE_LOCAL_CREATED); StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
XMPP.addToPresence("displayName", nickname);
})
} }
function setupEvents() { function setupEvents() {
@ -4551,7 +4554,7 @@ var XMPP = {
promptLogin: function () { promptLogin: function () {
UI.showLoginPopup(connect); UI.showLoginPopup(connect);
}, },
joinRooom: function(roomName, useNicks, nick) joinRoom: function(roomName, useNicks, nick)
{ {
var roomjid; var roomjid;
roomjid = roomName; roomjid = roomName;

View File

@ -10,7 +10,7 @@ var ToolbarToggler = require("./toolbars/ToolbarToggler");
var BottomToolbar = require("./toolbars/BottomToolbar"); var BottomToolbar = require("./toolbars/BottomToolbar");
var ContactList = require("./side_pannels/contactlist/ContactList"); var ContactList = require("./side_pannels/contactlist/ContactList");
var Avatar = require("./avatar/Avatar"); var Avatar = require("./avatar/Avatar");
//var EventEmitter = require("events"); var EventEmitter = require("events");
var SettingsMenu = require("./side_pannels/settings/SettingsMenu"); var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
var Settings = require("./side_pannels/settings/Settings"); var Settings = require("./side_pannels/settings/Settings");
var PanelToggler = require("./side_pannels/SidePanelToggler"); var PanelToggler = require("./side_pannels/SidePanelToggler");
@ -19,8 +19,9 @@ 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 eventEmitter = new EventEmitter(); var eventEmitter = new EventEmitter();
var roomName = null; var roomName = null;
@ -210,13 +211,15 @@ UI.start = function () {
// Set the defaults for prompt dialogs. // Set the defaults for prompt dialogs.
jQuery.prompt.setDefaults({persistent: false}); jQuery.prompt.setDefaults({persistent: false});
// KeyboardShortcut.init();
NicknameHandler.init(eventEmitter);
registerListeners(); registerListeners();
bindEvents(); bindEvents();
setupPrezi(); setupPrezi();
setupToolbars(); setupToolbars();
setupChat(); setupChat();
document.title = interfaceConfig.APP_NAME; document.title = interfaceConfig.APP_NAME;
$("#downloadlog").click(function (event) { $("#downloadlog").click(function (event) {
@ -684,5 +687,9 @@ UI.onLastNChanged = function (oldValue, newValue) {
} }
} }
UI.addListener = function (type, listener) {
eventEmitter.on(type, listener);
}
module.exports = UI; module.exports = UI;

View File

@ -3,6 +3,7 @@ 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 notificationInterval = false; var notificationInterval = false;
var unreadMessages = 0; var unreadMessages = 0;
@ -168,25 +169,20 @@ var Chat = (function (my) {
* Initializes chat related interface. * Initializes chat related interface.
*/ */
my.init = function () { my.init = function () {
var storedDisplayName = window.localStorage.displayname; if(NicknameHandler.getNickname())
if (storedDisplayName) {
nickname = storedDisplayName;
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 = Util.escapeHtml(this.value); var val = Util.escapeHtml(this.value);
this.value = ''; this.value = '';
if (!nickname) { if (!NicknameHandler.getNickname()) {
nickname = val; NicknameHandler.setNickname(val);
window.localStorage.displayname = nickname;
xmpp.addToPresence("displayName", nickname);
Chat.setChatConversationMode(true);
return; return;
} }
@ -207,7 +203,7 @@ var Chat = (function (my) {
else else
{ {
var message = Util.escapeHtml(value); var message = Util.escapeHtml(value);
xmpp.sendChatMessage(message, nickname); xmpp.sendChatMessage(message, NicknameHandler.getNickname());
} }
} }
}); });

View File

@ -0,0 +1,28 @@
var nickname = null;
var eventEmitter = null;
var NickanameHandler = {
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 = NickanameHandler;

View File

@ -4,6 +4,7 @@ var Chat = require("../side_pannels/chat/Chat");
var ContactList = require("../side_pannels/contactlist/ContactList"); var ContactList = require("../side_pannels/contactlist/ContactList");
var UIUtil = require("../util/UIUtil"); var UIUtil = require("../util/UIUtil");
var ConnectionIndicator = require("./ConnectionIndicator"); var ConnectionIndicator = require("./ConnectionIndicator");
var NicknameHandler = require("../util/NicknameHandler");
var currentDominantSpeaker = null; var currentDominantSpeaker = null;
var lastNCount = config.channelLastN; var lastNCount = config.channelLastN;
@ -1258,17 +1259,11 @@ var VideoLayout = (function (my) {
}; };
my.inputDisplayNameHandler = function (name) { my.inputDisplayNameHandler = function (name) {
if (name && nickname !== name) { NicknameHandler.setNickname(name);
nickname = name;
window.localStorage.displayname = nickname;
xmpp.addToPresence("displayName", nickname);
Chat.setChatConversationMode(true);
}
if (!$('#localDisplayName').is(":visible")) { if (!$('#localDisplayName').is(":visible")) {
if (nickname) if (NicknameHandler.getNickname())
$('#localDisplayName').text(nickname + " (me)"); $('#localDisplayName').text(NicknameHandler.getNickname() + " (me)");
else else
$('#localDisplayName') $('#localDisplayName')
.text(interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME); .text(interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
@ -1764,7 +1759,7 @@ var VideoLayout = (function (my) {
var name = null; var name = null;
if (jid === 'localVideoContainer' if (jid === 'localVideoContainer'
|| jid === xmpp.myJid()) { || jid === xmpp.myJid()) {
name = nickname; name = NicknameHandler.getNickname();
setDisplayName('localVideoContainer', setDisplayName('localVideoContainer',
displayName); displayName);
} else { } else {

View File

@ -103,6 +103,9 @@ function initStrophePlugins()
function registerListeners() { function registerListeners() {
RTC.addStreamListener(maybeDoJoin, RTC.addStreamListener(maybeDoJoin,
StreamEventTypes.EVENT_TYPE_LOCAL_CREATED); StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
XMPP.addToPresence("displayName", nickname);
})
} }
function setupEvents() { function setupEvents() {

4
service/UI/UIEvents.js Normal file
View File

@ -0,0 +1,4 @@
var UIEvents = {
NICKNAME_CHANGED: "UI.nickname_changed"
};
//module.exports = UIEvents;