/// declare module '@stoprocent/bluetooth-hci-socket' { type DriverType = any; // Fallback type interface BindParams { [key: string]: any; } } declare module '@stoprocent/noble' { import { EventEmitter } from 'events'; export type AdapterState = 'poweredOn' | 'poweredOff' | 'unauthorized' | 'unsupported' | 'unknown' | 'resetting'; export type PeripheralState = 'error' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected'; export type PeripheralAddressType = 'public' | 'random'; export type PeripheralIdOrAddress = string; /** * Linux HCI bindings emit the numeric controller status. Other bindings * and library-initiated cleanup paths emit a descriptive string. */ export type DisconnectReason = number | string; export type CharacteristicProperty = 'read' | 'write' | 'indicate' | 'notify' | 'writeWithoutResponse'; /** * Mirrors WinRT's `DevicePairingKinds` (Windows.Devices.Enumeration). * Bitfield: pass a single kind or OR several together to advertise * which ceremonies the caller knows how to handle. * * Only the Windows binding honors this; `pair()` on hci-socket / dbus / * mac surfaces "Pairing is not supported on this platform" regardless * of the value. */ export enum DevicePairingKinds { None = 0, ConfirmOnly = 0x00000008, DisplayPin = 0x00000010, ConfirmPinMatch = 0x00000020, ProvidePin = 0x00000040, ProvidePassword = 0x00000080, ConfirmPassword = 0x00000100, } /** * Mirrors WinRT's `DevicePairingProtectionLevel`. * Used only by the Windows binding. */ export enum DevicePairingProtectionLevel { Default = 0, None = 1, Encryption = 2, EncryptionAndAuthentication = 3, } export interface ConnectOptions { addressType?: PeripheralAddressType; minInterval?: number; maxInterval?: number; latency?: number; timeout?: number; } export class Noble extends EventEmitter { constructor(bindings: any); readonly state: AdapterState; readonly address: string; waitForPoweredOnAsync(timeout?: number): Promise; startScanningAsync(serviceUUIDs?: string[], allowDuplicates?: boolean): Promise; stopScanningAsync(): Promise; discoverAsync(): AsyncGenerator; connectAsync(idOrAddress: PeripheralIdOrAddress, options?: ConnectOptions): Promise; pairAsync(idOrAddress: PeripheralIdOrAddress, kind?: DevicePairingKinds, protectionLevel?: DevicePairingProtectionLevel): Promise; startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void; stopScanning(callback?: () => void): void; connect(idOrAddress: PeripheralIdOrAddress, options?: ConnectOptions, callback?: (error: Error | undefined, peripheral: Peripheral) => void): void; cancelConnect(idOrAddress: PeripheralIdOrAddress, options?: object): void; reset(): void; stop(): void; setAddress(address: string): void; /** * Pair with a peripheral. `kind` defaults to * `DevicePairingKinds.ConfirmOnly` and `protectionLevel` defaults to * `DevicePairingProtectionLevel.Encryption`. On Windows, `ConfirmOnly`, * `DisplayPin`, and `ConfirmPinMatch` use the OS pairing dialog. PIN / * password kinds (`ProvidePin`, `ProvidePassword`, `ConfirmPassword`) are * rejected because this library does not collect secrets to pass into * WinRT. On non-Windows platforms the call surfaces a "Pairing is not * supported" error. */ pair(idOrAddress: PeripheralIdOrAddress, callback: (error: Error | undefined) => void): void; pair(idOrAddress: PeripheralIdOrAddress, kind?: DevicePairingKinds, callback?: (error: Error | undefined) => void): void; pair(idOrAddress: PeripheralIdOrAddress, kind: DevicePairingKinds, protectionLevel: DevicePairingProtectionLevel, callback?: (error: Error | undefined) => void): void; on(event: "stateChange", listener: (state: AdapterState) => void): this; on(event: "scanStart", listener: () => void): this; on(event: "scanStop", listener: () => void): this; on(event: "discover", listener: (peripheral: Peripheral) => void): this; on(event: "pair", listener: (peripheral: Peripheral, error: Error | null) => void): this; on(event: string, listener: Function): this; once(event: "stateChange", listener: (state: AdapterState) => void): this; once(event: "scanStart", listener: () => void): this; once(event: "scanStop", listener: () => void): this; once(event: "discover", listener: (peripheral: Peripheral) => void): this; once(event: "pair", listener: (peripheral: Peripheral, error: Error | null) => void): this; once(event: string, listener: Function): this; removeListener(event: "stateChange", listener: (state: AdapterState) => void): this; removeListener(event: "scanStart", listener: () => void): this; removeListener(event: "scanStop", listener: () => void): this; removeListener(event: "discover", listener: (peripheral: Peripheral) => void): this; removeListener(event: string, listener: Function): this; } export interface ServicesAndCharacteristics { services: Service[]; characteristics: Characteristic[]; } export interface PeripheralAdvertisement { localName: string; serviceData: Array<{ uuid: string, data: Buffer }>; txPowerLevel: number; manufacturerData: Buffer; serviceUuids: string[]; serviceSolicitationUuids: string[]; } export class Peripheral extends EventEmitter { readonly id: string; readonly address: string; readonly addressType: PeripheralAddressType; readonly connectable: boolean; readonly advertisement: PeripheralAdvertisement; readonly rssi: number; readonly mtu: number | null; readonly services: Service[]; readonly state: PeripheralState; /** @deprecated Use id instead */ readonly uuid: string; connectAsync(): Promise; pairAsync(kind?: DevicePairingKinds, protectionLevel?: DevicePairingProtectionLevel): Promise; disconnectAsync(): Promise; updateRssiAsync(): Promise; discoverServicesAsync(): Promise; discoverServicesAsync(serviceUUIDs: string[]): Promise; discoverAllServicesAndCharacteristicsAsync(): Promise; discoverSomeServicesAndCharacteristicsAsync(serviceUUIDs: string[], characteristicUUIDs: string[]): Promise; readHandleAsync(handle: number): Promise; writeHandleAsync(handle: number, data: Buffer, withoutResponse: boolean): Promise; connect(callback?: (error: Error | undefined) => void): void; pair(callback: (error: Error | undefined) => void): void; pair(kind?: DevicePairingKinds, callback?: (error: Error | undefined) => void): void; pair(kind: DevicePairingKinds, protectionLevel: DevicePairingProtectionLevel, callback?: (error: Error | undefined) => void): void; disconnect(callback?: () => void): void; updateRssi(callback?: (error: Error | undefined, rssi: number) => void): void; discoverServices(): void; discoverServices(serviceUUIDs: string[], callback?: (error: Error | undefined, services: Service[]) => void): void; discoverAllServicesAndCharacteristics(callback?: (error: Error | undefined, services: Service[], characteristics: Characteristic[]) => void): void; discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback?: (error: Error | undefined, services: Service[], characteristics: Characteristic[]) => void): void; readHandle(handle: number, callback: (error: Error | undefined, data: Buffer) => void): void; writeHandle(handle: number, data: Buffer, withoutResponse: boolean, callback: (error: Error | undefined) => void): void; cancelConnect(options?: object): void; toString(): string; on(event: "connect", listener: (error: Error | undefined) => void): this; on(event: "pair", listener: (error: Error | null) => void): this; on(event: "disconnect", listener: (reason: DisconnectReason) => void): this; on(event: "rssiUpdate", listener: (rssi: number) => void): this; on(event: "servicesDiscover", listener: (services: Service[]) => void): this; on(event: "mtu", listener: (mtu: number) => void): this; on(event: string, listener: Function): this; once(event: "connect", listener: (error: Error | undefined) => void): this; once(event: "pair", listener: (error: Error | null) => void): this; once(event: "disconnect", listener: (reason: DisconnectReason) => void): this; once(event: "rssiUpdate", listener: (rssi: number) => void): this; once(event: "servicesDiscover", listener: (services: Service[]) => void): this; once(event: string, listener: Function): this; } export class Service extends EventEmitter { readonly uuid: string; readonly name: string; readonly type: string; readonly includedServiceUuids: string[]; readonly characteristics: Characteristic[]; discoverIncludedServicesAsync(): Promise; discoverIncludedServicesAsync(serviceUUIDs: string[]): Promise; discoverCharacteristicsAsync(): Promise; discoverCharacteristicsAsync(characteristicUUIDs: string[]): Promise; discoverIncludedServices(): void; discoverIncludedServices(serviceUUIDs: string[], callback?: (error: Error | undefined, includedServiceUuids: string[]) => void): void; discoverCharacteristics(): void; discoverCharacteristics(characteristicUUIDs: string[], callback?: (error: Error | undefined, characteristics: Characteristic[]) => void): void; toString(): string; on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this; on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this; on(event: string, listener: Function): this; once(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this; once(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this; once(event: string, listener: Function): this; } export class Characteristic extends EventEmitter { readonly uuid: string; readonly name: string; readonly type: string; readonly properties: CharacteristicProperty[]; readonly descriptors: Descriptor[]; readAsync(): Promise; writeAsync(data: Buffer, withoutResponse: boolean): Promise; subscribeAsync(): Promise; unsubscribeAsync(): Promise; discoverDescriptorsAsync(): Promise; broadcastAsync(broadcast: boolean): Promise; /** * Async iterator for receiving notifications from the characteristic. * Automatically handles subscription and cleanup when finished. * @returns AsyncGenerator that yields notification data */ notificationsAsync(): AsyncGenerator; read(callback?: (error: Error | undefined, data: Buffer) => void): void; write(data: Buffer, withoutResponse: boolean, callback?: (error: Error | undefined) => void): void; subscribe(callback?: (error: Error | undefined) => void): void; unsubscribe(callback?: (error: Error | undefined) => void): void; discoverDescriptors(callback?: (error: Error | undefined, descriptors: Descriptor[]) => void): void; broadcast(broadcast: boolean, callback?: (error: Error | undefined) => void): void; toString(): string; on(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this; on(event: "write", listener: (error: Error | undefined) => void): this; on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this; on(event: "broadcast", listener: (state: string) => void): this; on(event: string, listener: Function): this; once(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this; once(event: "write", listener: (error: Error | undefined) => void): this; once(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this; once(event: "broadcast", listener: (state: string) => void): this; once(event: string, listener: Function): this; } export class Descriptor extends EventEmitter { readonly uuid: string; readonly name: string; readonly type: string; readValueAsync(): Promise; writeValueAsync(data: Buffer): Promise; readValue(callback?: (error: Error | undefined, data: Buffer) => void): void; writeValue(data: Buffer, callback?: (error: Error | undefined) => void): void; toString(): string; on(event: "valueRead", listener: (error: Error | undefined, data: Buffer) => void): this; on(event: "valueWrite", listener: (error: Error | undefined) => void): this; on(event: string, listener: Function): this; once(event: "valueRead", listener: (error: Error | undefined, data: Buffer) => void): this; once(event: "valueWrite", listener: (error: Error | undefined) => void): this; once(event: string, listener: Function): this; } export type BindingType = 'default' | 'hci' | 'mac' | 'win'; export interface BaseBindingsOptions {} export interface HciBindingsOptions extends BaseBindingsOptions { /** Driver Type ('default' | 'uart' | 'usb' | 'native') */ hciDriver?: import('@stoprocent/bluetooth-hci-socket').DriverType; /** Bind Params (for USB and UART Hci Drivers only) */ bindParams?: import('@stoprocent/bluetooth-hci-socket').BindParams; /** HCI Device ID (Linux Only), Default is 0 */ deviceId?: number; /** Use With BLE5 Extended Features, Default is based on the result of LE_READ_LOCAL_SUPPORTED_FEATURES command */ extended?: boolean; /** * Use the exclusive Linux HCI user channel instead of the shared raw * channel. The selected adapter must be down before binding. */ userChannel?: boolean; /** * Offer LE Coded PHY as an acceptable PHY for connections, for * long-range links. Off by default: Coded PHY trades throughput for * range, and a peer may negotiate onto it. Ignored on controllers * that do not report the LE Coded PHY feature. Does not affect * scanning. */ codedPhy?: boolean; } export interface MacBindingsOptions extends BaseBindingsOptions {} export interface WinBindingsOptions extends BaseBindingsOptions {} export type WithBindingsOptions = HciBindingsOptions | MacBindingsOptions | WinBindingsOptions; export function withBindings( bindingType?: BindingType, options?: WithBindingsOptions ): Noble; /** Resolve a numeric HCI status code to its Bluetooth specification message. */ export function hciStatusMessage(reason: DisconnectReason): string; // Define a default export const NobleDefault: Noble; export default NobleDefault; }