Skip to content

Instantly share code, notes, and snippets.

@Scub3d
Created January 7, 2019 22:31
Show Gist options
  • Save Scub3d/b86cafceef3faabe748121857fb78968 to your computer and use it in GitHub Desktop.
Save Scub3d/b86cafceef3faabe748121857fb78968 to your computer and use it in GitHub Desktop.
Nodejs script that allows the user to access the websocket stream of the lcu. Works assuming the League of Legends client is running on the computer
const websocket = require("ws");
const { exec } = require("child_process");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
exec('WMIC PROCESS get Caption,Commandline', {maxBuffer: 1024 * 500}, (err, stdout, stderr) => {
if(err) {
console.log(err);
return;
}
var lines = stdout.split('\n');
var result = '';
var _break = false;
lines.every(function(line, index) {
if(line.indexOf('LeagueClientUx.exe') > -1) {
result = line.replace(' +', ' ').replace(/|\s+$/g, '');
_break = true;;
}
if(_break) return false;
else return true;
});
if(result != '' || result != null || result != ' ') {
let token = result.match(/\"--remoting-auth-token=(\S+)\"/)[1];
let port = parseInt(result.match(/\"--app-port=(\S+)\"/)[1]);
const ws = new websocket('wss://riot:' + token + '@127.0.0.1:' + port.toString(), {
headers: {
Authorization: 'Basic ' + Buffer.from('riot:' + token).toString('base64'),
},
rejectUnauthorized: false,
});
ws.on('open', () => {
console.log("=== Open ===");
ws.send(JSON.stringify([5, 'OnJsonApiEvent']));
});
ws.on('message', data => {
if(data != null || data != '' || data != ' ') {
console.log(data);
}
});
ws.on('close', () => {
console.log("=== Closing ===");
});
ws.on('error', err => {
console.log("Error:", err);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment