Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
beevelop committed Mar 8, 2015
0 parents commit 423f1c7
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 0 deletions.
Binary file added .gitignore
Binary file not shown.
10 changes: 10 additions & 0 deletions .npmignore
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/


14 changes: 14 additions & 0 deletions Gruntfile.js
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']);
};
13 changes: 13 additions & 0 deletions LICENSE.md
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.
61 changes: 61 additions & 0 deletions README.md
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...
});
});
```
26 changes: 26 additions & 0 deletions bower.json
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": "*"
}
}
76 changes: 76 additions & 0 deletions ng-stomp.js
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;
};
}]
);
1 change: 1 addition & 0 deletions ng-stomp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions package.json
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"
}

0 comments on commit 423f1c7

Please sign in to comment.