watchAdvertisements method
Start watching for advertisements. The advertisements will be received
on the advertisementreceived
event. See BluetoothAdvertisementReceivedEvent
for the object that is emitted every time the event fires.
Not very browser has this implemented yet without the
enable-experimental-web-platform-features
flag enabled.
So use hasWatchAdvertisements or it will throw an
NativeAPINotImplementedError.
If you want to stop watching for advertisements then you will need to call this method again and with a WatchAdvertisementsOptions.signal that has already been aborted. If you do this then the method will throw a DOMException that you will need to handle.
Example of the exception is: DOMException: Failed to execute 'watchAdvertisements' on 'BluetoothDevice': The Bluetooth operation was cancelled.
Implementation
Future<void> watchAdvertisements(
[final WatchAdvertisementsOptions? options]) async {
if (!hasWatchAdvertisements()) {
throw NativeAPINotImplementedError("watchAdvertisements");
}
if (options == null) {
await _watchAdvertisements().toDart;
} else {
await _watchAdvertisements(options).toDart;
}
}