events.EventEmitter.call(this);
this.websocket = websocket;
+
+ // Clients address
this.real_address = this.websocket.handshake.real_address;
+
+ // A hash to identify this client instance
this.hash = crypto.createHash('sha256').update(this.real_address).update('' + Date.now()).digest('hex');
this.irc_connections = [];
-/*
- * Web listeners
- */
-
// Holder for all the connected clients
-global.clients = { clients: Object.create(null),
+global.clients = {
+ clients: Object.create(null),
addresses: Object.create(null),
+
add: function (client) {
this.clients[client.hash] = client;
if (typeof this.addresses[client.real_address] === 'undefined') {
}
this.addresses[client.real_address][client.hash] = client;
},
+
remove: function (client) {
if (typeof this.clients[client.hash] !== 'undefined') {
delete this.clients[client.hash];
}
}
},
+
numOnAddress: function (addr) {
if (typeof this.addresses[addr] !== 'undefined') {
return Object.keys(this.addresses[addr]).length;
}
};
+
+
+
+/*
+ * Web listeners
+ */
+
+
// Start up a weblistener for each found in the config
_.each(config.get().servers, function (server) {
var wl = new WebListener(server, config.get().transports);
+
wl.on('connection', function (client) {
clients.add(client);
- console.log(clients);
});
+
wl.on('destroy', function (client) {
clients.remove(client);
- //client.dispose();
- console.log(clients);
});
});