Last active
January 11, 2025 23:32
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "lcu-ws-protocol", | |
"version": "0.0.1", | |
"main": "index.js", | |
"author": "Robert Manolea <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"ws": "^4.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You were missing the request ID. Either add an empty string, or add one randomly generated by you. E.g.
[2, "123", "GetLolSummonerV1CurrentSummoner"]
.