import { type InferState, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types'; import { Room } from './Room.ts'; import { SchemaConstructor } from './serializer/SchemaSerializer.ts'; import { HTTP, type FetchFn } from './HTTP.ts'; import { Auth } from './Auth.ts'; export type JoinOptions = any; export type { ISeatReservation }; export interface EndpointSettings { hostname: string; secure: boolean; port?: number; pathname?: string; searchParams?: string; /** @see {@link ClientOptions.protocol} — `"h3"` is experimental. */ protocol?: "ws" | "h3"; } export interface ClientOptions { headers?: { [id: string]: string; }; urlBuilder?: (url: URL) => string; /** * Wire protocol: `"ws"` (WebSocket, the default) or `"h3"` (WebTransport). * * **`"h3"` is experimental.** It is the only protocol with a real * unreliable channel, so it's what `room.input({ mode: "unreliable" })` and * `@unreliable` state fields need to actually ride datagrams — on `"ws"` * that traffic is correct but travels the reliable channel. It needs * `@colyseus/h3-transport` server-side, and WebTransport browser support * (absent in Safari at time of writing). */ protocol?: "ws" | "h3"; fetchFn?: FetchFn; } /** A room listing entry returned by matchmaking queries. */ export interface RoomAvailable { name: string; roomId: string; clients: number; maxClients: number; metadata?: Metadata; } export interface LatencyOptions { /** "ws" for WebSocket, "h3" for WebTransport (default: "ws"). @see {@link ClientOptions.protocol} */ protocol?: "ws" | "h3"; /** Number of pings to send (default: 1). Returns the average latency when > 1. */ pingCount?: number; /** * Milliseconds to wait for the measurement before rejecting (default: 1500). * Bounds unreachable/blackholed endpoints so they can't stall selection. */ timeout?: number; } export declare class ColyseusSDK { static VERSION: string; /** * The HTTP client to make requests to the server. */ http: HTTP; /** * The authentication module to authenticate into requests and rooms. */ auth: Auth; /** * The settings used to connect to the server. */ settings: EndpointSettings; protected urlBuilder: (url: URL) => string; constructor(settings?: string | EndpointSettings, options?: ClientOptions); /** * Select the endpoint with the lowest latency. * @param endpoints Array of endpoints to select from. * @param options Client options. * @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call. * @returns The client with the lowest latency. */ static selectByLatency(endpoints: Array, options?: ClientOptions, latencyOptions?: LatencyOptions): Promise>; joinOrCreate>(roomName: R, options?: Parameters[1], rootSchema?: SchemaConstructor): Promise>; joinOrCreate(roomName: string, options?: Parameters>[1], rootSchema?: SchemaConstructor): Promise>; joinOrCreate(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor): Promise>; create>(roomName: R, options?: Parameters[1], rootSchema?: SchemaConstructor): Promise>; create(roomName: string, options?: Parameters>[1], rootSchema?: SchemaConstructor): Promise>; create(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor): Promise>; join>(roomName: R, options?: Parameters[1], rootSchema?: SchemaConstructor): Promise>; join(roomName: string, options?: Parameters>[1], rootSchema?: SchemaConstructor): Promise>; join(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor): Promise>; joinById>(roomName: R, options?: Parameters[1], rootSchema?: SchemaConstructor): Promise>; joinById(roomId: string, options?: Parameters>[1], rootSchema?: SchemaConstructor): Promise>; joinById(roomId: string, options?: JoinOptions, rootSchema?: SchemaConstructor): Promise>; /** * Re-establish connection with a room this client was previously connected to. * * @param reconnectionToken The `room.reconnectionToken` from previously connected room. * @param rootSchema (optional) Concrete root schema definition * @returns Promise */ reconnect(reconnectionToken: string, roomName?: R): Promise>; reconnect(reconnectionToken: string, rootSchema?: SchemaConstructor): Promise>; reconnect(reconnectionToken: string, rootSchema?: SchemaConstructor): Promise>; consumeSeatReservation(response: ISeatReservation, rootSchema?: SchemaConstructor): Promise>; /** * Create a new connection with the server, and measure the latency. * * Always settles: resolves with the (average) round-trip time, or rejects on * connection error, server-side close before all pongs arrive, or timeout. * * @param options Latency measurement options (protocol, pingCount, timeout). */ getLatency(options?: LatencyOptions): Promise; protected createMatchMakeRequest(method: string, roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor): Promise>; protected createRoom(roomName: string, rootSchema?: SchemaConstructor): Room; protected buildEndpoint(seatReservation: ISeatReservation, options?: any): string; protected getHttpEndpoint(segments?: string): string; protected getEndpointPort(): string; } export declare const Client: typeof ColyseusSDK; export type Client = InstanceType>;