From 95f0b91a0ea7540d62f336abb656902b9f61d708 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 26 Feb 2022 21:17:15 +0000 Subject: [PATCH] Only send stats to clients if there is a client watching them. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3846 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/app.js | 6 ++++++ core/client.js | 10 ++++++---- core/core.js | 14 +++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/app.js b/core/app.js index 97afb5e7..4f0c4878 100644 --- a/core/app.js +++ b/core/app.js @@ -128,6 +128,12 @@ function socket(request, response, client) { if (process && process.timeout > 0) { setTimeout(ping, process.timeout); } + } else if (message.action == 'enableStats') { + process.stats = message.enabled; + if (!gStatsTimer) { + sendStats(); + gStatsTimer = true; + } } else { if (process && process.eventHandlers['message']) { await invoke(process.eventHandlers['message'], [message]); diff --git a/core/client.js b/core/client.js index db87512e..f136ac02 100644 --- a/core/client.js +++ b/core/client.js @@ -156,6 +156,12 @@ function trace() { function stats() { document.getElementById("statsPane").style.display = 'flex'; + send({action: 'enableStats', enabled: true}); +} + +function closeStats() { + document.getElementById("statsPane").style.display = 'none'; + send({action: 'enableStats', enabled: false}); } function toggleStats() { @@ -235,10 +241,6 @@ function load(path) { }); } -function closeStats() { - document.getElementById("statsPane").style.display = 'none'; -} - function closeEditor() { document.getElementById("editPane").style.display = 'none'; if (gSplit) { diff --git a/core/core.js b/core/core.js index f48075c9..43aa54d7 100644 --- a/core/core.js +++ b/core/core.js @@ -6,6 +6,7 @@ var app = require("app"); var gProcessIndex = 0; var gProcesses = {}; var gSessionIndex = 0; +var gStatsTimer = false; var gGlobalSettings = { index: "/~core/index", @@ -157,6 +158,7 @@ async function getProcessBlob(blobId, key, options) { process.lastActive = Date.now(); process.lastPing = null; process.timeout = options.timeout; + process.stats = false; var resolveReady; var rejectReady; process.ready = new Promise(function(resolve, reject) { @@ -548,14 +550,20 @@ async function loadSettings() { } function sendStats() { + var any = false; for (var process of Object.values(gProcesses)) { - if (process.app) { + if (process.app && process.stats) { process.app.send({action: 'stats', stats: getStats()}); + any = true; } } - setTimeout(sendStats, 1000); + + if (any) { + setTimeout(sendStats, 1000); + } else { + gStatsTimer = false; + } } -setTimeout(sendStats, 1000); loadSettings().then(function() { var auth = require("auth");