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:
@@ -8,14 +8,16 @@ import 'package:nearby_service_example_full/utils/files_saver.dart';
|
||||
import 'app_state.dart';
|
||||
|
||||
class AppService extends ChangeNotifier {
|
||||
late final _nearbyService = NearbyService.getInstance()
|
||||
..communicationChannelState.addListener(notifyListeners);
|
||||
late final _nearbyService = NearbyService.getInstance();
|
||||
|
||||
AppState state = AppState.idle;
|
||||
List<NearbyDevice>? peers;
|
||||
NearbyDevice? connectedDevice;
|
||||
NearbyDeviceInfo? currentDeviceInfo;
|
||||
NearbyConnectionAndroidInfo? _connectionAndroidInfo;
|
||||
CommunicationChannelState _communicationChannelState =
|
||||
CommunicationChannelState.notConnected;
|
||||
bool _isIOSBrowser = true;
|
||||
|
||||
String platformVersion = 'Unknown';
|
||||
String platformModel = 'Unknown';
|
||||
@@ -47,6 +49,10 @@ class AppService extends ChangeNotifier {
|
||||
await _nearbyService.initialize(
|
||||
data: NearbyInitializeData(iosDeviceName: iosDeviceName),
|
||||
);
|
||||
_nearbyService.ios?.getIsBrowserStream().listen((event) {
|
||||
_isIOSBrowser = event;
|
||||
});
|
||||
startListeningCommunicationChannelState();
|
||||
updateState(
|
||||
Platform.isAndroid ? AppState.permissions : AppState.selectClientType,
|
||||
);
|
||||
@@ -152,7 +158,7 @@ class AppService extends ChangeNotifier {
|
||||
|
||||
Future<void> connect(NearbyDevice device) async {
|
||||
try {
|
||||
await _nearbyService.connect(device);
|
||||
await _nearbyService.connectById(device.info.id);
|
||||
} on NearbyServiceBusyException catch (_) {
|
||||
_logBusyException();
|
||||
} catch (e, s) {
|
||||
@@ -163,7 +169,7 @@ class AppService extends ChangeNotifier {
|
||||
|
||||
Future<void> disconnect([NearbyDevice? device]) async {
|
||||
try {
|
||||
await _nearbyService.disconnect(device);
|
||||
await _nearbyService.disconnectById(device?.info.id);
|
||||
} on NearbyServiceBusyException catch (_) {
|
||||
_logBusyException();
|
||||
} catch (e, s) {
|
||||
@@ -204,12 +210,11 @@ class AppService extends ChangeNotifier {
|
||||
}
|
||||
|
||||
extension GettersExtension on AppService {
|
||||
CommunicationChannelState get communicationChannelState {
|
||||
return _nearbyService.communicationChannelState.value;
|
||||
}
|
||||
CommunicationChannelState get communicationChannelState =>
|
||||
_communicationChannelState;
|
||||
|
||||
bool get isIOSBrowser {
|
||||
return _nearbyService.ios?.isBrowser.value ?? false;
|
||||
return _isIOSBrowser;
|
||||
}
|
||||
|
||||
bool? get isAndroidGroupOwner {
|
||||
@@ -233,6 +238,21 @@ extension ConnectionInfoExtension on AppService {
|
||||
_notify();
|
||||
}
|
||||
|
||||
void startListeningCommunicationChannelState() {
|
||||
try {
|
||||
_connectionInfoSubscription =
|
||||
_nearbyService.getCommunicationChannelStateStream().listen(
|
||||
(event) async {
|
||||
_communicationChannelState = event;
|
||||
_notify();
|
||||
},
|
||||
);
|
||||
} catch (e, s) {
|
||||
_log(e, s);
|
||||
}
|
||||
_notify();
|
||||
}
|
||||
|
||||
Future<void> stopListeningConnectionInfo() async {
|
||||
await _connectionInfoSubscription?.cancel();
|
||||
_connectionInfoSubscription = null;
|
||||
@@ -266,7 +286,7 @@ extension ConnectedDeviceExtension on AppService {
|
||||
updateState(AppState.loadingConnection);
|
||||
try {
|
||||
_connectedDeviceSubscription =
|
||||
_nearbyService.getConnectedDeviceStream(device).listen(
|
||||
_nearbyService.getConnectedDeviceStreamById(device.info.id).listen(
|
||||
(event) async {
|
||||
final wasConnected = connectedDevice?.status.isConnected ?? false;
|
||||
final nowConnected = event?.status.isConnected ?? false;
|
||||
|
||||
Reference in New Issue
Block a user