/// <reference types="node" />
import * as WebsocketUtils from "./ws";
import { BufferedEventEmitter } from "../common/event";
import { CrtError } from "../browser";
import { SocketOptions } from "./io";
import { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill } from "../common/mqtt";
export declare type WebsocketOptions = WebsocketUtils.WebsocketOptions;
export declare type AWSCredentials = WebsocketUtils.AWSCredentials;
export interface MqttConnectionConfig {
    client_id: string;
    host_name: string;
    socket_options: SocketOptions;
    port: number;
    clean_session?: boolean;
    keep_alive?: number;
    timeout?: number;
    will?: MqttWill;
    username?: string;
    password?: string;
    websocket?: WebsocketOptions;
    credentials?: AWSCredentials;
}
export declare class MqttClient {
    new_connection(config: MqttConnectionConfig): MqttClientConnection;
}
export declare class MqttClientConnection extends BufferedEventEmitter {
    readonly client: MqttClient;
    private config;
    private connection;
    private subscriptions;
    private connection_count;
    constructor(client: MqttClient, config: MqttConnectionConfig);
    /** Emitted when the connection is ready and is about to start sending response data */
    on(event: 'connect', listener: (session_present: boolean) => void): this;
    /** Emitted when connection has closed sucessfully. */
    on(event: 'disconnect', listener: () => void): this;
    /**
     * Emitted when an error occurs
     * @param error - A CrtError containing the error that occurred
     */
    on(event: 'error', listener: (error: CrtError) => void): this;
    /**
     * Emitted when the connection is dropped unexpectedly. The error will contain the error
     * code and message.
     */
    on(event: 'interrupt', listener: (error: CrtError) => void): this;
    /**
     * Emitted when the connection reconnects. Only triggers on connections after the initial one.
     */
    on(event: 'resume', listener: (return_code: number, session_present: boolean) => void): this;
    on(event: 'message', listener: (topic: string, payload: Buffer) => void): this;
    private on_online;
    private on_offline;
    private on_disconnected;
    private on_message;
    private _reject;
    connect(): Promise<boolean>;
    reconnect(): Promise<boolean>;
    publish(topic: string, payload: Payload, qos: QoS, retain?: boolean): Promise<MqttRequest>;
    subscribe(topic: string, qos: QoS, on_message?: (topic: string, payload: ArrayBuffer) => void): Promise<MqttSubscribeRequest>;
    unsubscribe(topic: string): Promise<MqttRequest>;
    disconnect(): Promise<void>;
}
