React hooks wrapper for the Web Bluetooth API
npm install react-web-bluetoothThis is a package that provides a hooks wrapper around the new Web Bluetooth API
It is an experimental feature implemented under a flag in Chrome. In order to use this feature in Chrome, enable:
chrome://flags/#enable-experimental-web-platform-features
The getDevices method requires also to enable the new permissions backend experimental feature.
chrome://flags/#enable-web-bluetooth-new-permissions-backend
getDevices is used to retrieve already paired Bluetooth devices from the browser, for example after a refresh instead of pairing a device again getDevices can be used to connect to it without pairing.
``
const { onClick, device } = useRequestDevice({
acceptAllDevices: true,
});
// ...
return <>
{!device && }
{device && {device.name}}
>
`
_Params:_
device: BluetoothDevice
_Returns:_
server: BluetoothRemoteGATTServer
_Params:_
service: BluetoothRemoteGATTService
bluetoothCharacteristicUUID: string
_Returns:_
characteristic: BluetoothRemoteGATTCharacteristic
_Returns:_ devices[]: BluetoothDevice[]
_Params:_
options: https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#parameters
_Returns:_
onClick: (event) => void // returns a onClick function that can be used to trigget the browser's pairing window and list the scanned Bluetooth devices.
device: BluetoothDevice // returns a device chosen from the Bluetooth pairing dialogue.
_Params:_
device: BluetoothDevice
_Returns:_
service: BluetoothRemoteGATTService
_Params:_
characteristic: BluetoothRemoteGATTCharacteristic
_Returns:_:
value: DataView
_Params:_
characteristic: BluetoothRemoteGATTCharacteristic
value`: ArrayBuffer