Skip to content

Commit 8ec138e

Browse files
committed
add delay when websocket disconnected
1 parent e3c84a5 commit 8ec138e

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

services/app/assets/js/widgets/containers/NetworkAlert.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import GameContext from './GameContext';
55
const NetworkAlert = () => {
66
const { current: gameCurrent } = useContext(GameContext);
77

8-
if (gameCurrent.matches({ network: networkMachineStates.disconnected })) {
8+
if (gameCurrent.matches({ network: networkMachineStates.disconnectedWithMessage })) {
99
return <div className="col-12 bg-warning text-center">Check your network connection</div>;
1010
}
1111

services/app/assets/js/widgets/machines/game.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { assign } from 'xstate';
1+
import { assign, actions } from 'xstate';
22
import speedModes from '../config/speedModes';
33
import sound from '../lib/sound';
44
import GameStatusCodes from '../config/gameStatusCodes';
55

6+
const { send } = actions;
7+
68
const recordMachine = {
79
initial: 'ended',
810
states: {
@@ -78,17 +80,29 @@ const machine = {
7880
on: {
7981
JOIN: { target: 'connected' },
8082
FAILURE_JOIN: { target: 'disconnected', actions: ['handleFailureJoin'] },
81-
FAILURE: { target: 'disconnected', actions: ['handleDisconnection'] },
83+
FAILURE: { target: 'disconnected' },
8284
},
8385
},
8486
disconnected: {
87+
entry: send(
88+
{ type: 'SHOW_ERROR_MESSAGE' },
89+
{
90+
delay: 5000,
91+
},
92+
),
93+
on: {
94+
JOIN: { target: 'connected', actions: ['handleReconnection'] },
95+
SHOW_ERROR_MESSAGE: { target: 'disconnectedWithMessage', actions: ['handleDisconnection'] },
96+
},
97+
},
98+
disconnectedWithMessage: {
8599
on: {
86100
JOIN: { target: 'connected', actions: ['handleReconnection'] },
87101
},
88102
},
89103
connected: {
90104
on: {
91-
FAILURE: { target: 'disconnected', actions: ['handleDisconnection'] },
105+
FAILURE: { target: 'disconnected' },
92106
},
93107
},
94108
},
@@ -269,6 +283,7 @@ const states = {
269283
network: {
270284
none: 'none',
271285
disconnected: 'disconnected',
286+
disconnectedWithMessage: 'disconnectedWithMessage',
272287
connected: 'connected',
273288
},
274289
};

0 commit comments

Comments
 (0)