Pass existing WebSockets into realtime APIs #1420
Unanswered
kristianfreeman
asked this question in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I've been experimenting with Supabase running on Cloudflare Workers - basic API requests are working, but I'm stuck on working with realtime data!
We recently announced WebSocket support in Workers. You can work with WSs in Workers by creating a
WebSocketPair, which is an object containing a server and client WebSocket. TheclientWebSocket is sent down to the client, and theserverWebSocket remains available in an open connection for the Workers function to work with:This
serverWebSocket instance is a great candidate for being used by Supabase to provide realtime data through the Workers function to the client. Our WebSocket API is fairly similar to the w3c spec, but differs in some respects, specifically around event handling (we useaddEventListenerinstead ofonopen,onclose, etc.) and a few fields we don't implement.It would be great to use these WebSockets with Supabase! Given that we already create WebSockets in Workers via our own API, allowing users to pass in an existing WebSocket would simplify the work on the Supabase end. Ideally, we could wrap the WebSocket with a few more functions, and basically polyfill a class that would make it compatible with the work you've already done. For instance, we can patch
oncloseto equaladdEventListener('close'), etc.Here's a stab at what that would look like -- not sure if it's the right place, but the idea would be that at some point in the setup process for a subscription, you could pass in a
websocketconfig option, like insubscribe():Another neat option would be to expose the websocket as an argument to the
oncallback function, so you could access it directly inside of the function itself:I'm still pretty new to Supabase and wrapping my head around the different codebases, and how they all work together. If any thoughts come out of this or if I can give more details, let me know! Super excited about Supabase and having a lot of fun building with it right now :)
All reactions