UNPKG

@sfourdrinier/react-native-ble-plx

Version:
98 lines 2.89 kB
import { Device } from './Device'; import type { BleManager } from './BleManager'; import type { DeviceId, ConnectionOptions } from './TypeDefinition'; /** * Options for queuing a connection attempt */ export interface QueuedConnectionOptions { /** * Connection options to pass to the device */ connectionOptions?: ConnectionOptions; /** * Maximum number of retry attempts (default: 3) */ maxRetries?: number; /** * Initial delay before first retry in milliseconds (default: 1000) */ initialDelayMs?: number; /** * Maximum delay between retries in milliseconds (default: 30000) */ maxDelayMs?: number; /** * Multiplier for exponential backoff (default: 2) */ backoffMultiplier?: number; } /** * ConnectionQueue manages connection attempts with automatic retry logic * and queue management to prevent connection storms. * * Features: * - Queues connection attempts to prevent multiple simultaneous connections * - Exponential backoff retry logic * - Configurable retry limits and delays * - Ability to cancel pending/in-progress connections * * @example * const queue = new ConnectionQueue(bleManager); * * // Connect with retry logic * const device = await queue.connect('AA:BB:CC:DD:EE:FF', { * maxRetries: 5, * initialDelayMs: 1000, * backoffMultiplier: 2 * }); * * // Cancel a pending connection * queue.cancel('AA:BB:CC:DD:EE:FF'); */ export declare class ConnectionQueue { private _manager; private _queue; constructor(manager: BleManager); /** * Queue a connection attempt with retry logic. * * @param deviceId Device identifier to connect to * @param options Connection and retry options * @returns Promise resolving to connected Device */ connect(deviceId: DeviceId, options?: QueuedConnectionOptions): Promise<Device>; /** * Cancel a pending or in-progress connection attempt. * * @param deviceId Device identifier to cancel connection for * @returns True if a connection was cancelled */ cancel(deviceId: DeviceId): boolean; /** * Cancel all pending connections. */ cancelAll(): void; /** * Get the number of pending connections in the queue. */ get pendingCount(): number; /** * Check if a device has a pending connection. */ isPending(deviceId: DeviceId): boolean; /** * Process the connection queue * Allows concurrent connections to different devices */ private _processQueue; /** * Attempt to connect to a device with retry logic * Runs asynchronously per device, allowing concurrent connections */ private _attemptConnection; /** * Destroy the queue and cancel all pending connections. */ destroy(): void; } //# sourceMappingURL=ConnectionQueue.d.ts.map