import { EventEmitter } from 'events';
import * as protobuf from 'protobufjs/minimal';
import { sesame } from './proto/api';
import { SesameConnection } from './sesame-connection';
export interface IProtobufType {
    encode(message: any, writer?: protobuf.Writer): protobuf.Writer;
    decode(reader: (protobuf.Reader | Uint8Array), length?: number): any;
    toObject(message: any, options?: protobuf.IConversionOptions): {
        [k: string]: any;
    };
}
/**
 * RPC Client options
 */
export interface IClientOptions {
    /**
     * Event names to protobuf types, any event assigned a type will have
     * its payload decoded before the event is posted.
     */
    eventTypes?: {
        [topic: number]: IProtobufType;
    };
    /**
     * How long in milliseconds before a message times out, set to `0` to disable.
     * Default = `5 * 1000`.
     */
    sendTimeout?: number;
}
/**
 * RPC Client events
 * -----------------
 */
export interface IClientEvents {
    /**
     * Emitted when the connection closes/opens.
     */
    on(event: 'open' | 'close', listener: () => void): this;
    /**
     * Emitted on error, throws if there is no listener.
     */
    on(event: 'error', listener: (error: Error) => void): this;
    /**
     * RPC event sent by the server. If the event topic is given a type
     * constructor in {@link IClientOptions.eventTypes} the data will
     * be decoded before the event is emitted.
     */
    on(event: 'event', listener: (topic: sesame.v1.common.EventTopic, data?: Uint8Array | {
        [k: string]: any;
    }) => void): this;
}
/**
 * RPC Client
 * ----------
 * Can be used in both node.js and the browser. Also see {@link IClientOptions}.
 */
export declare class RPCClient<T extends protobuf.rpc.Service> extends EventEmitter implements IClientEvents {
    /**
     * Client options, *readonly*.
     */
    readonly options: IClientOptions;
    /**
     * The protobuf service instance which holds all the rpc methods defined in your protocol.
     */
    readonly service: T;
    private connection;
    private eventTypes;
    private messageBuffer;
    private nextSeq;
    private sendTimeout;
    /**
     * @param address The address to the {@link Server}, eg `ws://example.com:8042`.
     * @param service The protocol buffer service class to use, an instance of this
     *                will be available as {@link Client.service}.
     */
    constructor(connection: SesameConnection, service: {
        create(rpcImpl: protobuf.RPCImpl): T;
    }, options?: IClientOptions);
    private openHandler;
    private rpcImpl;
    private rpcCallback;
    private writeMessage;
    private flushMessageBuffer;
    private errorHandler;
    private messageHandler;
    private responseHandler;
    private eventHandler;
}
/**
 * Default backoff function.
 * ```min(tries*10^2, 10 seconds)```
 */
//# sourceMappingURL=rpc-client.d.ts.map