From 83ecea2af33fe3a90b44e7fe6b66b05f8a79c557 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 28 Oct 2018 16:40:01 +0100 Subject: [PATCH] Some refactoring for self-tests --- Backend/BackendLoop.cs | 2 +- FrontSocket/FrontendLoop.cs | 3 ++- Site/Pages/v5/Financial/Donate.aspx | 2 +- Site/Scripts/Swarmops-v5.js | 18 ++++++++++++------ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index d9e508da..25098ca9 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -901,7 +901,7 @@ namespace Swarmops.Backend private static void InternalHeartbeat() { JObject json = new JObject(); - json["MessageType"] = "InternalHeartbeat"; + json["MessageType"] = "BackendHeartbeat"; json["Timestamp"] = DateTime.UtcNow.ToUnix(); _socketServer.WebSocketServices.Broadcast(json.ToString()); diff --git a/FrontSocket/FrontendLoop.cs b/FrontSocket/FrontendLoop.cs index 31840f3c..319e850e 100644 --- a/FrontSocket/FrontendLoop.cs +++ b/FrontSocket/FrontendLoop.cs @@ -290,9 +290,10 @@ namespace Swarmops.Frontend.Socket Console.WriteLine(" - Backend message: " + args.Data); } - if (messageType == "InternalHeartbeat") + if (messageType == "BackendHeartbeat") { _lastBackendHeartBeat = DateTime.UtcNow; + _socketServer.WebSocketServices.Broadcast(args.Data); // send unfiltered to all sessions, for now } else { diff --git a/Site/Pages/v5/Financial/Donate.aspx b/Site/Pages/v5/Financial/Donate.aspx index aad96d53..62dad9c1 100644 --- a/Site/Pages/v5/Financial/Donate.aspx +++ b/Site/Pages/v5/Financial/Donate.aspx @@ -54,7 +54,7 @@ }); - function pageBitcoinReceived(address, hash, satoshis, cents, currencyCode) { + function pageOnBitcoinReceived(address, hash, satoshis, cents, currencyCode) { // This function is detected called by the Master Page; it is not // called from this page or anything visible here diff --git a/Site/Scripts/Swarmops-v5.js b/Site/Scripts/Swarmops-v5.js index 10cf858a..ac87dbbd 100644 --- a/Site/Scripts/Swarmops-v5.js +++ b/Site/Scripts/Swarmops-v5.js @@ -74,27 +74,33 @@ function _masterInitializeSocket(authenticationTicket) { _masterSocket.onmessage = function (data) { - console.log(data.data); - var message = $.parseJSON(data.data); if (message.MessageType == "Heartbeat") { _masterSocketLastHeartbeat = new Date().getTime(); - console.log("Heartbeat"); - if (_masterSocketHeartbeatsLost) { console.log(" - receiving heartbeats again"); _masterSocketHeartbeatsLost = false; _master_updateMalfunctions(); } + + if (typeof pageOnHeartbeat === "function") { // if it's defined on the page, indicating there's a handler for it + pageOnHeartbeat('Frontend', _masterSocketLastHeartbeat); + } + + } + else if (message.MessageType == "BackendHeartbeat") { + if (typeof pageOnHeartbeat === "function") { // if it's defined on the page, indicating there's a handler for it + pageOnHeartbeat('Backend', new Date().getTime()); + } } else if (message.MessageType == "BitcoinReceived") { // console.log("Currency is " + message.Currency); // console.log(message); var handled = false; - if (typeof pageBitcoinReceived === "function") { // if it's defined on the page indicating the page handles it - handled = pageBitcoinReceived(message.Address, message.Hash, message.Satoshis, message.Cents, message.Currency); + if (typeof pageOnBitcoinReceived === "function") { // if it's defined on the page indicating the page handles it + handled = pageOnBitcoinReceived(message.Address, message.Hash, message.Satoshis, message.Cents, message.Currency); } if (!handled) {