import { Socket, type Server } from "socket.io"; import { Connection, MaybePromise, Proc } from "../core"; import { ServerConnectionBroadcastOptions } from "../server"; /** * Takes the procedure's input data and a socket object. * The `connection` represents a link to the client. */ export type SocketIOServerProcHandler = (input: I, connection: SocketIOServerConnection) => MaybePromise; interface ConnectionInfo { ws: Socket; } /** * Options passed to the Server constructor. */ export interface SocketIOChatterServerOptions { /** * Called just after the client connects. The return value is set as the `data` field on the connection object. */ getConnectionData?: (info: ConnectionInfo) => Promise; /** * Called just after the connection is initialized, but before it starts receiving events. */ onOpen?: (connection: SocketIOServerConnection) => void | Promise; /** * Called just after the connection is closed. */ onClose?: (connection: SocketIOServerConnection, reason: string) => void | Promise; } export declare function createServer(io: Server, options?: SocketIOChatterServerOptions): SocketIOChatterServer; declare class SocketIOChatterServer { #private; constructor(server: Server, options?: SocketIOChatterServerOptions); /** * Implements a `Proc` so it can be called from the other end of the connection. */ on(proc: Proc, handler: SocketIOServerProcHandler): void; /** * Calls a procedure on all clients subscribed to `topic`. */ broadcast(topic: string, proc: Proc, input?: null): Promise; broadcast(topic: string, proc: Proc, input: I): Promise; /** * Calls a procedure on all clients subscribed to any topic in `topics`. */ broadcast(topics: Iterable, proc: Proc, input?: null): Promise; broadcast(topics: Iterable, proc: Proc, input: I): Promise; } declare class SocketIOServerConnection implements Connection { #private; get data(): ConnectionData; constructor(server: SocketIOChatterServer, socket: Socket); /** * Calls a procedure on the client and returns its response. */ call(proc: Proc): Promise; call(proc: Proc, input: I): Promise; /** * Calls a procedure on all clients subscribed to `topic`. * Excludes this client unless `options.includeSelf` is true. */ broadcast(topic: string, proc: Proc, input?: null, options?: ServerConnectionBroadcastOptions): Promise; broadcast(topic: string, proc: Proc, input: I, options?: ServerConnectionBroadcastOptions): Promise; /** * Calls a procedure on all clients subscribed to any topic in `topics`. * Excludes this client unless `options.includeSelf` is true. */ broadcast(topics: Iterable, proc: Proc, input?: null, options?: ServerConnectionBroadcastOptions): Promise; broadcast(topics: Iterable, proc: Proc, input: I, options?: ServerConnectionBroadcastOptions): Promise; /** * Subscribes this connection to `topic`. */ subscribe(topic: string | Iterable): void; /** * Unsubscribes this connection from `topic`. */ unsubscribe(topic: string | Iterable): void; } export {};