d12/social_spaces

Handle people leaving the game

d12 opened this issue · 2 comments

d12 commented

When someone leaves a game, we need to send a message to the game

d12 commented

In ActivityChannel we have a method #unsubscribed which gets fired every time a client closes the websocket connection:

But we don't want to immediately boot people from the game or skip their turn if they just lose internet for a moment and immediately reconnect.

What if we set disconnected_at on the user model when they disconnect, and unset when they re-connect. Then if we detect it's been > (10s, 20s, 30s) since they disconnected, we can let the game know that the user is officially "disconnected" and should be temporarily removed from the game.

Would it be excessive to have a job run every 5 seconds that checks for players in a game who've been disconnected for more than 30s? We could also lump this into the ActivityLoop thing we built out but aren't actually using yet. It could be a check that the loop runs every cycle or every few cycles.

d12 commented

disconnected_at is all working and hooked up to the activity loop system. If the number of players dips below the minimum number of players, the game is ended and all remaining players are sent to the activity index. Otherwise, we send an event to the activity telling it a player disconnected. Each activity is in charge of figuring out how to handle this event since each activity is different and may need to modify internal state to keep the activity working and moving forward.