Add android stats channel

This commit is contained in:
problematicconsumer
2023-12-14 12:12:12 +03:30
parent 5ba0784178
commit b9f1e83473
3 changed files with 76 additions and 2 deletions

View File

@@ -149,8 +149,17 @@ class PlatformSingboxService with InfraLogger implements SingboxService {
@override
Stream<SingboxStats> watchStats() {
// TODO: implement watchStats
return const Stream.empty();
const channel = EventChannel("com.hiddify.app/stats", JSONMethodCodec());
loggy.debug("watching stats");
return channel.receiveBroadcastStream().map(
(event) {
if (event case Map<String, dynamic> _) {
return SingboxStats.fromJson(event);
}
loggy.error("[stats client] unexpected type, msg: $event");
throw "invalid type";
},
);
}
@override