annotate plugins/disco.js @ 75:619f3ffa125a

Lightstring.namespaces has been renamed to Lightstring.ns.
author Sonny Piers <sonny.piers@gmail.com>
date Mon, 06 Feb 2012 17:37:16 +0100
parents 5dbf93cef55d
children 0b8e7ca19f83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /////////
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
22 (function() {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
23 var identities = [{category: 'client', type: 'browser'}];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
24 var features = [];
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
25
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
26 Lightstring.plugins['disco'] = {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
27 namespaces: {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
28 'disco#info': "http://jabber.org/protocol/disco#info",
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
29 'disco#items': "http://jabber.org/protocol/disco#items"
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
30 },
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
31 stanzas: {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
32 items: function(aTo, aNode) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
33 if(aTo)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
34 var iq = "<iq type='get' to='" + aTo + "'>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
35 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
36 var iq = "<iq type='get'>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
37
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
38 if(aNode)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
39 var query = "<query xmlns='" + Lightstring.ns['disco#items'] + "' node='" + aNode + "'/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
40 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
41 var query = "<query xmlns='" + Lightstring.ns['disco#items'] + "'/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
42
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
43 return iq + query + "</iq>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
44 },
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
45 info: function(aTo, aNode) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
46 if(aTo)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
47 var iq = "<iq type='get' to='" + aTo + "'>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
48 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
49 var iq = "<iq type='get'>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
50 if(aNode)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
51 var query = "<query xmlns='" + Lightstring.ns['disco#info'] + "' node='" + aNode + "'/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
52 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
53 var query = "<query xmlns='" + Lightstring.ns['disco#info'] + "'/>";
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
54
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
55 return iq + query + "</iq>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
56 }
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
57 },
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
58 methods: {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
59 items: function(aTo, aResult, aError) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
60 this.send(Lightstring.stanzas.disco.items(aTo), function (stanza) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
61 var items = [];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
62
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
63 var children = stanza.DOM.firstChild.childNodes;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
64 var length = children.length;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
65
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
66 for (var i = 0; i < length; i++) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
67 var node = children[i];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
68 if (node.localName !== 'item')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
69 continue;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
71 var item = {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
72 jid: node.getAttributeNS(null, 'jid'),
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
73 name: node.getAttributeNS(null, 'name'),
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
74 node: node.getAttributeNS(null, 'node')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
75 };
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
76 items.push(item);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
77 }
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
78
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
79 stanza.items = items;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
80
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
81 if (aResult)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
82 aResult(stanza);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
83 }, aError);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
84 },
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
85 info: function(aTo, aNode, aResult, aError) {
72
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
86 this.send(Lightstring.stanzas.disco.info(aTo, aNode), function(stanza) {
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
87 var identities = [];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
88 var features = [];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
89 var fields = {};
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
90
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
91 var children = stanza.DOM.firstChild.childNodes;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
92 var length = children.length;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
93
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
94 for (var i = 0; i < length; i++) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
95 var child = children[i];
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
96 var ns = child.namespaceURI;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
97 var name = child.localName;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
98
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
99 if (ns === Lightstring.namespaces['disco#info'] && name === 'feature')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
100 features.push(child.getAttributeNS(null, 'var'));
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
101
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
102 else if (ns === Lightstring.namespaces['disco#info'] && name === 'identity') {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
103 var identity = {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
104 category: child.getAttributeNS(null, 'category'),
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
105 type: child.getAttributeNS(null, 'type')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
106 };
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
107 var name = child.getAttributeNS(null, 'name');
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
108 if (name)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
109 identity.name = name;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
110 identities.push(identity);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
111 }
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
112
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
113 else if (ns === Lightstring.namespaces['dataforms'] && name === 'x')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
114 this.disco.parse(child); //TODO: check if that plugin is enabled.
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
115
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
116 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
117 ; //TODO: emit a warning.
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
118 }
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
119
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
120 stanza.identities = identities;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
121 stanza.features = features;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
122 stanza.fields = fields;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
123
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
124 if (aResult)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
125 aResult(stanza);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
126 }, aError);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
127 },
72
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
128 addFeatures: function() {
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
129 for (var i = 0; i < arguments.length; i++)
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
130 features.push(arguments[i]);
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
131 }
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
132 },
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
133 init: function() {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
134 conn.on('iq/' + Lightstring.ns['disco#info'] + ':query', function(stanza) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
135 if (stanza.DOM.getAttributeNS(null, 'type') !== 'get')
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
136 return false;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
137
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
138 var query = stanza.DOM.firstChild;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
139 if (query.getAttributeNS(null, 'node')) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
140 var response = "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
141 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
142 " type='error'/>"; //TODO: precise the error.
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
143 conn.send(response);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
144 return true;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
145 }
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
146
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
147 var res = "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
148 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
149 " type='result'>" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
150 "<query xmlns='" + Lightstring.ns['disco#info'] + "'>";
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
151
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
152 identities.forEach(function(i) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
153 res += "<identity";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
154 if (i.category)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
155 res += " category='" + i.category + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
156 if (i.name)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
157 res += " name='" + i.name + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
158 if (i.type)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
159 res += " type='" + i.type + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
160 res += "/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
161 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
162
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
163 features.forEach(function(f) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
164 res += "<feature var='" + f + "'/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
165 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
166
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
167 res += "</query>" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
168 "</iq>";
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
169
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
170 conn.send(res);
72
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
171 return true;
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
172 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
173 }
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
174 };
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
175 })();