Skip to main content

Realtime Clients

Off-main-thread WebSockets and Server-Sent Events (SSE) clients running inside Web Workers. Offloads high-frequency stream parsing and data filtering from the main thread, communicating status and message streams via Angular Signals and RxJS.

TypeScriptexample.ts
import { Realtime Clients } from '@angular-helpers/worker-http/realtime'

# Methods

MethodSignatureReturnsDescription
attachRealtimeWorkerattachRealtimeWorker(globalScope?: any): voidvoidWorker-side message handler that attaches listeners to manage WebSocket and SSE connections. Call this inside your web worker file.
WorkerWebSocketClientconstructor(worker: Worker | MessagePort, config: WebSocketClientConfig, destroyRef?: DestroyRef)WorkerWebSocketClientClient for managing WebSocket connections off-main-thread. Exposes status() signal and messages$ stream.
WorkerSseClientconstructor(worker: Worker | MessagePort, config: SseClientConfig, destroyRef?: DestroyRef)WorkerSseClientClient for managing Server-Sent Events (EventSource) connections off-main-thread. Exposes status() signal and events$ stream.
sendsend(message: WebSocketMessage): voidvoidSends a JSON-serialized WebSocket message from the main thread via the worker.
sendRawsendRaw(data: string): voidvoidSends a raw text WebSocket message from the main thread via the worker.
requestrequest(type: string, data: any, opts?: WebSocketRequestOptions): Promise<any>Promise<any>Sends a request message and waits for a response message with matching correlationId. Rejects on timeout.
LCP N/A
CLS N/A
INP N/A