From 9af989e021e10ee0a497a4e4328861e57160cd76 Mon Sep 17 00:00:00 2001 From: Gold87 Date: Sat, 27 Apr 2024 21:24:13 -0400 Subject: [PATCH] Changed network latency to a decimal value --- lib/pages/dashboard_page.dart | 4 ++-- lib/services/nt4_client.dart | 8 ++++---- lib/services/nt_connection.dart | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pages/dashboard_page.dart b/lib/pages/dashboard_page.dart index 0c9188ec..8a196476 100644 --- a/lib/pages/dashboard_page.dart +++ b/lib/pages/dashboard_page.dart @@ -1565,10 +1565,10 @@ class _DashboardPageState extends State with WindowListener { ntConnection.latencyStream()), builder: (context, snapshot) { double bandwidth = snapshot.snapshot1.data ?? 0.0; - int latency = snapshot.snapshot2.data ?? 0; + double latency = snapshot.snapshot2.data ?? 0.0; return Text( - '${bandwidth.toStringAsFixed(2).padLeft(5)} kb/s | ${latency.toString().padLeft(1)} ms', + '${bandwidth.toStringAsFixed(2).padLeft(5)} kb/s | ${latency.toStringAsFixed(2).padLeft(4)} ms', textAlign: TextAlign.right, ); }), diff --git a/lib/services/nt4_client.dart b/lib/services/nt4_client.dart index 13d881ab..bae593c5 100644 --- a/lib/services/nt4_client.dart +++ b/lib/services/nt4_client.dart @@ -256,7 +256,7 @@ class NT4Client { final Map announcedTopics = {}; int _clientId = 0; int _serverTimeOffsetUS = 0; - int _latencyMs = 0; + double _latencyMs = 0; int _bitUsage = 0; double _dataRateKbPerSecond = 0; @@ -297,10 +297,10 @@ class NT4Client { _wsOnClose(); } - Stream latencyStream() async* { + Stream latencyStream() async* { yield _latencyMs; - int lastYielded = _latencyMs; + double lastYielded = _latencyMs; while (true) { await Future.delayed(const Duration(seconds: 1)); @@ -543,7 +543,7 @@ class NT4Client { _lastPongTime = rxTime; - _latencyMs = (rtt / 2) ~/ 1000; + _latencyMs = (rtt / 2) / 1000; } void _wsSubscribe(NT4Subscription sub) { diff --git a/lib/services/nt_connection.dart b/lib/services/nt_connection.dart index 319c67c1..96e98b6d 100644 --- a/lib/services/nt_connection.dart +++ b/lib/services/nt_connection.dart @@ -116,7 +116,7 @@ class NTConnection { } } - Stream latencyStream() { + Stream latencyStream() { return nt4Client.latencyStream(); }