js_web_bluetooth library

A library to make the Javascript web bluetooth api available in Dart. It's a direct conversion of the original API without any helpers. It is recommended that you use flutter_web_bluetooth instead.

Classes

AdvertisementReceivedEventInterface<T>
An interface for the advertisementreceived event.
Bluetooth
The main Bluetooth class. This is the entrypoint to the library. This is where you can get your devices and go further from there.
BluetoothLEScan
An object representing a running Bluetooth LE scan. This object can be retrieved using Bluetooth.requestLEScan. It will have a copy of the BluetoothLEScanOptions used for the original call.
BluetoothLEScanOptions
The js object for request options. This is used for Bluetooth.requestLEScan.
BluetoothManufacturerDataFilter
The js object for Bluetooth scan filters. At least one of the filter must be set, the rest can be left undefined.
BluetoothScanFilter
The js object for Bluetooth scan filters. At least one of the filter must be set, the rest can be left undefined.
BluetoothScanFilterHelper
A class with a helper function to create the correct js object from a filter.
BluetoothServiceDataFilter
The js object for Bluetooth scan filters. At least one of the filter must be set, the rest can be left undefined.
NativeBluetooth
The native interface to the browser's navigator.bluetooth object. This allows for the replacement of this interface if needed for testing.
NativeBluetoothRemoteGATTServer
A class for calling methods and values for a NativeBluetoothRemoteGATTServer. This is where most of the interesting stuff happens.
RequestOptions
The js object for request options. This is used for Bluetooth.requestDevice.
WatchAdvertisementsOptions
The options to configure the WebBluetoothDevice.watchAdvertisements method.
WebAdvertisementReceivedEvent
This is the object that is emitted for the advertisementreceived event. This object only has the specific fields for the event and not the fields form the basic javascript Event (target field and all that stuff).
WebBluetoothCharacteristicProperties
A class for calling methods and values for a WebBluetoothCharacteristicProperties.
WebBluetoothConverters
Some converters to convert from Dart objects to native js object expected by some API calls.
WebBluetoothDevice
A class for calling methods and values for a BluetoothDevice.
WebBluetoothRemoteGATTCharacteristic
A class for calling methods and values for a WebBluetoothRemoteGATTCharacteristic. This is where reading and writing values happens.
WebBluetoothRemoteGATTDescriptor
A class for calling methods and values for a WebBluetoothRemoteGATTDescriptor.
WebBluetoothRemoteGATTService
A class for calling methods and values for WebBluetoothRemoteGATTService.

Functions

setNativeBluetooth(NativeBluetooth nativeBluetooth) → void
Replace the NativeBluetooth api interface to allow for testing. This shouldn't be done for production code.
testingSetJSUtils(JSUtilsInterface utils) → void
Override the js utils implementation.
testingSetNavigator(Object? navigatorObject) → void
Change the navigator object used. This method is meant for testing!

Exceptions / Errors

BrowserError
This error is the base error for any error that the browser may throw. It exists because browser errors are just strings and thus won't have any nice Dart features. It has for example no stack trace.
DeviceNotFoundError
An Error that is thrown if no device could be found to match the RequestOptions. For Bluetooth.requestDevice.
MissingUserGestureError
An error thrown if a method has not been called from a user gesture. Some actions require a user gesture before they can be run. This stops websites from for example showing annoying popups as soon as the user loads the site
NativeAPINotImplementedError
An Error thrown if a field/ method is not implemented in the browser.
PermissionError
An error thrown if a permission has been denied by the user.
PolicyError
An administrator may disable Bluetooth in the browser via a policy. If this is the case this error may get returned.
UserCancelledDialogError
A subclass of DeviceNotFoundError for the case where the user has cancelled the pair dialog.