/** * MQTT Client for HoloScript IoT Integration * * Provides MQTT 3.1.1 and 5.0 protocol support for IoT device communication. * Supports pub/sub patterns, QoS levels, and wildcard subscriptions. * * @version 1.0.0 */ export type QoS = 0 | 1 | 2; export type MQTTVersion = '3.1.1' | '5.0'; export interface MQTTClientConfig { /** Broker URL (e.g., mqtt://localhost:1883, wss://broker.example.com) */ broker: string; /** Client ID (auto-generated if not provided) */ clientId?: string; /** MQTT protocol version */ version?: MQTTVersion; /** Username for authentication */ username?: string; /** Password for authentication */ password?: string; /** Keep-alive interval in seconds */ keepAlive?: number; /** Clean session flag */ cleanSession?: boolean; /** Reconnect options */ reconnect?: { enabled: boolean; maxAttempts?: number; baseDelay?: number; maxDelay?: number; }; /** TLS/SSL options */ tls?: { enabled: boolean; rejectUnauthorized?: boolean; ca?: string; cert?: string; key?: string; }; /** Will message */ will?: { topic: string; payload: string | Buffer; qos?: QoS; retain?: boolean; }; } export interface MQTTMessage { topic: string; payload: Buffer | string; qos: QoS; retain: boolean; /** MQTT 5.0 properties */ properties?: { payloadFormatIndicator?: number; messageExpiryInterval?: number; contentType?: string; responseTopic?: string; correlationData?: Buffer; userProperties?: Record; }; } export interface MQTTSubscription { topic: string; qos: QoS; /** No Local flag (MQTT 5.0) */ noLocal?: boolean; /** Retain as Published flag (MQTT 5.0) */ retainAsPublished?: boolean; /** Retain handling option (MQTT 5.0) */ retainHandling?: 0 | 1 | 2; } export interface MQTTPublishOptions { qos?: QoS; retain?: boolean; /** MQTT 5.0 properties */ properties?: MQTTMessage['properties']; } export type MQTTClientState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'closed'; export interface MQTTClientEvents { connect: () => void; disconnect: (reason?: string) => void; reconnect: (attempt: number) => void; message: (topic: string, message: MQTTMessage) => void; error: (error: Error) => void; offline: () => void; } export declare class MQTTClient { private config; private state; private subscriptions; private messageQueue; private reconnectAttempts; private reconnectTimeout; private eventHandlers; private simulatedMode; constructor(config: MQTTClientConfig); /** * Connect to the MQTT broker */ connect(): Promise; /** * Disconnect from the MQTT broker */ disconnect(): Promise; /** * Get current connection state */ getState(): MQTTClientState; /** * Check if connected */ isConnected(): boolean; /** * Publish a message to a topic */ publish(topic: string, payload: string | Buffer | object, options?: MQTTPublishOptions): Promise; /** * Subscribe to a topic pattern */ subscribe(topicOrSubscription: string | MQTTSubscription, handler: (message: MQTTMessage) => void): Promise; /** * Unsubscribe from a topic */ unsubscribe(topic: string, handler?: (message: MQTTMessage) => void): Promise; /** * Get active subscriptions */ getSubscriptions(): string[]; /** * Register an event handler */ on(event: K, handler: MQTTClientEvents[K]): void; /** * Remove an event handler */ off(event: K, handler: MQTTClientEvents[K]): void; /** * Emit an event */ private emit; /** * Check if a topic matches a subscription pattern * Supports + (single-level) and # (multi-level) wildcards */ static matchTopic(pattern: string, topic: string): boolean; /** * Parse message payload based on content type */ static parsePayload(message: MQTTMessage): unknown; private generateClientId; private simulateConnect; private simulatePublish; private simulateSubscribe; private simulateUnsubscribe; private deliverMessage; private scheduleReconnect; private flushMessageQueue; /** * Inject a message for testing purposes */ _injectMessage(topic: string, payload: string | Buffer | object): void; } /** * Create an MQTT client */ export declare function createMQTTClient(config: MQTTClientConfig): MQTTClient; /** * Register a named MQTT client */ export declare function registerMQTTClient(name: string, client: MQTTClient): void; /** * Get a registered MQTT client */ export declare function getMQTTClient(name: string): MQTTClient | undefined; /** * Unregister an MQTT client */ export declare function unregisterMQTTClient(name: string): void; export default MQTTClient; //# sourceMappingURL=MQTTClient.d.ts.map