Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
joernKoenen authored Jul 18, 2019
1 parent 4714139 commit 1163d1a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
14 changes: 14 additions & 0 deletions csgo_cfg/gamestate_integration_csgomedia.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"CSGO Mediacontrol"
{
"uri" "http://localhost:3337"
"timeout" "5.0"
"buffer" "1.0"
"throttle" "1.0"
"heartbeat" "60.0"
"data"
{
"provider" "1"
"player_id" "1"
"player_state" "1"
}
}
53 changes: 53 additions & 0 deletions src/csgo_mediacontrol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const http = require('http');
var robot = require('robotjs');

var playing = true;
//robot.keyTap("audio_play");

const port = 3337;
const host = 'localhost';

const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html'
});

req.on('data', (data) => {
try {
processPayload(JSON.parse(data.toString()));
} catch (e) {
console.error(`Error retrieving data from API`)
}
});

req.on('end', () => {
res.end('');
});
});

/**
* Processes payloads to parse game events
*
* @param {object} data - Payload as JSON object
*/
function processPayload(data) {
if (!data.previously && !data.player) return;

if ((data.player.state.health === 0 || data.player.steamid !== data.provider.steamid) || (data.round && data.round.phase !== "live")) {
if (!playing) {
console.log('Play music');
robot.keyTap("audio_play");
playing = true;
}
} else {
if (playing) {
console.log('Stop music');
robot.keyTap("audio_pause");
playing = false;
}
}
}

server.listen(port, host);

console.log('Monitoring CS:GO rounds');

0 comments on commit 1163d1a

Please sign in to comment.