Skip to content

Commit

Permalink
Trying to fix multiple EventStream connections, one more time
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Dec 2, 2021
1 parent a99b9b4 commit 69615f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 8 additions & 2 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import createAdminStore from './store/createAdminStore'
import { i18nProvider } from './i18n'
import config from './config'
import { setDispatch, startEventStream } from './eventStream'
import { setDispatch, startEventStream, stopEventStream } from './eventStream'
import { keyMap } from './hotkeys'
import useChangeThemeColor from './useChangeThemeColor'

Expand Down Expand Up @@ -70,7 +70,13 @@ const Admin = (props) => {
useEffect(() => {
if (config.devActivityPanel) {
setDispatch(adminStore.dispatch)
authProvider.checkAuth().then(() => startEventStream(adminStore.dispatch))
authProvider
.checkAuth()
.then(() => startEventStream(adminStore.dispatch))
.catch(() => {})
}
return () => {
stopEventStream()
}
}, [])

Expand Down
11 changes: 5 additions & 6 deletions ui/src/eventStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ const setTimeout = (value) => {
window.clearTimeout(timeout)
}
timeout = window.setTimeout(async () => {
if (es) {
es.close()
}
es?.close()
es = null
await startEventStream()
}, currentIntervalCheck)
}

const stopEventStream = () => {
if (es) {
es.close()
}
es?.close()
es = null
if (timeout) {
window.clearTimeout(timeout)
}
timeout = null
console.log('eventSource closed') // TODO For debug purposes. Remove later
}

const setDispatch = (dispatchFunc) => {
Expand Down Expand Up @@ -77,6 +74,8 @@ const startEventStream = async () => {
newStream.addEventListener('keepAlive', eventHandler)
newStream.onerror = (e) => {
console.log('EventStream error', e)
es?.close()
es = null
setTimeout(reconnectIntervalCheck)
dispatch(serverDown())
}
Expand Down

0 comments on commit 69615f1

Please sign in to comment.