Registry / communication / ngx-websocket

ngx-websocket

JSON →
library0.4.2jsnpmunverified

A simple WebSocket connection manager for Angular 4+ applications. Current version 0.4.2 is highly unstable and explicitly warns against use in production due to potential breaking changes without notice. Ships TypeScript types and requires Angular 6+ (peer deps). Minimal documentation and incomplete error handling (as noted in TODOs). Not recommended for new projects; consider alternatives like RxJS WebSocket or ngx-socket-io.

npm install ngx-websocket
INSTALL
IMPORT
SIG · NGX-WEBSOCKET
N
ngx-websocket
communicationjavascriptv0.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NgxWebSocketModule
import { NgxWebSocketModule } from 'ngx-websocket';
import NgxWebSocketModule from 'ngx-websocket';
Named export, not default.
NgxWebsocketService
import { NgxWebsocketService } from 'ngx-websocket';
import { NgxWebsocketService } from 'ngx-websocket/ngx-websocket-service';
Service is exported from the main module barrel.
Socket
import { Socket } from 'ngx-websocket';
const Socket = require('ngx-websocket').Socket;
ESM only; CommonJS require may work but is not the intended pattern. TypeScript definitions are included.

Demonstrates importing the module, injecting services, and opening a WebSocket connection.

import { NgxWebSocketModule, NgxWebsocketService, Socket } from 'ngx-websocket'; @NgModule({ imports: [NgxWebSocketModule], // ... }) export class AppModule {} @Component({...}) export class TestComponent { constructor(private service: NgxWebsocketService, private socket: Socket) {} open(): void { this.service.open('ws://echo.websocket.org') .then((d: any, socket: any) => socket.send('hi')) .message((d: any) => d + ' siri') .then((d: any) => console.log(d)); } }
Debug
Known issues
breakingPackage is explicitly marked as 'extreamly unstable' and will be overwritten occasionally.
fix
Do not use in production. Consider RxJS WebSocket or ngx-socket-io instead.
affects: >=0.0.0
deprecatedPackage has not been updated since 2018 and relies on Angular 6+ peer dependencies. It is incompatible with Angular 12+.
fix
Migrate to a maintained WebSocket library like rxjs/webSocket or ngx-socket-io.
affects: >=0.4.0
gotchaThe API is non-standard and undocumented. The open() method returns a promise with a custom chainable .message() method that may not exist in the future.
fix
Refer to minimal examples in README; avoid relying on undocumented features.
affects: >=0.4.0
Errors
Common errors & fixes
Cannot find module 'ngx-websocket' or its corresponding type declarations.
Missing TypeScript types or incorrect import path.
fix
Use 'import { ... } from 'ngx-websocket';' – the library ships its own types.
NullInjectorError: No provider for NgxWebsocketService!
NgxWebSocketModule not imported in the Angular module.
fix
Add 'NgxWebSocketModule' to the imports array of your @NgModule.
Property 'message' does not exist on type 'Promise<void>'.
TypeScript does not recognize the custom .message() chain method on the promise returned by open().
fix
Cast to 'any' or define a custom interface. Example: '(this.service.open(...) as any).message(...)'.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
@angular/commonrequiredRequired peer dependency for Angular module and service functionality.
@angular/corerequiredRequired peer dependency for Angular dependency injection and decorators.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
ngx-websocket — npm install ngx-websocket · libregistry