import { EventEmitter } from '../core/EventEmitter'; export interface CloudPrintOptions { /** WebSocket 服务器地址 */ serverUrl: string; /** 设备 ID */ deviceId: string; /** API 密钥(可选) */ apiKey?: string; /** 自动重连 */ reconnect?: boolean; /** 重连间隔 (ms) */ reconnectInterval?: number; /** 心跳间隔 (ms) */ heartbeatInterval?: number; /** 连接超时 (ms) */ connectTimeout?: number; } export interface PrintJob { /** 任务 ID */ id: string; /** 打印数据 */ data: Uint8Array | string; /** 份数 */ copies?: number; /** 优先级 */ priority?: number; } export interface CloudPrinterStatus { /** 打印机状态 */ status: 'idle' | 'printing' | 'error' | 'offline'; /** 纸张状态 */ paper?: 'ok' | 'low' | 'out'; /** 错误信息 */ error?: string; /** 最后更新时间 */ timestamp: number; } export interface CloudPrintEvents { /** 连接成功 */ connect: void; /** 断开连接 */ disconnect: void; /** 连接错误 */ error: Error; /** 状态更新 */ status: CloudPrinterStatus; /** 打印完成 */ 'print-complete': string; /** 打印失败 */ 'print-error': { jobId: string; error: string; }; /** 收到原始消息 */ message: Record; } export type CloudPrintEvent = keyof CloudPrintEvents; export declare class CloudPrintManager extends EventEmitter { private readonly log; private options; private ws; private isConnected; private reconnectTimer; private heartbeatTimer; private status; private connectResolve; private connectReject; constructor(options: CloudPrintOptions); /** * 检查是否已连接 */ get connected(): boolean; /** * 获取当前打印机状态 */ get currentStatus(): CloudPrinterStatus; /** * 连接到云端服务器 */ connect(): Promise; /** * 断开连接 */ disconnect(): void; /** * 发送打印任务 * @throws Error 如果未连接 */ print(job: PrintJob): void; /** * 获取打印机状态 */ getStatus(): CloudPrinterStatus; /** * 处理接收到的消息 */ private handleMessage; /** * 启动心跳 */ private startHeartbeat; /** * 停止心跳 */ private stopHeartbeat; /** * 安排重连 */ private scheduleReconnect; /** * 取消重连 */ private cancelReconnect; /** * ArrayBuffer 转 Base64 */ private arrayBufferToBase64; }