wifi udp stream activity indicator added
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user