Only setup event stream when mounting the app
This commit is contained in:
+10
-8
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import ReactGA from 'react-ga'
|
import ReactGA from 'react-ga'
|
||||||
import 'react-jinke-music-player/assets/index.css'
|
import 'react-jinke-music-player/assets/index.css'
|
||||||
import { Provider, useDispatch } from 'react-redux'
|
import { Provider, useDispatch } from 'react-redux'
|
||||||
@@ -65,13 +65,15 @@ const App = () => (
|
|||||||
const Admin = (props) => {
|
const Admin = (props) => {
|
||||||
useChangeThemeColor()
|
useChangeThemeColor()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
if (config.devActivityPanel) {
|
useEffect(() => {
|
||||||
setDispatch(dispatch)
|
if (config.devActivityPanel) {
|
||||||
authProvider
|
setDispatch(dispatch)
|
||||||
.checkAuth()
|
authProvider
|
||||||
.then(() => startEventStream())
|
.checkAuth()
|
||||||
.catch(() => {}) // ignore if not logged in
|
.then(() => startEventStream())
|
||||||
}
|
.catch(() => {}) // ignore if not logged in
|
||||||
|
}
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RAAdmin
|
<RAAdmin
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ let timeout = null
|
|||||||
const getEventStream = async () => {
|
const getEventStream = async () => {
|
||||||
if (!es) {
|
if (!es) {
|
||||||
// Call `keepalive` to refresh the jwt token
|
// Call `keepalive` to refresh the jwt token
|
||||||
await httpClient(`${REST_URL}/keepalive/eventSource`)
|
await httpClient(`${REST_URL}/keepalive/keepalive`)
|
||||||
es = new EventSource(
|
es = new EventSource(
|
||||||
baseUrl(`${REST_URL}/events?jwt=${localStorage.getItem('token')}`)
|
baseUrl(`${REST_URL}/events?jwt=${localStorage.getItem('token')}`)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user