angular-websocket-service
v0.2.0
Published
Event-less JSON WebSocket service for AngularJS
Downloads
1
Readme
angular-websocket-service is a WebSocket service for AngularJS. Use it to send and receive messages consisting of a topic string (without spaces) followed by a space and a JSON payload. For example:
/state/put {"name": "Alice", "friends": ["Bob", "Charlie"]}
The user-facing API is:
$websocket.connect(endpoint)
to return a new wrapped WebSocket object connected to the WebSocket server atendpoint
.
Wrapped WebSocket instances have the following user-facing API:
emit(topic, body)
to send outgoing messages. Messages send before the WebSocket connects are queued until the connection completes.register(topic, callback[, options])
to add a callback for incoming messages. The callback fingerprint should becallback(topic, body)
. The callback is triggered for messages who's topic starts with the registered topic. For example, callbacks registered for/state
and/state/get
will both be invoked for a/state/get
message. You can optionally pass in anoptions
object to configure the registration. For example, if you do want an exact topic match (instead of a prefix match), use{exact: true}
(a callback registered for/state
willexact
set to true will not be invoked for a/state/get
message).
Similar packages
- angular-websocket sends and receives opaque messages using a
send
method and events with a configurable prefix (MIT). The event-generating code is not clear to me, so I'm not actually sure how the prefix bit works. - angular-websocket-provider sends and receives JSON messages
using a
request
method andwebsocket.<METHOD>
andwebsocket.message
events.<METHOD>
is set using the payload'smethod
value (GPLv2). - angular-reconnecting-websocket wraps websockets to automatically reconnect after accidental disconnections (MIT).