-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocketservice.js
More file actions
66 lines (51 loc) · 1.75 KB
/
socketservice.js
File metadata and controls
66 lines (51 loc) · 1.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const WebSocket = require('ws');
const si = require('systeminformation');
// promises style - new since version 3
var cpu_data;
var load_data;
var system_data;
var graphics_data;
var active = "Active";
si.cpu()
.then(data => cpu_data = data.manufacturer + " " + data.brand)
.catch(error => console.error(error));
si.fullLoad()
.then(data => load_data = data)
si.system()
.then(data => system_data = data.manufacturer + " " + data.model)
var n;
si.graphics()
.then(data => n = data.controllers.length - 1)
si.graphics()
.then(data => graphics_data = data.controllers[n].vendor + " " + data.controllers[n].model)
module.exports.jobstarted = function (projectId){
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
si.cpu()
.then(data => cpu_data = data.manufacturer + " " + data.brand)
.catch(error => console.error(error));
si.fullLoad()
.then(data => load_data = data)
si.system()
.then(data => system_data = data.manufacturer + " " + data.model)
si.graphics()
.then(data => graphics_data = data.controllers[n].vendor + " " + data.controllers[n].model)
ws.send(JSON.stringify({
cpu_data,
graphics_data,
load_data,
system_data,
active
}));
});
ws.send(JSON.stringify({
cpu_data,
graphics_data,
load_data,
system_data,
active
}));
});
}
module.exports.jobstarted();