Retry connecting to the events endpoint more frequently on first load

This commit is contained in:
Deluan
2020-11-16 15:38:03 -05:00
parent 972a94dbf0
commit 1ee39835dd
+4 -4
View File
@@ -6,8 +6,8 @@ let es = null
let dispatch = null let dispatch = null
let timeout = null let timeout = null
const defaultIntervalCheck = 20000 const defaultIntervalCheck = 20000
const errorIntervalCheck = 2000 const reconnectIntervalCheck = 2000
let currentIntervalCheck = defaultIntervalCheck let currentIntervalCheck = reconnectIntervalCheck
const getEventStream = () => { const getEventStream = () => {
if (es === null) { if (es === null) {
@@ -37,7 +37,7 @@ export const startEventStream = (dispatchFunc) => {
dispatch = dispatchFunc dispatch = dispatchFunc
setTimeout(currentIntervalCheck) setTimeout(currentIntervalCheck)
if (!localStorage.getItem('token')) { if (!localStorage.getItem('token')) {
console.log('Cannot create a unauthenticated EventSource') console.log('Cannot create a unauthenticated EventSource connection')
return return
} }
const es = getEventStream() const es = getEventStream()
@@ -53,7 +53,7 @@ export const startEventStream = (dispatchFunc) => {
{ trailing: true } { trailing: true }
) )
es.onerror = (e) => { es.onerror = (e) => {
setTimeout(errorIntervalCheck) setTimeout(reconnectIntervalCheck)
dispatch(serverDown()) dispatch(serverDown())
} }