Rename connect event to term_detected, add connected and disconnected events

This commit is contained in:
Josh M. McKee 2017-06-10 18:46:28 -07:00
parent 5572ca5d24
commit c45824b3ad
3 changed files with 17 additions and 12 deletions

View File

@ -3,6 +3,7 @@
// ENiGMA½
const logger = require('./logger.js');
const events = require('./events.js');
// deps
const _ = require('lodash');
@ -22,7 +23,7 @@ function getActiveConnections() { return clientConnections; }
function getActiveNodeList(authUsersOnly) {
if(!_.isBoolean(authUsersOnly)) {
authUsersOnly = true;
authUsersOnly = true;
}
const now = moment();
@ -30,7 +31,7 @@ function getActiveNodeList(authUsersOnly) {
const activeConnections = getActiveConnections().filter(ac => {
return ((authUsersOnly && ac.user.isAuthenticated()) || !authUsersOnly);
});
return _.map(activeConnections, ac => {
const entry = {
node : ac.node,
@ -41,7 +42,7 @@ function getActiveNodeList(authUsersOnly) {
//
// There may be a connection, but not a logged in user as of yet
//
//
if(ac.user.isAuthenticated()) {
entry.userName = ac.user.username;
entry.realName = ac.user.properties.real_name;
@ -49,7 +50,7 @@ function getActiveNodeList(authUsersOnly) {
entry.affils = ac.user.properties.affiliation;
const diff = now.diff(moment(ac.user.properties.last_login_timestamp), 'minutes');
entry.timeOn = moment.duration(diff, 'minutes');
entry.timeOn = moment.duration(diff, 'minutes');
}
return entry;
});
@ -59,7 +60,7 @@ function addNewClient(client, clientSock) {
const id = client.session.id = clientConnections.push(client) - 1;
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
// Create a client specific logger
// Create a client specific logger
// Note that this will be updated @ login with additional information
client.log = logger.log.child( { clientId : id } );
@ -76,6 +77,8 @@ function addNewClient(client, clientSock) {
client.log.info(connInfo, 'Client connected');
events.emit('codes.l33t.enigma.system.connected', {'client': client});
return id;
}
@ -85,17 +88,19 @@ function removeClient(client) {
const i = clientConnections.indexOf(client);
if(i > -1) {
clientConnections.splice(i, 1);
logger.log.info(
{
{
connectionCount : clientConnections.length,
clientId : client.session.id
},
clientId : client.session.id
},
'Client disconnected'
);
events.emit('codes.l33t.enigma.system.disconnected', {'client': client});
}
}
function getConnectionByUserId(userId) {
return getActiveConnections().find( ac => userId === ac.user.userId );
}
}

View File

@ -177,7 +177,7 @@ function connectEntry(client, nextMenu) {
displayBanner(term);
// fire event
events.emit('codes.l33t.enigma.system.connect', {'client': client});
events.emit('codes.l33t.enigma.system.term_detected', {'client': client});
setTimeout( () => {
return client.menuStack.goto(nextMenu);

View File

@ -32,7 +32,7 @@ var self = module.exports = {
}
if (fs.existsSync(modPath)) {
var module = require(modPath);
if (module.registerEvents !== undefined) {
logger.log.debug(modPath+" calling registerEvents function");
module.registerEvents();