import type { AuthenticationResult, ConnectPacket, ConnNext, ProtocolLevel, PublishPacket, Store, SubscribePacket } from "./deps.ts"; import type { AuthenticatedResult } from "./context.ts"; import type { ConnectionState } from "./ConnectionState.ts"; /** All properties of a connect packet, except for type and protocol name */ export type ConnectOptions = Omit; /** ConnectParameters define how to connect */ export type ConnectParameters = { /** the URL to connect to */ url?: URL | undefined; /** any CA Certs to trust */ caCerts?: string[] | undefined; /** the clients certificate */ cert?: string | undefined; /** the clients private key*/ key?: string | undefined; /** number of retries before stopping connection attempts */ numberOfRetries?: number | undefined; /** maximum size of receive buffer, only used by webSockets for now */ maxBufferSize?: number | undefined; /** connect options */ options?: ConnectOptions | undefined; }; /** PublishParameters define how a message should be published */ export type PublishParameters = Omit; /** SubscribeParameters define how to subscribe to a topic */ export type SubscribeParameters = Omit; /** the default MQTT URL to connect to */ export declare const DEFAULT_URL = "mqtt://localhost:1883/"; /** the default protocol level to connect with*/ export declare const DEFAULT_PROTOCOLLEVEL: ProtocolLevel; /** the default keepalive time */ export declare const DEFAULT_KEEPALIVE = 60; /** * The Client class provides an MQTT Client that can be used to connect to * a MQTT broker and publish/subscribe messages. * * The Client class is not meant to be used directly, but * instead should be subclassed and the subclass should * override the createConn() method to provide a * connection type that is supported by the subclass. */ export declare class Client { /** callback to handle v5 extended authentication, see /examples folder */ onAuth: (authMethod: string, authData: Uint8Array) => AuthenticatedResult; /** callback for errors */ onError: (err: Error) => void; /** callback for publish packets */ onPacket: (pkt: PublishPacket) => void | Promise; /** callback once connected */ onConnected: () => void; /** callback once disconnected */ onDisconnected: () => void; /** callback when reconnecting */ onReconnecting: () => void; /** clientId prefix used when automatically generating a client Id */ protected clientIdPrefix: string; /** number of times to retry connect */ protected numberOfRetries: number; /** the URL to connect to */ protected connectUrl: URL; /** the keepAlive value in number of seconds */ protected keepAlive: number; /** the requested protocol level */ protected protocolLevel: ProtocolLevel; /** try auto reconnect if connection is lost */ protected autoReconnect: boolean; /** any CA Certs to trust */ protected caCerts?: string[] | undefined; /** the clients certificate */ protected cert?: string | undefined; /** the clients private key*/ protected key?: string | undefined; /** the MQTT clientId */ protected clientId: string; /** the maximum number of bytes buffered by a ws/wss client */ protected maxBufferSize: number | undefined; private ctx; private connectPacket?; /** * Creates a new MQTT client instance */ constructor(store?: Store); /** * Current connection state * @returns connectionState as ConnectionState */ get connectionState(): ConnectionState; /** * Current configured connection URL * @returns URL object */ get url(): URL; /** * Placeholder for MQTT, override in subclass * @param _hostname * @param _port */ protected connectMQTT(_hostname: string, _port: number): Promise; /** * Connect using MQTT over TLS * @param hostname the name of the host to connect to * @param port the port number * @param caCerts the CA certificates to trust * @param cert the clients certificate * @param key the clients private key * @returns a ConnNext object */ protected connectMQTTS(_hostname: string, _port: number, _caCerts?: string[], _cert?: string, _key?: string): Promise; /** * Creates a new connection to the MQTT broker * Override this in a subclass if you need other protocols * @returns Promise resolving to a ConnNext connection */ protected createConn(): Promise; /** * Handles the connection process including retries and reconnection * @returns Promise that resolves when connection is established or fails */ private doConnect; /** * Connects to the MQTT broker * @param params - Connection parameters * @returns Promise resolving to authentication result */ connect(params?: ConnectParameters): Promise; /** * Disconnects from the MQTT broker * @returns Promise that resolves when disconnected */ disconnect(): Promise; /** * Publishes a message to the MQTT broker * @param params - Publish parameters including topic and payload * @returns Promise that resolves when published */ publish(params: PublishParameters): Promise; /** * Subscribes to topics on the MQTT broker * @param params - Subscribe parameters including topics * @returns Promise that resolves when subscribed */ subscribe(params: SubscribeParameters): Promise; /** * Gets an async iterator for received messages * @returns AsyncGenerator yielding received publish packets */ messages(): AsyncIterable; } //# sourceMappingURL=client.d.ts.map