Attempt to gracefully close the socket

This commit is contained in:
Frank A. Krueger 2017-11-15 21:59:01 -06:00
parent d63d7e7ffc
commit b67e87d19e
1 changed files with 11 additions and 1 deletions

View File

@ -18,6 +18,15 @@ const mouseEvents = {
wheel: true,
};
window.onbeforeunload = function() {
if (socket != null) {
socket.close (1001, "Unloading page");
socket = null;
console.log ("Web socket closed");
}
return null;
}
function ooui (rootElementPath) {
var opened = false;
@ -135,7 +144,8 @@ function msgListen (m) {
};
}
const ems = JSON.stringify (em);
socket.send (ems);
if (socket != null)
socket.send (ems);
if (debug) console.log ("Event", em);
if (em.k === "submit")
e.preventDefault ();