chore: rename base classes, comments, formatting

This commit is contained in:
ksenia312
2024-02-05 13:25:36 +01:00
parent 4c2360bb27
commit 258cdf0adc
18 changed files with 103 additions and 96 deletions
+7 -7
View File
@@ -194,8 +194,8 @@ class AppService extends ChangeNotifier {
..communicationChannelState.addListener(notifyListeners); ..communicationChannelState.addListener(notifyListeners);
AppState state = AppState.idle; AppState state = AppState.idle;
List<NearbyDeviceBase>? peers; List<NearbyDevice>? peers;
NearbyDeviceBase? connectedDevice; NearbyDevice? connectedDevice;
NearbyDeviceInfo? currentDeviceInfo; NearbyDeviceInfo? currentDeviceInfo;
NearbyConnectionAndroidInfo? connectionAndroidInfo; NearbyConnectionAndroidInfo? connectionAndroidInfo;
@@ -333,7 +333,7 @@ class AppService extends ChangeNotifier {
updateState(AppState.discoveringPeers); updateState(AppState.discoveringPeers);
} }
Future<void> connect(NearbyDeviceBase device) async { Future<void> connect(NearbyDevice device) async {
try { try {
await _nearbyService.connect(device); await _nearbyService.connect(device);
} catch (e) { } catch (e) {
@@ -366,7 +366,7 @@ class AppService extends ChangeNotifier {
connectionInfoSubscription = null; connectionInfoSubscription = null;
} }
Future<void> startListeningConnectedDevice(NearbyDeviceBase device) async { Future<void> startListeningConnectedDevice(NearbyDevice device) async {
updateState(AppState.loadingConnection); updateState(AppState.loadingConnection);
try { try {
connectedDeviceSubscription = connectedDeviceSubscription =
@@ -468,7 +468,7 @@ class AppService extends ChangeNotifier {
if (connectedDevice == null) return; if (connectedDevice == null) return;
_nearbyService.send( _nearbyService.send(
OutgoingNearbyMessage( OutgoingNearbyMessage(
content: NearbyMessageFilesRequest( content: NearbyMessageFilesRequest.create(
files: [ files: [
...paths.map((e) => NearbyFileInfo(path: e)), ...paths.map((e) => NearbyFileInfo(path: e)),
], ],
@@ -494,7 +494,7 @@ class AppService extends ChangeNotifier {
); );
} }
Future<void> disconnect([NearbyDeviceBase? device]) async { Future<void> disconnect([NearbyDevice? device]) async {
try { try {
await _nearbyService.disconnect(device); await _nearbyService.disconnect(device);
} catch (e) { } catch (e) {
@@ -1004,7 +1004,7 @@ class _ConnectedSocketBodyState extends State<_ConnectedSocketBody> {
class _DevicePreview extends StatelessWidget { class _DevicePreview extends StatelessWidget {
const _DevicePreview({required this.device, this.largeView = false}); const _DevicePreview({required this.device, this.largeView = false});
final NearbyDeviceBase device; final NearbyDevice device;
final bool largeView; final bool largeView;
@override @override
+9 -9
View File
@@ -128,26 +128,26 @@ abstract class NearbyService {
/// ///
/// A single retrieval of the current list of devices in a P2P network. /// A single retrieval of the current list of devices in a P2P network.
/// ///
/// Returns the list of [NearbyDeviceBase] that have been stored so far. /// Returns the list of [NearbyDevice] that have been stored so far.
/// If you want to use a constantly updated list of devices, use [getPeersStream]. /// If you want to use a constantly updated list of devices, use [getPeersStream].
/// ///
Future<List<NearbyDeviceBase>> getPeers() { Future<List<NearbyDevice>> getPeers() {
return NearbyServicePlatform.instance.getPeers(); return NearbyServicePlatform.instance.getPeers();
} }
/// ///
/// Returns a constantly updating list of [NearbyDeviceBase] that /// Returns a constantly updating list of [NearbyDevice] that
/// the platform-specific service has found at each point in time. /// the platform-specific service has found at each point in time.
/// ///
Stream<List<NearbyDeviceBase>> getPeersStream() { Stream<List<NearbyDevice>> getPeersStream() {
return NearbyServicePlatform.instance.getPeersStream(); return NearbyServicePlatform.instance.getPeersStream();
} }
/// ///
/// Returns the constantly updating [NearbyDeviceBase] you are currently connected to. /// Returns the constantly updating [NearbyDevice] you are currently connected to.
/// If it returns null, then there is no connection at the moment. /// If it returns null, then there is no connection at the moment.
/// ///
Stream<NearbyDeviceBase?> getConnectedDeviceStream(NearbyDeviceBase device) { Stream<NearbyDevice?> getConnectedDeviceStream(NearbyDevice device) {
return NearbyServicePlatform.instance.getConnectedDeviceStream(device); return NearbyServicePlatform.instance.getConnectedDeviceStream(device);
} }
@@ -187,7 +187,7 @@ abstract class NearbyService {
/// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed. /// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed.
/// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed. /// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed.
/// ///
Future<bool> connect(NearbyDeviceBase device); Future<bool> connect(NearbyDevice device);
/// ///
/// Disconnects from passed [device] using a platform-specific service. /// Disconnects from passed [device] using a platform-specific service.
@@ -195,8 +195,8 @@ abstract class NearbyService {
/// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed. /// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed.
/// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed. /// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed.
/// ///
/// For IOS [device] is required!!! /// **For IOS [device] is required!!!**
Future<bool> disconnect([NearbyDeviceBase? device]); Future<bool> disconnect([NearbyDevice? device]);
/// ///
/// If the device is already connected, it does not mean that you can /// If the device is already connected, it does not mean that you can
+3 -3
View File
@@ -35,14 +35,14 @@ class MethodChannelNearbyService extends NearbyServicePlatform {
} }
@override @override
Future<List<NearbyDeviceBase>> getPeers() async { Future<List<NearbyDevice>> getPeers() async {
return NearbyDeviceMapper.instance.mapToDeviceList( return NearbyDeviceMapper.instance.mapToDeviceList(
await methodChannel.invokeMethod('fetchPeers'), await methodChannel.invokeMethod('fetchPeers'),
); );
} }
@override @override
Stream<List<NearbyDeviceBase>> getPeersStream() { Stream<List<NearbyDevice>> getPeersStream() {
const peersChannel = EventChannel("nearby_service_peers"); const peersChannel = EventChannel("nearby_service_peers");
return peersChannel.receiveBroadcastStream().map((e) { return peersChannel.receiveBroadcastStream().map((e) {
return NearbyDeviceMapper.instance.mapToDeviceList(e); return NearbyDeviceMapper.instance.mapToDeviceList(e);
@@ -50,7 +50,7 @@ class MethodChannelNearbyService extends NearbyServicePlatform {
} }
@override @override
Stream<NearbyDeviceBase?> getConnectedDeviceStream(NearbyDeviceBase device) { Stream<NearbyDevice?> getConnectedDeviceStream(NearbyDevice device) {
const connectedDeviceChannel = EventChannel( const connectedDeviceChannel = EventChannel(
"nearby_service_connected_device", "nearby_service_connected_device",
); );
+4 -4
View File
@@ -40,20 +40,20 @@ abstract class NearbyServicePlatform extends PlatformInterface {
'openServicesSettings() has not been implemented.'); 'openServicesSettings() has not been implemented.');
} }
Future<List<NearbyDeviceBase>> getPeers() { Future<List<NearbyDevice>> getPeers() {
throw UnimplementedError('getPeers() has not been implemented.'); throw UnimplementedError('getPeers() has not been implemented.');
} }
Stream<List<NearbyDeviceBase>> getPeersStream() { Stream<List<NearbyDevice>> getPeersStream() {
throw UnimplementedError('streamPeers() has not been implemented.'); throw UnimplementedError('streamPeers() has not been implemented.');
} }
Stream<NearbyDeviceBase?> getConnectedDeviceStream(NearbyDeviceBase device) { Stream<NearbyDevice?> getConnectedDeviceStream(NearbyDevice device) {
throw UnimplementedError( throw UnimplementedError(
'getConnectedDeviceStream() has not been implemented.'); 'getConnectedDeviceStream() has not been implemented.');
} }
Future<bool> disconnect(NearbyDeviceBase device) { Future<bool> disconnect(NearbyDevice device) {
throw UnimplementedError('disconnect() has not been implemented.'); throw UnimplementedError('disconnect() has not been implemented.');
} }
} }
+7 -7
View File
@@ -5,12 +5,12 @@ import 'package:nearby_service/nearby_service.dart';
/// ///
/// The model of the device found in the P2P network. /// The model of the device found in the P2P network.
/// ///
abstract base class NearbyDeviceBase { abstract base class NearbyDevice {
/// ///
/// The base device contains [info] and [status]. /// The base device contains [info] and [status].
/// These are parameters that devices will have independent of the platform. /// These are parameters that devices will have independent of the platform.
/// ///
const NearbyDeviceBase({required this.info, required this.status}); const NearbyDevice({required this.info, required this.status});
/// ///
/// The minimum information about the device required /// The minimum information about the device required
@@ -26,7 +26,7 @@ abstract base class NearbyDeviceBase {
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
other is NearbyDeviceBase && other is NearbyDevice &&
runtimeType == other.runtimeType && runtimeType == other.runtimeType &&
info == other.info && info == other.info &&
status == other.status; status == other.status;
@@ -43,17 +43,17 @@ abstract base class NearbyDeviceBase {
/// If you want to get different data /// If you want to get different data
/// **depending on the platform**, use [byPlatform]. /// **depending on the platform**, use [byPlatform].
/// ///
/// * The [onAndroid] callback returns this instance of [NearbyDeviceBase], /// * The [onAndroid] callback returns this instance of [NearbyDevice],
/// cast as [NearbyAndroidDevice] if [Platform.isAndroid] is true. /// cast as [NearbyAndroidDevice] if [Platform.isAndroid] is true.
/// ///
/// * The [onIOS] callback returns this instance of [NearbyDeviceBase], /// * The [onIOS] callback returns this instance of [NearbyDevice],
/// cast as [NearbyIOSDevice] if [Platform.isIOS] is true. /// cast as [NearbyIOSDevice] if [Platform.isIOS] is true.
/// ///
/// * The [onAny] callback returns this instance of [NearbyDeviceBase] with /// * The [onAny] callback returns this instance of [NearbyDevice] with
/// no casting if both [Platform.isAndroid] and [Platform.isIOS] are false. /// no casting if both [Platform.isAndroid] and [Platform.isIOS] are false.
/// ///
T? byPlatform<T>({ T? byPlatform<T>({
T Function(NearbyDeviceBase)? onAny, T Function(NearbyDevice)? onAny,
T Function(NearbyAndroidDevice)? onAndroid, T Function(NearbyAndroidDevice)? onAndroid,
T Function(NearbyIOSDevice)? onIOS, T Function(NearbyIOSDevice)? onIOS,
}) { }) {
+3 -3
View File
@@ -3,12 +3,12 @@ import 'package:nearby_service/nearby_service.dart';
/// ///
/// Basic Message Abstraction. /// Basic Message Abstraction.
/// ///
abstract base class NearbyMessageBase<C extends NearbyMessageContentBase> { abstract base class NearbyMessage<C extends NearbyMessageContent> {
/// ///
/// The basic message contains only [content] - the content /// The basic message contains only [content] - the content
/// to be sent or received. /// to be sent or received.
/// ///
const NearbyMessageBase({required this.content}); const NearbyMessage({required this.content});
/// ///
/// Model representing content to be sent or received /// Model representing content to be sent or received
@@ -25,7 +25,7 @@ abstract base class NearbyMessageBase<C extends NearbyMessageContentBase> {
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
other is NearbyMessageBase && other is NearbyMessage &&
runtimeType == other.runtimeType && runtimeType == other.runtimeType &&
content == other.content; content == other.content;
+28 -14
View File
@@ -2,28 +2,30 @@ import 'package:nearby_service/nearby_service.dart';
/// ///
/// Abstraction for the message content. /// Abstraction for the message content.
/// The [type] is used to determine, what type of content is it. /// The [NearbyMessageContentType] is used to
/// determine, what type of content is it.
/// ///
abstract base class NearbyMessageContentBase { abstract base class NearbyMessageContent {
const NearbyMessageContentBase(); const NearbyMessageContent();
/// ///
/// Contains the conditional logic of creating [NearbyMessageFilesRequest], /// Contains the conditional logic of creating [NearbyMessageFilesRequest],
/// [NearbyMessageFilesResponse] or [NearbyMessageTextContent] /// [NearbyMessageFilesResponse] or [NearbyMessageTextContent]
/// by `type` field of [json]. /// by `type` field of [json].
/// ///
static Content fromJson<Content extends NearbyMessageContentBase>( static C fromJson<C extends NearbyMessageContent>(
Map<String, dynamic>? json) { Map<String, dynamic>? json,
) {
try { try {
final type = NearbyMessageContentType.values.firstWhere( final type = NearbyMessageContentType.values.firstWhere(
(e) => e.name == json?['type'], (e) => e.name == json?['type'],
); );
if (type.isText) { if (type.isText) {
return NearbyMessageTextContent.fromJson(json) as Content; return NearbyMessageTextContent.fromJson(json) as C;
} else if (type.isFilesRequest) { } else if (type.isFilesRequest) {
return NearbyMessageFilesRequest.fromJson(json) as Content; return NearbyMessageFilesRequest.fromJson(json) as C;
} else if (type.isFilesResponse) { } else if (type.isFilesResponse) {
return NearbyMessageFilesResponse.fromJson(json) as Content; return NearbyMessageFilesResponse.fromJson(json) as C;
} else { } else {
throw NearbyServiceException.unsupportedDecoding(json); throw NearbyServiceException.unsupportedDecoding(json);
} }
@@ -32,7 +34,19 @@ abstract base class NearbyMessageContentBase {
} }
} }
NearbyMessageContentType get type; NearbyMessageContentType get _type {
final type = byType(
onText: (_) => NearbyMessageContentType.text,
onFilesRequest: (_) => NearbyMessageContentType.filesRequest,
onFilesResponse: (_) => NearbyMessageContentType.filesResponse,
);
if (type != null) {
return type;
}
throw NearbyServiceException(
'Unknown type on NearbyMessageContent - $runtimeType',
);
}
/// ///
/// Check for the content if it is valid for sending or receiving. /// Check for the content if it is valid for sending or receiving.
@@ -40,13 +54,13 @@ abstract base class NearbyMessageContentBase {
bool get isValid; bool get isValid;
/// ///
/// * The [onText] callback returns this instance of [NearbyMessageContentBase], /// * The [onText] callback returns this instance of [NearbyMessageContent],
/// cast as [NearbyMessageTextContent] if is a text. /// cast as [NearbyMessageTextContent] if is a text.
/// ///
/// * The [onFilesRequest] callback returns this instance of [NearbyMessageContentBase], /// * The [onFilesRequest] callback returns this instance of [NearbyMessageContent],
/// cast as [NearbyMessageFilesRequest] if is a files pack request. /// cast as [NearbyMessageFilesRequest] if is a files pack request.
/// ///
/// * The [onFilesResponse] callback returns this instance of [NearbyMessageContentBase], /// * The [onFilesResponse] callback returns this instance of [NearbyMessageContent],
/// cast as [NearbyMessageFilesResponse] if is a files pack response. /// cast as [NearbyMessageFilesResponse] if is a files pack response.
/// ///
T? byType<T>({ T? byType<T>({
@@ -65,9 +79,9 @@ abstract base class NearbyMessageContentBase {
} }
/// ///
/// Gets [Map] from [NearbyMessageContentBase] /// Gets [Map] from [NearbyMessageContent]
/// ///
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return {'type': type.name}; return {'type': _type.name};
} }
} }
+4 -4
View File
@@ -23,12 +23,12 @@ abstract interface class NearbyDeviceMapper {
} }
/// ///
/// Converts JSON to a list of [NearbyDeviceBase]. /// Converts JSON to a list of [NearbyDevice].
/// ///
List<NearbyDeviceBase> mapToDeviceList(dynamic value); List<NearbyDevice> mapToDeviceList(dynamic value);
/// ///
/// Converts JSON to a [NearbyDeviceBase]. /// Converts JSON to a [NearbyDevice].
/// ///
NearbyDeviceBase? mapToDevice(dynamic value); NearbyDevice? mapToDevice(dynamic value);
} }
+3
View File
@@ -25,6 +25,9 @@ class ReceivedNearbyFilesPack implements NearbyReceivedInterface {
@override @override
final NearbyDeviceInfo sender; final NearbyDeviceInfo sender;
///
/// Received list of [NearbyFileInfo].
///
final List<NearbyFileInfo> files; final List<NearbyFileInfo> files;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
+5 -5
View File
@@ -3,8 +3,8 @@ import 'package:nearby_service/nearby_service.dart';
/// ///
/// The message that will be sent from the current device. /// The message that will be sent from the current device.
/// ///
final class OutgoingNearbyMessage<C extends NearbyMessageContentBase> final class OutgoingNearbyMessage<C extends NearbyMessageContent>
extends NearbyMessageBase<C> implements NearbyOutgoingInterface { extends NearbyMessage<C> implements NearbyOutgoingInterface {
/// ///
/// To send a message, in addition to [content], you need to pass [receiver] /// To send a message, in addition to [content], you need to pass [receiver]
/// to know to whom the message is addressed. /// to know to whom the message is addressed.
@@ -50,8 +50,8 @@ final class OutgoingNearbyMessage<C extends NearbyMessageContentBase>
/// ///
/// Message received by the current device. /// Message received by the current device.
/// ///
final class ReceivedNearbyMessage<C extends NearbyMessageContentBase> final class ReceivedNearbyMessage<C extends NearbyMessageContent>
extends NearbyMessageBase<C> implements NearbyReceivedInterface { extends NearbyMessage<C> implements NearbyReceivedInterface {
/// ///
/// The received message contains a [sender] in addition to [content], /// The received message contains a [sender] in addition to [content],
/// to know from whom the message came. /// to know from whom the message came.
@@ -66,7 +66,7 @@ final class ReceivedNearbyMessage<C extends NearbyMessageContentBase>
/// ///
factory ReceivedNearbyMessage.fromJson(Map<String, dynamic>? json) { factory ReceivedNearbyMessage.fromJson(Map<String, dynamic>? json) {
return ReceivedNearbyMessage( return ReceivedNearbyMessage(
content: NearbyMessageContentBase.fromJson(json?['content']), content: NearbyMessageContent.fromJson(json?['content']),
sender: NearbyDeviceInfo.fromJson(json?['sender']), sender: NearbyDeviceInfo.fromJson(json?['sender']),
); );
} }
+12 -21
View File
@@ -6,7 +6,7 @@ import 'package:nearby_service/src/utils/random.dart';
/// ///
/// Contains [value] - the message to be sent or received. /// Contains [value] - the message to be sent or received.
/// ///
final class NearbyMessageTextContent extends NearbyMessageContentBase { final class NearbyMessageTextContent extends NearbyMessageContent {
const NearbyMessageTextContent({required this.value}); const NearbyMessageTextContent({required this.value});
/// ///
@@ -23,9 +23,6 @@ final class NearbyMessageTextContent extends NearbyMessageContentBase {
/// ///
final String value; final String value;
@override
NearbyMessageContentType get type => NearbyMessageContentType.text;
@override @override
bool get isValid => value.isNotEmpty; bool get isValid => value.isNotEmpty;
@@ -56,13 +53,12 @@ final class NearbyMessageTextContent extends NearbyMessageContentBase {
/// ///
/// Sealed class for files content in NearbyMessage. /// Sealed class for files content in NearbyMessage.
/// ///
sealed class NearbyMessageFilesContent extends NearbyMessageContentBase { sealed class NearbyMessageFilesContent extends NearbyMessageContent {
/// ///
/// Here [type] = [NearbyMessageContentType.filesResponse] or /// Here type is [NearbyMessageContentType.filesResponse] or
/// [type] = [NearbyMessageContentType.filesRequest] /// [NearbyMessageContentType.filesRequest]
/// ///
/// Also [NearbyMessageFilesContent] contains [id] of the files pack and /// Also [NearbyMessageFilesContent] contains [id] of the files pack.
/// list of [NearbyFileInfo] to determine the files.
/// ///
const NearbyMessageFilesContent({required this.id}); const NearbyMessageFilesContent({required this.id});
@@ -103,6 +99,9 @@ sealed class NearbyMessageFilesContent extends NearbyMessageContentBase {
/// Contains info about the [files]. /// Contains info about the [files].
/// ///
final class NearbyMessageFilesRequest extends NearbyMessageFilesContent { final class NearbyMessageFilesRequest extends NearbyMessageFilesContent {
///
/// Adds a [NearbyFileInfo] list to [id] to identify files.
///
const NearbyMessageFilesRequest._({ const NearbyMessageFilesRequest._({
required super.id, required super.id,
required this.files, required this.files,
@@ -110,8 +109,9 @@ final class NearbyMessageFilesRequest extends NearbyMessageFilesContent {
/// ///
/// Basic constructor with [files] to be sent or received. /// Basic constructor with [files] to be sent or received.
/// Generates [id] in constructor.
/// ///
NearbyMessageFilesRequest({required this.files}) NearbyMessageFilesRequest.create({required this.files})
: super( : super(
id: RandomUtils.instance.nextInt(1000000, 9999999).toString(), id: RandomUtils.instance.nextInt(1000000, 9999999).toString(),
); );
@@ -135,9 +135,6 @@ final class NearbyMessageFilesRequest extends NearbyMessageFilesContent {
/// ///
final List<NearbyFileInfo> files; final List<NearbyFileInfo> files;
@override
NearbyMessageContentType get type => NearbyMessageContentType.filesRequest;
@override @override
String toString() { String toString() {
return 'NearbyMessageFileRequest{id: $id, files: $files}'; return 'NearbyMessageFileRequest{id: $id, files: $files}';
@@ -157,9 +154,7 @@ final class NearbyMessageFilesRequest extends NearbyMessageFilesContent {
bool get isValid => bool get isValid =>
super.isValid && super.isValid &&
files.isNotEmpty && files.isNotEmpty &&
files.every( files.every((element) => element.path.isNotEmpty);
(element) => element.path.isNotEmpty,
);
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
@@ -175,12 +170,11 @@ final class NearbyMessageFilesRequest extends NearbyMessageFilesContent {
/// ///
/// Nearby message File Response. Used for file sending responses. /// Nearby message File Response. Used for file sending responses.
/// Does not contain files' bytes!
/// ///
final class NearbyMessageFilesResponse extends NearbyMessageFilesContent { final class NearbyMessageFilesResponse extends NearbyMessageFilesContent {
/// ///
/// Used to send a response to a previously received request. /// Used to send a response to a previously received request.
/// Provide [id] from [NearbyMessageFilesRequest] or /// Provide [id] from [NearbyMessageFilesRequest].
/// ///
NearbyMessageFilesResponse({ NearbyMessageFilesResponse({
required super.id, required super.id,
@@ -202,9 +196,6 @@ final class NearbyMessageFilesResponse extends NearbyMessageFilesContent {
/// ///
final bool response; final bool response;
@override
NearbyMessageContentType get type => NearbyMessageContentType.filesResponse;
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
@@ -5,7 +5,7 @@ import 'package:nearby_service/src/utils/unknown.dart';
/// ///
/// A device on a P2P network obtained from the Android platform. /// A device on a P2P network obtained from the Android platform.
/// ///
final class NearbyAndroidDevice extends NearbyDeviceBase { final class NearbyAndroidDevice extends NearbyDevice {
/// ///
/// The class representing the Android class /// The class representing the Android class
/// [WifiP2pDevice](https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pDevice). /// [WifiP2pDevice](https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pDevice).
@@ -139,7 +139,7 @@ final class NearbyAndroidDevice extends NearbyDeviceBase {
/// ///
class NearbyAndroidMapper implements NearbyDeviceMapper { class NearbyAndroidMapper implements NearbyDeviceMapper {
@override @override
List<NearbyDeviceBase> mapToDeviceList(dynamic value) { List<NearbyDevice> mapToDeviceList(dynamic value) {
final decoded = JSONDecoder.decodeList(value); final decoded = JSONDecoder.decodeList(value);
return [ return [
...?decoded?.map( ...?decoded?.map(
@@ -149,7 +149,7 @@ class NearbyAndroidMapper implements NearbyDeviceMapper {
} }
@override @override
NearbyDeviceBase? mapToDevice(dynamic value) { NearbyDevice? mapToDevice(dynamic value) {
final decoded = JSONDecoder.decodeMap(value); final decoded = JSONDecoder.decodeMap(value);
if (decoded == null) return null; if (decoded == null) return null;
@@ -54,7 +54,7 @@ class NearbyAndroidService extends NearbyService {
/// Note! Requires [NearbyAndroidDevice] to be passed. /// Note! Requires [NearbyAndroidDevice] to be passed.
/// ///
@override @override
Future<bool> connect(NearbyDeviceBase device) { Future<bool> connect(NearbyDevice device) {
_requireAndroidDevice(device); _requireAndroidDevice(device);
return NearbyServiceAndroidPlatform.instance.connect(device.info.id); return NearbyServiceAndroidPlatform.instance.connect(device.info.id);
} }
@@ -65,7 +65,7 @@ class NearbyAndroidService extends NearbyService {
/// Note! Requires [NearbyAndroidDevice] to be passed. /// Note! Requires [NearbyAndroidDevice] to be passed.
/// ///
@override @override
Future<bool> disconnect([NearbyDeviceBase? device]) { Future<bool> disconnect([NearbyDevice? device]) {
return NearbyServiceAndroidPlatform.instance.disconnect(); return NearbyServiceAndroidPlatform.instance.disconnect();
} }
@@ -133,7 +133,7 @@ class NearbyAndroidService extends NearbyService {
return NearbyServiceAndroidPlatform.instance.getConnectionInfoStream(); return NearbyServiceAndroidPlatform.instance.getConnectionInfoStream();
} }
void _requireAndroidDevice(NearbyDeviceBase device) { void _requireAndroidDevice(NearbyDevice device) {
assert( assert(
device is NearbyAndroidDevice, device is NearbyAndroidDevice,
'The Nearby Android Service can only work with the NearbyAndroidDevice and not with ${device.runtimeType}', 'The Nearby Android Service can only work with the NearbyAndroidDevice and not with ${device.runtimeType}',
@@ -235,7 +235,7 @@ class NearbySocketService {
} }
} }
void _handleMessage(NearbyMessageBase message) { void _handleMessage(NearbyMessage message) {
if (message.content is NearbyMessageFilesContent) { if (message.content is NearbyMessageFilesContent) {
_fileSocketsManager.handleFileMessageContent( _fileSocketsManager.handleFileMessageContent(
message.content as NearbyMessageFilesContent, message.content as NearbyMessageFilesContent,
@@ -4,7 +4,7 @@ import 'package:nearby_service/src/utils/json_decoder.dart';
/// ///
/// A device on a P2P network obtained from the IOS platform. /// A device on a P2P network obtained from the IOS platform.
/// ///
final class NearbyIOSDevice extends NearbyDeviceBase { final class NearbyIOSDevice extends NearbyDevice {
/// ///
/// A class representing an IOS device on a P2P network. /// A class representing an IOS device on a P2P network.
/// ///
@@ -74,7 +74,7 @@ final class NearbyIOSDevice extends NearbyDeviceBase {
/// ///
class NearbyIOSMapper implements NearbyDeviceMapper { class NearbyIOSMapper implements NearbyDeviceMapper {
@override @override
List<NearbyDeviceBase> mapToDeviceList(dynamic value) { List<NearbyDevice> mapToDeviceList(dynamic value) {
final decoded = JSONDecoder.decodeList(value); final decoded = JSONDecoder.decodeList(value);
return [ return [
...?decoded?.map( ...?decoded?.map(
@@ -84,7 +84,7 @@ class NearbyIOSMapper implements NearbyDeviceMapper {
} }
@override @override
NearbyDeviceBase? mapToDevice(dynamic value) { NearbyDevice? mapToDevice(dynamic value) {
final decoded = JSONDecoder.decodeMap(value); final decoded = JSONDecoder.decodeMap(value);
if (decoded == null) return null; if (decoded == null) return null;
@@ -118,7 +118,7 @@ class NearbyIOSService extends NearbyService {
/// Note! Requires [NearbyIOSDevice] to be passed. /// Note! Requires [NearbyIOSDevice] to be passed.
/// ///
@override @override
Future<bool> connect(NearbyDeviceBase device) async { Future<bool> connect(NearbyDevice device) async {
_requireIOSDevice(device); _requireIOSDevice(device);
final result = _isBrowser.value final result = _isBrowser.value
? await NearbyServiceIOSPlatform.instance.invite(device.info.id) ? await NearbyServiceIOSPlatform.instance.invite(device.info.id)
@@ -140,7 +140,7 @@ class NearbyIOSService extends NearbyService {
/// Note! Requires [NearbyIOSDevice] to be passed. /// Note! Requires [NearbyIOSDevice] to be passed.
/// ///
@override @override
Future<bool> disconnect([NearbyDeviceBase? device]) async { Future<bool> disconnect([NearbyDevice? device]) async {
if (device == null) return false; if (device == null) return false;
_requireIOSDevice(device); _requireIOSDevice(device);
final result = await NearbyServiceIOSPlatform.instance.disconnect( final result = await NearbyServiceIOSPlatform.instance.disconnect(
@@ -272,7 +272,7 @@ class NearbyIOSService extends NearbyService {
} }
} }
void _requireIOSDevice(NearbyDeviceBase device) { void _requireIOSDevice(NearbyDevice device) {
assert( assert(
device is NearbyIOSDevice, device is NearbyIOSDevice,
'The Nearby IOS Service can only work with the NearbyIOSDevice and not with ${device.runtimeType}', 'The Nearby IOS Service can only work with the NearbyIOSDevice and not with ${device.runtimeType}',
+1 -2
View File
@@ -31,8 +31,7 @@ class NearbyServiceException implements Exception {
); );
} }
factory NearbyServiceException.invalidMessage( factory NearbyServiceException.invalidMessage(NearbyMessageContent content) {
NearbyMessageContentBase content) {
return NearbyServiceException( return NearbyServiceException(
'The message="$content" is not valid', 'The message="$content" is not valid',
); );
+4 -4
View File
@@ -8,19 +8,19 @@ class MockNearbyServicePlatform
with MockPlatformInterfaceMixin with MockPlatformInterfaceMixin
implements NearbyServicePlatform { implements NearbyServicePlatform {
@override @override
Stream<NearbyDeviceBase?> getConnectedDeviceStream(device) { Stream<NearbyDevice?> getConnectedDeviceStream(device) {
// TODO: implement getConnectedDeviceStream // TODO: implement getConnectedDeviceStream
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
Future<List<NearbyDeviceBase>> getPeers() { Future<List<NearbyDevice>> getPeers() {
// TODO: implement getPeers // TODO: implement getPeers
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
Stream<List<NearbyDeviceBase>> getPeersStream() { Stream<List<NearbyDevice>> getPeersStream() {
// TODO: implement getPeersStream // TODO: implement getPeersStream
throw UnimplementedError(); throw UnimplementedError();
} }
@@ -44,7 +44,7 @@ class MockNearbyServicePlatform
} }
@override @override
Future<bool> disconnect(NearbyDeviceBase device) { Future<bool> disconnect(NearbyDevice device) {
// TODO: implement disconnect // TODO: implement disconnect
throw UnimplementedError(); throw UnimplementedError();
} }