@colyseus/core
Version:
Multiplayer Framework for Node.js.
101 lines (100 loc) • 3.92 kB
TypeScript
import http, { IncomingMessage, ServerResponse } from 'http';
import * as matchMaker from './MatchMaker.js';
import { RegisteredHandler } from './matchmaker/RegisteredHandler.js';
import { Presence } from './presence/Presence.js';
import { Room } from './Room.js';
import { Type } from './utils/types.js';
import { Transport } from './Transport.js';
export type ServerOptions = {
publicAddress?: string;
presence?: Presence;
driver?: matchMaker.MatchMakerDriver;
transport?: Transport;
gracefullyShutdown?: boolean;
logger?: any;
/**
* 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;
/**
* 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;
/**
* Options below are now part of WebSocketTransport (@colyseus/ws-transport)
* TODO: remove me on 0.15.0
*/
/** @deprecated */
pingInterval?: number;
/** @deprecated */
pingMaxRetries?: number;
/** @deprecated */
verifyClient?: any;
/** @deprecated */
server?: http.Server;
};
export declare class Server {
transport: Transport;
protected presence: Presence;
protected driver: matchMaker.MatchMakerDriver;
protected port: number;
protected greet: boolean;
private _originalRoomOnMessage;
constructor(options?: ServerOptions);
attach(options: ServerOptions): void;
/**
* Bind the server into the port specified.
*
* @param port
* @param hostname
* @param backlog
* @param listeningListener
*/
listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Promise<void>;
registerProcessForDiscovery(): Promise<void>;
/**
* 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<T extends Type<Room>>(roomClass: T, defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0]): RegisteredHandler;
define<T extends Type<Room>>(name: string, roomClass: T, defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0]): 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<void>;
/**
* 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<any>): void;
onBeforeShutdown(callback: () => void | Promise<any>): void;
protected getDefaultTransport(_: any): Transport;
protected onShutdownCallback: () => void | Promise<any>;
protected onBeforeShutdownCallback: () => void | Promise<any>;
protected attachMatchMakingRoutes(server: http.Server): void;
protected handleMatchMakeRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
}