feat(realtime): long polling for app-wide events behind proxies
When a proxy lets neither WebSocket nor SSE through, the app opens a poll connection: the server buffers its events (an SSEClient without a stream), each GET waits up to 25 s, and room joins work like for SSE. Tasks and lists now update live there too, and note sync takes its notifications from it instead of a second long poll. Idle connections close after two minutes. The profile shows such a connection as limited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c19d8fd03e
commit
2b7356d043
16 files changed
+369
-20
No files matched your search
@@ -1,10 +1,10 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
|
||||
let statusListener: ((connected: boolean) => void) | null = null;
|
||||
let statusListener: ((connected: boolean, transport?: string) => void) | null = null;
|
||||
let currentConnected = false;
|
||||
vi.mock('../api', () => ({
|
||||
onRealtimeStatus: (cb: (connected: boolean) => void) => {
|
||||
onRealtimeStatus: (cb: (connected: boolean, transport?: string) => void) => {
|
||||
statusListener = cb;
|
||||
cb(currentConnected);
|
||||
return () => (statusListener = null);
|
||||
@@ -86,6 +86,15 @@ describe('useConnectionState', () => {
|
||||
expect(fetchMock.mock.calls.length).toBe(calls);
|
||||
});
|
||||
|
||||
it('is limited while changes only come by long polling', async () => {
|
||||
const { result } = renderHook(() => useConnectionState());
|
||||
act(() => statusListener?.(true, 'poll'));
|
||||
expect(result.current).toBe('limited');
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
act(() => statusListener?.(true, 'sse'));
|
||||
expect(result.current).toBe('online');
|
||||
});
|
||||
|
||||
it('repeated failed reconnects do not postpone the check', async () => {
|
||||
currentConnected = true;
|
||||
const { result } = renderHook(() => useConnectionState());
|
||||
|
||||
Reference in new issue
Block a user