-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
56 lines (43 loc) · 1.21 KB
/
index.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
53
54
55
56
'use strict';
console.log('CSGO Gamestate Integration Music Player starting...');
const http = require('http');
let shouldPlay = true;
let playerDead = false;
let lastUpdate = null;
http.createServer((req, res) => {
if (req.method !== 'POST') return res.end();
res.writeHead(200, {'Content-Type': 'text/html'});
let body = '';
req.on('data', (data) => {
body += data;
});
req.on('end', () => {
console.log(body);
statusUpdate(JSON.parse(body));
res.end();
});
}).listen(3000);
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*'});
res.end(`{"play":${shouldPlay}}`);
}).listen(3001);
function statusUpdate (data) {
lastUpdate = new Date();
// Discard unwanted messenges
if (!data.previously && !data.player) return;
/*
Music should play when
- in menu
- dead
*/
if (
(data.player && data.player.activity === 'menu') || // menu
(data.player.state.health === 0 || data.player.steamid !== data.provider.steamid) // dead
) {
shouldPlay = true;
playerDead = true;
} else {
shouldPlay = false;
playerDead = false;
}
}