BREAKING CHANGE: Update API for connection, communication channel state and is browser value (#14)

* refactor(lib, example, example_full): use streams for communication channel and is ios browser

* feat: add abstract toJson() to message

* refactor: add deprecations for nearby_service

* feat(example): update main.dart

* feat(nearby_service): add comments

* feat(nearby_service_platform_interface): add deprecation to getConnectedDeviceStream

* feat(nearby_service/message): add concrete implementation for toJson()

* feat(nearby_service/android): add deprecations

* fix(nearby_service/android): reset check for android device

* fix(nearby_service/ios): change ios service to deprecations variant

* chore(nearby_service): edit deprecation messages

* chore: update gitignore

* doc: add CONTRIBUTING file

* doc: update CONTRIBUTING file

* chore: update CONTRIBUTING.md

* chore: update CONTRIBUTING.md

* chore: version 0.1.0

* fix(example_full): move startListeningCommunicationChannelState() upper
This commit is contained in:
Kseniia Nikitina
2024-08-18 15:42:53 +02:00
committed by GitHub
parent 1818166d06
commit 7049c39cf0
15 changed files with 388 additions and 79 deletions
+83 -9
View File
@@ -74,8 +74,26 @@ abstract class NearbyService {
/// For **IOS** this is the state of the message stream subscription.
/// which is generated for the device with the current connected device ID.
///
@Deprecated(
'Use getCommunicationChannelStateStream or communicationChannelStateValue instead',
)
ValueListenable<CommunicationChannelState> get communicationChannelState;
///
/// **A value to determine the communication channel's status.**
///
/// For **Android** this is the socket connection state.
/// The server can wait for the client to connect,
/// and the client can be waiting for the server to be created.
/// Also, both can be in connected and unconnected states.
///
/// For **IOS** this is the state of the message stream subscription.
/// which is generated for the device with the current connected device ID.
///
/// **Can be used to retrieve the current state of the communication channel without listening to the stream via** [getCommunicationChannelStateStream].
///
CommunicationChannelState get communicationChannelStateValue;
///
/// Gets version of current platform.
///
@@ -147,10 +165,20 @@ abstract class NearbyService {
/// Returns the constantly updating [NearbyDevice] you are currently connected to.
/// If it returns null, then there is no connection at the moment.
///
@Deprecated('Use getConnectedDeviceStreamById instead')
Stream<NearbyDevice?> getConnectedDeviceStream(NearbyDevice device) {
return NearbyServicePlatform.instance.getConnectedDeviceStream(device);
}
///
/// Returns the constantly updating [NearbyDevice] you are currently connected to.
/// If it returns null, then there is no connection at the moment.
///
Stream<NearbyDevice?> getConnectedDeviceStreamById(String deviceId) {
return NearbyServicePlatform.instance
.getConnectedDeviceStreamById(deviceId);
}
///
/// Initialization of a platform-specific service.
///
@@ -166,7 +194,7 @@ abstract class NearbyService {
/// Starts searching for devices using a platform-specific service.
///
/// Note that the [NearbyIOSService] implementation starts **browsing** or
/// **advertising** depending on the [NearbyIOSService.isBrowser].
/// **advertising** depending on the [NearbyIOSService.isBrowserValue].
///
/// On Android can throw mapped from native platform exceptions:
/// 1. [NearbyServiceBusyException]
@@ -181,7 +209,7 @@ abstract class NearbyService {
/// Stops searching for devices using a platform-specific service.
///
/// Note that the [NearbyIOSService] implementation stops **browsing** or
/// **advertising** depending on the [NearbyIOSService.isBrowser].
/// **advertising** depending on the [NearbyIOSService.isBrowserValue].
///
/// On Android can throw mapped from native platform exceptions:
/// 1. [NearbyServiceBusyException]
@@ -208,16 +236,18 @@ abstract class NearbyService {
/// 4. [NearbyServiceGenericErrorException]
/// 5. [NearbyServiceUnknownException]
///
@Deprecated('Use connectById instead')
Future<bool> connect(NearbyDevice device);
///
/// Disconnects from passed [device] using a platform-specific service.
/// Connects to passed [deviceId] using a platform-specific service.
///
/// Note that the [NearbyIOSService] implementation **invites** or
/// **accepts invite** depending on the [NearbyIOSService.isBrowserValue].
///
/// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed.
/// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed.
///
/// **For IOS [device] is required!!!**
///
/// On Android can throw mapped from native platform exceptions:
/// 1. [NearbyServiceBusyException]
/// 2. [NearbyServiceP2PUnsupportedException]
@@ -225,8 +255,41 @@ abstract class NearbyService {
/// 4. [NearbyServiceGenericErrorException]
/// 5. [NearbyServiceUnknownException]
///
Future<bool> connectById(String deviceId);
///
/// Disconnects from passed [device] using a platform-specific service.
///
/// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed.
/// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed.
///
/// On Android can throw mapped from native platform exceptions:
/// 1. [NearbyServiceBusyException]
/// 2. [NearbyServiceP2PUnsupportedException]
/// 3. [NearbyServiceNoServiceRequestsException]
/// 4. [NearbyServiceGenericErrorException]
/// 5. [NearbyServiceUnknownException]
///
/// **For IOS [device] is required!!!**
@Deprecated('Use disconnectById instead')
Future<bool> disconnect([NearbyDevice? device]);
///
/// Disconnects from passed [deviceId] using a platform-specific service.
///
/// Note that if [Platform.isIOS] == true, [NearbyIOSDevice] should be passed.
/// If [Platform.isAndroid] == true, [NearbyAndroidDevice] should be passed.
///
/// On Android can throw mapped from native platform exceptions:
/// 1. [NearbyServiceBusyException]
/// 2. [NearbyServiceP2PUnsupportedException]
/// 3. [NearbyServiceNoServiceRequestsException]
/// 4. [NearbyServiceGenericErrorException]
/// 5. [NearbyServiceUnknownException]
///
/// **For IOS [deviceId] is required!!!**
Future<bool> disconnectById([String? deviceId]);
///
/// If the device is already connected, it does not mean that you can
/// send and receive data.
@@ -235,11 +298,9 @@ abstract class NearbyService {
/// You need to call [startCommunicationChannel] before using [send].
/// A communication channel can only be created if you are connected to some device.
///
/// You can monitor changes in communication channel state using the [communicationChannelState] getter.
/// You can monitor changes in communication channel state using the [getCommunicationChannelStateStream] method.
///
FutureOr<bool> startCommunicationChannel(
NearbyCommunicationChannelData data,
);
FutureOr<bool> startCommunicationChannel(NearbyCommunicationChannelData data);
///
/// If you called [startCommunicationChannel], remember that you have
@@ -250,6 +311,19 @@ abstract class NearbyService {
///
FutureOr<bool> endCommunicationChannel();
///
/// **A stream with values of [CommunicationChannelState] to determine the communication channel's status.**
///
/// For **Android** this is the socket connection state.
/// The server can wait for the client to connect,
/// and the client can be waiting for the server to be created.
/// Also, both can be in connected and unconnected states.
///
/// For **IOS** this is the state of the message stream subscription.
/// which is generated for the device with the current connected device ID.
///
Stream<CommunicationChannelState> getCommunicationChannelStateStream();
///
/// Method to send data to the created communication channel.
///