-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
52 lines (46 loc) · 1.64 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
46
47
48
49
50
51
52
var NodeHelper = require("node_helper");
var io = require('socket.io-client');
const { exec } = require('child_process');
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for: " + this.name);
this.socket = null;
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'CONNECT_SOCKET') {
this.config = payload;
this.connectSocket();
}
if (notification === 'SCREEN_ACTION') {
this.handleScreenEvent(payload);
}
},
connectSocket: function() {
this.socket = io.connect(this.config.socketUrl + "?token=" + this.config.socketToken);
this.socket.on("event", (event) => {
this.sendSocketNotification('EVENT_ACTION', event);
});
},
handleScreenEvent: function(event) {
switch (event) {
case "ON":
console.log("Turning on screen");
exec('xrandr --output ' + this.config.hdmiInput + ' --auto', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
});
break;
case "OFF":
console.log("Turning off screen");
exec('xrandr --output ' + this.config.hdmiInput + ' --off', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
});
break;
}
},
});