Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

chg: [serializer] add support for phoenix version 2 serialization#68

Closed
gallypette wants to merge 37 commits intosupabase:mainfrom
flowintel:master
Closed

chg: [serializer] add support for phoenix version 2 serialization#68
gallypette wants to merge 37 commits intosupabase:mainfrom
flowintel:master

Conversation

@gallypette
Copy link
Copy Markdown

A PR to be able to use this library with latest phoenix versions.

feature: support phoenix version 2 serialization (mostly turn {} in [])
bugfix: socket.summary was broken
default: set hearbeat to 30 seconds (javascript's version default)

I did not test whether I broke compatibility with version 1, so consider this as a request for comments.

@gallypette
Copy link
Copy Markdown
Author

I added basic support for sending data.

@MindsightsAI
Copy link
Copy Markdown

@gallypette Is broadcast functionality working right now?

@gallypette
Copy link
Copy Markdown
Author

It is still a poc, but yes.
I am a bit short on the documentation side but something like this should do to send packets:

from realtime.connection import Socket

if __name__ == "__main__":
    TOKEN = "your token
    URL = f"ws://127.0.0.1:4000/socket/websocket?token={TOKEN}&vsn=2.0.0"

    ss = Socket(URL)
    ss.connect()

    channel_s = ss.set_channel("your channel")
    channel_s.join()
    channel_s.send("your event", "this is my payload 1", None)

The library has to be converted to full async to be able to send/receive without getting stuck in the listen function.

@MindsightsAI
Copy link
Copy Markdown

MindsightsAI commented Oct 20, 2023

@gallypette i can't make it workable

    def test_function(payload):
        print(payload)   -> there error 'unmatched topic'

    t1 = s.set_channel("test function")
    t1.join()
    t1.on("test event", callback=test_function, ref=None)
    t1.send("test event", "Bla bla bla", None)

image

@gallypette
Copy link
Copy Markdown
Author

I guess you don't match correctly on your topic name in your channel code. Something like this would do:

def join(_topic, _payload, socket) do
   {:ok, socket}
end

def handle_in("test event", payload, socket) do
  {:reply, {:ok, payload}, socket}
end

For listening for the answer is a bit tricky though (because of the while loop in listen) but it could work for a few message. You could react on any event:

channel_s.on(None, None, callback1)
t1.listen()

Get answer to your input:

t1.on(None, 1, callback1)
t1.send("test event", "this is my payload 1", 1)
t1.listen()

@gallypette
Copy link
Copy Markdown
Author

I pushed an async version that is more suitable for send/receive patterns.
It diverged significantly so don't merge that, the API is not compatible anymore.

@gallypette gallypette closed this Oct 20, 2023
@MindsightsAI
Copy link
Copy Markdown

MindsightsAI commented Oct 24, 2023

@gallypette Can we use broadcast events using your asynchronous branch(flowintel:master) with realtime server in saas version of supabase? Or we need implement some handlers at Phoenix?

@gallypette
Copy link
Copy Markdown
Author

@MindsightsAI I was not aware that supabase realtime had this feature.

Going quickly through realtime-js source code for send and _push, it looks like sending a "broadcast" event should work out of the box using this branch.

@gallypette
Copy link
Copy Markdown
Author

I reopen this PR as it seems relevant after all.

@silentworks silentworks self-requested a review November 13, 2023 19:01
@silentworks silentworks self-assigned this Nov 13, 2023
@gallypette
Copy link
Copy Markdown
Author

I just found out about @maxbaluev and @karvetskiy 's fork and decided to merge their forks into this PR to keep track of their progress.

@ghost
Copy link
Copy Markdown

ghost commented Dec 2, 2023

@gallypette Hey. Thanks for noticing my PR. Want to notify you to be careful with sync callbacks because they are running blocking now. I think it is better to implement Thread execution logic if you want to use it

@adulau
Copy link
Copy Markdown

adulau commented Feb 9, 2024

Thanks for the work on this. Any news for the merge in the default branch? We recently saw https://github.com/bitnom/aiorealtime so maybe it's another option.

@o-santi
Copy link
Copy Markdown
Contributor

o-santi commented Jul 31, 2025

Closing this as too old.

@o-santi o-santi closed this Jul 31, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Supabase Python Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants