import { IPrinterAdapter, PrinterState } from '../types'; import { IConnectionManager } from './interfaces'; import { BluetoothPrintError } from '../errors/baseError'; import { EventEmitter } from '../core/EventEmitter'; /** * Connection manager configuration */ export interface ConnectionManagerConfig { /** Enable heartbeat detection (default: true) */ heartbeatEnabled?: boolean; /** Heartbeat interval in milliseconds (default: 5000) */ heartbeatInterval?: number; /** Enable auto-reconnect (default: true) */ autoReconnect?: boolean; /** Maximum reconnect attempts (default: 3) */ maxReconnectAttempts?: number; /** Reconnect interval in milliseconds (default: 2000) */ reconnectInterval?: number; /** Connection timeout in milliseconds (default: 10000) */ connectionTimeout?: number; } /** * Connection manager events */ export interface ConnectionManagerEvents { /** Emitted when connection state changes */ 'state-change': PrinterState; /** Emitted when device is connected */ connected: string; /** Emitted when device is disconnected */ disconnected: string; /** Emitted when reconnection starts */ reconnecting: { deviceId: string; attempt: number; maxAttempts: number; }; /** Emitted when reconnection succeeds */ reconnected: string; /** Emitted when reconnection fails after all attempts */ 'reconnect-failed': { deviceId: string; error: Error; }; /** Emitted when heartbeat detects connection loss */ 'heartbeat-lost': string; /** Emitted on any error */ error: BluetoothPrintError; } /** * Connection Manager implementation with heartbeat and auto-reconnect */ export declare class ConnectionManager extends EventEmitter implements IConnectionManager { private adapter; private deviceId; private state; private readonly connLogger; private readonly config; private heartbeatTimer; private reconnectAttempts; private isReconnecting; private reconnectTimer; /** * Creates a new ConnectionManager instance */ constructor(adapter?: IPrinterAdapter, config?: ConnectionManagerConfig); /** * Handle adapter state changes */ private handleStateChange; /** * Connects to a Bluetooth device */ connect(deviceId: string, options?: { retries?: number; timeout?: number; }): Promise; /** * Disconnects from the current device */ disconnect(): Promise; /** * Start heartbeat detection */ private startHeartbeat; /** * Stop heartbeat detection */ private stopHeartbeat; /** * Check connection status via heartbeat */ private checkHeartbeat; /** * Handle heartbeat loss */ private handleHeartbeatLost; /** * Start auto-reconnect process */ private startReconnect; /** * Attempt to reconnect */ private attemptReconnect; /** * Clear reconnect timer */ private clearReconnectTimer; /** * Checks if a device is connected */ isConnected(): boolean; /** * Gets the current device ID */ getDeviceId(): string | null; /** * Gets the current connection state */ getState(): PrinterState; /** * Gets the printer adapter instance */ getAdapter(): IPrinterAdapter; /** * Gets the current configuration */ getConfig(): Required; /** * Gets reconnect status */ getReconnectStatus(): { isReconnecting: boolean; attempts: number; maxAttempts: number; }; /** * Manually trigger reconnect */ reconnect(): void; /** * Stop reconnect attempts */ stopReconnect(): void; /** * Cleanup resources */ destroy(): void; }