wifi udp stream activity indicator added

This commit is contained in:
Constantin Leue
2026-07-31 10:50:41 +02:00
parent cb91436fe4
commit ee97a7cb9a
2 changed files with 76 additions and 0 deletions
@@ -32,6 +32,53 @@ final wifiLinkErrorReasonProvider = Provider<LinkErrorReason?>((ref) {
return ref.watch(wifiTransportProvider).lastErrorReason;
});
/// Zeigt an, ob gerade UDP-Pakete ankommen ("receiving"/"not receiving"),
/// unabhaengig vom (binaeren) Verbindungszustand - der Socket kann offen
/// sein (LinkState.connected), ohne dass die Gegenstelle tatsaechlich
/// sendet. Faellt [_receivingTimeout] nach dem letzten Paket automatisch
/// wieder auf "not receiving" zurueck, dafuer muss ein Timer laufen statt
/// nur auf den incoming-Stream zu reagieren.
class WifiStreamActivityNotifier extends Notifier<bool> {
static const _receivingTimeout = Duration(seconds: 2);
StreamSubscription<void>? _dataSub;
StreamSubscription<LinkState>? _stateSub;
Timer? _timeoutTimer;
@override
bool build() {
final transport = ref.watch(wifiTransportProvider);
_dataSub?.cancel();
_stateSub?.cancel();
_timeoutTimer?.cancel();
_dataSub = transport.incoming.listen((_) => _onPacket());
_stateSub = transport.state.listen(_onStateChanged);
ref.onDispose(() {
_dataSub?.cancel();
_stateSub?.cancel();
_timeoutTimer?.cancel();
});
return false;
}
void _onPacket() {
state = true;
_timeoutTimer?.cancel();
_timeoutTimer = Timer(_receivingTimeout, () => state = false);
}
void _onStateChanged(LinkState linkState) {
if (linkState != LinkState.connected) {
_timeoutTimer?.cancel();
state = false;
}
}
}
final wifiStreamActivityProvider =
NotifierProvider<WifiStreamActivityNotifier, bool>(
WifiStreamActivityNotifier.new);
/// Ein Eintrag im WLAN-Verbindungsprotokoll (Doku 7).
class WifiConnectionLogEntry {
const WifiConnectionLogEntry(this.timestamp, this.message);