import type { LogContext } from '@rocicorp/logger';
import { Server } from 'node:http';
import { Socket } from 'node:net';
import { WebSocketServer, type WebSocket, type ServerOptions } from 'ws';
import { type IncomingMessageSubset } from './http.ts';
import { MESSAGE_TYPES, type Receiver, type Sender, type Worker } from './processes.ts';
export type HandoffSpec<P> = {
    payload: P;
    sender: Sender;
};
/**
 * The WebSocketHandoff is a function that either returns the payload and
 * receiver, or invokes the specified `callback` with the payload and
 * receiver. It must not do both.
 *
 * Similarly, an error can be handled by throwing synchronously from the
 * function, or invoking the `onerror` callback.
 */
export type WebSocketHandoff<P> = (message: IncomingMessageSubset, callback: (h: HandoffSpec<P>) => void, onerror: (reason: unknown) => void) => HandoffSpec<P> | void;
export type WebSocketReceiver<P> = (ws: WebSocket, payload: P, msg: IncomingMessageSubset) => void;
export type WebSocketHandoffHandler = (message: IncomingMessageSubset, socket: Socket, head: Buffer) => void;
/**
 * Installs websocket handoff logic from either an http.Server
 * receiving requests, or a parent Worker process
 * that is handing off requests to this process.
 */
export declare function createWebSocketHandoffHandler<P>(lc: LogContext, handoff: WebSocketHandoff<P>, serverOptions?: ServerOptions): WebSocketHandoffHandler;
/**
 * Installs websocket handoff logic from either an http.Server
 * receiving requests, or a parent Worker process
 * that is handing off requests to this process.
 */
export declare function installWebSocketHandoff<P>(lc: LogContext, handoff: WebSocketHandoff<P>, source: Server | Worker, serverOptions?: ServerOptions): void;
export declare function installWebSocketReceiver<P>(lc: LogContext, server: WebSocketServer, receive: WebSocketReceiver<P>, receiver: Receiver): void;
export type Handoff<P> = [
    typeof MESSAGE_TYPES.handoff,
    {
        message: IncomingMessageSubset;
        head: ArrayBuffer;
        payload: P;
    }
];
//# sourceMappingURL=websocket-handoff.d.ts.map