From a76879d80f76746f7db58541d13ab687a3be3623 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Thu, 6 Jul 2017 14:31:54 -0700 Subject: [PATCH] Reload the page when the socket connection is closed Fixes #1 --- Ooui/Client.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Ooui/Client.js b/Ooui/Client.js index 8c37561..d9cf206 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -8,11 +8,20 @@ let socket = null; function ooui (rootElementPath) { socket = new WebSocket ("ws://" + document.location.host + rootElementPath, "ooui"); - socket.addEventListener('open', function (event) { - console.log("Web socket opened"); + 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)) {