annotate plugins/disco.js @ 109:cd1f57661439 default tip

Fix files permissions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Aug 2012 23:18:03 +0200
parents c5240333ea4c
children
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'),
91
c5240333ea4c pubsub item node
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
74 node: node.getAttributeNS(null, 'node') || ''
70
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
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 76
diff changeset
99 if (ns === Lightstring.ns['disco#info'] && name === 'feature')
70
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
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 76
diff changeset
102 else if (ns === Lightstring.ns['disco#info'] && name === 'identity') {
70
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 }
81
7500bc048dbc Typo errors.
Sonny Piers <sonny.piers@gmail.com>
parents: 80
diff changeset
112 else if (ns === Lightstring.ns['dataforms'] && name === 'x')
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 76
diff changeset
113 var fields = this.dataforms.parse(child); //TODO: check if that plugin is enabled.
81
7500bc048dbc Typo errors.
Sonny Piers <sonny.piers@gmail.com>
parents: 80
diff changeset
114
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
115 else
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
116 ; //TODO: emit a warning.
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
117 }
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 stanza.identities = identities;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
120 stanza.features = features;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
121 stanza.fields = fields;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
122
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
123 if (aResult)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
124 aResult(stanza);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
125 }, aError);
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
126 },
72
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
127 addFeatures: function() {
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
128 for (var i = 0; i < arguments.length; i++)
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
129 features.push(arguments[i]);
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
130 }
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 init: function() {
76
0b8e7ca19f83 Plugins init functions are now called with Lightstring.Connection scope.
Sonny Piers <sonny.piers@gmail.com>
parents: 72
diff changeset
133 this.on('iq/' + Lightstring.ns['disco#info'] + ':query', function(stanza) {
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
134 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
135 return false;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
136
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
137 var query = stanza.DOM.firstChild;
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
138 if (query.getAttributeNS(null, 'node')) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
139 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
140 " 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
141 " type='error'/>"; //TODO: precise the error.
76
0b8e7ca19f83 Plugins init functions are now called with Lightstring.Connection scope.
Sonny Piers <sonny.piers@gmail.com>
parents: 72
diff changeset
142 this.send(response);
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
143 return true;
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
144 }
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
145
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
146 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
147 " 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
148 " type='result'>" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
149 "<query xmlns='" + Lightstring.ns['disco#info'] + "'>";
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
150
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
151 identities.forEach(function(i) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
152 res += "<identity";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
153 if (i.category)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
154 res += " category='" + i.category + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
155 if (i.name)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
156 res += " name='" + i.name + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
157 if (i.type)
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
158 res += " type='" + i.type + "'";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
159 res += "/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
160 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
161
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
162 features.forEach(function(f) {
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
163 res += "<feature var='" + f + "'/>";
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
164 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
165
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
166 res += "</query>" +
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
167 "</iq>";
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
168
76
0b8e7ca19f83 Plugins init functions are now called with Lightstring.Connection scope.
Sonny Piers <sonny.piers@gmail.com>
parents: 72
diff changeset
169 this.send(res);
72
5dbf93cef55d Various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 70
diff changeset
170 return true;
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
171 });
45
063e31247e71 Fix disco plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37
diff changeset
172 }
70
fdd1ae375067 Fix disco plugin and add it an handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 58
diff changeset
173 };
84
7f4e43d6cb15 My mistake.
Sonny Piers <sonny.piers@gmail.com>
parents: 83
diff changeset
174 })();