comparison nickname.js @ 1:d6df73b466f6

Implement XEP-0156 to discover the right BOSH endpoint.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 21 Dec 2018 23:44:18 +0100
parents 2a8d4e8600d0
children 13e8e4ea53c0
comparison
equal deleted inserted replaced
0:2a8d4e8600d0 1:d6df73b466f6
6 6
7 const iq = $iq({type: 'get'}) 7 const iq = $iq({type: 'get'})
8 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) 8 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
9 .c('items', {node: 'http://jabber.org/protocol/nick'}); 9 .c('items', {node: 'http://jabber.org/protocol/nick'});
10 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.')); 10 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.'));
11
12 function nsResolver(prefix) {
13 return {
14 pubsub: 'http://jabber.org/protocol/pubsub',
15 nickname: 'http://jabber.org/protocol/nick',
16 }[prefix] || null;
17 }
18
19 function parseXPath(elem, xpath)
20 {
21 return elem.getRootNode().evaluate(xpath, elem, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
22 }
23 11
24 function onNickname(result_iq) 12 function onNickname(result_iq)
25 { 13 {
26 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); 14 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item');
27 if (item == null) 15 if (item == null)