annotate functions.js @ 15:5149a856d9dd default tip

Fix hybrid mode.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 03 Nov 2011 17:28:49 -0700
parents 161d4ea1c3f8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 var Error = function(s) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 this.error = s;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 this.toString = function() {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 return this.error;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 };
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 };
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 var Item = function(service, node, id, payload) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 this.service = service;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 this.node = node;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 this.id = id;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 this.payload = payload;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 this.ns = payload.namespaceURI;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 };
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 var verify = function(elem, ns, name, attributes, children) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 if (ns && elem.namespaceURI !== ns)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 throw new Error('not the right namespace.');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 if (name && elem.localName !== name)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 throw new Error('not the right name.');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 if (attributes)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 for (var attribute in attributes) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 var value = attributes[attribute]
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 if (elem.getAttributeNS(null, attribute) !== value)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 throw new Error('attribute '+attribute+' invalid.');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 }
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 if (typeof children === 'number' && children < 2 && elem.children.length != children)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 throw new Error('not the right number of children');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 };
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 XMPP.prototype = {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 discoInfo: function(aTo, aNode, aCallback) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 this.send(stanzas.discoInfo(aTo, aNode), function(answer){
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 aCallback(answer);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 });
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 },
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 pubsubItems: function(aTo, aNode, aCallback) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 this.send(stanzas.pubsubItems(aTo, aNode), function(answer){
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 var items = [];
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 //try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 verify(answer, ns.j, 'iq', {type: 'result', from: aTo}, 1);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 var pubsub = answer.firstChild;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 verify(pubsub, ns.ps, 'pubsub', undefined, 1);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 var items = pubsub.firstChild;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 verify(items, ns.ps, 'items', {node: aNode});
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 var items = items.children;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 var list = [];
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 for (var i in items) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 var node = items[i];
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 var id = node.getAttributeNS(null, 'id');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 if (!id)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 throw new Error('WARNING: invalid item! (no id)');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 if (node.children.length != 1)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 throw new Error('WARNING: invalid item! (more than one payload)');
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 var payload = node.firstChild;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 list[id] = new Item(aTo, aNode, id, payload);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 }
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 /*} catch (e) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 aCallback(e);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 }*/
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 if(aCallback)
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 aCallback({service: aTo, node: aNode, items: list});
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 });
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 }
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 };