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:
+14
-10
@@ -60,7 +60,7 @@ class _AppBodyState extends State<AppBody> {
|
||||
late final _nearbyService = NearbyService.getInstance(
|
||||
/// Define log level here
|
||||
logLevel: NearbyServiceLogLevel.debug,
|
||||
)..communicationChannelState.addListener(() => setState(() {}));
|
||||
);
|
||||
|
||||
AppState _state = AppState.idle;
|
||||
|
||||
@@ -70,9 +70,11 @@ class _AppBodyState extends State<AppBody> {
|
||||
/// List of discovered devices
|
||||
List<NearbyDevice> _peers = [];
|
||||
StreamSubscription? _peersSubscription;
|
||||
CommunicationChannelState _communicationChannelState =
|
||||
CommunicationChannelState.notConnected;
|
||||
|
||||
/// Temporary solution to check the connection,
|
||||
/// use [NearbyService.getConnectedDeviceStream] for this purpose
|
||||
/// use [NearbyService.getConnectedDeviceStreamById] for this purpose
|
||||
/// in your application
|
||||
Timer? _connectionCheckTimer;
|
||||
NearbyDevice? _connectedDevice;
|
||||
@@ -158,10 +160,6 @@ class _AppBodyState extends State<AppBody> {
|
||||
return Container();
|
||||
}
|
||||
|
||||
CommunicationChannelState get _communicationChannelState {
|
||||
return _nearbyService.communicationChannelState.value;
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
await _nearbyService.initialize();
|
||||
}
|
||||
@@ -204,7 +202,7 @@ class _AppBodyState extends State<AppBody> {
|
||||
Future<void> _connect(NearbyDevice device) async {
|
||||
// Be careful with already connected devices,
|
||||
// double connection may be unnecessary
|
||||
final result = await _nearbyService.connect(device);
|
||||
final result = await _nearbyService.connectById(device.info.id);
|
||||
if (result || device.status.isConnected) {
|
||||
final channelStarting = _tryCommunicate(device);
|
||||
if (!channelStarting) {
|
||||
@@ -240,8 +238,14 @@ class _AppBodyState extends State<AppBody> {
|
||||
}
|
||||
|
||||
void _startCommunicationChannel(NearbyDevice device) {
|
||||
if (!_communicationChannelState.isNotConnected) return;
|
||||
|
||||
if (_communicationChannelState != CommunicationChannelState.notConnected) {
|
||||
// channel is loading or already connected
|
||||
return;
|
||||
}
|
||||
// start listening communication channel state
|
||||
_nearbyService.getCommunicationChannelStateStream().listen((event) {
|
||||
_communicationChannelState = event;
|
||||
});
|
||||
_nearbyService.startCommunicationChannel(
|
||||
NearbyCommunicationChannelData(
|
||||
device.info.id,
|
||||
@@ -275,7 +279,7 @@ class _AppBodyState extends State<AppBody> {
|
||||
|
||||
Future<void> _disconnect() async {
|
||||
try {
|
||||
await _nearbyService.disconnect(_connectedDevice!);
|
||||
await _nearbyService.disconnectById(_connectedDevice!.info.id);
|
||||
} finally {
|
||||
await _nearbyService.endCommunicationChannel();
|
||||
await _nearbyService.stopDiscovery();
|
||||
|
||||
Reference in New Issue
Block a user