bridgething
Surfaces ↓

Bluetooth

client.bluetooth

Daemon -> webapp bluetooth surface: connection status/events, in-flight pairing feedback, and the reply to bluetooth.list.

Requests

you ask, the daemon answers; await the tagged result and check .ok

list(): Promise<TypedRequestResult<PairedDevicesMap, never>>

push form: onPairedDevices (subscribe instead of awaiting)

Marker request: webapp asks the bridge for the paired bluetooth devices map. Pairs with BridgeToClientBluetoothMsg::PairedDevices.

const res = await client.bluetooth.list();
if (res.ok) {
  // res.response: PairedDevicesMap
}

Commands

fire-and-forget; the promise resolves once the daemon has taken the message

connect(ConnectBluetooth): Promise<void>

await client.bluetooth.connect({ mac: '...' });

enableDiscoverable(): Promise<void>

await client.bluetooth.enableDiscoverable();

disableDiscoverable(): Promise<void>

await client.bluetooth.disableDiscoverable();

forget(ForgetBluetooth): Promise<void>

await client.bluetooth.forget({ mac: '...' });

setAlias(SetBluetoothAlias): Promise<void>

await client.bluetooth.setAlias({ name: '...' });

Events

the daemon pushes these unprompted; subscribing returns an unsubscribe function

onStatus(handler: (BluetoothStatus) => void): () => void

const off = client.bluetooth.onStatus((bluetoothStatus) => {
  console.log(bluetoothStatus.connected);
});
// call off() to unsubscribe

onConnectedDevice(handler: (ConnectedDevice) => void): () => void

const off = client.bluetooth.onConnectedDevice((connectedDevice) => {
  console.log(connectedDevice.name);
});
// call off() to unsubscribe

onInterface(handler: (BluetoothInterface) => void): () => void

const off = client.bluetooth.onInterface((bluetoothInterface) => {
  console.log(bluetoothInterface.mac);
});
// call off() to unsubscribe

onPairingResult(handler: (BluetoothPairingResult) => void): () => void

const off = client.bluetooth.onPairingResult((bluetoothPairingResult) => {
  console.log(bluetoothPairingResult.success);
});
// call off() to unsubscribe

onPin(handler: (BluetoothPin) => void): () => void

const off = client.bluetooth.onPin((bluetoothPin) => {
  console.log(bluetoothPin.mac);
});
// call off() to unsubscribe

Types

shapes referenced above, as the SDK types them

Whether a companion phone is currently connected over bluetooth.

type BluetoothStatus = {
  connected: boolean;
};

The bluetooth device currently connected to the daemon.

type ConnectedDevice = {
  name: string;
  mac: string;
};

Describes the device's own bluetooth adapter. interface is the host-side interface name (e.g. hci0).

type BluetoothInterface = {
  mac: string;
  name: string;
  interface: string;
};

Outcome of an in-flight pairing attempt initiated by a peer device.

type BluetoothPairingResult = {
  success: boolean;
};

A pairing PIN a peer device is displaying, for a webapp to show as on-screen confirmation.

type BluetoothPin = {
  mac: string;
  name: string;
  pin: string;
};

Map of MAC string to Device.

type PairedDevicesMap = {};

Payload for bluetooth.connect: connect to an already-paired device by MAC.

type ConnectBluetooth = {
  mac: string;
};

Payload for bluetooth.forget: unpair a device and drop it from the daemon's known-device set.

type ForgetBluetooth = {
  mac: string;
};

Payload for bluetooth.setAlias: rename the device's own adapter as seen by peers during discovery and pairing.

type SetBluetoothAlias = {
  name: string;
};