-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitorMessageReceiver.js
44 lines (34 loc) · 1.1 KB
/
monitorMessageReceiver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//init and get serverState
var state = require('./serverState');
// load utility module
var utils = require('./utils');
//Logging System
var logSystem = require('./logger');
var serverLog = logSystem.getServerLog();
var msgHandler = require('./messageHandler');
/**
* Called after receiving HELLO:monitor, registers for all messages a monitor can send a listener
* with socket.on() and takes corresponding actions.
* @param socket
* @param pingInterval
*/
exports.handleMonitor = function(socket, pingInterval) {
var monitor = {
socket: socket
};
msgHandler.emitMessageToSocket(socket, 'HELLO:ack', {
messageId: utils.rand()
});
state.addMonitor(monitor);
msgHandler.sendConfigInformation(socket);
msgHandler.sendTeamInformation(socket);
/**
* Removes the monitor socket from the state as reaction to a disconnect event
*/
socket.on('disconnect', function () {
serverLog.log("info", "monitor device disconnected");
clearInterval(pingInterval);
// remove the admin from the list
state.removeMonitor(socket);
});
};