add ws reconnection logic

This commit is contained in:
Skip R. 2018-07-13 19:11:50 -07:00
parent 1b74c3da3f
commit d4e280a563
No known key found for this signature in database
GPG key ID: 1508C19D7436A26D

View file

@ -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);