Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed network latency to a decimal value #35

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading