Code Monkey home page Code Monkey logo

Comments (6)

Lyfhael avatar Lyfhael commented on May 18, 2024 1

I'm sorry, the event name JsonApiEvent was wrong. The correct name is OnJsonApiEvent.

-ws.onopen = () => ws.send(JSON.stringify([5, 'JsonApiEvent']))
+ws.onopen = () => ws.send(JSON.stringify([5, 'OnJsonApiEvent']))

Yay, it works <3 Thank you man

from penguloader.

nomi-san avatar nomi-san commented on May 18, 2024

You should subscribe to LCU websocket to detect it.
Please refer to LCU Websocket in README to do that in your plugin.

Here is an API to get the current phase.

GET /lol-gameflow/v1/gameflow-phase

The "ReadyCheck" result means ready to accept matchmaking found.
And "ChampSelect" means you're in champ-select phase.

from penguloader.

Lyfhael avatar Lyfhael commented on May 18, 2024

You should subscribe to LCU websocket to detect it. Please refer to LCU Websocket in README to do that in your plugin.

Here is an API to get the current phase.

GET /lol-gameflow/v1/gameflow-phase

The "ReadyCheck" result means ready to accept matchmaking found. And "ChampSelect" means you're in champ-select phase.

I managed to send the GET request and it worked. So I think I should send a GET Request every 1 second to detect whenever I get into a champ select.

Lastly I would need to know when someone send a message, if you have any idea

from penguloader.

nomi-san avatar nomi-san commented on May 18, 2024

You should subscribe to LCU websocket to detect it.
Please refer to LCU Websocket in README to do that in your plugin.

This will solve your problem.

In my comment above, you no need to call this API every seconds.
The websocket's onmessage callback will give you which API is called and its data.

ws.onmessage = async message => {
  const data = JSON.parse(message.data)
  console.log(data)

  const api = /* extract the data to get API */
  if (api === '/lol-gameflow/v1/gameflow-phase') {
    // todo
  }
}

from penguloader.

Lyfhael avatar Lyfhael commented on May 18, 2024

You should subscribe to LCU websocket to detect it.
Please refer to LCU Websocket in README to do that in your plugin.

This will solve your problem.

In my comment above, you no need to call this API every seconds. The websocket's onmessage callback will give you which API is called and its data.

ws.onmessage = async message => {
  const data = JSON.parse(message.data)
  console.log(data)

  const api = /* extract the data to get API */
  if (api === '/lol-gameflow/v1/gameflow-phase') {
    // todo
  }
}

Oh, there's been a misunderstanding.

When I said I sent a GET request and that it worked, I meant that I tried :

async function acceptMatchFound() {
  await fetch('/lol-matchmaking/v1/ready-check/accept', {
    method: 'POST'  
  })
}

The issue I had with the subscribe() function is that it wouldn't send back anything else than the initial response :
TquPb9s

After this when I connected to a champ-select, or when someone sent a message in champ-select, it wouldn't tell me(I put a console.log() inside it printing "yay", as you see it gets triggered once but then it doesn't anymroe)

Here is the code I pasted in the console to clear any misunderstanding :

function subscribe() {
  const uri = document.querySelector('link[rel="riot:plugins:websocket"]').href
  const ws = new WebSocket(uri, 'wamp')
  
  ws.onopen = () => ws.send(JSON.stringify([5, 'JsonApiEvent']))
  ws.onmessage = async message => {
    const data = JSON.parse(message.data)
    console.log(data)
    console.log("yay")
  }
}

from penguloader.

nomi-san avatar nomi-san commented on May 18, 2024

I'm sorry, the event name JsonApiEvent was wrong.
The correct name is OnJsonApiEvent.

-ws.onopen = () => ws.send(JSON.stringify([5, 'JsonApiEvent']))
+ws.onopen = () => ws.send(JSON.stringify([5, 'OnJsonApiEvent']))

from penguloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.