Rename connect event to term_detected, add connected and disconnected events
This commit is contained in:
parent
5572ca5d24
commit
c45824b3ad
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const logger = require('./logger.js');
|
const logger = require('./logger.js');
|
||||||
|
const events = require('./events.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -22,7 +23,7 @@ function getActiveConnections() { return clientConnections; }
|
||||||
function getActiveNodeList(authUsersOnly) {
|
function getActiveNodeList(authUsersOnly) {
|
||||||
|
|
||||||
if(!_.isBoolean(authUsersOnly)) {
|
if(!_.isBoolean(authUsersOnly)) {
|
||||||
authUsersOnly = true;
|
authUsersOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = moment();
|
const now = moment();
|
||||||
|
@ -30,7 +31,7 @@ function getActiveNodeList(authUsersOnly) {
|
||||||
const activeConnections = getActiveConnections().filter(ac => {
|
const activeConnections = getActiveConnections().filter(ac => {
|
||||||
return ((authUsersOnly && ac.user.isAuthenticated()) || !authUsersOnly);
|
return ((authUsersOnly && ac.user.isAuthenticated()) || !authUsersOnly);
|
||||||
});
|
});
|
||||||
|
|
||||||
return _.map(activeConnections, ac => {
|
return _.map(activeConnections, ac => {
|
||||||
const entry = {
|
const entry = {
|
||||||
node : ac.node,
|
node : ac.node,
|
||||||
|
@ -41,7 +42,7 @@ function getActiveNodeList(authUsersOnly) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// There may be a connection, but not a logged in user as of yet
|
// There may be a connection, but not a logged in user as of yet
|
||||||
//
|
//
|
||||||
if(ac.user.isAuthenticated()) {
|
if(ac.user.isAuthenticated()) {
|
||||||
entry.userName = ac.user.username;
|
entry.userName = ac.user.username;
|
||||||
entry.realName = ac.user.properties.real_name;
|
entry.realName = ac.user.properties.real_name;
|
||||||
|
@ -49,7 +50,7 @@ function getActiveNodeList(authUsersOnly) {
|
||||||
entry.affils = ac.user.properties.affiliation;
|
entry.affils = ac.user.properties.affiliation;
|
||||||
|
|
||||||
const diff = now.diff(moment(ac.user.properties.last_login_timestamp), 'minutes');
|
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;
|
return entry;
|
||||||
});
|
});
|
||||||
|
@ -59,7 +60,7 @@ function addNewClient(client, clientSock) {
|
||||||
const id = client.session.id = clientConnections.push(client) - 1;
|
const id = client.session.id = clientConnections.push(client) - 1;
|
||||||
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
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
|
// Note that this will be updated @ login with additional information
|
||||||
client.log = logger.log.child( { clientId : id } );
|
client.log = logger.log.child( { clientId : id } );
|
||||||
|
|
||||||
|
@ -76,6 +77,8 @@ function addNewClient(client, clientSock) {
|
||||||
|
|
||||||
client.log.info(connInfo, 'Client connected');
|
client.log.info(connInfo, 'Client connected');
|
||||||
|
|
||||||
|
events.emit('codes.l33t.enigma.system.connected', {'client': client});
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,17 +88,19 @@ function removeClient(client) {
|
||||||
const i = clientConnections.indexOf(client);
|
const i = clientConnections.indexOf(client);
|
||||||
if(i > -1) {
|
if(i > -1) {
|
||||||
clientConnections.splice(i, 1);
|
clientConnections.splice(i, 1);
|
||||||
|
|
||||||
logger.log.info(
|
logger.log.info(
|
||||||
{
|
{
|
||||||
connectionCount : clientConnections.length,
|
connectionCount : clientConnections.length,
|
||||||
clientId : client.session.id
|
clientId : client.session.id
|
||||||
},
|
},
|
||||||
'Client disconnected'
|
'Client disconnected'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
events.emit('codes.l33t.enigma.system.disconnected', {'client': client});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConnectionByUserId(userId) {
|
function getConnectionByUserId(userId) {
|
||||||
return getActiveConnections().find( ac => userId === ac.user.userId );
|
return getActiveConnections().find( ac => userId === ac.user.userId );
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ function connectEntry(client, nextMenu) {
|
||||||
displayBanner(term);
|
displayBanner(term);
|
||||||
|
|
||||||
// fire event
|
// fire event
|
||||||
events.emit('codes.l33t.enigma.system.connect', {'client': client});
|
events.emit('codes.l33t.enigma.system.term_detected', {'client': client});
|
||||||
|
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
return client.menuStack.goto(nextMenu);
|
return client.menuStack.goto(nextMenu);
|
||||||
|
|
|
@ -32,7 +32,7 @@ var self = module.exports = {
|
||||||
}
|
}
|
||||||
if (fs.existsSync(modPath)) {
|
if (fs.existsSync(modPath)) {
|
||||||
var module = require(modPath);
|
var module = require(modPath);
|
||||||
|
|
||||||
if (module.registerEvents !== undefined) {
|
if (module.registerEvents !== undefined) {
|
||||||
logger.log.debug(modPath+" calling registerEvents function");
|
logger.log.debug(modPath+" calling registerEvents function");
|
||||||
module.registerEvents();
|
module.registerEvents();
|
||||||
|
|
Loading…
Reference in New Issue