-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathangular-stomp.js
More file actions
53 lines (46 loc) · 1.57 KB
/
angular-stomp.js
File metadata and controls
53 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright: 2012, V. Glenn Tarcea
* MIT License Applies
*/
angular.module('AngularStomp', []).
factory('ngstomp', function($rootScope) {
var stompClient = {};
function NGStomp(url) {
this.stompClient = Stomp.client(url);
}
NGStomp.prototype.subscribe = function(queue, callback) {
this.stompClient.subscribe(queue, function() {
var args = arguments;
$rootScope.$apply(function() {
callback(args[0]);
})
})
}
NGStomp.prototype.send = function(queue, headers, data) {
this.stompClient.send(queue, headers, data);
}
NGStomp.prototype.connect = function(user, password, on_connect, on_error, vhost) {
this.stompClient.connect(user, password,
function(frame) {
$rootScope.$apply(function() {
on_connect.apply(stompClient, frame);
})
},
function(frame) {
$rootScope.$apply(function() {
on_error.apply(stompClient, frame);
})
}, vhost);
}
NGStomp.prototype.disconnect = function(callback) {
this.stompClient.disconnect(function() {
var args = arguments;
$rootScope.$apply(function() {
callback.apply(args);
})
})
}
return function(url) {
return new NGStomp(url);
}
});