add ws reconnection logic
This commit is contained in:
parent
1b74c3da3f
commit
d4e280a563
1 changed files with 8 additions and 0 deletions
|
@ -12,6 +12,8 @@ const DOMAIN = 'https://elstatus.stayathomeserver.club';
|
|||
export default class App extends Component {
|
||||
websocket = null;
|
||||
|
||||
reconnectionTime = 1000;
|
||||
|
||||
state = {
|
||||
loading: true,
|
||||
error: null,
|
||||
|
@ -75,6 +77,12 @@ export default class App extends Component {
|
|||
this.subscribeToChannels();
|
||||
};
|
||||
|
||||
this.websocket.onclose = () => {
|
||||
log(`ws closed; attempting to reconnect in ${this.reconnectionTime}ms`);
|
||||
setTimeout(() => this.connect(), this.reconnectionTime);
|
||||
this.reconnectionTime *= 2;
|
||||
};
|
||||
|
||||
this.websocket.onmessage = (message) => {
|
||||
const { data } = message;
|
||||
const parsed = JSON.parse(data);
|
||||
|
|
Loading…
Reference in a new issue