/** * Bluetooth Manager - Abstraction layer over react-native-ble-plx */ import { Device, State, Subscription } from 'react-native-ble-plx'; import { Buffer } from 'buffer'; import EventEmitter from 'eventemitter3'; import type { DiscoveredDevice, ScanOptions } from '../models/Device'; /** * Events emitted by BleManager */ interface BleManagerEvents { stateChange: (state: State) => void; deviceDiscovered: (device: DiscoveredDevice) => void; deviceConnected: (deviceId: string) => void; deviceDisconnected: (deviceId: string, error?: Error) => void; } /** * Bluetooth Manager class - singleton wrapper around react-native-ble-plx */ export declare class BleManager extends EventEmitter { private manager; private stateSubscription; private disconnectSubscriptions; private connectedDevices; private discoveredDevices; private pendingConnects; private isScanning; private cachedState; constructor(); /** * Set up Bluetooth state change listener */ private setupStateListener; /** * Get current Bluetooth state */ getState(): Promise; /** * Get cached Bluetooth state (synchronous) */ getCachedState(): State; /** * Check if Bluetooth is ready for operations */ isReady(): Promise; /** * Wait for Bluetooth to be ready */ waitForReady(timeoutMs?: number): Promise; /** * Start scanning for Bota devices */ startScan(options?: ScanOptions): Promise; /** * Stop scanning for devices */ stopScan(): void; /** * Get list of discovered devices */ getDiscoveredDevices(): DiscoveredDevice[]; /** * Parse a discovered device from Bluetooth advertisement data */ private parseDiscoveredDevice; /** * Connect to a device. * Deduplicates concurrent calls — if a connect is already in progress * for this device, callers share the same promise. */ connect(deviceId: string): Promise; private doConnect; /** * Disconnect from a device */ disconnect(deviceId: string): Promise; /** * Check if a device is connected */ isConnected(deviceId: string): boolean; /** * Check if a connected device has a specific Bluetooth service */ hasService(deviceId: string, serviceUuid: string): Promise; /** * Get a connected device */ getConnectedDevice(deviceId: string): Device | undefined; /** * Get negotiated MTU for a device. * * react-native-ble-plx captures `device.mtu` at the moment connectToDevice * resolves, which on iOS happens BEFORE the async ATT-MTU exchange * completes. The cached value stays at the BLE default (23) even after the * peripheral has negotiated up to its real maximum (e.g. 509 on JieLi). * Re-querying the Device through `manager.devices([id])` returns a fresh * object reflecting the current MTU. Falls back to the cached value if the * refresh fails. Polls briefly because the negotiation can lag the connect * by ~1 s; chunked writes that read MTU=23 explode into 200+ chunks and * pairing crawls. */ getMtu(deviceId: string): Promise; /** * Read a characteristic value */ readCharacteristic(deviceId: string, serviceUuid: string, characteristicUuid: string): Promise; /** * Write a characteristic value */ writeCharacteristic(deviceId: string, serviceUuid: string, characteristicUuid: string, data: Buffer, withResponse?: boolean): Promise; /** * Subscribe to characteristic notifications */ subscribeToCharacteristic(deviceId: string, serviceUuid: string, characteristicUuid: string, onData: (data: Buffer) => void, onError?: (error: Error) => void): Subscription; /** * Destroy the Bluetooth manager and clean up resources */ destroy(): void; } /** * Get or create the Bluetooth manager singleton */ export declare function getBleManager(): BleManager; /** * Reset the Bluetooth manager singleton (for testing) */ export declare function resetBleManager(): void; export {}; //# sourceMappingURL=BleManager.d.ts.map