-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstrophe.pep.js
50 lines (49 loc) · 1.39 KB
/
strophe.pep.js
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
// Generated by CoffeeScript 1.8.0
(function() {
Strophe.addConnectionPlugin('pep', (function() {
var conn, init, publish, subscribe, unsubscribe;
conn = null;
init = function(c) {
conn = c;
if (conn.caps === void 0) {
throw new Error("caps plugin required!");
}
if (conn.pubsub === void 0) {
throw new Error("pubsub plugin required!");
}
};
subscribe = function(node, handler) {
conn.caps.addFeature(node);
conn.caps.addFeature("" + node + "+notify");
conn.addHandler(handler, Strophe.NS.PUBSUB_EVENT, "message", null, null, null);
return conn.caps.sendPres();
};
unsubscribe = function(node) {
conn.caps.removeFeature(node);
conn.caps.removeFeature("" + node + "+notify");
return conn.caps.sendPres();
};
publish = function(node, items, callback) {
var iqid;
iqid = conn.getUniqueId("pubsubpublishnode");
conn.addHandler(callback, null, 'iq', null, iqid, null);
conn.send($iq({
from: conn.jid,
type: 'set',
id: iqid
})).c('pubsub', {
xmlns: Strophe.NS.PUBSUB
}).c('publish', {
node: node,
jid: conn.jid
}).list('item', items).tree();
return iqid;
};
return {
init: init,
publish: publish,
subscribe: subscribe,
unsubscribe: unsubscribe
};
})());
}).call(this);