Reload the page when the socket connection is closed

Fixes #1
This commit is contained in:
Frank A. Krueger 2017-07-06 14:31:54 -07:00
parent 4d70553afa
commit a76879d80f
1 changed files with 12 additions and 3 deletions

View File

@ -8,11 +8,20 @@ let socket = null;
function ooui (rootElementPath) {
socket = new WebSocket ("ws://" + document.location.host + rootElementPath, "ooui");
socket.addEventListener('open', function (event) {
socket.addEventListener ("open", function (event) {
console.log ("Web socket opened");
});
socket.addEventListener('message', function (event) {
socket.addEventListener ("error", function (event) {
console.error ("Web socket error", event);
});
socket.addEventListener ("close", function (event) {
console.error ("Web socket close", event);
location.reload ();
});
socket.addEventListener("message", function (event) {
const messages = JSON.parse (event.data);
if (debug) console.log("Messages", messages);
if (Array.isArray (messages)) {