feat(teamsbot): session auto-refresh polling for dashboard and session view
- Dashboard: poll sessions every 10s when active sessions exist - Session view: poll every 5s as fallback when SSE not connected Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
40fe8a0a31
commit
7421aebf74
2 changed files with 31 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useCurrentInstance } from '../../../hooks/useCurrentInstance';
|
||||
import * as teamsbotApi from '../../../api/teamsbotApi';
|
||||
import type { TeamsbotSession, StartSessionRequest } from '../../../api/teamsbotApi';
|
||||
|
|
@ -39,6 +39,18 @@ export const TeamsbotDashboardView: React.FC = () => {
|
|||
_loadSessions();
|
||||
}, [_loadSessions]);
|
||||
|
||||
// Auto-refresh: poll every 10s when there are active sessions
|
||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
useEffect(() => {
|
||||
const hasActiveSessions = sessions.some(s => ['pending', 'joining', 'active'].includes(s.status));
|
||||
if (hasActiveSessions && instanceId) {
|
||||
pollRef.current = setInterval(() => {
|
||||
teamsbotApi.listSessions(instanceId).then(r => setSessions(r.sessions || [])).catch(() => {});
|
||||
}, 10000);
|
||||
}
|
||||
return () => { if (pollRef.current) clearInterval(pollRef.current); };
|
||||
}, [sessions, instanceId]);
|
||||
|
||||
const _handleStartSession = async () => {
|
||||
if (!meetingLink.trim()) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useCurrentInstance } from '../../../hooks/useCurrentInstance';
|
||||
import * as teamsbotApi from '../../../api/teamsbotApi';
|
||||
|
|
@ -121,6 +121,23 @@ export const TeamsbotSessionView: React.FC = () => {
|
|||
};
|
||||
}, [instanceId, sessionId, session?.status]);
|
||||
|
||||
// Polling fallback: refresh session data every 5s when session is active (in case SSE fails)
|
||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
const isActive = useMemo(() => session && ['pending', 'joining', 'active'].includes(session.status), [session]);
|
||||
useEffect(() => {
|
||||
if (isActive && instanceId && sessionId && !isLive) {
|
||||
pollRef.current = setInterval(async () => {
|
||||
try {
|
||||
const result = await teamsbotApi.getSession(instanceId, sessionId);
|
||||
setSession(result.session);
|
||||
if (result.transcripts) setTranscripts(result.transcripts);
|
||||
if (result.botResponses) setBotResponses(result.botResponses);
|
||||
} catch {}
|
||||
}, 5000);
|
||||
}
|
||||
return () => { if (pollRef.current) clearInterval(pollRef.current); };
|
||||
}, [isActive, instanceId, sessionId, isLive]);
|
||||
|
||||
// Auto-scroll transcript
|
||||
useEffect(() => {
|
||||
transcriptEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
|
|
|
|||
Loading…
Reference in a new issue