API active game changes

Hello, I could use some hints how to correctly update my UI for changes in the active games.
The trivial approach i guess is to poll /api/v1/ui/overview in an interval and look for changes there.
But i feel that the usage of the websockets API might be the cleaner solution. But i can’t figure out to what channel i need to subscribe.

  1. Observe Games page
  2. Open Network tab
  3. view sent messages only
  4. Filter by “game”
  5. enjoy :slight_smile:

Also, the relevant source would be GobanCore. ctrl+Fing for _socket_on should get you where you need to go!

3 Likes

Thanks a lot @benjito!
I saw the game channel before, just didn’t expect it to be used for that purpose. But yes, it makes sense.

1 Like

I got it to work, thanks for your help so far!

I hope you don’t mind me asking two more questions:

  • what do i need to listen to on the websocket to get notified about new games created?
  • what would be the correct timeout for the ping/pong game the websockets play?

Thanks in advance for any answer.

1 Like

There will be an active_game message on the socket when there is a new game. I’m not sure how to get it though, but probably you need to send some combination of authenticate, notification/connect, and chat/connect (I always send all 3 of them after the socket is connected).

10 seconds. The code for that is located at src/lib/sockets.ts.

2 Likes

Thanks @HongAnhKhoa for your answer!

Unfortunately, i couldn’t get the active_game messages to appear so far.
I am sending both, notification and chat connect messages now. Although i have no idea what the ranking and ui_class parameters do, i don’t get any error messeages, so i assume they are accepted.

Any further ideas what I could try would be highly appreceated :slight_smile:

@monsterkodi have you made any progress on this? My guess is that you need to authenticate a user before you will be able to see the messages from active_games. Have you done anything with the authenticate message?

1 Like

Hello @benjito
thanks for asking. Unfortunately, no, i couldn’t get it to work.
And yes, i am authenticating myself. I guess i couldn’t play games otherwise.
I get all kinds of information on the web-socket, even stuff i didn’t ask for :slight_smile:
What I get:
pong, active-bots, score-estimator-enabled-state, automatch/* and game/* messages.
I noticed, that i don’t get chat messages when i chat during a game, although i send a chat/connect after authentication.
I am using the same socket.io-client node module as the code on github. What i find strange: the documentation states that i can add a callback as last argument to get some acknowlegment status, but those get never called, so i am not really sure the stuff i send gets accepted.

1 Like

This worked for me in the past: ogs_api/chat.py at master · flovo/ogs_api · GitHub

Note there is a separate chat-auth-token send with the connect message. Also you need to chat/join a chat to get chat messages.

I don’t think it will send you anything about games, not even game chat.

2 Likes

The server bundles them with the chat message, so the client can use these cached values until it receives the actual values over other API-calls.

1 Like

Thanks @flovo.
I got the game chat to work now.
But my main issue (getting notifications about new active games) is still unsolved :frowning:

Hello,
I finally figured it out: it seems that the active_game messages get sent after a successful emit of notification/connect
My problem was that i somehow missed that there is a separate auth key for notifications.
I am happy now, and will even get chat working now, which wasn’t actually planned :slight_smile: Thanks all for your help!

1 Like

Hello again :slight_smile:

I have observed a weird behaviour of the web socket and thought it might be of interest to someone:

Sometimes the websocket announces old finished games as active games.
I haven’t figured out any pattern why it might do that, it happens not frequently enough.

I can just filter and ignore those games, but I am curious if that is a bug or am i missing something?

Could you share the json? Two scenarios I can think of:

  • casual rengo where you’ve left the game but the game is still ongoing
  • post game chat notification (not sure if this goes out over the active games api, just throwing stuff out there)
1 Like

Yes i will, i have to wait until it happens again though, which is not that often. Usually I notice it only when I use my client for longer periods (a couple of hours).

I am pretty sure it’s not one of the cases you mentioned. I have never played rengo and there is no new chat. Those are just arbitrary and quite old games. I have the feeling they are all from 9x9 tournaments, but i am not sure about that.

I will send you the data if it happens again.

1 Like

I have a theory that a server-restart causes this to happen, as well…

2 Likes