I’m currently working on a real-time application where I utilize Gorilla WebSocket in conjunction with Next.js. One of the challenges I’m facing is that when a user refreshes the page, a new WebSocket connection is established. This causes the user to lose control of their session or data, especially in scenarios like multiplayer games where continuity is crucial.
Is there a recommended approach or best practice to handle WebSocket connections in a way that maintains session integrity even if the user refreshes the page? Ideally, I’d like to ensure that the user retains their session state and doesn’t lose their place or control upon refreshing.
I am currently working on trying to use cookies to store the client id, but I’m not sure how to reconnect the user to the same websocket connection given a client id.