-
-
Save Pupix/eb662b1b784bb704a1390643738a8c15 to your computer and use it in GitHub Desktop.
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" | |
} | |
} |
because I need a ws for listening baron and dragon killed but I dont know how to do it
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?
@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.
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"]
.
what code? you mean the name of the event or what?