WebSocketService
Manages WebSocket connections with automatic reconnection, heartbeat support, and typed message streams via Observables.
TypeScriptexample.ts
import { WebSocketService } from '@angular-helpers/browser-web-apis'# Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
createClient | createClient(config: WebSocketClientConfig): WebSocketClient | WebSocketClient | Create a new WebSocket client. The client owns one connection and is the recommended surface for all interactions (status signal, request/response, reconnect, etc.). The returned client is automatically disposed when the host injector is destroyed. |
disposeAll | disposeAll(): void | void | Dispose every client created via `createClient()` (also called automatically on destroy). |
connect | connect(config: WebSocketConfig): Observable<WebSocketStatus> | Observable<WebSocketStatus> | Public method connect. |
disconnect | disconnect(): void | void | Public method disconnect. |
send | send(message: WebSocketMessage<T>): void | void | Public method send. |
sendRaw | sendRaw(data: string): void | void | Public method sendRaw. |
getStatus | getStatus(): Observable<WebSocketStatus> | Observable<WebSocketStatus> | Public method getStatus. |
getMessages | getMessages(): Observable<WebSocketMessage<T>> | Observable<WebSocketMessage<T>> | Public method getMessages. |
getMessagesByType | getMessagesByType(type: string): Observable<WebSocketMessage<T>> | Observable<WebSocketMessage<T>> | Public method getMessagesByType. |
getNativeWebSocket | getNativeWebSocket(): WebSocket | null | WebSocket | null | Public method getNativeWebSocket. |
isConnected | isConnected(): boolean | boolean | Public method isConnected. |
getReadyState | getReadyState(): number | number | Public method getReadyState. |