Skip to content

Instantly share code, notes, and snippets.

@Pupix
Last active March 14, 2026 13:39
Show Gist options
  • Select an option

  • Save Pupix/eb662b1b784bb704a1390643738a8c15 to your computer and use it in GitHub Desktop.

Select an option

Save Pupix/eb662b1b784bb704a1390643738a8c15 to your computer and use it in GitHub Desktop.
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
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Author

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
Copy link
Copy Markdown

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

@Pupix
Copy link
Copy Markdown
Author

Pupix commented Feb 26, 2020

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

@w3webtool
Copy link
Copy Markdown

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

@BalintGergely
Copy link
Copy Markdown

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?

@iczero
Copy link
Copy Markdown

iczero commented Jun 20, 2021

@BalintGergely, if you still care, WAMP function calls are in the form of METHOD /path/name, matching those used for http. I wrote a thing a long time ago using it, see https://github.com/iczero/lol-client-api#api-documentation for examples.

@mikaeldui
Copy link
Copy Markdown

mikaeldui commented Mar 27, 2022

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?

You were missing the request ID. Either add an empty string, or add one randomly generated by you. E.g. [2, "123", "GetLolSummonerV1CurrentSummoner"].

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