import { NativeModule, requireNativeModule } from 'expo'; import { State, LogLevel, ScanMode, ScanCallbackType } from './Blekit.types'; export type NativeDevice = { id: string; name: string | null; rssi: number | null; mtu: number; manufacturerData: string | null; serviceUUIDs: string[] | null; serviceData: Record | null; txPowerLevel: number | null; solicitedServiceUUIDs: string[] | null; overflowServiceUUIDs: string[] | null; localName: string | null; }; export type NativeService = { id: number; uuid: string; deviceID: string; isPrimary: boolean; }; export type NativeCharacteristic = { id: number; uuid: string; serviceID: number; serviceUUID: string; deviceID: string; isReadable: boolean; isWritableWithResponse: boolean; isWritableWithoutResponse: boolean; isNotifiable: boolean; isIndicatable: boolean; value: string | null; }; export type NativeDescriptor = { id: number; uuid: string; characteristicID: number; characteristicUUID: string; serviceID: number; serviceUUID: string; deviceID: string; value: string | null; }; export type NativeBleRestoredState = { connectedPeripherals: NativeDevice[]; }; export type BlekitModuleEvents = { onStateChange: (params: { state: State }) => void; onDeviceDiscovered: (params: { device: NativeDevice }) => void; onCharacteristicNotification: (params: { characteristicId: number; characteristic?: NativeCharacteristic; value: string | null; error: any | null; }) => void; onDeviceDisconnected: (params: { deviceId: string; error: any | null }) => void; // Included to keep backwards compatibility for event template onChange: (params: { value: string }) => void; }; declare class BlekitModule extends NativeModule { // Client lifecycle createClient(restoreIdentifier: string | null): Promise; destroyClient(): Promise; // State operations getBluetoothState(): Promise; enable(transactionId: string | null): Promise; disable(transactionId: string | null): Promise; // Logging setLogLevel(logLevel: LogLevel): Promise; logLevel(): Promise; // Transactions cancelTransaction(transactionId: string): Promise; // Scanning startDeviceScan( filteredUUIDs: string[] | null, options: { allowDuplicates?: boolean; scanMode?: ScanMode; callbackType?: ScanCallbackType; legacyScan?: boolean; } | null ): Promise; stopDeviceScan(): Promise; // Connection connectToDevice( deviceAddress: string, options: { autoConnect?: boolean; requestMTU?: number; refreshGatt?: 'OnConnected'; timeout?: number; } | null ): Promise; cancelDeviceConnection(deviceAddress: string): Promise; isDeviceConnected(deviceAddress: string): Promise; // Discovery discoverAllServicesAndCharacteristicsForDevice( deviceAddress: string, transactionId: string | null ): Promise; // Service / Characteristic retrieval servicesForDevice(deviceAddress: string): Promise; characteristicsForDevice( deviceAddress: string, serviceUUID: string ): Promise; descriptorsForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string ): Promise; // UUID-based GATT operations readCharacteristicForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string, transactionId: string | null ): Promise; writeCharacteristicForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string, valueBase64: string, withResponse: boolean, transactionId: string | null ): Promise; monitorCharacteristicForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string, transactionId: string | null ): Promise; // returns characteristic ID stopMonitoringCharacteristicForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string ): Promise; // ID-based GATT operations readCharacteristic( characteristicId: number, transactionId: string | null ): Promise; writeCharacteristic( characteristicId: number, valueBase64: string, withResponse: boolean, transactionId: string | null ): Promise; monitorCharacteristic(characteristicId: number, transactionId: string | null): Promise; stopMonitoringCharacteristic(characteristicId: number): Promise; // Descriptor operations readDescriptorForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, transactionId: string | null ): Promise; writeDescriptorForDevice( deviceAddress: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, valueBase64: string, transactionId: string | null ): Promise; readDescriptor(descriptorId: number, transactionId: string | null): Promise; writeDescriptor( descriptorId: number, valueBase64: string, transactionId: string | null ): Promise; // Extras requestMTUForDevice( deviceAddress: string, mtu: number, transactionId: string | null ): Promise; requestConnectionPriorityForDevice( deviceAddress: string, connectionPriority: number, transactionId: string | null ): Promise; readRSSIForDevice(deviceAddress: string, transactionId: string | null): Promise; // Backwards compatibility template function hello(): string; setValueAsync(value: string): Promise; } export default requireNativeModule('Blekit'); export type { BlekitModule };