# @ovok/native/next/bluetooth/web

Canonical page: https://docs.ovok.com/native-sdk/reference/next-bluetooth-web

Bluetooth for `@ovok/native/next` in browsers, over Web Bluetooth: the same `BluetoothRuntime`, devices, result
policies and hooks as `@ovok/native/next/bluetooth`, with a Web Bluetooth scanner instead of `react-native-ble-plx`.
Nothing here loads `react-native-ble-plx` or `react-native-permissions`, so a web bundle can import it.

Import from `@ovok/native/next/bluetooth/web`.

## Functions [#functions]

### createWebBluetoothRuntime() [#createwebbluetoothruntime]

```ts
function createWebBluetoothRuntime(__namedParameters): BluetoothRuntime;
```

A `BluetoothRuntime` wired for browsers: Web Bluetooth through `scanner`, saving through `client`.

#### Parameters [#parameters]

| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | [`CreateWebBluetoothRuntimeOptions`](#createwebbluetoothruntimeoptions) |

#### Returns [#returns]

[`BluetoothRuntime`](/native-sdk/reference/next-bluetooth#bluetoothruntime)

***

### isWebBluetoothAvailable() [#iswebbluetoothavailable]

```ts
function isWebBluetoothAvailable(): boolean;
```

Whether this browser has Web Bluetooth, such as Chrome and Edge on desktop and Android, or Bluefy on iOS.

#### Returns [#returns-1]

`boolean`

***

### webBluetoothPermissions() [#webbluetoothpermissions]

```ts
function webBluetoothPermissions(): BluetoothPermissions;
```

Browser permissions: the browser asks per device in its chooser, so there is no prompt to show first. Granted where
the browser has Web Bluetooth, denied where it has none; no settings page can change that.

#### Returns [#returns-2]

[`BluetoothPermissions`](/native-sdk/reference/next-bluetooth#bluetoothpermissions)

***

### webBluetoothScanner() [#webbluetoothscanner]

```ts
function webBluetoothScanner(__namedParameters?): WebBluetoothScanner;
```

Finds devices through Web Bluetooth. A scan reports the devices this site may already use (`getDevices`, where the
browser has it) and every device picked with `chooseDevice`; browsers can't scan in the background or without the
user picking.

#### Parameters [#parameters-1]

| Parameter | Type |
| ------ | ------ |
| `__namedParameters?` | [`WebBluetoothScannerOptions`](#webbluetoothscanneroptions) |

#### Returns [#returns-3]

[`WebBluetoothScanner`](#webbluetoothscanner)

***

### webBluetoothServicesFor() [#webbluetoothservicesfor]

```ts
function webBluetoothServicesFor(acceptedDevices?): string[];
```

`WEB_BLUETOOTH_SERVICES` and the services of the `defineCustomDevice` declarations among `acceptedDevices`.

#### Parameters [#parameters-2]

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `acceptedDevices?` | readonly [`AcceptedDevice`](/native-sdk/reference/bt-management#accepteddevice)[] | `[]` |

#### Returns [#returns-4]

`string`[]

## Interfaces [#interfaces]

### WebBluetoothScanner [#webbluetoothscanner-1]

A `BluetoothScanner` for browsers, where a page only reaches the devices the user picks in the browser's chooser.

#### Extends [#extends]

- [`BluetoothScanner`](/native-sdk/reference/next-bluetooth#bluetoothscanner)

#### Methods [#methods]

##### chooseDevice() [#choosedevice]

```ts
chooseDevice(): Promise<Peripheral | undefined>;
```

Opens the browser's device chooser, so it must run from a user gesture such as a tap. Resolves to the picked device,
which a running scan also reports, or to `undefined` when the user closes the chooser.

###### Returns [#returns-5]

`Promise`\<[`Peripheral`](/native-sdk/reference/next-bluetooth#peripheral) \| `undefined`\>

##### scan() [#scan]

```ts
scan(onFound, onError): () => void;
```

Reports peripherals until the returned stop is called; `onError` may be called before `scan` returns.

###### Parameters [#parameters-3]

| Parameter | Type |
| ------ | ------ |
| `onFound` | (`peripheral`) => `void` |
| `onError` | (`error`) => `void` |

###### Returns [#returns-6]

() => `void`

###### Inherited from [#inherited-from]

[`BluetoothScanner`](/native-sdk/reference/next-bluetooth#bluetoothscanner).[`scan`](/native-sdk/reference/next-bluetooth#scan)

##### watchState() [#watchstate]

```ts
watchState(listener): () => void;
```

Reports the adapter state now and on every change; returns the unsubscribe.

###### Parameters [#parameters-4]

| Parameter | Type |
| ------ | ------ |
| `listener` | (`state`) => `void` |

###### Returns [#returns-7]

() => `void`

###### Inherited from [#inherited-from-1]

[`BluetoothScanner`](/native-sdk/reference/next-bluetooth#bluetoothscanner).[`watchState`](/native-sdk/reference/next-bluetooth#watchstate)

## Type Aliases [#type-aliases]

### CreateWebBluetoothRuntimeOptions [#createwebbluetoothruntimeoptions]

```ts
type CreateWebBluetoothRuntimeOptions = object;
```

What `createWebBluetoothRuntime` needs.

#### Properties [#properties]

##### client [#client]

```ts
client: Pick<Ovok, "measurements">;
```

Saves the readings.

##### devices [#devices]

```ts
devices: readonly DeviceSupport[];
```

The devices to look for.

##### pairedStorage? [#pairedstorage]

```ts
pairedStorage?: OvokStorage;
```

Where the paired device IDs persist; without it pairing lasts until the runtime is disposed.

##### resultPolicy? [#resultpolicy]

```ts
resultPolicy?: ResultPolicy;
```

Which readings of a connection to keep; defaults to every reading.

##### scanner [#scanner]

```ts
scanner: WebBluetoothScanner;
```

The browser's devices, from `webBluetoothScanner`; the app calls its `chooseDevice` from a tap.

***

### WebBluetoothScannerOptions [#webbluetoothscanneroptions]

```ts
type WebBluetoothScannerOptions = object;
```

What `webBluetoothScanner` needs.

#### Properties [#properties-1]

##### acceptedDevices? [#accepteddevices]

```ts
acceptedDevices?: readonly AcceptedDevice[];
```

The accepted devices; the chooser also allows the services of their `defineCustomDevice` declarations.

##### bluetooth? [#bluetooth]

```ts
bluetooth?: WebBluetooth;
```

The Web Bluetooth API; defaults to `navigator.bluetooth`.

## Variables [#variables]

### WEB\_BLUETOOTH\_SERVICES [#web_bluetooth_services]

```ts
const WEB_BLUETOOTH_SERVICES: readonly string[];
```

Every GATT service an integrated device uses, as a browser must be told when the user picks a device: a page can
only reach the services it named in `navigator.bluetooth.requestDevice`'s `optionalServices`.

## References [#references]

### AcceptedDevice [#accepteddevice]

Re-exports [AcceptedDevice](/native-sdk/reference/bt-management#accepteddevice)

***

### acceptedMemorySlots [#acceptedmemoryslots]

Re-exports [acceptedMemorySlots](/native-sdk/reference/next-bluetooth#acceptedmemoryslots)

***

### AdapterState [#adapterstate]

Re-exports [AdapterState](/native-sdk/reference/next-bluetooth#adapterstate)

***

### Advertisement [#advertisement]

Re-exports [Advertisement](/native-sdk/reference/next-bluetooth#advertisement)

***

### BluetoothError [#bluetootherror]

Re-exports [BluetoothError](/native-sdk/reference/next-bluetooth#bluetootherror)

***

### BluetoothErrorCode [#bluetootherrorcode]

Re-exports [BluetoothErrorCode](/native-sdk/reference/next-bluetooth#bluetootherrorcode)

***

### BluetoothPermission [#bluetoothpermission]

Re-exports [BluetoothPermission](/native-sdk/reference/next-bluetooth#bluetoothpermission)

***

### BluetoothPermissions [#bluetoothpermissions]

Re-exports [BluetoothPermissions](/native-sdk/reference/next-bluetooth#bluetoothpermissions)

***

### BluetoothProvider [#bluetoothprovider]

Re-exports [BluetoothProvider](/native-sdk/reference/next-bluetooth#bluetoothprovider)

***

### BluetoothProviderProps [#bluetoothproviderprops]

Re-exports [BluetoothProviderProps](/native-sdk/reference/next-bluetooth#bluetoothproviderprops)

***

### BluetoothRuntime [#bluetoothruntime]

Re-exports [BluetoothRuntime](/native-sdk/reference/next-bluetooth#bluetoothruntime)

***

### BluetoothRuntimeOptions [#bluetoothruntimeoptions]

Re-exports [BluetoothRuntimeOptions](/native-sdk/reference/next-bluetooth#bluetoothruntimeoptions)

***

### BluetoothScanner [#bluetoothscanner]

Re-exports [BluetoothScanner](/native-sdk/reference/next-bluetooth#bluetoothscanner)

***

### BluetoothSnapshot [#bluetoothsnapshot]

Re-exports [BluetoothSnapshot](/native-sdk/reference/next-bluetooth#bluetoothsnapshot)

***

### builtInDevices [#builtindevices]

Re-exports [builtInDevices](/native-sdk/reference/next-bluetooth#builtindevices)

***

### BuiltInDevicesOptions [#builtindevicesoptions]

Re-exports [BuiltInDevicesOptions](/native-sdk/reference/next-bluetooth#builtindevicesoptions)

***

### ConnectionState [#connectionstate]

Re-exports [ConnectionState](/native-sdk/reference/next-bluetooth#connectionstate)

***

### dailyTotalsOnly [#dailytotalsonly]

Re-exports [dailyTotalsOnly](/native-sdk/reference/next-bluetooth#dailytotalsonly)

***

### defineDevice [#definedevice]

Re-exports [defineDevice](/native-sdk/reference/next-bluetooth#definedevice)

***

### DeviceDefinition [#devicedefinition]

Re-exports [DeviceDefinition](/native-sdk/reference/next-bluetooth#devicedefinition)

***

### DeviceEvent [#deviceevent]

Re-exports [DeviceEvent](/native-sdk/reference/next-bluetooth#deviceevent)

***

### DeviceInformation [#deviceinformation]

Re-exports [DeviceInformation](/native-sdk/reference/next-bluetooth#deviceinformation)

***

### DeviceMatch [#devicematch]

Re-exports [DeviceMatch](/native-sdk/reference/next-bluetooth#devicematch)

***

### DeviceProtocol [#deviceprotocol]

Re-exports [DeviceProtocol](/native-sdk/reference/next-bluetooth#deviceprotocol)

***

### DeviceReading [#devicereading]

Re-exports [DeviceReading](/native-sdk/reference/next-bluetooth#devicereading)

***

### Devices [#devices-1]

Re-exports [Devices](/native-sdk/reference/bt-device#devices)

***

### DeviceSupport [#devicesupport]

Re-exports [DeviceSupport](/native-sdk/reference/next-bluetooth#devicesupport)

***

### Driver [#driver]

Re-exports [Driver](/native-sdk/reference/next-bluetooth#driver-1)

***

### everyReading [#everyreading]

Re-exports [everyReading](/native-sdk/reference/next-bluetooth#everyreading)

***

### firstReadingPerKind [#firstreadingperkind]

Re-exports [firstReadingPerKind](/native-sdk/reference/next-bluetooth#firstreadingperkind)

***

### IntegratedDevices [#integrateddevices]

Re-exports [IntegratedDevices](/native-sdk/reference/bt-management#integrateddevices)

***

### keepReadings [#keepreadings]

Re-exports [keepReadings](/native-sdk/reference/next-bluetooth#keepreadings)

***

### Link [#link]

Re-exports [Link](/native-sdk/reference/next-bluetooth#link)

***

### NearbyDevice [#nearbydevice]

Re-exports [NearbyDevice](/native-sdk/reference/next-bluetooth#nearbydevice)

***

### ovokReadingSink [#ovokreadingsink]

Re-exports [ovokReadingSink](/native-sdk/reference/next-bluetooth#ovokreadingsink)

***

### Peripheral [#peripheral]

Re-exports [Peripheral](/native-sdk/reference/next-bluetooth#peripheral)

***

### policyByKind [#policybykind]

Re-exports [policyByKind](/native-sdk/reference/next-bluetooth#policybykind)

***

### ReadingSink [#readingsink]

Re-exports [ReadingSink](/native-sdk/reference/next-bluetooth#readingsink)

***

### resultPoliciesFor [#resultpoliciesfor]

Re-exports [resultPoliciesFor](/native-sdk/reference/bt-device#resultpoliciesfor)

***

### ResultPolicy [#resultpolicy-1]

Re-exports [ResultPolicy](/native-sdk/reference/next-bluetooth#resultpolicy-2)

***

### SaveResult [#saveresult]

Re-exports [SaveResult](/native-sdk/reference/next-bluetooth#saveresult)

***

### SaveState [#savestate]

Re-exports [SaveState](/native-sdk/reference/next-bluetooth#savestate)

***

### SIG\_PROTOCOLS [#sig_protocols]

Re-exports [SIG_PROTOCOLS](/native-sdk/reference/next-bluetooth#sig_protocols)

***

### SUPPORTED\_DEVICES [#supported_devices]

Re-exports [SUPPORTED_DEVICES](/native-sdk/reference/bt-device#supported_devices)

***

### SupportedDeviceDefinition [#supporteddevicedefinition]

Re-exports [SupportedDeviceDefinition](/native-sdk/reference/bt-device#supporteddevicedefinition)

***

### useBluetooth [#usebluetooth]

Re-exports [useBluetooth](/native-sdk/reference/next-bluetooth#usebluetooth)

***

### useBluetoothPermission [#usebluetoothpermission]

Re-exports [useBluetoothPermission](/native-sdk/reference/next-bluetooth#usebluetoothpermission)

***

### useBluetoothState [#usebluetoothstate]

Re-exports [useBluetoothState](/native-sdk/reference/next-bluetooth#usebluetoothstate)

***

### useMeasurements [#usemeasurements]

Re-exports [useMeasurements](/native-sdk/reference/next-bluetooth#usemeasurements)

***

### useNearbyDevice [#usenearbydevice]

Re-exports [useNearbyDevice](/native-sdk/reference/next-bluetooth#usenearbydevice)

***

### useNearbyDevices [#usenearbydevices]

Re-exports [useNearbyDevices](/native-sdk/reference/next-bluetooth#usenearbydevices)

***

### usePairedDevices [#usepaireddevices]

Re-exports [usePairedDevices](/native-sdk/reference/next-bluetooth#usepaireddevices)

***

### useScanning [#usescanning]

Re-exports [useScanning](/native-sdk/reference/next-bluetooth#usescanning)
