mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 03:35:26 +03:00
Refresh page when websocket is closed but user has interacted with page
This commit is contained in:
parent
e32bd4ab15
commit
43e715465a
@ -3,7 +3,7 @@ import { baseUrl } from './baseUrl';
|
|||||||
import { produce } from 'immer';
|
import { produce } from 'immer';
|
||||||
import { useCallback, useContext, useEffect, useRef, useReducer } from 'preact/hooks';
|
import { useCallback, useContext, useEffect, useRef, useReducer } from 'preact/hooks';
|
||||||
|
|
||||||
const initialState = Object.freeze({ __connected: false });
|
const initialState = Object.freeze({ __connected: false, __reconnectAttempts: 0 });
|
||||||
export const WS = createContext({ state: initialState, connection: null });
|
export const WS = createContext({ state: initialState, connection: null });
|
||||||
|
|
||||||
const defaultCreateWebsocket = (url) => new WebSocket(url);
|
const defaultCreateWebsocket = (url) => new WebSocket(url);
|
||||||
@ -80,6 +80,12 @@ export function useWs(watchTopic, publishTopic) {
|
|||||||
|
|
||||||
const send = useCallback(
|
const send = useCallback(
|
||||||
(payload, retain = false) => {
|
(payload, retain = false) => {
|
||||||
|
// if ws is closed but user has interacted with page
|
||||||
|
// refresh to ensure state is up to date
|
||||||
|
if (ws.readyState == WebSocket.CLOSED) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
ws.send(
|
ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
topic: publishTopic || watchTopic,
|
topic: publishTopic || watchTopic,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user