-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 423f1c7
Showing
9 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Yeoman template | ||
node_modules/ | ||
bower_components/ | ||
*.log | ||
|
||
build/ | ||
dist/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function (grunt) { | ||
grunt.initConfig({ | ||
uglify: { | ||
main: { | ||
files: { | ||
'ng-stomp.min.js': ['ng-stomp.js'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.registerTask('default', ['uglify']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# ngStomp | ||
|
||
> [STOMP](http://jmesnil.net/stomp-websocket/doc/) promised for [AngularJS](https://angularjs.org) | ||
## Installation | ||
|
||
Install via Bower: | ||
```bash | ||
bower install --save ngStomp | ||
``` | ||
|
||
Add SockJS + STOMP + (minified) Stompie: | ||
```html | ||
<script src="/bower_components/sockjs/sockjs.min.js"></script> | ||
<script src="/bower_components/stomp-websocket/lib/stomp.min.js"></script> | ||
<script src="/bower_components/stompie/stompie.min.js"></script> | ||
``` | ||
|
||
Declare the module as a dependency in your application: | ||
```js | ||
angular.module('yourApp', ['ngStomp']); | ||
``` | ||
|
||
## Usage | ||
|
||
Inject it in your controller: | ||
```js | ||
angular | ||
.module('yourApp') | ||
.controller('YourCtrl', ['$stomp', '$scope', function ($stomp, $scope) { | ||
// ... | ||
} | ||
``` | ||
Use and subscribe: | ||
```js | ||
//frame = CONNECTED headers | ||
$stompie.using('/endpoint', function (frame) { | ||
// The $scope bindings are updated for you so no need to $scope.$apply. | ||
// The subscription object is returned by the method. | ||
var subscription = $stompie.subscribe('/your/topic', function (data) { | ||
$scope.foo = data; | ||
}); | ||
|
||
// Unsubscribe using said subscription object. | ||
subscription.unsubscribe(); | ||
|
||
// Send messages to a STOMP broker. | ||
$stompie.send('/some/queue', { | ||
message: 'some message' | ||
}, { | ||
priority: 9, | ||
custom: 42 //Custom Headers | ||
}); | ||
|
||
// Disconnect from the socket. | ||
$stompie.disconnect(function () { | ||
// Called once you're out... | ||
}); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ngStomp", | ||
"version": "0.0.1-alpha.1", | ||
"homepage": "https://github.com/beevelop/ngStomp", | ||
"authors": [ | ||
"Maik Hummel <yo@beevelop.com>" | ||
], | ||
"description": "STOMP for AngularJS", | ||
"main": "ng-stomp.js", | ||
"keywords": [ | ||
"STOMP", | ||
"websockets" | ||
], | ||
"license": "WTFPL", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": { | ||
"sockjs": "*", | ||
"stomp-websocket": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* ngStomp | ||
* | ||
* @version 0.0.1-alpha.1 | ||
* @author Maik Hummel <yo@beevelop.com> | ||
* @license WTFPL | ||
*/ | ||
angular | ||
.module('ngStomp', []) | ||
.service('$stomp', [ | ||
'$rootScope', '$q', | ||
function ($rootScope, $q) { | ||
|
||
this.sock = null; | ||
this.stomp = null; | ||
this.debug = null; | ||
|
||
this.setDebug = function (callback) { | ||
this.debug = callback; | ||
}; | ||
|
||
this.connect = function (endpoint, headers) { | ||
headers = headers || {}; | ||
|
||
var dfd = $q.defer(); | ||
|
||
this.sock = new SockJS(endpoint); | ||
this.stomp = Stomp.over(this.sock); | ||
this.stomp.debug = this.debug; | ||
this.stomp.connect(headers, function (frame) { | ||
dfd.resolve(frame); | ||
}, function (err) { | ||
dfd.reject(err); | ||
}); | ||
|
||
return dfd.promise; | ||
}; | ||
|
||
this.disconnect = function () { | ||
var dfd = $q.defer(); | ||
this.stomp.disconnect(dfd.resolve); | ||
return dfd.promise; | ||
}; | ||
|
||
this.subscribe = this.on = function (destination, callback, headers) { | ||
headers = headers || {}; | ||
return this.stomp.subscribe(destination, function (res) { | ||
var payload = null; | ||
try { | ||
payload = JSON.parse(res.body); | ||
} finally { | ||
if (callback) { | ||
callback(payload, res.headers, res); | ||
} | ||
} | ||
}, headers); | ||
}; | ||
|
||
this.unsubscribe = this.off = function (subscription) { | ||
subscription.unsubscribe(); | ||
}; | ||
|
||
this.send = function (destination, body, headers) { | ||
var dfd = $q.defer(); | ||
try { | ||
var payloadJson = JSON.stringify(body); | ||
headers = headers || {}; | ||
this.stomp.send(destination, headers, payloadJson); | ||
dfd.resolve(); | ||
} catch (e) { | ||
dfd.reject(e); | ||
} | ||
return dfd.promise; | ||
}; | ||
}] | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "ngStomp", | ||
"version": "0.0.1-alpha.1", | ||
"description": "STOMP for AngularJS", | ||
"main": "ng-stomp.js", | ||
"dependencies": { | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-uglify": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-uglify": "^0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/beevelop/ngStomp.git" | ||
}, | ||
"keywords": [ | ||
"AngularJS", | ||
"STOMP.", | ||
"websocket" | ||
], | ||
"author": "Maik Hummel <yo@beevelop.com>", | ||
"license": "WTFPL", | ||
"bugs": { | ||
"url": "https://github.com/beevelop/ngStomp/issues" | ||
}, | ||
"homepage": "https://github.com/beevelop/ngStomp" | ||
} |