mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
analytics and embed meta update!!!
This commit is contained in:
@@ -19,9 +19,7 @@ export default function useUserIdentitySync({ identitySurface = 'passive' } = {}
|
||||
{ enabled: false },
|
||||
);
|
||||
|
||||
const inFlightRef = useRef(false);
|
||||
const lastAckSocketRef = useRef(null);
|
||||
const retryTimerRef = useRef(null);
|
||||
const fingerprintRef = useRef('');
|
||||
|
||||
const ready =
|
||||
@@ -31,16 +29,8 @@ export default function useUserIdentitySync({ identitySurface = 'passive' } = {}
|
||||
const overseerEnabled = Boolean(overseerPreference?.enabled);
|
||||
const normalizedIdentitySurface = identitySurface === 'driver' ? 'driver' : 'passive';
|
||||
|
||||
const clearRetry = useCallback(() => {
|
||||
if (retryTimerRef.current) {
|
||||
clearTimeout(retryTimerRef.current);
|
||||
retryTimerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const sendIdentify = useCallback(async () => {
|
||||
if (!ready || !connected || !socket?.id || inFlightRef.current) return;
|
||||
inFlightRef.current = true;
|
||||
if (!ready || !connected || !socket?.id) return;
|
||||
try {
|
||||
if (!fingerprintRef.current) {
|
||||
/*
|
||||
@@ -68,17 +58,14 @@ export default function useUserIdentitySync({ identitySurface = 'passive' } = {}
|
||||
saveIdentity((current) => ({ ...(current || {}), cookieUserId: nextKey }));
|
||||
}
|
||||
lastAckSocketRef.current = socket.id;
|
||||
clearRetry();
|
||||
} catch {
|
||||
clearRetry();
|
||||
retryTimerRef.current = setTimeout(() => {
|
||||
sendIdentify();
|
||||
}, 2000);
|
||||
} finally {
|
||||
inFlightRef.current = false;
|
||||
/*
|
||||
The permanent heartbeat below is the retry mechanism. A failed or
|
||||
half-open request must not create separate timer state that can stop
|
||||
future identity sends or disappear during a socket transition.
|
||||
*/
|
||||
}
|
||||
}, [
|
||||
clearRetry,
|
||||
connected,
|
||||
cookieUserId,
|
||||
identifySession,
|
||||
@@ -87,7 +74,7 @@ export default function useUserIdentitySync({ identitySurface = 'passive' } = {}
|
||||
overseerEnabled,
|
||||
ready,
|
||||
saveIdentity,
|
||||
socket?.id,
|
||||
socket,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -120,13 +107,17 @@ export default function useUserIdentitySync({ identitySurface = 'passive' } = {}
|
||||
}, [sendIdentify, socket?.connected]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ready || !socket?.connected) return undefined;
|
||||
/*
|
||||
Keep this interval installed whenever persisted identity settings are
|
||||
ready, including while Socket.IO is reconnecting. Each tick checks the
|
||||
current connection before sending, so reconnects resume heartbeats without
|
||||
depending on an acknowledgement or another effect recreating the timer.
|
||||
*/
|
||||
if (!ready) return undefined;
|
||||
const timer = setInterval(() => {
|
||||
if (!socket?.connected) return;
|
||||
sendIdentify();
|
||||
}, 60000);
|
||||
}, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, [ready, sendIdentify, socket?.connected]);
|
||||
|
||||
useEffect(() => () => clearRetry(), [clearRetry]);
|
||||
}, [ready, sendIdentify, socket]);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Purpose: Coordinates client-side video stream request intents and authorization timing. Scope: Provides reusable request helpers for rover and room video consumers.
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useSocket } from '../context/SocketContext.jsx';
|
||||
import { trackAnalyticsEventThrottled } from '../analytics/index.js';
|
||||
|
||||
function normalizeEntry(entry) {
|
||||
if (!entry) return null;
|
||||
@@ -96,23 +95,6 @@ export function useVideoRequests(sourceList = [], options = {}) {
|
||||
: { roverId: entry.id };
|
||||
socket.emit('video:request', payload, (resp = {}) => {
|
||||
if (cancelled) return;
|
||||
if (resp?.error) {
|
||||
/*
|
||||
Video authorization/session failures are operational signals, but
|
||||
this hook can request several feeds at once and retry after socket
|
||||
reconnects. Throttle by feed key so one broken camera does not flood
|
||||
Umami while still showing which rover or room camera is affected.
|
||||
*/
|
||||
trackAnalyticsEventThrottled(
|
||||
'video_request_failed',
|
||||
{
|
||||
type: entry.type,
|
||||
sourceId: entry.id,
|
||||
reason: resp.error,
|
||||
},
|
||||
{ key: `${entry.type}:${entry.id}:${resp.error}`, throttleMs: 60 * 1000 },
|
||||
);
|
||||
}
|
||||
setSources((prev) => ({ ...prev, [entry.key]: resp }));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user