Trying to fix multiple EventStream connections, one more time
This commit is contained in:
+8
-2
@@ -29,7 +29,7 @@ import {
|
|||||||
import createAdminStore from './store/createAdminStore'
|
import createAdminStore from './store/createAdminStore'
|
||||||
import { i18nProvider } from './i18n'
|
import { i18nProvider } from './i18n'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { setDispatch, startEventStream } from './eventStream'
|
import { setDispatch, startEventStream, stopEventStream } from './eventStream'
|
||||||
import { keyMap } from './hotkeys'
|
import { keyMap } from './hotkeys'
|
||||||
import useChangeThemeColor from './useChangeThemeColor'
|
import useChangeThemeColor from './useChangeThemeColor'
|
||||||
|
|
||||||
@@ -70,7 +70,13 @@ const Admin = (props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (config.devActivityPanel) {
|
if (config.devActivityPanel) {
|
||||||
setDispatch(adminStore.dispatch)
|
setDispatch(adminStore.dispatch)
|
||||||
authProvider.checkAuth().then(() => startEventStream(adminStore.dispatch))
|
authProvider
|
||||||
|
.checkAuth()
|
||||||
|
.then(() => startEventStream(adminStore.dispatch))
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
stopEventStream()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
@@ -31,23 +31,20 @@ const setTimeout = (value) => {
|
|||||||
window.clearTimeout(timeout)
|
window.clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
timeout = window.setTimeout(async () => {
|
timeout = window.setTimeout(async () => {
|
||||||
if (es) {
|
es?.close()
|
||||||
es.close()
|
|
||||||
}
|
|
||||||
es = null
|
es = null
|
||||||
await startEventStream()
|
await startEventStream()
|
||||||
}, currentIntervalCheck)
|
}, currentIntervalCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopEventStream = () => {
|
const stopEventStream = () => {
|
||||||
if (es) {
|
es?.close()
|
||||||
es.close()
|
|
||||||
}
|
|
||||||
es = null
|
es = null
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
window.clearTimeout(timeout)
|
window.clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
timeout = null
|
timeout = null
|
||||||
|
console.log('eventSource closed') // TODO For debug purposes. Remove later
|
||||||
}
|
}
|
||||||
|
|
||||||
const setDispatch = (dispatchFunc) => {
|
const setDispatch = (dispatchFunc) => {
|
||||||
@@ -77,6 +74,8 @@ const startEventStream = async () => {
|
|||||||
newStream.addEventListener('keepAlive', eventHandler)
|
newStream.addEventListener('keepAlive', eventHandler)
|
||||||
newStream.onerror = (e) => {
|
newStream.onerror = (e) => {
|
||||||
console.log('EventStream error', e)
|
console.log('EventStream error', e)
|
||||||
|
es?.close()
|
||||||
|
es = null
|
||||||
setTimeout(reconnectIntervalCheck)
|
setTimeout(reconnectIntervalCheck)
|
||||||
dispatch(serverDown())
|
dispatch(serverDown())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user