import WebSocket from 'ws';
import { Browser } from './browser.js';
import { Target } from './target.js';
import { CdpTargetInfo } from './types.js';
export declare class Connection {
    protected browser: Browser;
    protected sessions: Map<string, Target>;
    protected targetSessions: Map<string, string>;
    protected ws: WebSocket | null;
    protected awaitingCommands: Map<number, CommandHandler>;
    protected nextCommandId: number;
    bytesSent: number;
    bytesReceived: number;
    protected listeners: {
        onMessage: (data: string) => void;
        onClose: () => void;
    };
    constructor(browser: Browser);
    isConnected(): boolean;
    connect(webSocketDebuggerUrl: string): Promise<void>;
    attachWebSocket(ws: WebSocket): void;
    detachWebSocket(): void;
    disconnect(): void;
    rejectAllForTarget(sessionId: string, errFn: (handler: CommandHandler) => Error): void;
    rejectAll(errFn: (handler: CommandHandler) => Error): void;
    getTarget(sessionId: string): Target;
    refreshTargets(): Promise<void>;
    findTargetById(targetId: string): Target | null;
    protected attachIfNeeded({ targetId, type }: CdpTargetInfo): void;
    protected addSession(sessionId: string, targetInfo: CdpTargetInfo): void;
    protected removeSession(sessionId: string): void;
    sendAndForget(payload: Command): void;
    send(command: Command): Promise<any>;
    attachedTargets(): IterableIterator<Target>;
    protected onClose(): void;
    protected onMessage(data: string): void;
    protected onTargetCreated(params: {
        targetInfo: CdpTargetInfo;
    }): void;
    protected onTargetDestroyed(params: {
        targetId: string;
    }): void;
    protected onAttachedToTarget(params: {
        sessionId: string;
        targetInfo: CdpTargetInfo;
    }): void;
    protected onDetachedFromTarget(params: {
        sessionId: string;
    }): void;
    protected onTargetInfoChanged(params: {
        targetInfo: CdpTargetInfo;
    }): void;
}
interface CommandHandler {
    id: number;
    method: string;
    sessionId?: string;
    params: any;
    resolve(result: any): void;
    reject(err: Error): void;
}
export interface Command {
    method: string;
    params?: any;
    sessionId?: string;
    timeout?: number;
}
export {};
//# sourceMappingURL=connection.d.ts.map