-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstrophe.CAPS.js
92 lines (91 loc) · 2.74 KB
/
strophe.CAPS.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Generated by CoffeeScript 1.8.0
(function() {
Strophe.addConnectionPlugin('caps', (function() {
var addFeature, conn, createCapsNode, generateVerificationString, init, propertySort, removeFeature, sendPres;
conn = null;
init = function(c) {
conn = c;
Strophe.addNamespace('CAPS', "http://jabber.org/protocol/caps");
if (conn.disco === void 0) {
throw new Error("disco plugin required!");
}
if (b64_sha1 === void 0) {
throw new Error("SHA-1 library required!");
}
conn.disco.addFeature(Strophe.NS.CAPS);
conn.disco.addFeature(Strophe.NS.DISCO_INFO);
if (conn.disco._identities.length === 0) {
return conn.disco.addIdentity("client", "pc", "strophejs", "");
}
};
addFeature = function(feature) {
return conn.disco.addFeature(feature);
};
removeFeature = function(feature) {
return conn.disco.removeFeature(feature);
};
sendPres = function() {
return conn.send($pres().cnode(createCapsNode().tree()));
};
createCapsNode = function() {
var node;
if (conn.disco._identities.length > 0) {
node = conn.disco._identities[0].name || "";
} else {
node = dummyId.name;
}
return $build("c", {
xmlns: Strophe.NS.CAPS,
hash: "sha-1",
node: node,
ver: generateVerificationString()
});
};
propertySort = function(array, property) {
return array.sort(function(a, b) {
if (a[property] > b[property]) {
return -1;
} else {
return 1;
}
});
};
generateVerificationString = function() {
var S, features, i, id, ids, k, key, ns, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
ids = [];
_ref = conn.disco._identities;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
ids.push(i);
}
features = [];
_ref1 = conn.disco._features;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
k = _ref1[_j];
features.push(k);
}
S = "";
propertySort(ids, "category");
propertySort(ids, "type");
propertySort(ids, "lang");
for (key in ids) {
id = ids[key];
S += "" + id.category + "/" + id.type + "/" + id.lang + "/" + id.name + "<";
}
features.sort();
for (_k = 0, _len2 = features.length; _k < _len2; _k++) {
ns = features[_k];
S += "" + ns + "<";
}
return "" + (b64_sha1(S)) + "=";
};
return {
init: init,
removeFeature: removeFeature,
addFeature: addFeature,
sendPres: sendPres,
generateVerificationString: generateVerificationString,
createCapsNode: createCapsNode
};
})());
}).call(this);