Skip to content

Commit 377748d

Browse files
committed
add network disconnect message
1 parent 0d83b12 commit 377748d

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { useContext } from 'react';
2+
import { networkMachineStates } from '../machines/game';
3+
import GameContext from './GameContext';
4+
5+
const NetworkAlert = () => {
6+
const { current: gameCurrent } = useContext(GameContext);
7+
8+
if (gameCurrent.matches({ network: networkMachineStates.disconnected })) {
9+
return <div className="col-12 bg-warning text-center">Check your network connection</div>;
10+
}
11+
12+
return (<></>);
13+
};
14+
15+
export default NetworkAlert;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import FeedBackWidget from '../components/FeedBackWidget';
2020
import GamePreview from '../components/Game/GamePreview';
2121
import { replayerMachineStates } from '../machines/game';
2222
import AnimationModal from '../components/AnimationModal';
23+
import NetworkAlert from './NetworkAlert';
2324

2425
const steps = [
2526
{
@@ -235,6 +236,7 @@ const RootContainer = ({
235236
<GameContext.Provider value={{ current, send, service }}>
236237
<div className="x-outline-none">
237238
<GameWidgetGuide />
239+
<NetworkAlert />
238240
<div className="container-fluid">
239241
<div className="row no-gutter cb-game">
240242
<AnimationModal setModalShowing={setModalShowing} modalShowing={modalShowing} />

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ const machine = {
7777
none: {
7878
on: {
7979
JOIN: { target: 'connected' },
80-
FAILURE: { target: 'disconnected', actions: ['handleFailureJoin'] },
80+
FAILURE_JOIN: { target: 'disconnected', actions: ['handleFailureJoin'] },
81+
FAILURE: { target: 'disconnected', actions: ['handleDisconnection'] },
8182
},
8283
},
8384
disconnected: {
@@ -265,9 +266,15 @@ const states = {
265266
ended: 'on.ended',
266267
off: 'off',
267268
},
269+
network: {
270+
none: 'none',
271+
disconnected: 'disconnected',
272+
connected: 'connected',
273+
},
268274
};
269275

270276
export const gameMachineStates = states.game;
271277
export const replayerMachineStates = states.replayer;
278+
export const networkMachineStates = states.network;
272279

273280
export default machine;

0 commit comments

Comments
 (0)