(Note: hypothetical code examples below are in context of example chatting app)
(Note: I’m also beginner, so I apologize for any misunderstanding in the upcoming text)
Hello,
I’d like to ask how should I construct my channels.
Now I’m standing on the beginning and I dont know how to start… Most examples show how to create channel with topic: room:room_id. Thats ok, I understand that. But what about events such as room_created, room_renamed, room_deleted. Is it OK to write a channel with dedicated topic for such events? Also, where should I put code for broadcasting such events? Would it be inside the responsible socket’s handle_in("create_room" ...) (the one that originally issued a request for creating new room)? Or should I have some sort of PubSub baked into my business logic code that would accept that “new room” has been created and forward this information to interested sockets/channels? (if so, would it be a dedicated channel for this?)
You can create a lobby room where you’ll dispatch general messages such as room_created… so basically, when user join your chat app, they’ll join the room:lobby channel. After that their free to join other channel like `room:{id}ˋ
Where lobby is a fixed value and id is a variable.
When user join a room (e.g the lobby room) you can broadcast message into that room. So every user in lobby will be notify that a new room was created.
Oh yes, the docs indeed solve the problem I’m talking about… Has not realized that. It also makes sense to keep websocket stuff and event distribution inside the channel… (or the web app in general).