watchAdvertisements method

Future<void> watchAdvertisements([
  1. WatchAdvertisementsOptions? options
])

Start watching for advertisements. The advertisements will be received on the advertisementreceived event. See WebAdvertisementReceivedEvent 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 _JSUtil.promiseToFuture(
        _JSUtil.callMethod(_jsObject, "watchAdvertisements", []));
  } else {
    await _JSUtil.promiseToFuture(
        _JSUtil.callMethod(_jsObject, "watchAdvertisements", [options]));
  }
}