Skip to content

Commit 28b0bc6

Browse files
Add platform specific options in start scan (#65)
* Add platform specific options in start scan * Add code level doc and ChangeLog * Minor improvements
1 parent 0d6b612 commit 28b0bc6

File tree

11 files changed

+123
-83
lines changed

11 files changed

+123
-83
lines changed

.vscode/launch.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@
3232
"--web-hostname=127.0.0.1",
3333
"--web-port=8080"
3434
],
35-
"preLaunchTask": "open_chrome"
3635
},
3736
],
38-
"tasks": [
39-
{
40-
"label": "open_chrome",
41-
"type": "shell",
42-
"command": "open",
43-
"args": [
44-
"-na",
45-
"Google Chrome",
46-
"--args",
47-
"--user-data-dir=/tmp/temporary-chrome-profile-dir",
48-
"--disable-web-security",
49-
"--disable-site-isolation-trials"
50-
],
51-
}
52-
],
5337
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.11.2
2+
* Add `PlatformConfig` property in `StartScan`
3+
* Add `WebConfig` property in `PlatformConfig`
4+
15
## 0.11.1
26
* Trim spaces in UUIDs
37
* Receive advertisement events on web

example/lib/data/mock_universal_ble.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class MockUniversalBle extends UniversalBlePlatform {
2323
]);
2424

2525
@override
26-
Future<void> startScan({ScanFilter? scanFilter}) async =>
26+
Future<void> startScan({
27+
ScanFilter? scanFilter,
28+
PlatformConfig? platformConfig,
29+
}) async =>
2730
onScanResult?.call(_mockBleDevice);
2831

2932
@override

example/lib/peripheral_details/peripheral_detail_page.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
102102
});
103103

104104
if (kIsWeb) {
105-
_addLog("DiscoverServices",
106-
'${services.length} services discovered,\nNote: Only services added in ScanFilter will be discovered');
105+
_addLog(
106+
"DiscoverServices",
107+
'${services.length} services discovered,\nNote: Only services added in ScanFilter or WebConfig will be discovered',
108+
);
107109
}
108110
} catch (e) {
109-
_addLog("DiscoverServicesError", e);
111+
_addLog(
112+
"DiscoverServicesError",
113+
'$e\nNote: Only services added in ScanFilter or WebConfig will be discovered',
114+
);
110115
}
111116
}
112117

lib/src/models/model_exports.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export 'package:universal_ble/src/models/platform_config.dart';
12
export 'package:universal_ble/src/models/queue_type.dart';
23
export 'package:universal_ble/src/models/ble_uuid_parser.dart';
34
export 'package:universal_ble/src/models/scan_filter.dart';

lib/src/models/platform_config.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// Platform specific config to scan devices
2+
class PlatformConfig {
3+
WebConfig? web;
4+
5+
PlatformConfig({this.web});
6+
}
7+
8+
/// Web config to scan devices
9+
/// [optionalServices] is a list of service uuid's to ensure that you can access the specified services after connecting to the device,
10+
/// by default services from scanFilter will be used
11+
/// [optionalManufacturerData] is list of `CompanyIdentifier's` and used to add `ManufacturerData` in advertisement results of selected device from web dialog,
12+
/// by default manufacturerData from scanFilter will be used
13+
/// Checkout more details on [web](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice)
14+
/// Note: you will only get advertisements if Experimental Flag is enabled in the browser
15+
class WebConfig {
16+
List<String> optionalServices;
17+
List<int> optionalManufacturerData;
18+
19+
WebConfig({
20+
this.optionalServices = const [],
21+
this.optionalManufacturerData = const [],
22+
});
23+
}

lib/src/universal_ble.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ class UniversalBle {
4949
/// `webRequestOptions` is supported on Web only
5050
static Future<void> startScan({
5151
ScanFilter? scanFilter,
52+
PlatformConfig? platformConfig,
5253
}) async {
5354
return await _bleCommandQueue.queueCommand(
54-
() => _platform.startScan(scanFilter: scanFilter),
55+
() => _platform.startScan(
56+
scanFilter: scanFilter,
57+
platformConfig: platformConfig,
58+
),
5559
withTimeout: false,
5660
);
5761
}

lib/src/universal_ble_linux/universal_ble_linux.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class UniversalBleLinux extends UniversalBlePlatform {
5555
@override
5656
Future<void> startScan({
5757
ScanFilter? scanFilter,
58+
PlatformConfig? platformConfig,
5859
}) async {
5960
await _ensureInitialized();
6061
await super.startScan(scanFilter: scanFilter);

lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class UniversalBlePigeonChannel extends UniversalBlePlatform {
3030
@override
3131
Future<void> startScan({
3232
ScanFilter? scanFilter,
33+
PlatformConfig? platformConfig,
3334
}) async {
3435
await super.startScan(scanFilter: scanFilter);
3536
await _channel.startScan(

lib/src/universal_ble_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ abstract class UniversalBlePlatform {
1111

1212
Future<void> startScan({
1313
ScanFilter? scanFilter,
14+
PlatformConfig? platformConfig,
1415
}) async {
1516
_scanFilter = scanFilter;
1617
}

0 commit comments

Comments
 (0)