Some structure for the RealtimeClient as well as some common events/responses from the server.
A way to connect/disconnect to the Realtime server websocket.
Heartbeat mechanism to keep the connection alive without blocking.
Retrying mechanism when the heartbeat has failed to reach the server.
What is the current behavior?
N/A. Extremely happy to be the first one to deliver a feature :D
What is the new behavior?
New behaviour: RealtimeClient, persistent Websocket connections. Below is the output of a very simple program that creates a RealtimeClient and connect to a deployed database for 1 minute before disconnecting.
➜ go run .
Creating new websocket
2024/05/12 01:01:40 Sending heartbeat
2024/05/12 01:02:00 Sending heartbeat
2024/05/12 01:02:20 Sending heartbeat
2024/05/12 01:02:40 Sending heartbeat
Ending the program
Additional context
All the time-stamped logging are from within internal logger, which can definitely exposed in the future for users to customize their logging. Also, a side quick side note/explanation. Errors are logged for internal methods that cannot be returned to the user such as startHeartbeats, reconnect, etc. meanwhile, those that can be returned are returned to be handled by the user.
Unsure about our policy on using a third-party package yet, but to establish websocket, I chose nhooyr.io/websocket as it's widely used and it'll be able to compile to WASM.
What kind of change does this PR introduce?
This PR delivers #1. At its core, it provides:
RealtimeClient
as well as some common events/responses from the server.What is the current behavior?
N/A. Extremely happy to be the first one to deliver a feature :D
What is the new behavior?
New behaviour: RealtimeClient, persistent Websocket connections. Below is the output of a very simple program that creates a
RealtimeClient
and connect to a deployed database for 1 minute before disconnecting.Additional context
All the time-stamped logging are from within internal logger, which can definitely exposed in the future for users to customize their logging. Also, a side quick side note/explanation. Errors are logged for internal methods that cannot be returned to the user such as
startHeartbeats
,reconnect
, etc. meanwhile, those that can be returned are returned to be handled by the user.Unsure about our policy on using a third-party package yet, but to establish websocket, I chose nhooyr.io/websocket as it's widely used and it'll be able to compile to WASM.