Skip to content

Commit

Permalink
src/client: add type checks in Client ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Jun 30, 2016
1 parent bdb215a commit bdec503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var inputs = [
}, {});

function Client(manager, name, config) {
if (typeof config !== "object") {
config = {};
}
_.merge(this, {
activeChannel: -1,
config: config,
Expand All @@ -67,12 +70,11 @@ function Client(manager, name, config) {

var client = this;

if (client.config) {
if (!client.config.token) {
client.updateToken(function(token) {
client.manager.updateUser(client.name, {token: token});
});
}
if (!client.config.token) {
client.updateToken(function(token) {
client.manager.updateUser(client.name, {token: token});
});
}

var delay = 0;
(client.config.networks || []).forEach(function(n) {
Expand All @@ -82,14 +84,16 @@ function Client(manager, name, config) {
delay += 1000;
});

log.info("User '" + name + "' loaded");
if (name) {
log.info("User '" + name + "' loaded");
}
}

Client.prototype.emit = function(event, data) {
if (this.sockets !== null) {
this.sockets.in(this.id).emit(event, data);
}
var config = this.config || {};
var config = this.config;
if (config.log === true) {
if (event === "msg") {
var target = this.find(data.chan);
Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function init(socket, client) {
socket.emit("init", {
active: client.activeChannel,
networks: client.networks,
token: client.config ? client.config.token : null
token: client.config.token || null
});
}
}
Expand Down

0 comments on commit bdec503

Please sign in to comment.