From 14d62783a3e15a52def585996932c55d010084bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rik=20Levente?= <33373714+Levminer@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:02:34 +0200 Subject: [PATCH] Web load last 60s and 60m stats --- apps/web/src/routes/(app)/+layout.svelte | 12 ++++++++++++ platforms/windows/service/RTCServer.cs | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/web/src/routes/(app)/+layout.svelte b/apps/web/src/routes/(app)/+layout.svelte index d3ef9df..be248b7 100644 --- a/apps/web/src/routes/(app)/+layout.svelte +++ b/apps/web/src/routes/(app)/+layout.svelte @@ -125,6 +125,18 @@ updateHardwareStats(WSData.data) } } + + if (WSData.type == "secondsData") { + for (let i = 0; i < 3; i++) { + updateHardwareStats(WSData.data) + } + } + + if (WSData.type == "minutesData") { + for (let i = 0; i < 3; i++) { + $hardwareStatistics.minutes.push(generateSecondsData(WSData.data)) + } + } }) } diff --git a/platforms/windows/service/RTCServer.cs b/platforms/windows/service/RTCServer.cs index 3736562..cd21e2f 100644 --- a/platforms/windows/service/RTCServer.cs +++ b/platforms/windows/service/RTCServer.cs @@ -2,6 +2,7 @@ using lib; using SIPSorcery.Net; using System.Text.Json; +using System.Text.Json.Nodes; namespace service; public class RTCServer { @@ -14,8 +15,22 @@ public void Start(HardwareInfo hardwareInfo) { EzRTCHost.Start(); }); - EzRTCHost.dataChannelOpen += (data) => { + EzRTCHost.dataChannelOpen += (RTCDataChannel data) => { EzRTCHost.sendMessageToAll(JsonSerializer.Serialize(new GenericMessage() { Type = "initialData", Data = hardwareInfo.API }, Program.CompressedSerializerOptions)); + + if (data.readyState == RTCDataChannelState.open) { + var secondsList = Program.HardwareStats.seconds.Where((x, i) => (i + 1) % 3 == 0).ToList(); + + for (int i = 0; i < secondsList.Count; i++) { + data.send(JsonSerializer.Serialize(new GenericMessage() { Type = "secondsData", Data = JsonNode.Parse(secondsList[i]) }, Program.CompressedSerializerOptions)); + } + + var minutesList = Program.HardwareStats.minutes.Where((x, i) => (i + 1) % 3 == 0).ToList(); + + for (int i = 0; i < minutesList.Count; i++) { + data.send(JsonSerializer.Serialize(new GenericMessage() { Type = "minutesData", Data = JsonNode.Parse(minutesList[i]) }, Program.CompressedSerializerOptions)); + } + } }; EzRTCHost.dataChannelMessage += (data) => {