0.2.0 • Published 11 years ago
angular-websocket-service v0.2.0
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/stateand/state/getwill both be invoked for a/state/getmessage. You can optionally pass in anoptionsobject 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/statewillexactset to true will not be invoked for a/state/getmessage).
Similar packages
- angular-websocket sends and receives opaque messages using a
sendmethod 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
requestmethod andwebsocket.<METHOD>andwebsocket.messageevents.<METHOD>is set using the payload'smethodvalue (GPLv2). - angular-reconnecting-websocket wraps websockets to automatically reconnect after accidental disconnections (MIT).