fix: prevent presence race condition during WebRTC handshake

Add /joining, /joined, and /leave endpoints to track user join intent
and trigger presence updates.

Backend:
- Add pending_joins Redis module with 30s TTL
- Add /joining endpoint (before WebRTC handshake)
- Add /joined endpoint (after connection, triggers presence poll)
- Add /leave endpoint (on tab close, triggers presence poll)
- Check for pending joins before deactivating meetings in worker

Frontend:
- Generate unique connectionId per browser tab
- Call /joining before Daily.co join, /joined after connection
- Add beforeunload handler calling /leave via sendBeacon
This commit is contained in:
Igor Loskutov
2026-02-05 20:58:34 -05:00
parent 1ce1c7a910
commit 08462338de
9 changed files with 1116 additions and 10 deletions

View File

@@ -807,6 +807,35 @@ export function useRoomJoinMeeting() {
);
}
// Presence race fix endpoints (not yet in OpenAPI spec)
// These signal join intent to prevent race conditions during WebRTC handshake
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useMeetingJoining(): any {
return ($api as any).useMutation(
"post",
"/v1/rooms/{room_name}/meetings/{meeting_id}/joining",
{},
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useMeetingJoined(): any {
return ($api as any).useMutation(
"post",
"/v1/rooms/{room_name}/meetings/{meeting_id}/joined",
{},
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useMeetingLeave(): any {
return ($api as any).useMutation(
"post",
"/v1/rooms/{room_name}/meetings/{meeting_id}/leave",
{},
);
}
export function useRoomIcsSync() {
const { setError } = useError();