UNPKG

taro-hooks

Version:
31 lines (30 loc) 1.58 kB
import type { PromiseAction, PromiseOptionalAction, PromiseWithoutOptionAction, ExcludeOption, ExcludeSuccess, WithUndefind } from '../type'; export type AdapterState = Taro.getBluetoothAdapterState.SuccessCallbackResult; export type Adapter = ExcludeSuccess<AdapterState>; export type AdapterMode = 'central' | 'peripheral'; export type ToggleAdapter = PromiseOptionalAction<boolean | AdapterMode, TaroGeneral.BluetoothError>; export type GetState = PromiseWithoutOptionAction<AdapterState>; export type GetDevices = PromiseWithoutOptionAction<Taro.getBluetoothDevices.SuccessCallbackResult>; export type GetConnected = PromiseWithoutOptionAction<Taro.getConnectedBluetoothDevices.SuccessCallbackResult>; export type MakePair = PromiseAction<ExcludeOption<Taro.makeBluetoothPair.Option>>; export type IsPaired = PromiseAction<string>; export type ToggleDiscovery = PromiseOptionalAction<ExcludeOption<Taro.startBluetoothDevicesDiscovery.Option>, TaroGeneral.BluetoothError>; export type Devices = Taro.getBluetoothDevices.SuccessCallbackResultBlueToothDevice[]; export type ConnectDevices = Taro.getConnectedBluetoothDevices.BluetoothDeviceInfo[]; declare function useBluetooth(): [ { devices: Devices; connectedDevices: ConnectDevices; adapter: WithUndefind<Adapter>; }, { toggleAdapter: ToggleAdapter; getState: GetState; getDevices: GetDevices; getConnected: GetConnected; makePair: MakePair; isPaired: IsPaired; toggleDiscovery: ToggleDiscovery; } ]; export default useBluetooth;