Some refactoring for self-tests

This commit is contained in:
Rick Falkvinge
2018-10-28 16:40:01 +01:00
parent 7e7f07ab67
commit 83ecea2af3
4 changed files with 16 additions and 9 deletions
+1 -1
View File
@@ -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());
+2 -1
View File
@@ -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
{
+1 -1
View File
@@ -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
+12 -6
View File
@@ -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) {