Simple-ng-websocket (v0.3.1) is a lightweight, minimal Angular wrapper around the browser's native WebSocket API. It provides a straightforward injectable service with event-based messaging (open, message, close, error) and supports optional JSON serialization. This package requires Angular >=12 and offers no reconnection logic, observables, or advanced features; it's designed for simple real-time communication without the overhead of larger libraries like ngx-socket-io or rxjs-websocket. Being an early release, it has minimal community adoption and limited ongoing maintenance.
npm install simple-ng-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to provide the WebSocket service in an Angular module using CONNECT_URL and LOGGER tokens, and use it inside an injectable service with event listeners.
Provide tokens in NgModule and let the constructor inject them automatically.
Always ensure the WebSocket is connected before sending by listening to the 'open' event.
Pass false as the second argument to send() when the message is already a string.
Listen to 'close' event and call connect() to re-establish the connection.
Add { provide: CONNECT_URL, useValue: 'wss://your-server.com/ws' } to the providers array.Ensure SimpleNgWebSocket is injected via constructor, and import it correctly: import { SimpleNgWebSocket } from 'simple-ng-websocket';Upgrade to the latest version or cast: (ngws as any).on(...). Alternatively, the 'on' method expects string event name and callback.