All files / web/src/providers sse.tsx

100% Statements 21/21
100% Branches 4/4
100% Functions 2/2
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55      1x               1x                               1x 4x 4x   4x   4x 4x 4x 4x 4x   4x 4x   4x         1x 6x 6x 2x 2x 4x 4x  
'use client';
 
import type React from 'react';
import { createContext, type ReactElement, useContext } from 'react';
 
interface SSEContextType {
  connected: boolean;
  connecting: boolean;
  error: Error | null;
}
 
const SSEContext = createContext<SSEContextType | undefined>(undefined);
 
/**
 * SSE Provider
 *
 * NOTE: SSE is disabled because the API runs on Cloudflare Workers,
 * which doesn't support long-running connections like Server-Sent Events.
 *
 * This provider returns a disabled state. Real-time updates are not available.
 * To see updates, refresh the page manually.
 *
 * For real-time functionality with Cloudflare Workers, consider:
 * - Durable Objects with WebSockets
 * - Cloudflare Queues + polling
 * - Third-party services (Pusher, Ably, etc.)
 */
export const SSEProvider = ({
  children,
}: {
  children: React.ReactNode;
}): ReactElement => {
  // SSE is disabled - Cloudflare Workers doesn't support long-running connections
  const contextValue: SSEContextType = {
    connected: false,
    connecting: false,
    error: new Error('SSE not supported on Cloudflare Workers'),
  };
 
  return (
    <SSEContext.Provider value={contextValue}>{children}</SSEContext.Provider>
  );
};
 
/**
 * Hook to access SSE connection status
 */
export const useSSEStatus = (): SSEContextType => {
  const context = useContext(SSEContext);
  if (!context) {
    throw new Error('useSSEStatus must be used within an SSEProvider');
  }
  return context;
};