Commit 450885f3 authored by Boris Kocherov's avatar Boris Kocherov

erp5_web_jabber_client: connection immediately disconnect on browser window close

it save from message loss.
parent 8f702e79
...@@ -50,6 +50,18 @@ ...@@ -50,6 +50,18 @@
} }
function disconnectOnbeforeunload(connection) {
return function (event) {
/* XXX it can be interfere with changed warning
if (changed && $('button.save')) {
return unsaved_warn_message;
}*/
connection.sync = true;
connection.disconnect();
connection.flush();
};
}
function deferOnMessageStanza(message) { function deferOnMessageStanza(message) {
var gadget = this; var gadget = this;
enqueueDefer(gadget, function () { enqueueDefer(gadget, function () {
...@@ -148,27 +160,29 @@ ...@@ -148,27 +160,29 @@
// Try to auto connection // Try to auto connection
if (gadget.props.server !== undefined) { if (gadget.props.server !== undefined) {
gadget.props.connection = new Strophe.Connection(gadget.props.server); gadget.props.connection = new Strophe.Connection(gadget.props.server);
var connection = gadget.props.connection;
// gadget.props.connection.rawInput = function (data) {
// console.log("RECEIVING SOMETHING"); // connection.rawInput = function (data) {
// console.log(data); // console.log("RECEIVING SOMETHING");
// }; // console.log(data);
// gadget.props.connection.rawOutput = function (data) { // };
// console.log("SENDING SOMETHING"); // connection.rawOutput = function (data) {
// console.log(data); // console.log("SENDING SOMETHING");
// }; // console.log(data);
// };
gadget.props.connection.connect(
connection.connect(
gadget.props.jid, gadget.props.jid,
gadget.props.passwd, gadget.props.passwd,
handleConnectionCallback handleConnectionCallback
); );
gadget.props.connection.addHandler( window.onbeforeunload = disconnectOnbeforeunload(connection);
connection.addHandler(
deferOnPresenceStanza.bind(gadget), deferOnPresenceStanza.bind(gadget),
null, null,
"presence" "presence"
); );
gadget.props.connection.addHandler( connection.addHandler(
deferOnMessageStanza.bind(gadget), deferOnMessageStanza.bind(gadget),
null, null,
"message", "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