Skip to content

Commit

Permalink
Merge pull request #35 from Gold872/latency-decimal
Browse files Browse the repository at this point in the history
Changed network latency to a decimal value
  • Loading branch information
Gold872 authored Apr 28, 2024
2 parents bc2ead6 + 9af989e commit dccdcd7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1565,10 +1565,10 @@ class _DashboardPageState extends State<DashboardPage> 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,
);
}),
Expand Down
8 changes: 4 additions & 4 deletions lib/services/nt4_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class NT4Client {
final Map<int, NT4Topic> announcedTopics = {};
int _clientId = 0;
int _serverTimeOffsetUS = 0;
int _latencyMs = 0;
double _latencyMs = 0;
int _bitUsage = 0;
double _dataRateKbPerSecond = 0;

Expand Down Expand Up @@ -297,10 +297,10 @@ class NT4Client {
_wsOnClose();
}

Stream<int> latencyStream() async* {
Stream<double> latencyStream() async* {
yield _latencyMs;

int lastYielded = _latencyMs;
double lastYielded = _latencyMs;

while (true) {
await Future.delayed(const Duration(seconds: 1));
Expand Down Expand Up @@ -543,7 +543,7 @@ class NT4Client {

_lastPongTime = rxTime;

_latencyMs = (rtt / 2) ~/ 1000;
_latencyMs = (rtt / 2) / 1000;
}

void _wsSubscribe(NT4Subscription sub) {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/nt_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class NTConnection {
}
}

Stream<int> latencyStream() {
Stream<double> latencyStream() {
return nt4Client.latencyStream();
}

Expand Down

0 comments on commit dccdcd7

Please sign in to comment.