feat(android): stream the connection info

This commit is contained in:
ksenia312
2024-02-04 17:11:25 +01:00
parent 66a79eb4ba
commit 90c2908496
7 changed files with 94 additions and 20 deletions
@@ -126,6 +126,14 @@ class NearbyAndroidService extends NearbyService {
return NearbyServiceAndroidPlatform.instance.getConnectionInfo();
}
///
/// Streams [NearbyConnectionAndroidInfo] -
/// information about the connection information.
///
Stream<NearbyConnectionAndroidInfo?> getConnectionInfoStream() {
return NearbyServiceAndroidPlatform.instance.getConnectionInfoStream();
}
void _requireAndroidDevice(NearbyDevice device) {
assert(
device is NearbyAndroidDevice,
@@ -54,4 +54,10 @@ abstract class NearbyServiceAndroidPlatform extends PlatformInterface {
Future<bool> disconnect(String deviceAddress) {
throw UnimplementedError('disconnect() has not been implemented.');
}
Stream<NearbyConnectionAndroidInfo?> getConnectionInfoStream() {
throw UnimplementedError(
'getConnectionInfoStream() has not been implemented.',
);
}
}
@@ -64,4 +64,14 @@ class MethodChannelAndroidNearbyService extends NearbyServiceAndroidPlatform {
)) ??
false;
}
@override
Stream<NearbyConnectionAndroidInfo?> getConnectionInfoStream() {
const connectedDeviceChannel = EventChannel(
"nearby_service_connection_info",
);
return connectedDeviceChannel.receiveBroadcastStream().map(
(e) => NearbyConnectionInfoMapper.mapToInfo(e),
);
}
}
+1 -1
View File
@@ -31,8 +31,8 @@ class FilesSocket {
final NearbyMessageFilesContent content;
final void Function(String) onDestroy;
final NearbyServiceFilesListener? listener;
final WebSocket _socket;
final _files = <NearbyFile>[];
final _bytesTable = <String, List<int>>{'0': []};
final _futures = <Future>[];