Skip to content

Commit

Permalink
Remove unload event (#192)
Browse files Browse the repository at this point in the history
* use page hide event, manually reconnect

* comment

* lint
  • Loading branch information
AlecM33 committed Mar 27, 2024
1 parent 1833bde commit 01ed3c6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/src/modules/page_handlers/gameHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { InProgress } from '../game_state/states/InProgress.js';
import { Ended } from '../game_state/states/Ended.js';

export const gameHandler = (socket, window, gameDOM) => {
window.onunload = () => {
window.onpagehide = () => {
socket.close();
};
document.body.innerHTML = gameDOM + document.body.innerHTML;
Expand Down Expand Up @@ -60,8 +60,11 @@ export const gameHandler = (socket, window, gameDOM) => {
toast(err, 'error', true, false);
});

socket.on('disconnect', () => {
socket.on('disconnect', (reason) => {
toast('Disconnected. Attempting reconnect...', 'error', true, false);
if (reason === 'io client disconnect') { // see https://socket.io/docs/v4/client-api/#event-disconnect
socket.connect();
}
});
setClientSocketHandlers(stateBucket, socket);
resolve();
Expand Down

0 comments on commit 01ed3c6

Please sign in to comment.