-
Notifications
You must be signed in to change notification settings - Fork 2
Websocket
I would look at api.js, in particular the "AutoWebsocket" function, for the best, most up-to-date code example for how to connect to and utilize the websocket manually
Endpoint is: api/live/ws?token=<yourlogintoken>&lastId=<lastEventIdOr0>
You need your login token to connect to the websocket. The websocket will use the same token for the entire duration of the connection, and will disconnect once the token is invalid with a badtoken response type. This is one of the critical errors that will close the websocket described in https://github.com/randomouscrap98/contentapi/wiki/Errors#websocket-errors.
The token is sent as a GET parameter. I know this is probably spooky, and if it is extremely bothersome, we can create a new way to do so, it just greatly simplifies both ends of the connection to have the token available on connect, and the websocket spec does not allow you to send arbitrary headers, so we can't just reuse the current token header.
If your connection is accepted, you will IMMEDIATELY receive a lastId response type from the websocket. You should not under any circumstance receive another message first. You can use the lastId response type as a "true open" event, meaning both your token and the lastId was accepted and live updates will now commence. This is how Api.AutoWebsocket works in api.js. You should NOT send any websocket requests (such as request or setuserstatus) until you receive this response.