Mercurial > xmpp-account-manager
diff util.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 | |
children | 5aa1bf7154b0 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/util.js @@ -0,0 +1,19 @@ +function nsResolver(prefix) { + return { + xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0', + pubsub: 'http://jabber.org/protocol/pubsub', + avatar_metadata: 'urn:xmpp:avatar:metadata', + avatar_data: 'urn:xmpp:avatar:data', + nickname: 'http://jabber.org/protocol/nick', + }[prefix] || null; +} + +function parseXPath(elem, xpath, result) +{ + if (result === undefined) + result = XPathResult.FIRST_ORDERED_NODE_TYPE; + const value = elem.getRootNode().evaluate(xpath, elem, nsResolver, result, null); + if (result == XPathResult.FIRST_ORDERED_NODE_TYPE) + return value.singleNodeValue; + return value; +}