import type express from 'express'; import * as matchMaker from './MatchMaker.ts'; import { RegisteredHandler } from './matchmaker/RegisteredHandler.ts'; import { type OnCreateOptions, Room } from './Room.ts'; import { Deferred, type Type } from './utils/Utils.ts'; import type { Presence } from "./presence/Presence.ts"; import { Transport } from './Transport.ts'; import { type Router } from './router/index.ts'; import { type SDKTypes as SharedSDKTypes } from '@colyseus/shared-types'; export type ServerOptions = { publicAddress?: string; presence?: Presence; driver?: matchMaker.MatchMakerDriver; transport?: Transport; gracefullyShutdown?: boolean; logger?: any; /** * Optional callback to execute before the server listens. * This is useful for example to connect into a database or other services before the server listens. */ beforeListen?: () => Promise | void; /** * Optional callback to configure Express routes. * When provided, the transport layer will initialize an Express-compatible app * and pass it to this callback for custom route configuration. * * For uWebSockets transport, this uses the uwebsockets-express module. */ express?: (app: express.Application) => Promise | void; /** * Custom function to determine which process should handle room creation. * Default: assign new rooms the process with least amount of rooms created */ selectProcessIdToCreateRoom?: matchMaker.SelectProcessIdCallback; /** * Whether this process is running as a standalone match-maker or not. (default: false) * When enabled, this process will not spawn rooms and will only be responsible for matchmaking. */ isStandaloneMatchMaker?: boolean; /** * If enabled, rooms are going to be restored in the server-side upon restart, * clients are going to automatically re-connect when server reboots. * * Beware of "schema mismatch" issues. When updating Schema structures and * reloading existing data, you may see "schema mismatch" errors in the * client-side. * * (This operation is costly and should not be used in a production * environment) */ devMode?: boolean; /** * Display greeting message on server start. * Default: true */ greet?: boolean; }; /** * Exposed types for the client-side SDK. * Re-exported from @colyseus/shared-types with specific type constraints. */ export interface SDKTypes = any, Routes extends Router = any> extends SharedSDKTypes { } export declare class Server = any, Routes extends Router = any> implements SDKTypes { '~rooms': RoomTypes; '~routes': Routes; transport: Transport; router: Routes; options: ServerOptions; protected presence: Presence; protected driver: matchMaker.MatchMakerDriver; protected port: number | string; protected greet: boolean; protected _onTransportReady: Deferred; private _originalRoomOnMessage; constructor(options?: ServerOptions); attach(options: ServerOptions): Promise; /** * Bind the server into the port specified. * * @param port - Port number or Unix socket path * @param hostname * @param backlog * @param listeningListener */ listen(port: number | string, hostname?: string, backlog?: number, listeningListener?: Function): Promise; /** * Define a new type of room for matchmaking. * * @param name public room identifier for match-making. * @param roomClass Room class definition * @param defaultOptions default options for `onCreate` */ define>(roomClass: T, defaultOptions?: OnCreateOptions): RegisteredHandler; define>(name: string, roomClass: T, defaultOptions?: OnCreateOptions): RegisteredHandler; /** * Remove a room definition from matchmaking. * This method does not destroy any room. It only dissallows matchmaking */ removeRoomType(name: string): void; gracefullyShutdown(exit?: boolean, err?: Error): Promise; /** * Add simulated latency between client and server. * @param milliseconds round trip latency in milliseconds. */ simulateLatency(milliseconds: number): void; /** * Register a callback that is going to be executed before the server shuts down. * @param callback */ onShutdown(callback: () => void | Promise): void; onBeforeShutdown(callback: () => void | Promise): void; protected getDefaultTransport(options: any): Promise; protected onShutdownCallback: () => void | Promise; protected onBeforeShutdownCallback: () => void | Promise; } export type RoomDefinitions = Record>; export declare function registerRoomDefinitions(rooms: T): string[]; export declare function unregisterRoomDefinitions(roomNames: Iterable): void; export type DefineServerOptions, R extends Router> = ServerOptions & { rooms: T; routes?: R; }; export declare function defineServer, R extends Router>(options: DefineServerOptions): Server; export declare function defineRoom>(roomKlass: T, defaultOptions?: Parameters['onCreate']>>[0]): RegisteredHandler>;