Registry / messaging / angular-websocket

angular-websocket

JSON →
library2.0.1jsnpmunverified

An AngularJS 1.x service for real-time WebSocket communication, version 2.0.1. Designed for Angular 1.x applications, it provides a $websocket factory that wraps the native WebSocket API with Angular's digest cycle. Features include auto-reconnection, message queuing before connection, and promise-based lifecycle events. Last stable release via npm/Bower, but development appears stalled (no updates since 2016). Alternatives for Angular 2+ include rxjs/webSocket or Socket.IO.

npm install angular-websocket
INSTALL
IMPORT
SIG · ANGULAR-WEBSOCKET
A
angular-websocket
messagingjavascriptv2.0.1
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.

ngWebSocket
angular.module('myApp', ['ngWebSocket'])
angular.module('myApp', ['angular-websocket'])
Module name is 'ngWebSocket' or 'angular-websocket' as string literal.
$websocket
angular.module('myApp').factory('MyData', function($websocket) { ... })
import { $websocket } from 'angular-websocket'
Injected as Angular service, not imported via ES modules.
WebSocket
var ws = new WebSocket('ws://example.com')
var ws = $websocket.WebSocket('ws://example.com')
Use $websocket factory directly: $websocket('ws://...')

Demonstrates creating a WebSocket connection, receiving messages, sending messages, and integrating with Angular scope.

angular.module('quickstartApp', ['ngWebSocket']).controller('ChatCtrl', function($scope, $websocket) { var ws = $websocket('wss://echo.websocket.org'); $scope.messages = []; ws.onMessage(function(event) { $scope.messages.push(event.data); $scope.$apply(); }); $scope.send = function(msg) { ws.send(msg); }; }); <!-- HTML --> <div ng-controller="ChatCtrl"> <ul><li ng-repeat="m in messages">{{m}}</li></ul> <input ng-model="msg"><button ng-click="send(msg)">Send</button> </div>
Debug
Known issues
gotchaAutomatic $digest is not triggered on incoming WebSocket messages: you must call $scope.$apply() or use $timeout to update bindings.
fix
Wrap message handling in $scope.$apply() or use $timeout.
affects: >=1.0.0
deprecatedPackage has not been updated since 2016 and is no longer maintained. AngularJS 1.x is in long-term support only.
fix
Consider migrating to Angular 2+ and using native WebSocket or rxjs/webSocket.
affects: >=2.0.0
gotchaThe module name can be either 'ngWebSocket' or 'angular-websocket', which may cause confusion.
fix
Always use 'ngWebSocket' as the module name for consistency.
affects: >=1.0.0
breakingIn version 2.0.0, the API changed significantly: $websocket is now a factory returning an instance, not a constructor with prototype methods.
fix
Use $websocket(url) to create a connection, and methods like .send(), .onMessage() on the returned instance.
affects: >=2.0.0
Errors
Common errors & fixes
$websocket is not a function
Injecting $websocket as a constructor or calling it incorrectly.
fix
Use `var ws = $websocket('ws://...');` after injecting '$websocket' into your service/controller.
Unknown provider: $websocketProvider
Module 'ngWebSocket' not loaded in the application.
fix
Add `'ngWebSocket'` to your module dependencies: `angular.module('myApp', ['ngWebSocket'])`
$digest already in progress
Calling $scope.$apply() inside Angular's digest cycle (e.g., from a $watch or another $apply).
fix
Use `$timeout(function() { ... });` instead of $scope.$apply() to safely run in next digest.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
angularrequiredPeer dependency: requires AngularJS 1.x
Agent activity
37 hits · last 30 days
node
30
OpenAI (training)
1
Resources
angular-websocket — npm install angular-websocket · libregistry