index ↓

bluetooth

client.bluetooth

Bluetooth pairing and connection state. onStatus and onConnectedDevice track the connected phone, onPin carries a code to show on screen, and list returns the paired devices.

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)

Returns the paired devices, keyed by MAC address.

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

type BluetoothStatus = {
  connected: boolean;
};
type ConnectedDevice = {
  name: string;
  mac: string;
};

The device's own bluetooth adapter.

type BluetoothInterface = {
  mac: string;
  name: string;
  interface: string; // For example `hci0`.
};
type BluetoothPairingResult = {
  success: boolean;
};
type BluetoothPin = {
  mac: string;
  name: string;
  pin: string;
};

Paired devices keyed by MAC address.

type PairedDevicesMap = {};
type ConnectBluetooth = {
  mac: string;
};
type ForgetBluetooth = {
  mac: string;
};
type SetBluetoothAlias = {
  name: string;
};