Reset game state on re-connect
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
def2afac6d
commit
dfc5123d25
@ -19,6 +19,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.Table .ErrorDialog {
|
.Table .ErrorDialog {
|
||||||
|
z-index: 10000;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -45,11 +45,27 @@ const Table = () => {
|
|||||||
setWs(event.target);
|
setWs(event.target);
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
|
|
||||||
/* Request a game-update */
|
/* Request a full game-update
|
||||||
event.target.send(JSON.stringify({
|
* We only need gameId and name for App.js, however in the event
|
||||||
type: 'get',
|
* of a network disconnect, we need to refresh the entire game
|
||||||
fields: [ 'name', 'id' ]
|
* state on reload so all bound components reflect the latest
|
||||||
}));
|
* state */
|
||||||
|
if (loaded) {
|
||||||
|
event.target.send(JSON.stringify({
|
||||||
|
type: 'game-update'
|
||||||
|
}));
|
||||||
|
if (name) {
|
||||||
|
event.target.send(JSON.stringify({
|
||||||
|
type: 'player-name',
|
||||||
|
name
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.target.send(JSON.stringify({
|
||||||
|
type: 'get',
|
||||||
|
fields: [ 'name', 'id' ]
|
||||||
|
}))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWsMessage = (event) => {
|
const onWsMessage = (event) => {
|
||||||
@ -97,12 +113,17 @@ const Table = () => {
|
|||||||
const error = `Connection to Ketr Ketran game server failed! ` +
|
const error = `Connection to Ketr Ketran game server failed! ` +
|
||||||
`Connection attempt will be retried every 5 seconds.`;
|
`Connection attempt will be retried every 5 seconds.`;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
setWs(undefined);
|
||||||
resetConnection();
|
resetConnection();
|
||||||
setError(error);
|
setError(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWsClose = (event) => {
|
const onWsClose = (event) => {
|
||||||
|
const error = `Connection to Ketr Ketran game was lost. ` +
|
||||||
|
`Attempting to reconnect...`;
|
||||||
|
console.error(error);
|
||||||
console.log(`ws: close`);
|
console.log(`ws: close`);
|
||||||
|
setWs(undefined);
|
||||||
resetConnection();
|
resetConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user