Allow Phoenix.Presence to specify the message dispatcher

Phoenix.Presence sends “presence_diff” events using

Phoenix.Channel.Server.local_broadcast/4

https://github.com/phoenixframework/phoenix/blob/675e924f73da1a594e07ba22fcbda6636790ce4a/lib/phoenix/presence.ex#L510-L515

If someone is using a non-standard metadata when subscribing to the topic it’s not possible to specify a custom dispatcher module. It will always use the Phoenix.Channel.Server.dispatch/3 function.

Would it make sense to allow a :dispatcher option and use instead:

 broadcast = %Broadcast{
      topic: topic,
      event: "presence_diff",
      payload: presence_diff
    }
Phoenix.PubSub.local_broadcast(state.pubsub_server, topic, broadcast, dispatcher) 

where dispatcher defaults to Phoenix.Channel.Server

Thoughts?

https://github.com/supabase/realtime/pull/1558

1 Like