Skip to content

Conversation

@peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Feb 11, 2025

We encounter several devices on which WebSocket are not available / are blocked.

This PR implements a fallback to HTTP POST-based log reporting when the WebSocket connection establishement does not succeed.

The idea for now is that the client send logs to the RxPaired server through HTTP POST every 2/3 seconds.

To divide messages sent in bulk between one another, those are sent as a JSON array in chronological order.

This adds many complexities especially on the server, as now the lifetime of a token might be unclear: is the device still using its token or not? With a WebSocket we just checked the connection state (and did keepalive ping-pong messages), when based on HTTP POST, we now rely on a timeout without any message, for now set to 30 seconds.

For now it's not possible to use sendInstruction when a device relies on HTTP POST. It could theoretically be done through several means including Server-Sent-Events and long polling, but I did not bother for now.

@peaBerberian
Copy link
Collaborator Author

NOTE: I realized that this feature interacts poorly with the "no-token" mode, as each HTTP POST might generate a new token there.

A solution has to be found for that case... (e.g. return generated token as the first http post's response?)

@peaBerberian
Copy link
Collaborator Author

I tried something:

- If using the `/!notoken` route, the server will send back the generated token
  for that connection as a response for that HTTP POST request.

  The client should then use that token for subsequent HTTP POST requests which
  should thus now be on the `/<TOKEN_ID>` URL.

We encounter several devices on which WebSocket are not available / are
blocked.

This commit implements a fallback to HTTP POST-based log reporting when
the WebSocket connection establishement does not succeed.

The idea for now is that basically the client send logs to the RxPaired
server through HTTP POST every 2/3 seconds.

To divide messages sent in bulk between one another, I chose for now a
NULL byte (`\0`). This is kind of ugly but thankfully having a real NULL
byte in a sent log should be extremely rare.
I could also have JSONified everything and set logs inside an array.

This adds many complexities especially on the server, as now the
lifetime of a token might be unclear: is the device still using its
token or not? With a WebSocket we just checked the connection state (and
did keepalive ping-pong messages), when based on HTTP POST, we now rely
on a timeout without any message, for now set to 30 seconds.

For now it's not possible to use `sendInstruction` when a device relies
on HTTP POST. It could theoretically be done through several means
including Server-Sent-Events and long polling, but I did not bother for
now.
@peaBerberian peaBerberian merged commit ff55986 into main Feb 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants