I want users to subsribe to zones. And based off the zone receive events.
In this example I have shout. But my client receives the shout message multiple times.
What am I doing wrong?
def join("world:lobby", _message, socket) do
PubSub.subscribe(Rotb.PubSub, "zone_1")
{:ok, socket}
end
def handle_info(%{message: message}, socket) do
broadcast(socket, "shout", %{"socket_id" => socket.id, "message" => message})
{:noreply, socket}
end
def handle_in("shout", payload, socket) do
PubSub.broadcast(Rotb.PubSub, "zone_1", %{
message: payload["message"]
})
{:noreply, socket}
end