import type { ConnectionOptions, NatsConnection, Server } from "./core"; import type { Deferred } from "./util"; import type { Transport } from "./transport"; /** * WsSocketFactory is a factory that returns a WebSocket and a boolean * indicating if the connection is encrypted. Client code is responsible * for creating a W3C WebSocket compliant transport. * * @param u the url to connect to * @param opts the connection options * @returns a promise that resolves to a WebSocket and a boolean indicating if * the connection is encrypted */ export type WsSocketFactory = (u: string, opts: ConnectionOptions) => Promise<{ socket: WebSocket; encrypted: boolean; }>; /** * WsConnectionOptions exposes wsconnect specific options not applicable to * other transports. */ export interface WsConnectionOptions extends ConnectionOptions { wsFactory?: WsSocketFactory; } export declare class WsTransport implements Transport { version: string; lang: string; closeError?: Error; connected: boolean; private done; private socket; private options; socketClosed: boolean; encrypted: boolean; peeked: boolean; yields: Uint8Array[]; signal: Deferred; closedNotification: Deferred; constructor(); connect(server: Server, options: WsConnectionOptions): Promise; _cleanup(): void; disconnect(): void; private _closed; get isClosed(): boolean; [Symbol.asyncIterator](): AsyncIterableIterator>; iterate(): AsyncIterableIterator; isEncrypted(): boolean; send(frame: Uint8Array): void; close(err?: Error | undefined): Promise; closed(): Promise; discard(): void; } export declare function wsUrlParseFn(u: string, encrypted?: boolean): string; export declare function wsconnect(opts?: ConnectionOptions | WsConnectionOptions): Promise;