UNPKG

@sfourdrinier/react-native-ble-plx

Version:
124 lines 4.05 kB
import { Device } from './Device'; import { BleError } from './BleError'; import type { BleManager } from './BleManager'; import type { DeviceId, ReconnectionOptions } from './TypeDefinition'; /** * Event callbacks for reconnection events */ export interface ReconnectionCallbacks { /** * Called when a device successfully reconnects */ onReconnect?: (device: Device) => void; /** * Called when reconnection fails after all retries */ onReconnectFailed?: (deviceId: DeviceId, error: BleError) => void; /** * Called when a reconnection attempt starts */ onReconnecting?: (deviceId: DeviceId, attempt: number, maxAttempts: number) => void; } /** * ReconnectionManager automatically handles reconnection when devices disconnect unexpectedly. * * Features: * - Automatic reconnection with exponential backoff * - Configurable retry limits and delays * - Event callbacks for monitoring reconnection status * - Per-device configuration * * @example * const reconnectionManager = new ReconnectionManager(bleManager); * * // Enable auto-reconnect for a device * reconnectionManager.enableAutoReconnect('AA:BB:CC:DD:EE:FF', { * maxRetries: 10, * initialDelayMs: 1000, * maxDelayMs: 60000, * backoffMultiplier: 1.5 * }, { * onReconnect: (device) => console.log('Reconnected!', device.id), * onReconnectFailed: (deviceId, error) => console.log('Failed to reconnect', deviceId) * }); * * // Disable auto-reconnect * reconnectionManager.disableAutoReconnect('AA:BB:CC:DD:EE:FF'); */ export declare class ReconnectionManager { private _manager; private _devices; private _globalCallbacks; constructor(manager: BleManager); /** * Set global callbacks for all reconnection events. * * @param callbacks Callback functions for reconnection events */ setGlobalCallbacks(callbacks: ReconnectionCallbacks): void; /** * Enable automatic reconnection for a device. * * @param deviceId Device identifier * @param options Reconnection options (retries, delays, etc.) * @param callbacks Optional callbacks for this specific device */ enableAutoReconnect(deviceId: DeviceId, options?: ReconnectionOptions, callbacks?: ReconnectionCallbacks): void; /** * Disable automatic reconnection for a device. * * @param deviceId Device identifier * @returns True if auto-reconnect was disabled, false if it wasn't enabled */ disableAutoReconnect(deviceId: DeviceId): boolean; /** * Disable auto-reconnect for all devices. */ disableAll(): void; /** * Check if auto-reconnect is enabled for a device. * * @param deviceId Device identifier * @returns True if auto-reconnect is enabled */ isEnabled(deviceId: DeviceId): boolean; /** * Check if a device is currently reconnecting. * * @param deviceId Device identifier * @returns True if reconnection is in progress */ isReconnecting(deviceId: DeviceId): boolean; /** * Get the current retry count for a device. * * @param deviceId Device identifier * @returns Current retry count, or -1 if auto-reconnect is not enabled */ getRetryCount(deviceId: DeviceId): number; /** * Manually trigger a reconnection attempt. * Useful if you want to retry after all automatic retries have been exhausted. * * @param deviceId Device identifier * @returns Promise resolving to connected Device */ manualReconnect(deviceId: DeviceId): Promise<Device>; /** * Start the reconnection process for a device */ private _startReconnection; /** * Schedule a reconnection attempt with delay */ private _scheduleReconnection; /** * Attempt to reconnect to a device */ private _attemptReconnection; /** * Destroy the manager and disable all auto-reconnect. */ destroy(): void; } //# sourceMappingURL=ReconnectionManager.d.ts.map