Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-ws

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-ws

WebSocket service for Angular.js.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

angular-ws

Build Status Dependency Status devDependency Status

WebSocket service for Angular.js.

Install

bower install angular-ws

Usage

angular.module('app', ['ws'])
.config(function (wsProvider) {
  wsProvider.setUrl('ws://echo.websocket.org');
})
.controller('WebSocketCtrl', function ($scope, ws, $log) {
  ws.on('message', function (event) {
    $log.info('New message', event.data);
  });

  ws.send('custom message');
});

Provider

wsProvider.setUrl(url)

Set the url of the WebSocket.

wsProvider.setUrl('ws://echo.websocket.org');
wsProvider.setProtocols(protocols)

Set the protocols used by the WebSocket.

wsProvider.setProtocols(['protocol']);
wsProvider.setTransport(transport)

Set a custom transport (example: ReconnectingWebSocket).

wsProvider.setTransport(ReconnectingWebSocket);

Service

ws.connect([config])

Connect the WebSocket, you can provide a custom config.

Note that if you use ws.on or ws.send the connection is automatic.

ws.connect({
  url: 'ws://echo.websocket.org',
  protocols: ['protocol']
})
.then(function () {
  $log.debug('WebSocket is connected.');
}, function () {
  $log.debug('An error occurs during WebSocket connection.');
});
ws.baseSocket

The base socket object.

ws.baseSocket.onmessage = function (event) {
  // event.data ...
}
ws.getReadyState()

Get the ready state of the WebSocket.

ws.getReadyState() // WebSocket.CLOSED, WebSocket.OPEN...
ws.on(event, listener)

Listen an event on the WebSocket, the function is already wrapped in $rootScope.$apply().

ws.on('message', function (event) {
  $log.info('New message', event.data);
});
ws.close()

Close the connection of the WebSocket.

ws.close();

Testing

To be able to test WebSocket in the good way, the module angular-ws-mock will provide you a transparent mock.

License

MIT

FAQs

Package last updated on 11 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc