This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
node_helper.js
45 lines (37 loc) · 1.57 KB
/
node_helper.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
45
'use strict';
const NodeHelper = require('node_helper');
const PythonShell = require('python-shell');
var pythonStarted = false
module.exports = NodeHelper.create({
python_start: function () {
const self = this;
const pyshell = new PythonShell('modules/' + this.name + '/facerecognition/facerecognition.py', { mode: 'json', args: [JSON.stringify(this.config)]});
pyshell.on('message', function (message) {
if (message.hasOwnProperty('status')){
console.log("[" + self.name + "] " + message.status);
}
if (message.hasOwnProperty('login')){
console.log("[" + self.name + "] " + "User " + self.config.users[message.login.user - 1] + " with confidence " + message.login.confidence + " logged in.");
self.sendSocketNotification('user', {action: "login", user: message.login.user - 1, confidence: message.login.confidence});
}
if (message.hasOwnProperty('logout')){
console.log("[" + self.name + "] " + "User " + self.config.users[message.logout.user - 1] + " logged out.");
self.sendSocketNotification('user', {action: "logout", user: message.logout.user - 1});
}
});
pyshell.end(function (err) {
if (err) throw err;
console.log("[" + self.name + "] " + 'finished running...');
});
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG') {
this.config = payload
if(!pythonStarted) {
pythonStarted = true;
this.python_start();
};
};
}
});