From 433fd43e61d45bb5f2af3048b266532658e04245 Mon Sep 17 00:00:00 2001 From: Remon Helmond Date: Mon, 8 Nov 2021 08:25:27 +0100 Subject: [PATCH 1/2] Revert "Merge pull request #406 from plyobits/queue_messages" This reverts commit 60f292f20633b1e3cc28fdeabaf9b698b626447b, reversing changes made to 51349d8c10cb40bfd9c73aaae3cceca52bcf8587. --- .../ios/Classes/Plugin/PluginController.swift | 58 ++++++++++--------- .../Plugin/SwiftReactiveBlePlugin.swift | 9 +-- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/packages/reactive_ble_mobile/ios/Classes/Plugin/PluginController.swift b/packages/reactive_ble_mobile/ios/Classes/Plugin/PluginController.swift index cc2d6c39..77a6a641 100644 --- a/packages/reactive_ble_mobile/ios/Classes/Plugin/PluginController.swift +++ b/packages/reactive_ble_mobile/ios/Classes/Plugin/PluginController.swift @@ -21,26 +21,10 @@ final class PluginController { } } } - var discoveryQueue: [PlatformMethodResult] = []; + var messageQueue: [CharacteristicValueInfo] = []; var connectedDeviceSink: EventSink? - - var valueQueue: [PlatformMethodResult] = []; var characteristicValueUpdateSink: EventSink? - func flushQueue(sink: EventSink, queue: inout [PlatformMethodResult]) { - queue.forEach(sink.add) - queue.removeAll() - } - - func sinkOrQueue(sink: EventSink?, queue: inout [PlatformMethodResult], value: PlatformMethodResult ) { - if let sink = sink { - flushQueue(sink: sink, queue: &queue) - sink.add(value) - } else { - queue.append(value) - } - } - func initialize(name: String, completion: @escaping PlatformMethodCompletionHandler) { if let central = central { central.stopScan() @@ -99,9 +83,12 @@ final class PluginController { } } - context.sinkOrQueue(sink: context.connectedDeviceSink, queue: &context.discoveryQueue, value: .success(message)) + context.connectedDeviceSink?.add(.success(message)) }, onServicesWithCharacteristicsInitialDiscovery: papply(weak: self) { context, central, peripheral, errors in + guard let sink = context.connectedDeviceSink + else { assert(false); return } + let message = DeviceInfo.with { $0.id = peripheral.identifier.uuidString $0.connectionState = encode(peripheral.state) @@ -112,7 +99,8 @@ final class PluginController { } } } - context.sinkOrQueue(sink: context.connectedDeviceSink, queue: &context.discoveryQueue, value: .success(message)) + + sink.add(.success(message)) }, onCharacteristicValueUpdate: papply(weak: self) { context, central, characteristic, value, error in let message = CharacteristicValueInfo.with { @@ -131,7 +119,14 @@ final class PluginController { } } } - context.sinkOrQueue(sink: context.characteristicValueUpdateSink, queue: &context.valueQueue, value: .success(message)) + let sink = context.characteristicValueUpdateSink + if (sink != nil) { + sink!.add(.success(message)) + } else { + // In case message arrives before sink is created + context.messageQueue.append(message); + } + } ) @@ -218,12 +213,16 @@ final class PluginController { let timeout = args.timeoutInMs > 0 ? TimeInterval(args.timeoutInMs) / 1000 : nil completion(.success(nil)) - - let message = DeviceInfo.with { - $0.id = args.deviceID - $0.connectionState = encode(.connecting) + + if let sink = connectedDeviceSink { + let message = DeviceInfo.with { + $0.id = args.deviceID + $0.connectionState = encode(.connecting) + } + sink.add(.success(message)) + } else { + print("Warning! No event channel set up to report a connection update") } - sinkOrQueue(sink: connectedDeviceSink, queue: &discoveryQueue, value: .success(message)) do { try central.connect( @@ -232,6 +231,12 @@ final class PluginController { timeout: timeout ) } catch { + guard let sink = connectedDeviceSink + else { + print("Warning! No event channel set up to report a connection failure: \(error)") + return + } + let message = DeviceInfo.with { $0.id = args.deviceID $0.connectionState = encode(.disconnected) @@ -240,7 +245,8 @@ final class PluginController { $0.message = "\(error)" } } - sinkOrQueue(sink: connectedDeviceSink, queue: &discoveryQueue, value: .success(message)) + + sink.add(.success(message)) } } diff --git a/packages/reactive_ble_mobile/ios/Classes/Plugin/SwiftReactiveBlePlugin.swift b/packages/reactive_ble_mobile/ios/Classes/Plugin/SwiftReactiveBlePlugin.swift index b1ff18f5..e0a4fb93 100644 --- a/packages/reactive_ble_mobile/ios/Classes/Plugin/SwiftReactiveBlePlugin.swift +++ b/packages/reactive_ble_mobile/ios/Classes/Plugin/SwiftReactiveBlePlugin.swift @@ -52,12 +52,10 @@ public class SwiftReactiveBlePlugin: NSObject, FlutterPlugin { context: context, onListen: { context, sink in context.connectedDeviceSink = sink - context.flushQueue(sink: sink, queue: &context.discoveryQueue) return nil }, onCancel: { context in context.connectedDeviceSink = nil - context.discoveryQueue.removeAll() return nil } ) @@ -69,11 +67,14 @@ public class SwiftReactiveBlePlugin: NSObject, FlutterPlugin { context: context, onListen: { context, sink in context.characteristicValueUpdateSink = sink - context.flushQueue(sink: sink, queue: &context.valueQueue) + context.messageQueue.forEach { msg in + sink.add(.success(msg)) + } + context.messageQueue.removeAll() return nil }, onCancel: { context in - context.valueQueue.removeAll() + context.messageQueue.removeAll() context.characteristicValueUpdateSink = nil return nil } From fe136d631340550ddfa7b1f4622a1a53acc1f86e Mon Sep 17 00:00:00 2001 From: Remon Helmond Date: Mon, 8 Nov 2021 20:49:31 +0100 Subject: [PATCH 2/2] bump version 5.0.2 --- example/pubspec.lock | 4 ++-- example/pubspec.yaml | 4 ++-- packages/flutter_reactive_ble/CHANGELOG.md | 4 ++++ packages/flutter_reactive_ble/pubspec.lock | 4 ++-- packages/flutter_reactive_ble/pubspec.yaml | 6 +++--- packages/reactive_ble_mobile/CHANGELOG.md | 4 ++++ packages/reactive_ble_mobile/pubspec.lock | 2 +- packages/reactive_ble_mobile/pubspec.yaml | 4 ++-- packages/reactive_ble_platform_interface/CHANGELOG.md | 4 ++++ packages/reactive_ble_platform_interface/pubspec.yaml | 2 +- 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 1ebcd3db..67ecf0b6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -402,14 +402,14 @@ packages: path: "../packages/reactive_ble_mobile" relative: true source: path - version: "5.0.1" + version: "5.0.2" reactive_ble_platform_interface: dependency: transitive description: name: reactive_ble_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.0.1" + version: "5.0.2" shelf: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ccdde200..559e6157 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_reactive_ble_example description: Demonstrates how to use the flutter_reactive_ble plugin. -version: 3.1.1+1 +version: 5.0.2 publish_to: 'none' environment: @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter flutter_lints: ^1.0.4 - flutter_reactive_ble: ^5.0.1 + flutter_reactive_ble: ^5.0.2 functional_data: ^1.0.0 intl: ^0.17.0 diff --git a/packages/flutter_reactive_ble/CHANGELOG.md b/packages/flutter_reactive_ble/CHANGELOG.md index d0628121..79404ff3 100644 --- a/packages/flutter_reactive_ble/CHANGELOG.md +++ b/packages/flutter_reactive_ble/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.2 + +* Revert Queue up messages on iOS until event channel is ready. Fix #439 + ## 5.0.1 * Bump protobuf so it includes binaries for Mac M1 #396. diff --git a/packages/flutter_reactive_ble/pubspec.lock b/packages/flutter_reactive_ble/pubspec.lock index 2b46a9e1..fcf56061 100644 --- a/packages/flutter_reactive_ble/pubspec.lock +++ b/packages/flutter_reactive_ble/pubspec.lock @@ -374,14 +374,14 @@ packages: name: reactive_ble_mobile url: "https://pub.dartlang.org" source: hosted - version: "5.0.1" + version: "5.0.2" reactive_ble_platform_interface: dependency: "direct main" description: name: reactive_ble_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.0.1" + version: "5.0.2" shelf: dependency: transitive description: diff --git a/packages/flutter_reactive_ble/pubspec.yaml b/packages/flutter_reactive_ble/pubspec.yaml index a68f7f2d..1e075d41 100644 --- a/packages/flutter_reactive_ble/pubspec.yaml +++ b/packages/flutter_reactive_ble/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_reactive_ble description: Reactive Bluetooth Low Energy (BLE) plugin that can communicate with multiple devices -version: 5.0.1 +version: 5.0.2 homepage: https://github.com/PhilipsHue/flutter_reactive_ble environment: @@ -21,8 +21,8 @@ dependencies: sdk: flutter functional_data: ^1.0.0 meta: ^1.3.0 - reactive_ble_mobile: ^5.0.1 - reactive_ble_platform_interface: ^5.0.1 + reactive_ble_mobile: ^5.0.2 + reactive_ble_platform_interface: ^5.0.2 dev_dependencies: build_runner: ^2.1.2 flutter_lints: ^1.0.4 diff --git a/packages/reactive_ble_mobile/CHANGELOG.md b/packages/reactive_ble_mobile/CHANGELOG.md index 5b14ee92..04f4e537 100644 --- a/packages/reactive_ble_mobile/CHANGELOG.md +++ b/packages/reactive_ble_mobile/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.2 + + * Revert Queue up messages on iOS until event channel is ready. Fix #439 + ## 5.0.1 * Bump protobuf so it includes binaries for Mac M1 #396. diff --git a/packages/reactive_ble_mobile/pubspec.lock b/packages/reactive_ble_mobile/pubspec.lock index 30e0e298..a1763002 100644 --- a/packages/reactive_ble_mobile/pubspec.lock +++ b/packages/reactive_ble_mobile/pubspec.lock @@ -353,7 +353,7 @@ packages: name: reactive_ble_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.0.1" + version: "5.0.2" shelf: dependency: transitive description: diff --git a/packages/reactive_ble_mobile/pubspec.yaml b/packages/reactive_ble_mobile/pubspec.yaml index 64a3f7f0..a64d7ce7 100644 --- a/packages/reactive_ble_mobile/pubspec.yaml +++ b/packages/reactive_ble_mobile/pubspec.yaml @@ -1,6 +1,6 @@ name: reactive_ble_mobile description: Official Android and iOS implementation for the flutter_reactive_ble plugin. -version: 5.0.1 +version: 5.0.2 homepage: https://github.com/PhilipsHue/flutter_reactive_ble environment: @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter protobuf: ^2.0.0 - reactive_ble_platform_interface: ^5.0.1 + reactive_ble_platform_interface: ^5.0.2 dev_dependencies: build_runner: ^2.1.2 flutter_test: diff --git a/packages/reactive_ble_platform_interface/CHANGELOG.md b/packages/reactive_ble_platform_interface/CHANGELOG.md index 76332104..8dfca12c 100644 --- a/packages/reactive_ble_platform_interface/CHANGELOG.md +++ b/packages/reactive_ble_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.2 + +* Revert Queue up messages on iOS until event channel is ready. Fix #439 + ## 5.0.1 * Bump protobuf so it includes binaries for Mac M1 #396. diff --git a/packages/reactive_ble_platform_interface/pubspec.yaml b/packages/reactive_ble_platform_interface/pubspec.yaml index 8c22b901..698a8038 100644 --- a/packages/reactive_ble_platform_interface/pubspec.yaml +++ b/packages/reactive_ble_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: reactive_ble_platform_interface description: Platform interface for the flutter_reactive_ble_project -version: 5.0.1 +version: 5.0.2 homepage: https://github.com/PhilipsHue/flutter_reactive_ble environment: