watchSingBoxConnectionStats method
Subscribe to connection statistics changes Returns Stream with statistics updates Statistics include: download/upload speed, bytes sent/received, ping, connection duration
Implementation
@override
Stream<SingBoxConnectionStats> watchSingBoxConnectionStats() {
try {
return statsEventChannel
.receiveBroadcastStream()
.map((dynamic event) {
if (event is Map) {
return SingBoxConnectionStats.fromMap(event);
}
return const SingBoxConnectionStats(
downloadSpeed: 0,
uploadSpeed: 0,
bytesSent: 0,
bytesReceived: 0,
connectionDuration: 0,
);
})
.handleError((error) {
debugPrint('Error in connection stats stream: $error');
});
} catch (e) {
debugPrint('Error creating connection stats stream: $e');
return Stream.value(
const SingBoxConnectionStats(
downloadSpeed: 0,
uploadSpeed: 0,
bytesSent: 0,
bytesReceived: 0,
connectionDuration: 0,
),
);
}
}