Mercurial > eldonilo > lightstring
annotate plugins/disco.js @ 37:6773e5bc2ca0
several fixes
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Mon, 30 Jan 2012 23:46:55 +0100 |
parents | bdfbd58b4835 |
children | 063e31247e71 |
rev | line source |
---|---|
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 'use strict'; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 /** |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 Permission to use, copy, modify, and/or distribute this software for any |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 purpose with or without fee is hereby granted, provided that the above |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 copyright notice and this permission notice appear in all copies. |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 */ |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 ///////// |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 //Disco// |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 ///////// |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 Lightstring.stanza.disco = { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 items: function(aTo, aNode) { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 if(aTo) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 var iq = "<iq type='get' to='"+aTo+"'>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 else |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 var iq = "<iq type='get'>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 if(aNode) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 else |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 return iq+query+"</iq>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 }, |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 info: function(aTo, aNode) { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 if(aTo) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 var iq = "<iq type='get' to='"+aTo+"'>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 else |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 var iq = "<iq type='get'>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 if(aNode) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 else |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 return iq+query+"</iq>"; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 }; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 Lightstring.discoItems = function(aConnection, aTo, aCallback) { |
35 | 52 aConnection.send(Lightstring.stanza.disco.items(aTo), function(stanza){ |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 var items = []; |
35 | 54 var elms = stanza.DOM.querySelectorAll('item'); |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 for(var i = 0; i < elms.length; i++) { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 var node = elms[i]; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 var item = { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 jid: node.getAttribute('jid'), |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 name: node.getAttribute('name'), |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 node: node.getAttribute('node') |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 items.push(item); |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 }; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 if(aCallback) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 aCallback(items); |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 }); |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 }; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) { |
35 | 69 aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(stanza){ |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 var identities = []; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 var features = []; |
37 | 72 var fields = {}; |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 |
37 | 74 var children = stanza.DOM.firstChild.childNodes; |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 var length = children.length; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 for (var i = 0; i < length; i++) { |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 |
37 | 79 if (children[i].localName === 'feature') |
80 features.push(children[i].getAttributeNS(null, 'var')); | |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 |
37 | 82 else if (children[i].localName === 'identity') { |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 var identity = { |
37 | 84 category: children[i].getAttributeNS(null, 'category'), |
85 type: children[i].getAttributeNS(null, 'type') | |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 }; |
37 | 87 var name = children[i].getAttributeNS(null, 'name'); |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 if (name) |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 identity.name = name; |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 identities.push(identity); |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 } |
37 | 92 |
93 else if (children[i].localName === 'x') { | |
94 for (var j = 0; j < children[i].childNodes.length; j++) { | |
95 var child = children[i].childNodes[j]; | |
96 var field = { | |
97 type: child.getAttribute('type') | |
98 }; | |
99 | |
100 var _var = child.getAttribute('var'); | |
101 | |
102 var label = child.getAttribute('label'); | |
103 if(label) field.label = label; | |
104 | |
105 | |
106 for (var y = 0; y < child.childNodes.length; y++) { | |
107 if(child.childNodes[y].localName === 'desc') | |
108 field.desc = child.childNodes[y].textContent; | |
109 else if(child.childNodes[y].localName === 'required') | |
110 field.required = true; | |
111 else if(child.childNodes[y].localName === 'value') | |
112 field.value = child.childNodes[y].textContent; | |
113 } | |
114 | |
115 | |
116 fields[_var] = field; | |
117 } | |
118 } | |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 |
37 | 121 aCallback({'identities': identities, 'features': features, 'fields': fields}, stanza); |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 }); |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 }; |