supabase-community / realtime-go

2 stars 3 forks source link

Establish & keep alive websocket connections with realtime server #3

Closed IcedTea2K closed 3 months ago

IcedTea2K commented 4 months ago

What kind of change does this PR introduce?

This PR delivers #1. At its core, it provides:

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.