-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode_helper.js
More file actions
49 lines (44 loc) · 1.37 KB
/
node_helper.js
File metadata and controls
49 lines (44 loc) · 1.37 KB
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
45
46
47
48
49
'use strict';
const NodeHelper = require('node_helper');
const { spawn } = require('child_process');
var procStarted = false
module.exports = NodeHelper.create({
proc_start: function () {
const self = this;
process.env.WERKZEUG_RUN_MAIN = 'true';
const proc = spawn('modules/' + this.name + '/pi-faced/bin/faced');
proc.stdout.on('data', (data) => {
const message = JSON.parse(data);
if (message.hasOwnProperty('status')){
console.log("[" + self.name + "] " + message.status);
}
if (message.hasOwnProperty('login')){
self.sendSocketNotification('user',
{
action: "login",
user: message.login.names[0]
});
}
if (message.hasOwnProperty('logout')){
self.sendSocketNotification('user',
{
action: "logout",
user: message.logout.names[0]
});
}
});
proc.on('close', (code) => {
console.log("[" + self.name + "] finished with code " + code);
});
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG') {
this.config = payload
if (!procStarted) {
procStarted = true;
this.proc_start();
};
};
}
});