@ovok/native/next/bluetooth/web

Bluetooth for `@ovok/native/next` in browsers, over Web Bluetooth: the same `BluetoothRuntime`, devices, result

  • Stable unknown
  • Release candidate not available
  • Development not available

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

createWebBluetoothRuntime()

function createWebBluetoothRuntime(__namedParameters): BluetoothRuntime;

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

Parameters

ParameterType
__namedParametersCreateWebBluetoothRuntimeOptions

Returns

BluetoothRuntime


isWebBluetoothAvailable()

function isWebBluetoothAvailable(): boolean;

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

Returns

boolean


webBluetoothPermissions()

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

BluetoothPermissions


webBluetoothScanner()

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

ParameterType
__namedParameters?WebBluetoothScannerOptions

Returns

WebBluetoothScanner


webBluetoothServicesFor()

function webBluetoothServicesFor(acceptedDevices?): string[];

WEB_BLUETOOTH_SERVICES and the services of the defineCustomDevice declarations among acceptedDevices.

Parameters

ParameterTypeDefault value
acceptedDevices?readonly AcceptedDevice[][]

Returns

string[]

Interfaces

WebBluetoothScanner

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

Extends

Methods

chooseDevice()
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

Promise<Peripheral | undefined>

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

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

Parameters
ParameterType
onFound(peripheral) => void
onError(error) => void
Returns

() => void

Inherited from

BluetoothScanner.scan

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

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

Parameters
ParameterType
listener(state) => void
Returns

() => void

Inherited from

BluetoothScanner.watchState

Type Aliases

CreateWebBluetoothRuntimeOptions

type CreateWebBluetoothRuntimeOptions = object;

What createWebBluetoothRuntime needs.

Properties

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

Saves the readings.

devices
devices: readonly DeviceSupport[];

The devices to look for.

pairedStorage?
pairedStorage?: OvokStorage;

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

resultPolicy?
resultPolicy?: ResultPolicy;

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

scanner
scanner: WebBluetoothScanner;

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


WebBluetoothScannerOptions

type WebBluetoothScannerOptions = object;

What webBluetoothScanner needs.

Properties

acceptedDevices?
acceptedDevices?: readonly AcceptedDevice[];

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

bluetooth?
bluetooth?: WebBluetooth;

The Web Bluetooth API; defaults to navigator.bluetooth.

Variables

WEB_BLUETOOTH_SERVICES

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

AcceptedDevice

Re-exports AcceptedDevice


acceptedMemorySlots

Re-exports acceptedMemorySlots


AdapterState

Re-exports AdapterState


Re-exports Advertisement


BluetoothError

Re-exports BluetoothError


BluetoothErrorCode

Re-exports BluetoothErrorCode


BluetoothPermission

Re-exports BluetoothPermission


BluetoothPermissions

Re-exports BluetoothPermissions


BluetoothProvider

Re-exports BluetoothProvider


BluetoothProviderProps

Re-exports BluetoothProviderProps


BluetoothRuntime

Re-exports BluetoothRuntime


BluetoothRuntimeOptions

Re-exports BluetoothRuntimeOptions


BluetoothScanner

Re-exports BluetoothScanner


BluetoothSnapshot

Re-exports BluetoothSnapshot


builtInDevices

Re-exports builtInDevices


BuiltInDevicesOptions

Re-exports BuiltInDevicesOptions


ConnectionState

Re-exports ConnectionState


dailyTotalsOnly

Re-exports dailyTotalsOnly


defineDevice

Re-exports defineDevice


DeviceDefinition

Re-exports DeviceDefinition


DeviceEvent

Re-exports DeviceEvent


DeviceInformation

Re-exports DeviceInformation


DeviceMatch

Re-exports DeviceMatch


DeviceProtocol

Re-exports DeviceProtocol


DeviceReading

Re-exports DeviceReading


Devices

Re-exports Devices


DeviceSupport

Re-exports DeviceSupport


Driver

Re-exports Driver


everyReading

Re-exports everyReading


firstReadingPerKind

Re-exports firstReadingPerKind


IntegratedDevices

Re-exports IntegratedDevices


keepReadings

Re-exports keepReadings


Re-exports Link


NearbyDevice

Re-exports NearbyDevice


ovokReadingSink

Re-exports ovokReadingSink


Peripheral

Re-exports Peripheral


policyByKind

Re-exports policyByKind


ReadingSink

Re-exports ReadingSink


resultPoliciesFor

Re-exports resultPoliciesFor


ResultPolicy

Re-exports ResultPolicy


SaveResult

Re-exports SaveResult


SaveState

Re-exports SaveState


SIG_PROTOCOLS

Re-exports SIG_PROTOCOLS


SUPPORTED_DEVICES

Re-exports SUPPORTED_DEVICES


SupportedDeviceDefinition

Re-exports SupportedDeviceDefinition


useBluetooth

Re-exports useBluetooth


useBluetoothPermission

Re-exports useBluetoothPermission


useBluetoothState

Re-exports useBluetoothState


useMeasurements

Re-exports useMeasurements


useNearbyDevice

Re-exports useNearbyDevice


useNearbyDevices

Re-exports useNearbyDevices


usePairedDevices

Re-exports usePairedDevices


useScanning

Re-exports useScanning

Last updated on

On this page