1
0

Hooking in No Network icon

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-02-28 18:59:36 -08:00
parent b2c4e54432
commit 3f97e66f46
3 changed files with 39 additions and 8 deletions

View File

@ -18,6 +18,25 @@
z-index: 10000; z-index: 10000;
} }
.NoNetwork {
position: absolute;
z-index: 10000;
display: flex;
top: 1em;
right: 31em;
width: 3em;
height: 3em;
background-image: url("./assets/no-network.png");
background-size: contain;
background-position: center;
}
.Roberta .Pip-Shape:hover,
.Roberta .Pip-Shape {
background-image:url("./assets/woman-robber.png");
}
.BottomBar { .BottomBar {
display: flex; display: flex;
margin-right: 30rem; margin-right: 30rem;

View File

@ -527,7 +527,8 @@ class Table extends React.Component {
signature: "", signature: "",
buildActive: false, buildActive: false,
cardActive: undefined, cardActive: undefined,
loading: 0 loading: 0,
noNetwork: false
}; };
this.componentDidMount = this.componentDidMount.bind(this); this.componentDidMount = this.componentDidMount.bind(this);
this.throwDice = this.throwDice.bind(this); this.throwDice = this.throwDice.bind(this);
@ -857,6 +858,16 @@ class Table extends React.Component {
this.setState({ message: message }); this.setState({ message: message });
} }
resetKeepAlive() {
if (this.keepAlive) {
clearTimeout(this.keepAlive);
}
this.keepAlive = setTimeout(() => {
console.error(`No server ping for 5 seconds!`);
this.setState({ noNetwork: true });
}, 5000);
}
componentDidMount() { componentDidMount() {
this.start = new Date(); this.start = new Date();
@ -872,6 +883,8 @@ class Table extends React.Component {
this.ws.onopen = (event) => { this.ws.onopen = (event) => {
console.log(`WebSocket open:`, event); console.log(`WebSocket open:`, event);
this.setState({ noNetwork: false });
this.resetKeepAlive();
}; };
this.ws.onmessage = (event) => { this.ws.onmessage = (event) => {
@ -892,18 +905,15 @@ class Table extends React.Component {
this.setError(error); this.setError(error);
break; break;
case 'ping': case 'ping':
if (this.keepAlive) {
clearTimeout(this.keepAlive);
}
this.keepAlive = setTimeout(() => {
console.error(`No server ping for 5 seconds!`);
}, 5000);
this.ws.send(JSON.stringify({ type: 'pong', timestamp: data.ping })); this.ws.send(JSON.stringify({ type: 'pong', timestamp: data.ping }));
break; break;
default: default:
console.log(`Unknown event type: ${data.type}`); console.log(`Unknown event type: ${data.type}`);
break; break;
} }
this.resetKeepAlive();
this.setState({ noNetwork: false });
} }
this.ws.onerror = (event) => { this.ws.onerror = (event) => {
@ -912,7 +922,7 @@ class Table extends React.Component {
}; };
this.ws.onclose = (event) => { this.ws.onclose = (event) => {
this.setState({ error: event.message }); this.setState({ noNetowrk: true, error: event.message });
console.error(`WebSocket close:`, event); console.error(`WebSocket close:`, event);
}; };
@ -1043,6 +1053,8 @@ class Table extends React.Component {
{ this.state.loading > 0 && { this.state.loading > 0 &&
<CircularProgress className='Loading'/> <CircularProgress className='Loading'/>
} }
{ this.state.noNetwork && <div className='NoNetwork'/> }
<div style={{display: "inline-flex", flex: 1, flexDirection: "column"}}> <div style={{display: "inline-flex", flex: 1, flexDirection: "column"}}>
<Board table={this} game={game}/> <Board table={this} game={game}/>

BIN
client/src/assets/no-network.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB