///
import { Disposable } from "@codesandbox/pitcher-common";
import WebSocket from "isomorphic-ws";
export type WebsocketData = string | Uint8Array;
export type DisconnectedEvent = {
code: number;
reason: string;
wasClean: boolean;
};
export declare class WebSocketClient extends Disposable {
private ws;
private bufferQueue;
private pongDetectionTimeout;
private onMessageEmitter;
/**
* Whenever we are disconnected we will create a new WebSocketClient
*/
private onDisconnectedEmitter;
/**
* Whenever the heartbeat is missing. This normally detects a disconnect, but
* there can be other reasons like a slow network or a big pending message causing it
*/
private onMissingHeartbeatEmitter;
private detectDisconnectByPongTimeout;
onMessage: import("@codesandbox/pitcher-common").Event;
onDisconnected: import("@codesandbox/pitcher-common").Event<{
code: number;
wasClean: boolean;
reason: string;
}>;
onMissingHeartbeat: import("@codesandbox/pitcher-common").Event;
lastActivity: number;
constructor(ws: WebSocket);
private isClosingOrClosed;
private emitMessage;
private get pingTimeout();
setPongDetectionTimeout(ms: number): void;
/**
We use "PING" to both keep the session alive, but also detect disconnects. Certain interactions, like
focusing the application should trigger an immediate "ping", which is why this is a public method. An optional
pong timeout can be set. This is useful to detect disconnects faster for example when focusing the application
*/
ping(pongTimeout?: number): void;
send(data: WebsocketData): void;
/**
* Closes the connection, triggering a disconnected event
*/
close(): void;
/**
* Keep connection alive, but do not trigger any events. Used with seamless forking
*/
silence(): void;
dispose(reason?: string): void;
}
export declare const createWebSocketClient: (url: string) => Promise;
//# sourceMappingURL=index.d.ts.map