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) => {