auto-refresh teamsbot session list every 10s to catch new/changed sessions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6c319a4170
commit
7da7ad5041
1 changed files with 22 additions and 0 deletions
|
|
@ -436,6 +436,28 @@ export const TeamsbotSessionView: React.FC = () => {
|
||||||
});
|
});
|
||||||
}, [session?.id, session?.status, session?.botName, session?.startedAt, session?.endedAt]);
|
}, [session?.id, session?.status, session?.botName, session?.startedAt, session?.endedAt]);
|
||||||
|
|
||||||
|
// Periodically refresh the full session list to discover new/changed/ended sessions.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!instanceId) return;
|
||||||
|
const listPollRef = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const listResult = await teamsbotApi.listSessions(instanceId, true);
|
||||||
|
const fresh = listResult.sessions || [];
|
||||||
|
setAllSessions((prev) => {
|
||||||
|
if (prev.length !== fresh.length) return fresh;
|
||||||
|
const changed = fresh.some((s, i) => {
|
||||||
|
const old = prev[i];
|
||||||
|
return !old || old.id !== s.id || old.status !== s.status
|
||||||
|
|| old.endedAt !== s.endedAt || old.startedAt !== s.startedAt;
|
||||||
|
});
|
||||||
|
return changed ? fresh : prev;
|
||||||
|
});
|
||||||
|
if (noSessions && fresh.length > 0) setNoSessions(false);
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}, 10_000);
|
||||||
|
return () => clearInterval(listPollRef);
|
||||||
|
}, [instanceId, noSessions]);
|
||||||
|
|
||||||
// Polling: while joining/pending, poll even if SSE is connected (status may not arrive on stream).
|
// Polling: while joining/pending, poll even if SSE is connected (status may not arrive on stream).
|
||||||
// For active-only, poll only when SSE is down (previous behavior).
|
// For active-only, poll only when SSE is down (previous behavior).
|
||||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue