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