mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 02:29:19 +03:00
clean up
This commit is contained in:
parent
92a2289e77
commit
7fc95c0e41
@ -42,10 +42,8 @@ type Listener = () => void;
|
|||||||
const wsState: WsState = {};
|
const wsState: WsState = {};
|
||||||
const wsTopicListeners = new Map<string, Set<Listener>>();
|
const wsTopicListeners = new Map<string, Set<Listener>>();
|
||||||
|
|
||||||
/**
|
// Reset all module-level state. Called on WsProvider unmount to prevent
|
||||||
* Reset all module-level state. Called on WsProvider unmount to prevent
|
// stale data from leaking across mount/unmount cycles (e.g. HMR, logout)
|
||||||
* stale data from leaking across mount/unmount cycles (e.g. HMR, logout).
|
|
||||||
*/
|
|
||||||
export function resetWsStore() {
|
export function resetWsStore() {
|
||||||
for (const key of Object.keys(wsState)) {
|
for (const key of Object.keys(wsState)) {
|
||||||
delete wsState[key];
|
delete wsState[key];
|
||||||
@ -56,10 +54,8 @@ export function resetWsStore() {
|
|||||||
wsMessageIdCounter = 0;
|
wsMessageIdCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Parse and apply a raw WS message synchronously.
|
||||||
* Parse and apply a raw WS message synchronously.
|
// Called directly from WsProvider's onmessage handler.
|
||||||
* Called directly from WsProvider's onmessage handler.
|
|
||||||
*/
|
|
||||||
export function processWsMessage(raw: string) {
|
export function processWsMessage(raw: string) {
|
||||||
const data: Update = JSON.parse(raw);
|
const data: Update = JSON.parse(raw);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
@ -101,7 +97,7 @@ function applyTopicUpdate(topic: string, newVal: unknown) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Subscriptions ---
|
// Subscriptions
|
||||||
|
|
||||||
export function subscribeWsTopic(
|
export function subscribeWsTopic(
|
||||||
topic: string,
|
topic: string,
|
||||||
@ -123,17 +119,12 @@ export function getWsTopicValue(topic: string): unknown {
|
|||||||
return wsState[topic];
|
return wsState[topic];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Feed message subscribers
|
// Feed message subscribers
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const wsMessageSubscribers = new Set<(msg: WsFeedMessage) => void>();
|
const wsMessageSubscribers = new Set<(msg: WsFeedMessage) => void>();
|
||||||
let wsMessageIdCounter = 0;
|
let wsMessageIdCounter = 0;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Camera activity expansion
|
// Camera activity expansion
|
||||||
// ---------------------------------------------------------------------------
|
//
|
||||||
|
|
||||||
// Cache the last raw camera_activity JSON string so we can skip JSON.parse
|
// Cache the last raw camera_activity JSON string so we can skip JSON.parse
|
||||||
// and the entire expansion when nothing has changed. This avoids creating
|
// and the entire expansion when nothing has changed. This avoids creating
|
||||||
// fresh objects (which defeat Object.is and force expensive isEqual deep
|
// fresh objects (which defeat Object.is and force expensive isEqual deep
|
||||||
@ -262,9 +253,7 @@ export function useWs(watchTopic: string, publishTopic: string) {
|
|||||||
return { value, send };
|
return { value, send };
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Convenience hooks
|
// Convenience hooks
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export function useEnabledState(camera: string): {
|
export function useEnabledState(camera: string): {
|
||||||
payload: ToggleableSetting;
|
payload: ToggleableSetting;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user