https://github.com/andrewstuart/angularsocket
angularsocket
https://github.com/andrewstuart/angularsocket
Last synced: 4 months ago
JSON representation
angularsocket
- Host: GitHub
- URL: https://github.com/andrewstuart/angularsocket
- Owner: andrewstuart
- Created: 2014-03-23T21:24:06.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-05T01:44:32.000Z (about 12 years ago)
- Last Synced: 2025-10-09T04:42:56.399Z (8 months ago)
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#AngularSocket
A quick and dirty websocket wrapper for angular. It gives some convenience methods for communicating with websockets from different services or controllers so that you can worry more about your implementation and less about how angular deals with sockets.
##Methods
##`.get(name, url)`
This method returns a wrapped websocket that will work without a call to $scope.$apply.
The `name` that is passed to the factory can be used at any point during the lifecycle of your application to retrieve the same socket instance, and thus does not need to constantly disconnect and reconnect with the server. The `url` is simply the endpoint url of your websocket server-side application.
The socket instance returned will have two methods: `emit(name, data)` and `on(event, handler)`.
###`emit(name, data)`
`emit` passes a named event to the server. This is similar to the socket.io functionality, but returns a promise will be fulfilled on confirmation or response from the server.
###`on(event, handler)`
`on` accepts an event name and a handler function that will be invoked when that named event is thrown by the server in the format `{event: , data: { /*...data...*/ }}`. The handler will be passed any data sent by the server.