/// <reference types="node" />
import { NativeResource } from "./native_resource";
import { BufferedEventEmitter } from '../common/event';
import { CrtError } from './error';
import * as io from "./io";
import { HttpProxyOptions, HttpRequest } from './http';
export { HttpProxyOptions } from './http';
import { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill } from "../common/mqtt";
export declare class MqttClient extends NativeResource {
    readonly bootstrap: io.ClientBootstrap;
    constructor(bootstrap: io.ClientBootstrap);
    new_connection(config: MqttConnectionConfig): MqttClientConnection;
}
export interface MqttConnectionConfig {
    client_id: string;
    host_name: string;
    port: number;
    socket_options: io.SocketOptions;
    use_websocket?: boolean;
    clean_session?: boolean;
    keep_alive?: number;
    timeout?: number;
    will?: MqttWill;
    username?: string;
    password?: string;
    tls_ctx?: io.ClientTlsContext;
    proxy_options?: HttpProxyOptions;
    websocket_handshake_transform?: (request: HttpRequest, done: (error_code?: number) => void) => void;
}
declare const MqttClientConnection_base: {
    new (...args: any[]): {
        _handle: any;
        _super(handle: any): void;
        native_handle(): any;
    };
} & typeof BufferedEventEmitter;
export declare class MqttClientConnection extends MqttClientConnection_base {
    readonly client: MqttClient;
    private config;
    readonly tls_ctx?: io.ClientTlsContext;
    constructor(client: MqttClient, config: MqttConnectionConfig);
    private close;
    /** 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 disconnected 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;
    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>;
    private _reject;
    private _on_connection_interrupted;
    private _on_connection_resumed;
    private _on_any_publish;
}
