From d4e280a56326ff37da54a03a997f740e89b5379c Mon Sep 17 00:00:00 2001 From: slice Date: Fri, 13 Jul 2018 19:11:50 -0700 Subject: [PATCH] add ws reconnection logic --- priv/frontend/src/components/App.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/priv/frontend/src/components/App.js b/priv/frontend/src/components/App.js index 4f3718e..131a3ed 100644 --- a/priv/frontend/src/components/App.js +++ b/priv/frontend/src/components/App.js @@ -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);