Skip to content

Commit

Permalink
Setup servicesDiscoveredChannel before invoking method. Fixes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldemarco committed Dec 22, 2018
1 parent 2cf8cec commit dd66653
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ class BluetoothDevice {

/// Discovers services offered by the remote device as well as their characteristics and descriptors
Future<List<BluetoothService>> discoverServices() async {
await FlutterBlue.instance._channel
.invokeMethod('discoverServices', id.toString());

return await FlutterBlue.instance._servicesDiscoveredChannel
var response = FlutterBlue.instance._servicesDiscoveredChannel
.receiveBroadcastStream()
.map((buffer) =>
new protos.DiscoverServicesResult.fromBuffer(buffer))
.map((buffer) => new protos.DiscoverServicesResult.fromBuffer(buffer))
.where((p) => p.remoteId == id.toString())
.map((p) => p.services)
.map((s) => s.map((p) => new BluetoothService.fromProto(p)).toList())
.first;

await FlutterBlue.instance._channel
.invokeMethod('discoverServices', id.toString());

return response;
}

/// Returns a list of Bluetooth GATT services offered by the remote device
Expand Down

0 comments on commit dd66653

Please sign in to comment.