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
This commit is contained in:
Cory McWilliams 2022-02-26 21:17:15 +00:00
parent ffaaec5b37
commit 95f0b91a0e
3 changed files with 23 additions and 7 deletions

View File

@ -128,6 +128,12 @@ function socket(request, response, client) {
if (process && process.timeout > 0) { if (process && process.timeout > 0) {
setTimeout(ping, process.timeout); setTimeout(ping, process.timeout);
} }
} else if (message.action == 'enableStats') {
process.stats = message.enabled;
if (!gStatsTimer) {
sendStats();
gStatsTimer = true;
}
} else { } else {
if (process && process.eventHandlers['message']) { if (process && process.eventHandlers['message']) {
await invoke(process.eventHandlers['message'], [message]); await invoke(process.eventHandlers['message'], [message]);

View File

@ -156,6 +156,12 @@ function trace() {
function stats() { function stats() {
document.getElementById("statsPane").style.display = 'flex'; 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() { function toggleStats() {
@ -235,10 +241,6 @@ function load(path) {
}); });
} }
function closeStats() {
document.getElementById("statsPane").style.display = 'none';
}
function closeEditor() { function closeEditor() {
document.getElementById("editPane").style.display = 'none'; document.getElementById("editPane").style.display = 'none';
if (gSplit) { if (gSplit) {

View File

@ -6,6 +6,7 @@ var app = require("app");
var gProcessIndex = 0; var gProcessIndex = 0;
var gProcesses = {}; var gProcesses = {};
var gSessionIndex = 0; var gSessionIndex = 0;
var gStatsTimer = false;
var gGlobalSettings = { var gGlobalSettings = {
index: "/~core/index", index: "/~core/index",
@ -157,6 +158,7 @@ async function getProcessBlob(blobId, key, options) {
process.lastActive = Date.now(); process.lastActive = Date.now();
process.lastPing = null; process.lastPing = null;
process.timeout = options.timeout; process.timeout = options.timeout;
process.stats = false;
var resolveReady; var resolveReady;
var rejectReady; var rejectReady;
process.ready = new Promise(function(resolve, reject) { process.ready = new Promise(function(resolve, reject) {
@ -548,14 +550,20 @@ async function loadSettings() {
} }
function sendStats() { function sendStats() {
var any = false;
for (var process of Object.values(gProcesses)) { for (var process of Object.values(gProcesses)) {
if (process.app) { if (process.app && process.stats) {
process.app.send({action: 'stats', stats: getStats()}); process.app.send({action: 'stats', stats: getStats()});
any = true;
} }
} }
if (any) {
setTimeout(sendStats, 1000); setTimeout(sendStats, 1000);
} else {
gStatsTimer = false;
}
} }
setTimeout(sendStats, 1000);
loadSettings().then(function() { loadSettings().then(function() {
var auth = require("auth"); var auth = require("auth");