Mercurial > xmpp-account-manager
comparison client.js @ 45:8b69b3a1ef8e
Add support for WebSocket.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 23 May 2020 18:58:01 +0200 |
parents | fe59565063af |
children | 010b905a74d4 |
comparison
equal
deleted
inserted
replaced
44:1b07435c7891 | 45:8b69b3a1ef8e |
---|---|
72 const xhr = new XMLHttpRequest(); | 72 const xhr = new XMLHttpRequest(); |
73 xhr.onload = function (evt) { | 73 xhr.onload = function (evt) { |
74 const xml = evt.target.responseXML; | 74 const xml = evt.target.responseXML; |
75 const links = parseXPath(xml, './xrd:XRD/xrd:Link', XPathResult.ORDERED_NODE_ITERATOR_TYPE); | 75 const links = parseXPath(xml, './xrd:XRD/xrd:Link', XPathResult.ORDERED_NODE_ITERATOR_TYPE); |
76 let bosh_service = null; | 76 let bosh_service = null; |
77 let ws_service = null; | |
77 while (true) { | 78 while (true) { |
78 const link = links.iterateNext(); | 79 const link = links.iterateNext(); |
79 if (!link) | 80 if (!link) |
80 break; | 81 break; |
81 if (link.getAttributeNS(null, 'rel') == 'urn:xmpp:alt-connections:xbosh') { | 82 const rel = link.getAttributeNS(null, 'rel'); |
83 if (rel == 'urn:xmpp:alt-connections:xbosh') | |
82 bosh_service = link.getAttributeNS(null, 'href'); | 84 bosh_service = link.getAttributeNS(null, 'href'); |
83 break; | 85 else if (rel == 'urn:xmpp:alt-connections:websocket') |
84 } | 86 ws_service = link.getAttributeNS(null, 'href'); |
85 // TODO: also support WebSocket. | |
86 } | 87 } |
87 console.log('bosh_service', bosh_service); | 88 console.log('bosh_service', bosh_service); |
88 resolve(bosh_service); | 89 console.log('ws_service', ws_service); |
90 resolve(ws_service || bosh_service); | |
89 }; | 91 }; |
90 xhr.open('GET', url); | 92 xhr.open('GET', url); |
91 xhr.send(); | 93 xhr.send(); |
92 }); | 94 }); |
93 } | 95 } |