Hi,
I’m building a game where n players play a party (don’t know the actual english word, like a game or a match) together. It’s kind of a quiz game.
This is a single page application, where a user can create a new party and send an invitation link to other players. Players who play several parties in a row never leave or reload the page, I use a router component with Svelte (it’s like Vue or React).
When a party is created, players join a party:XXXXXXX
channel. The channel pushes the game state on every change, and receives players answers for the quiz questions.
I’ve set up a bunch of listeners on the channel, with channel.on('some_event', fn)
, also an error reporting system with channel.onError
, etc.
When the party is finished, I call channel.leave()
, and when a new party is started, I rebind my channel
variable to the new channel.
But I have the feeling it is not enough, I have no guarantee that all these event listeners are properly cleaned up, and that their are not hanging somewhere with a lot of closures. Should I call channel.off(…)
before leaving the channel, for all listeners previously set up ? Would it be enough ?
Or should I instead join a private channel for the player, where I subscribe to parties server side ? I use the join/3
function (elixir side) to verify that the player has been invited to the party (or created it), or reply :error
otherwise, and I can keep the party ID in the socket data, so having a dedicated party channel is straightforward. But on the otherside it feels complicated to handle join rejections and managing channel setup/cleanup, where having a player channel would there be the straightforward solution.
Does someone have a similar situation or any advice on this topic ?
Thank you