Commit aca7c79a authored by Adrien Dorsaz's avatar Adrien Dorsaz

xmpp: manage stream close from client

parent a0e2bcce
......@@ -127,6 +127,14 @@ xmppClientListener = function (message, sender, sendResponse) {
);
break;
case 'disconnect':
xmppPaneClient.close();
sendResponse({
connected: false
});
break;
case 'exploreServer':
asynchroneResponse = true;
xmppPaneClient.discoPubsubService(message.payload)
......
......@@ -24,8 +24,13 @@ class Client {
this.password = _config.password;
delete this.config.password;
this.init();
}
// To go back or to construct the intial client state
init() {
// optional websocketURL
this.websocketURL = _config.websocketURL;
this.websocketURL = this.config.websocketURL;
// DOM toolbox
this.dom = document.implementation.createDocument(null, null);
......
......@@ -18,6 +18,9 @@ class Stream {
// XML DOM tree (cleared each time)
this.dom = document.implementation.createDocument(null, null);
// Closing state
this.isClosing = false;
// DOM Parser can parse XML string to DOM (created once)
if (!this.domParser) {
this.domParser = new DOMParser();
......
......@@ -56,6 +56,9 @@ class FramedStream extends Stream {
*/
close() {
return new Promise((resolve, reject) => {
// Save we are closing to avoid send again the same message
this.isClosing = true;
let close = this.dom.createElementNS(Constants.NS_XMPP_FRAMING, "close");
close.setAttribute("to", this.to);
close.setAttribute("version", Constants.XMPP_VERSION);
......@@ -78,7 +81,17 @@ class FramedStream extends Stream {
// Initiate close when receiving <close>
// <close> can contain see-other-uri to redirect the stream
// (be careful to keep same security at least in that case)
xmppClient.close();
if (this.isClosing) {
// Well we asked to close and the close has been aknowleged
console.log('framed-stream: received <close> after self-initiated close: reinit client.');
xmppClient.init();
}
else {
// We didn't initiate the close, call close and reinit directly the client
console.log('framed-stream: received <close> from server: acknowledge and reinit client.');
xmppClient.close();
xmppClient.init();
}
break;
default:
super.handle(xmppClient, message);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment