Skip to content

Instantly share code, notes, and snippets.

@Pupix

Pupix/index.js

Last active Jan 11, 2021
Embed
What would you like to do?
A minimal WAMP 1.0 protocol implementation to be used with the new League of Legends client (LCU)
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const WebSocket = require('ws');
const MESSAGE_TYPES = {
WELCOME: 0,
PREFIX: 1,
CALL: 2,
CALLRESULT: 3,
CALLERROR: 4,
SUBSCRIBE: 5,
UNSUBSCRIBE: 6,
PUBLISH: 7,
EVENT: 8
};
class RiotWSProtocol extends WebSocket {
constructor(url) {
super(url, 'wamp');
this.session = null;
this.on('message', this._onMessage.bind(this));
}
close() {
super.close();
this.session = null;
}
terminate() {
super.terminate();
this.session = null;
}
subscribe(topic, callback) {
super.addListener(topic, callback);
this.send(MESSAGE_TYPES.SUBSCRIBE, topic);
}
unsubscribe(topic, callback) {
super.removeListener(topic, callback);
this.send(MESSAGE_TYPES.UNSUBSCRIBE, topic);
}
send(type, message) {
super.send(JSON.stringify([type, message]));
}
_onMessage(message) {
const [type, ...data] = JSON.parse(message);
switch (type) {
case MESSAGE_TYPES.WELCOME:
this.session = data[0];
// this.protocolVersion = data[1];
// this.details = data[2];
break;
case MESSAGE_TYPES.CALLRESULT:
console.log('Unknown call, if you see this file an issue at https://discord.gg/hPtrMcx with the following data:', data);
break;
case MESSAGE_TYPES.TYPE_ID_CALLERROR:
console.log('Unknown call error, if you see this file an issue at https://discord.gg/hPtrMcx with the following data:', data);
break;
case MESSAGE_TYPES.EVENT:
const [topic, payload] = data;
this.emit(topic, payload);
break;
default:
console.log('Unknown type, if you see this file an issue with at https://discord.gg/hPtrMcx with the following data:', [type, data]);
break;
}
}
}
/** HOW TO USE */
const ws = new RiotWSProtocol('wss://riot:Vb4qOZdKanoA-9UB9gAN_Q@localhost:60588/');
ws.on('open', () => {
ws.subscribe('OnJsonApiEvent', console.log);
});
{
"name": "lcu-ws-protocol",
"version": "0.0.1",
"main": "index.js",
"author": "Robert Manolea <manolea.robert@gmail.com>",
"license": "MIT",
"dependencies": {
"ws": "^4.0.0"
}
}
@nomi-san

This comment has been minimized.

Copy link

@nomi-san nomi-san commented Feb 15, 2020

My short solution to subscribe "OnJsonApiEvent" topic 😁

// https://stackoverflow.com/questions/10888610/ignore-invalid-self-signed-ssl-certificate-in-node-js-with-https-request
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

// https://medium.com/@behrmann/league-client-update-extra-insights-f9f05c427657
// ws -> wss after security added
// just nodejs, no origin & authorization options
const ws = new WebSocket('wss://riot:PASS@127.0.0.1:PORT/', 'wamp');
ws.on('open', () => {
    ws.send('[5, "OnJsonApiEvent"]');
});
@Pupix

This comment has been minimized.

Copy link
Owner Author

@Pupix Pupix commented Feb 20, 2020

Because we all like obscure constants that you have no idea what they mean or that you forget about in a few months 😄

@w3webtool

This comment has been minimized.

Copy link

@w3webtool w3webtool commented Feb 25, 2020

hey Pupix, how to find the code OnJsonApiEvent to subcribe?

@Pupix

This comment has been minimized.

Copy link
Owner Author

@Pupix Pupix commented Feb 26, 2020

what code? you mean the name of the event or what?

@w3webtool

This comment has been minimized.

Copy link

@w3webtool w3webtool commented Mar 10, 2020

because I need a ws for listening baron and dragon killed but I dont know how to do it

@BalintGergely

This comment has been minimized.

Copy link

@BalintGergely BalintGergely commented Aug 2, 2020

I tried to send:
[2, "GetLolSummonerV1CurrentSummoner"]

I got back:
[4,"GetLolSummonerV1CurrentSummoner","InvalidRequest","Invalid WAMP call procedure URI.",0]

According to the WAMP documentation, I need some sort of resource identifier but I can not find what the LCU accepts. I have successfully retrieved the list of functions and subscribable events. How do I invoke functions through WAMP? What sort of prefix do they need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment