I have a lot of channels doing different things like the following:
starting_channel
game_channel
food_channel
chat_channel
And there's maybe 100 of them.
Everyone starts by joining starting_channel
. Later I can subscribe the socket to other channel topics and broadcast to different topics accordingly. But the thing is I would not be able to reuse the handle_in
functionalities in those channels because users don't actually join them in the first place.
For example, let's say room_channel has this handler:
def handle_in("show_room_happy_users", _payload, socket) do
broadcast! socket, "happy_users", Presence.list(socket)
{:noreply, socket}
end
But since you didn't join this channel when you send show_room_happy_users
message through the starting_channel
nothing would happen.
Is there a way to achieve this without joining all the channel at once?