import { IAdapterOptions } from '../types'; import { BaseAdapter } from './BaseAdapter'; /** * Request device options for Web Bluetooth */ export interface WebBluetoothRequestOptions { /** Filter by service UUIDs */ serviceUUIDs?: string[]; /** Filter by device name prefix */ namePrefix?: string; /** Accept all devices (requires at least one optional service) */ acceptAllDevices?: boolean; /** Optional services to access */ optionalServices?: string[]; /** Minimum RSSI signal strength (dBm) to accept device */ minRSSI?: number; /** Filter by device name (exact or partial match) */ name?: string; /** Filter by manufacturer data patterns */ manufacturerDataFilter?: Array<{ companyIdentifier: number; dataPrefix?: Uint8Array; }>; } /** * Discovered device information */ export interface DiscoveredDevice { /** Device instance */ device: BluetoothDevice; /** Device name */ name: string; /** Device ID */ deviceId: string; /** RSSI signal strength (dBm) */ rssi?: number; /** Timestamp when device was discovered */ discoveredAt: number; /** Manufacturer data if available */ manufacturerData?: Map; } /** * Device filter options for scanning */ export interface DeviceFilterOptions { /** Minimum RSSI threshold (dBm) */ minRSSI?: number; /** Maximum RSSI threshold (dBm) */ maxRSSI?: number; /** Name prefix filter */ namePrefix?: string; /** Name exact match filter */ name?: string; /** Service UUIDs to filter */ serviceUUIDs?: string[]; } /** * Web Bluetooth adapter for H5 environment * * @example * ```typescript * if (WebBluetoothAdapter.isSupported()) { * const adapter = new WebBluetoothAdapter(); * const device = await adapter.requestDevice(); * await adapter.connect(device.id); * await adapter.write(device.id, buffer); * await adapter.disconnect(device.id); * } * ``` */ export declare class WebBluetoothAdapter extends BaseAdapter { private devices; private discoveredDevices; private connectionCleanupTimeout; /** * Check if Web Bluetooth API is supported in the current browser * @returns True if Web Bluetooth is supported */ static isSupported(): boolean; /** * Request a Bluetooth device from the user * This will show the browser's device picker dialog * * @param options - Request options for filtering devices * @returns The selected Bluetooth device * @throws {BluetoothPrintError} When Web Bluetooth is not supported or user cancels */ requestDevice(options?: WebBluetoothRequestOptions): Promise; /** * Connect to a Bluetooth device * * @param deviceId - Bluetooth device ID * @throws {BluetoothPrintError} When connection fails */ connect(deviceId: string): Promise; /** * Disconnect from a Bluetooth device * * @param deviceId - Bluetooth device ID */ disconnect(deviceId: string): Promise; /** * Write data to the Bluetooth device * * @param deviceId - Bluetooth device ID * @param buffer - Data to write as ArrayBuffer * @param options - Write options (chunk size, delay, retries) * @throws {BluetoothPrintError} When write fails */ write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise; /** * Get device ID from a BluetoothDevice instance * Handles different browser implementations * * @param device - BluetoothDevice instance * @returns Device ID string */ getDeviceId(device: BluetoothDevice): string; /** * Get device information including RSSI * * @param deviceId - Bluetooth device ID * @returns Device info object with RSSI and metadata */ getDeviceInfo(deviceId: string): { deviceId: string; name: string; rssi?: number; connected: boolean; } | null; /** * Filter discovered devices by criteria * * @param devices - Array of discovered devices * @param filter - Filter criteria * @returns Filtered array of devices */ filterDevices(devices: DiscoveredDevice[], filter: DeviceFilterOptions): DiscoveredDevice[]; /** * Sort devices by signal strength (RSSI) * * @param devices - Array of discovered devices * @param ascending - Sort in ascending order (weakest first), default false (strongest first) * @returns Sorted array */ sortByRSSI(devices: DiscoveredDevice[], ascending?: boolean): DiscoveredDevice[]; /** * Build request options for navigator.bluetooth.requestDevice */ private buildRequestOptions; /** * Get existing device or request a new one */ private getOrRequestDevice; /** * Connect to GATT server with timeout */ private connectWithTimeout; /** * Discover services and find a writeable characteristic */ private discoverWriteableCharacteristic; /** * Handle device disconnection */ private handleDisconnection; /** * Clean up device information */ private cleanupDeviceInfo; /** * Generate a fallback device ID when device.id is not available * Uses device name + first seen timestamp as identifier */ private generateFallbackDeviceId; /** * Cleanup resources and destroy the adapter instance * Removes all event listeners and releases resources */ destroy(): void; }