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

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.
BluetoothEventStreamProviders
An abstract class that contains all the events that could be fired on Web Bluetooth EventTargets
BluetoothScanFilterHelper
A class with a helper function to create the correct js object from a filter.
NativeBluetooth
The native interface to the browser's navigator.bluetooth object. This allows for the replacement of this interface if needed for testing.

Extension Types

BluetoothAdvertisementReceivedEvent
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).
BluetoothDataFilter
The base type for a bluetooth data filter.
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.
BluetoothServiceDataFilter
The js object for Bluetooth scan filters. At least one of the filter must be set, the rest can be left undefined.
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.
WebBluetoothCharacteristicProperties
A class for calling methods and values for a WebBluetoothCharacteristicProperties.
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.
WebBluetoothValueEvent
This is the object that is emitted for the availabilitychanged 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).

Extensions

WebBluetoothDeviceEvents on WebBluetoothDevice
An extension class to add events as streams to the WebBluetoothDevice.
WebBluetoothRemoteGATTCharacteristicEvents on WebBluetoothRemoteGATTCharacteristic
An extension class to add events as streams to the WebBluetoothRemoteGATTCharacteristic.
WebBluetoothRemoteGATTServiceEvents on WebBluetoothRemoteGATTService
An extension class to add events as streams to the WebBluetoothRemoteGATTService.

Functions

setNativeBluetooth(NativeBluetooth nativeBluetooth) → void
Replace the NativeBluetooth api interface to allow for testing. This shouldn't be done for production code.
testingSetNavigator(Navigator? 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.