Registry / messaging / angular2-websocket

angular2-websocket

JSON →
library0.9.8jsnpmunverified

Angular 2+ WebSocket wrapper with RxJS Subject streams. Version 0.9.8 (latest since 2019) is built against Angular 2 and RxJS 5/6. Provides automatic reconnect, send modes (Direct, Observer, Promise), and binary type configuration. Differs from angular-websocket by targeting Angular 2+ with TypeScript. Requires peer dependencies: core-js, reflect-metadata, TypeScript 3.2, zone.js.

npm install angular2-websocket
INSTALL
IMPORT
SIG · ANGULAR2-WEBSOCKET
A
angular2-websocket
messagingjavascriptv0.9.8
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.

$WebSocket
import { $WebSocket } from 'angular2-websocket/angular2-websocket'
import { $WebSocket } from 'angular2-websocket'
Path must include full module path ending in 'angular2-websocket', not the package root.
WebSocketSendMode
import { WebSocketSendMode } from 'angular2-websocket/angular2-websocket'
import { WebSocketSendMode } from 'angular2-websocket'
Same path requirement as $WebSocket.
Subject
import { Subject } from 'rxjs'
import { Subject } from 'rxjs/Subject'
RxJS 6 uses { Subject } from 'rxjs'; RxJS 5 path is deprecated.

Basic usage: connect to a WebSocket, send a message, and handle incoming data using RxJS streams.

import { $WebSocket, WebSocketSendMode } from 'angular2-websocket/angular2-websocket'; import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-root', template: '' }) export class AppComponent implements OnInit { ngOnInit() { const ws = new $WebSocket('ws://echo.websocket.org'); ws.getDataStream().subscribe(msg => console.log('Received:', msg.data)); ws.send('Hello').subscribe(() => console.log('Sent')); ws.close(true); } }
Debug
Known issues
deprecatedLibrary has not been updated since 2019; no official support for Angular 12+ or RxJS 7.
fix
Consider using native WebSocket with RxJS 'webSocket' from 'rxjs/webSocket'.
affects: >=0.9.8
breakingImport path must include the full module: 'angular2-websocket/angular2-websocket'. Importing from package root fails.
fix
Change import to 'angular2-websocket/angular2-websocket'.
affects: >=0.9.0
gotchaDefault binary type is 'arrayBuffer', but documentation says 'blob'. Verify actual behavior.
fix
Explicitly set binary type in constructor: new $WebSocket(url, null, null, 'blob').
affects: >=0.9.0
breakingsend() returns an RxJS Observable that is cold by default; subscribers must call .publish().connect() to trigger send.
fix
Use WebSocketSendMode.Direct or call .publish().connect() on the returned Observable.
affects: >=0.9.0
deprecatedRequires reflect-metadata polyfill which is no longer needed in Angular 13+ with zone.js 0.12.
fix
Remove reflect-metadata import if using Angular 13+ and zone.js 0.12+
affects: >=0.9.0
Errors
Common errors & fixes
Cannot find module 'angular2-websocket'
Importing from package root instead of the full module path.
fix
Change import to 'angular2-websocket/angular2-websocket'.
TypeError: ws.getDataStream is not a function
Using CommonJS require incorrectly; getDataStream is a method, not a property.
fix
Use: const stream = ws.getDataStream(); stream.subscribe(...);
Expected 0 arguments, but got 1
Calling send() without a mode parameter but expecting Promise behavior.
fix
Send with mode: ws.send('data', WebSocketSendMode.Promise).then(...);
Upgrade
Version history
0.9.8latest on npm
Audit
Dependencies
core-jsrequiredAngular polyfills
reflect-metadatarequiredAngular dependency
zone.jsrequiredAngular runtime
typescriptrequiredTypeScript compiler
Agent activity
41 hits · last 30 days
node
34
OpenAI (training)
1
Resources
angular2-websocket — npm install angular2-websocket · libregistry