angular-ws
WebSocket service for Angular.js.
Install
bower install angular-ws
Usage
angular;
Provider
wsProvider.setUrl(url)
Set the url of the WebSocket.
wsProvider;
wsProvider.setProtocols(protocols)
Set the protocols used by the WebSocket.
wsProvider;
wsProvider.setTransport(transport)
Set a custom transport (example: ReconnectingWebSocket).
wsProvider;
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;
ws.baseSocket
The base socket object.
wsbaseSocket { // event.data ...}
ws.getReadyState()
Get the ready state of the WebSocket.
ws // WebSocket.CLOSED, WebSocket.OPEN...
ws.on(event, listener)
Listen an event on the WebSocket, the function is already wrapped in $rootScope.$apply()
.
ws;
ws.close()
Close the connection of the WebSocket.
ws;
Testing
To be able to test WebSocket in the good way, the module angular-ws-mock will provide you a transparent mock.
License
MIT