@colyseus/core 0.15.11-alpha.1 → 0.15.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/MatchMaker.d.ts +13 -11
- package/build/MatchMaker.js +53 -66
- package/build/MatchMaker.js.map +2 -2
- package/build/MatchMaker.mjs +52 -62
- package/build/MatchMaker.mjs.map +2 -2
- package/build/Room.d.ts +2 -5
- package/build/Room.js +32 -23
- package/build/Room.js.map +2 -2
- package/build/Room.mjs +32 -23
- package/build/Room.mjs.map +2 -2
- package/build/Server.d.ts +9 -5
- package/build/Server.js +4 -12
- package/build/Server.js.map +2 -2
- package/build/Server.mjs +4 -12
- package/build/Server.mjs.map +2 -2
- package/build/Stats.d.ts +12 -0
- package/build/Stats.js +84 -0
- package/build/Stats.js.map +7 -0
- package/build/Stats.mjs +56 -0
- package/build/Stats.mjs.map +7 -0
- package/build/index.d.ts +4 -4
- package/build/index.js +0 -10
- package/build/index.js.map +2 -2
- package/build/index.mjs +4 -9
- package/build/index.mjs.map +2 -2
- package/build/matchmaker/RegisteredHandler.d.ts +3 -7
- package/build/matchmaker/RegisteredHandler.js +0 -5
- package/build/matchmaker/RegisteredHandler.js.map +2 -2
- package/build/matchmaker/RegisteredHandler.mjs +0 -5
- package/build/matchmaker/RegisteredHandler.mjs.map +2 -2
- package/build/matchmaker/controller.d.ts +1 -3
- package/build/matchmaker/controller.js +3 -6
- package/build/matchmaker/controller.js.map +2 -2
- package/build/matchmaker/controller.mjs +3 -6
- package/build/matchmaker/controller.mjs.map +2 -2
- package/build/matchmaker/driver/index.d.ts +1 -1
- package/build/matchmaker/driver/index.js +2 -13
- package/build/matchmaker/driver/index.js.map +2 -2
- package/build/matchmaker/driver/index.mjs +1 -7
- package/build/matchmaker/driver/index.mjs.map +2 -2
- package/build/matchmaker/driver/interfaces.d.ts +1 -1
- package/build/matchmaker/driver/interfaces.js.map +1 -1
- package/build/utils/types.d.ts +1 -0
- package/build/utils/types.js +15 -0
- package/build/utils/types.js.map +7 -0
- package/build/utils/types.mjs +0 -0
- package/build/utils/types.mjs.map +7 -0
- package/package.json +2 -2
package/build/Server.js
CHANGED
|
@@ -48,7 +48,8 @@ class Server {
|
|
|
48
48
|
matchMaker.setup(
|
|
49
49
|
this.presence,
|
|
50
50
|
this.driver,
|
|
51
|
-
options.publicAddress
|
|
51
|
+
options.publicAddress,
|
|
52
|
+
options.selectProcessIdToCreateRoom
|
|
52
53
|
);
|
|
53
54
|
if (gracefullyShutdown) {
|
|
54
55
|
(0, import_Utils.registerGracefulShutdown)((err) => this.gracefullyShutdown(true, err));
|
|
@@ -104,11 +105,8 @@ class Server {
|
|
|
104
105
|
processId: matchMaker.processId
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
define(
|
|
108
|
-
|
|
109
|
-
const roomClass = typeof nameOrHandler === "string" ? handlerOrOptions : nameOrHandler;
|
|
110
|
-
const options = typeof nameOrHandler === "string" ? defaultOptions : handlerOrOptions;
|
|
111
|
-
return matchMaker.defineRoomType(name, roomClass, options);
|
|
108
|
+
define(name, handler, defaultOptions) {
|
|
109
|
+
return matchMaker.defineRoomType(name, handler, defaultOptions);
|
|
112
110
|
}
|
|
113
111
|
removeRoomType(name) {
|
|
114
112
|
matchMaker.removeRoomType(name);
|
|
@@ -191,12 +189,6 @@ class Server {
|
|
|
191
189
|
res.writeHead(200, headers);
|
|
192
190
|
try {
|
|
193
191
|
const clientOptions = JSON.parse(Buffer.concat(data).toString());
|
|
194
|
-
const roomClass = matchMaker.getRoomClass(roomName);
|
|
195
|
-
if (roomClass["onAuth"] !== import_Room.Room["onAuth"]) {
|
|
196
|
-
const authHeader = req.headers["authorization"];
|
|
197
|
-
const authToken = authHeader && authHeader.startsWith("Bearer ") && authHeader.substring(7, authHeader.length) || void 0;
|
|
198
|
-
clientOptions["$auth"] = await roomClass["onAuth"](authToken, req);
|
|
199
|
-
}
|
|
200
192
|
const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);
|
|
201
193
|
res.write(JSON.stringify(response));
|
|
202
194
|
} catch (e) {
|
package/build/Server.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Server.ts"],
|
|
4
|
-
"sourcesContent": ["import http, { IncomingMessage, ServerResponse } from 'http';\nimport greeting from \"@colyseus/greeting-banner\";\n\nimport { debugAndPrintError, debugMatchMaking } from './Debug';\nimport * as matchMaker from './MatchMaker';\nimport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nimport { Presence } from './presence/Presence';\n\nimport { Room } from './Room';\nimport { Type } from './types';\nimport { registerGracefulShutdown } from './utils/Utils';\n\nimport { registerNode, unregisterNode} from './discovery';\n\nimport { LocalPresence } from './presence/LocalPresence';\nimport { LocalDriver } from './matchmaker/driver';\n\nimport { Transport } from './Transport';\nimport { logger, setLogger } from './Logger';\nimport { setDevMode, isDevMode } from './utils/DevMode';\n\nexport type ServerOptions = {\n publicAddress?: string,\n presence?: Presence,\n driver?: matchMaker.MatchMakerDriver,\n transport?: Transport,\n gracefullyShutdown?: boolean,\n logger?: any;\n\n /**\n * If enabled, rooms are going to be restored in the server-side upon restart,\n * clients are going to automatically re-connect when server reboots.\n *\n * Beware of \"schema mismatch\" issues. When updating Schema structures and\n * reloading existing data, you may see \"schema mismatch\" errors in the\n * client-side.\n *\n * (This operation is costly and should not be used in a production\n * environment)\n */\n devMode?: boolean,\n\n /**\n * Display greeting message on server start.\n * Default: true\n */\n greet?: boolean,\n\n /**\n * Options below are now part of WebSocketTransport (@colyseus/ws-transport)\n * TODO: remove me on 0.15.0\n */\n /** @deprecated */\n pingInterval?: number,\n\n /** @deprecated */\n pingMaxRetries?: number,\n\n /** @deprecated */\n verifyClient?: any,\n\n /** @deprecated */\n server?: http.Server,\n};\n\nexport class Server {\n public transport: Transport;\n\n protected presence: Presence;\n protected driver: matchMaker.MatchMakerDriver;\n\n protected port: number;\n protected greet: boolean;\n\n constructor(options: ServerOptions = {}) {\n const { gracefullyShutdown = true, greet = true } = options;\n\n setDevMode(options.devMode === true);\n\n this.presence = options.presence || new LocalPresence();\n this.driver = options.driver || new LocalDriver();\n this.greet = greet;\n\n this.attach(options);\n\n matchMaker.setup(\n this.presence,\n this.driver,\n options.publicAddress,\n );\n\n if (gracefullyShutdown) {\n registerGracefulShutdown((err) => this.gracefullyShutdown(true, err));\n }\n\n if (options.logger) {\n setLogger(options.logger);\n }\n }\n\n public attach(options: ServerOptions) {\n /**\n * Display deprecation warnings for moved Transport options.\n * TODO: Remove me on 0.15\n */\n if (\n options.pingInterval !== undefined ||\n options.pingMaxRetries !== undefined ||\n options.server !== undefined ||\n options.verifyClient !== undefined\n ) {\n logger.warn(\"DEPRECATION WARNING: 'pingInterval', 'pingMaxRetries', 'server', and 'verifyClient' Server options will be permanently moved to WebSocketTransport on v0.15\");\n logger.warn(`new Server({\n transport: new WebSocketTransport({\n pingInterval: ...,\n pingMaxRetries: ...,\n server: ...,\n verifyClient: ...\n })\n})`);\n logger.warn(\"\uD83D\uDC49 Documentation: https://docs.colyseus.io/server/transport/\")\n }\n\n const transport = options.transport || this.getDefaultTransport(options);\n delete options.transport;\n\n this.transport = transport;\n\n if (this.transport.server) {\n this.transport.server.once('listening', () => this.registerProcessForDiscovery());\n this.attachMatchMakingRoutes(this.transport.server as http.Server);\n }\n }\n\n /**\n * Bind the server into the port specified.\n *\n * @param port\n * @param hostname\n * @param backlog\n * @param listeningListener\n */\n public async listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function) {\n this.port = port;\n\n //\n // Make sure matchmaker is ready before accepting connections\n // (isDevMode: matchmaker may take extra milliseconds to restore the rooms)\n //\n await matchMaker.onReady;\n\n /**\n * Greetings!\n */\n if (this.greet) {\n console.log(greeting);\n }\n\n return new Promise<void>((resolve, reject) => {\n this.transport.server?.on('error', (err) => reject(err));\n this.transport.listen(port, hostname, backlog, (err) => {\n if (listeningListener) {\n listeningListener(err);\n }\n\n if (err) {\n reject(err);\n\n } else {\n resolve();\n }\n });\n });\n }\n\n public async registerProcessForDiscovery() {\n // register node for proxy/service discovery\n await registerNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n }\n\n /**\n * Define a new type of room for matchmaking.\n *\n * @param name public room identifier for match-making.\n * @param roomClass Room class definition\n * @param defaultOptions default options for `onCreate`\n */\n public define<T extends Type<Room>>(\n roomClass: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler\n public define<T extends Type<Room>>(\n name: string,\n roomClass: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler\n public define<T extends Type<Room>>(\n nameOrHandler: string | T,\n handlerOrOptions: T | Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler {\n const name = (typeof(nameOrHandler) === \"string\")\n ? nameOrHandler\n : nameOrHandler.name;\n\n const roomClass = (typeof(nameOrHandler) === \"string\")\n ? handlerOrOptions\n : nameOrHandler;\n\n const options = (typeof(nameOrHandler) === \"string\")\n ? defaultOptions\n : handlerOrOptions;\n\n return matchMaker.defineRoomType(name, roomClass, options);\n }\n\n /**\n * Remove a room definition from matchmaking.\n * This method does not destroy any room. It only dissallows matchmaking\n */\n public removeRoomType(name: string): void {\n matchMaker.removeRoomType(name);\n }\n\n public async gracefullyShutdown(exit: boolean = true, err?: Error) {\n if (matchMaker.isGracefullyShuttingDown) {\n return;\n }\n\n await unregisterNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n\n try {\n await matchMaker.gracefullyShutdown();\n this.transport.shutdown();\n this.presence.shutdown();\n this.driver.shutdown();\n await this.onShutdownCallback();\n\n } catch (e) {\n debugAndPrintError(`error during shutdown: ${e}`);\n\n } finally {\n if (exit) {\n process.exit((err && !isDevMode) ? 1 : 0);\n }\n }\n }\n\n /**\n * Add simulated latency between client and server.\n * @param milliseconds round trip latency in milliseconds.\n */\n public simulateLatency(milliseconds: number) {\n logger.warn(`\uD83D\uDCF6\uFE0F\u2757 Colyseus latency simulation enabled \u2192 ${milliseconds}ms latency for round trip.`);\n\n const halfwayMS = (milliseconds / 2);\n this.transport.simulateLatency(halfwayMS);\n\n /* tslint:disable:no-string-literal */\n const _onMessage = Room.prototype['_onMessage'];\n /* tslint:disable:no-string-literal */\n Room.prototype['_onMessage'] = function (client, buffer) {\n // uWebSockets.js: duplicate buffer because it is cleared at native layer before the timeout.\n const cachedBuffer = Buffer.from(buffer);\n setTimeout(() => _onMessage.call(this, client, cachedBuffer), halfwayMS);\n };\n }\n\n /**\n * Register a callback that is going to be executed before the server shuts down.\n * @param callback\n */\n public onShutdown(callback: () => void | Promise<any>) {\n this.onShutdownCallback = callback;\n }\n\n protected getDefaultTransport(_: any): Transport {\n throw new Error(\"Please provide a 'transport' layer. Default transport not set.\");\n }\n\n protected onShutdownCallback: () => void | Promise<any> =\n () => Promise.resolve()\n\n protected attachMatchMakingRoutes(server: http.Server) {\n const listeners = server.listeners('request').slice(0);\n server.removeAllListeners('request');\n\n server.on('request', (req, res) => {\n if (req.url.indexOf(`/${matchMaker.controller.matchmakeRoute}`) !== -1) {\n debugMatchMaking('received matchmake request: %s', req.url);\n this.handleMatchMakeRequest(req, res);\n\n } else {\n for (let i = 0, l = listeners.length; i < l; i++) {\n listeners[i].call(server, req, res);\n }\n }\n });\n }\n\n protected async handleMatchMakeRequest(req: IncomingMessage, res: ServerResponse) {\n // do not accept matchmaking requests if already shutting down\n if (matchMaker.isGracefullyShuttingDown) {\n res.writeHead(503, {});\n res.end();\n return;\n }\n\n const headers = Object.assign(\n {},\n matchMaker.controller.DEFAULT_CORS_HEADERS,\n matchMaker.controller.getCorsHeaders.call(undefined, req)\n );\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204, headers);\n res.end();\n\n } else if (req.method === 'POST') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const matchmakeIndex = matchedParams.indexOf(matchMaker.controller.matchmakeRoute);\n const method = matchedParams[matchmakeIndex + 1];\n const roomName = matchedParams[matchmakeIndex + 2] || '';\n\n const data = [];\n req.on('data', (chunk) => data.push(chunk));\n req.on('end', async () => {\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n\n try {\n const clientOptions = JSON.parse(Buffer.concat(data).toString());\n const roomClass = matchMaker.getRoomClass(roomName);\n\n // check if static onAuth is implemented\n // (default implementation is just to satisfy TypeScript )\n if (roomClass['onAuth'] !== Room['onAuth']) {\n const authHeader = req.headers['authorization'];\n const authToken = (authHeader && authHeader.startsWith(\"Bearer \") && authHeader.substring(7, authHeader.length)) || undefined;\n clientOptions['$auth'] = await roomClass['onAuth'](authToken, req);\n }\n\n const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);\n res.write(JSON.stringify(response));\n\n } catch (e) {\n res.write(JSON.stringify({ code: e.code, error: e.message, }));\n }\n\n res.end();\n });\n\n } else if (req.method === 'GET') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const roomName = matchedParams.length > 1 ? matchedParams[matchedParams.length - 1] : \"\";\n\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n res.write(JSON.stringify(await matchMaker.controller.getAvailableRooms(roomName)));\n res.end();\n }\n\n }\n\n\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAAqB;AAErB,mBAAqD;AACrD,iBAA4B;AAI5B,kBAAqB;AAErB,mBAAyC;AAEzC,uBAA4C;AAE5C,2BAA8B;AAC9B,oBAA4B;AAG5B,oBAAkC;AAClC,qBAAsC;
|
|
4
|
+
"sourcesContent": ["import http, { IncomingMessage, ServerResponse } from 'http';\nimport greeting from \"@colyseus/greeting-banner\";\n\nimport { debugAndPrintError, debugMatchMaking } from './Debug';\nimport * as matchMaker from './MatchMaker';\nimport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nimport { Presence } from './presence/Presence';\n\nimport { Room } from './Room';\nimport { Type } from './utils/types';\nimport { registerGracefulShutdown } from './utils/Utils';\n\nimport { registerNode, unregisterNode} from './discovery';\n\nimport { LocalPresence } from './presence/LocalPresence';\nimport { LocalDriver } from './matchmaker/driver';\n\nimport { Transport } from './Transport';\nimport { logger, setLogger } from './Logger';\nimport { setDevMode, isDevMode } from './utils/DevMode';\n\n// IServerOptions &\nexport type ServerOptions = {\n publicAddress?: string,\n presence?: Presence,\n driver?: matchMaker.MatchMakerDriver,\n transport?: Transport,\n gracefullyShutdown?: boolean,\n logger?: any;\n\n /**\n * Custom function to determine which process should handle room creation.\n * Default: assign new rooms the process with least amount of rooms created\n */\n selectProcessIdToCreateRoom?: matchMaker.SelectProcessIdCallback;\n\n /**\n * If enabled, rooms are going to be restored in the server-side upon restart,\n * clients are going to automatically re-connect when server reboots.\n *\n * Beware of \"schema mismatch\" issues. When updating Schema structures and\n * reloading existing data, you may see \"schema mismatch\" errors in the\n * client-side.\n *\n * (This operation is costly and should never be used in a production\n * environment)\n */\n devMode?: boolean,\n\n /**\n * Display greeting message on server start.\n * Default: true\n */\n greet?: boolean,\n\n /**\n * Options below are now part of WebSocketTransport (@colyseus/ws-transport)\n * TODO: remove me on 0.15.0\n */\n /** @deprecated */\n pingInterval?: number,\n\n /** @deprecated */\n pingMaxRetries?: number,\n\n /** @deprecated */\n verifyClient?: any,\n\n /** @deprecated */\n server?: http.Server,\n};\n\nexport class Server {\n public transport: Transport;\n\n protected presence: Presence;\n protected driver: matchMaker.MatchMakerDriver;\n\n protected port: number;\n protected greet: boolean;\n\n constructor(options: ServerOptions = {}) {\n const { gracefullyShutdown = true, greet = true } = options;\n\n setDevMode(options.devMode === true);\n\n this.presence = options.presence || new LocalPresence();\n this.driver = options.driver || new LocalDriver();\n this.greet = greet;\n\n this.attach(options);\n\n matchMaker.setup(\n this.presence,\n this.driver,\n options.publicAddress,\n options.selectProcessIdToCreateRoom,\n );\n\n if (gracefullyShutdown) {\n registerGracefulShutdown((err) => this.gracefullyShutdown(true, err));\n }\n\n if (options.logger) {\n setLogger(options.logger);\n }\n }\n\n public attach(options: ServerOptions) {\n /**\n * Display deprecation warnings for moved Transport options.\n * TODO: Remove me on 0.15\n */\n if (\n options.pingInterval !== undefined ||\n options.pingMaxRetries !== undefined ||\n options.server !== undefined ||\n options.verifyClient !== undefined\n ) {\n logger.warn(\"DEPRECATION WARNING: 'pingInterval', 'pingMaxRetries', 'server', and 'verifyClient' Server options will be permanently moved to WebSocketTransport on v0.15\");\n logger.warn(`new Server({\n transport: new WebSocketTransport({\n pingInterval: ...,\n pingMaxRetries: ...,\n server: ...,\n verifyClient: ...\n })\n})`);\n logger.warn(\"\uD83D\uDC49 Documentation: https://docs.colyseus.io/server/transport/\")\n }\n\n const transport = options.transport || this.getDefaultTransport(options);\n delete options.transport;\n\n this.transport = transport;\n\n if (this.transport.server) {\n this.transport.server.once('listening', () => this.registerProcessForDiscovery());\n this.attachMatchMakingRoutes(this.transport.server as http.Server);\n }\n }\n\n /**\n * Bind the server into the port specified.\n *\n * @param port\n * @param hostname\n * @param backlog\n * @param listeningListener\n */\n public async listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function) {\n this.port = port;\n\n //\n // Make sure matchmaker is ready before accepting connections\n // (isDevMode: matchmaker may take extra milliseconds to restore the rooms)\n //\n await matchMaker.onReady;\n\n /**\n * Greetings!\n */\n if (this.greet) {\n console.log(greeting);\n }\n\n return new Promise<void>((resolve, reject) => {\n this.transport.server?.on('error', (err) => reject(err));\n this.transport.listen(port, hostname, backlog, (err) => {\n if (listeningListener) {\n listeningListener(err);\n }\n\n if (err) {\n reject(err);\n\n } else {\n resolve();\n }\n });\n });\n }\n\n public async registerProcessForDiscovery() {\n // register node for proxy/service discovery\n await registerNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n }\n\n /**\n * Define a new type of room for matchmaking.\n *\n * @param name public room identifier for match-making.\n * @param handler Room class definition\n * @param defaultOptions default options for `onCreate`\n */\n public define<T extends Type<Room>>(\n name: string,\n handler: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler {\n return matchMaker.defineRoomType(name, handler, defaultOptions);\n }\n\n /**\n * Remove a room definition from matchmaking.\n * This method does not destroy any room. It only dissallows matchmaking\n */\n public removeRoomType(name: string): void {\n matchMaker.removeRoomType(name);\n }\n\n public async gracefullyShutdown(exit: boolean = true, err?: Error) {\n if (matchMaker.isGracefullyShuttingDown) {\n return;\n }\n\n await unregisterNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n\n try {\n await matchMaker.gracefullyShutdown();\n this.transport.shutdown();\n this.presence.shutdown();\n this.driver.shutdown();\n await this.onShutdownCallback();\n\n } catch (e) {\n debugAndPrintError(`error during shutdown: ${e}`);\n\n } finally {\n if (exit) {\n process.exit((err && !isDevMode) ? 1 : 0);\n }\n }\n }\n\n /**\n * Add simulated latency between client and server.\n * @param milliseconds round trip latency in milliseconds.\n */\n public simulateLatency(milliseconds: number) {\n logger.warn(`\uD83D\uDCF6\uFE0F\u2757 Colyseus latency simulation enabled \u2192 ${milliseconds}ms latency for round trip.`);\n\n const halfwayMS = (milliseconds / 2);\n this.transport.simulateLatency(halfwayMS);\n\n /* tslint:disable:no-string-literal */\n const _onMessage = Room.prototype['_onMessage'];\n /* tslint:disable:no-string-literal */\n Room.prototype['_onMessage'] = function (client, buffer) {\n // uWebSockets.js: duplicate buffer because it is cleared at native layer before the timeout.\n const cachedBuffer = Buffer.from(buffer);\n setTimeout(() => _onMessage.call(this, client, cachedBuffer), halfwayMS);\n };\n }\n\n /**\n * Register a callback that is going to be executed before the server shuts down.\n * @param callback\n */\n public onShutdown(callback: () => void | Promise<any>) {\n this.onShutdownCallback = callback;\n }\n\n protected getDefaultTransport(_: any): Transport {\n throw new Error(\"Please provide a 'transport' layer. Default transport not set.\");\n }\n\n protected onShutdownCallback: () => void | Promise<any> =\n () => Promise.resolve()\n\n protected attachMatchMakingRoutes(server: http.Server) {\n const listeners = server.listeners('request').slice(0);\n server.removeAllListeners('request');\n\n server.on('request', (req, res) => {\n if (req.url.indexOf(`/${matchMaker.controller.matchmakeRoute}`) !== -1) {\n debugMatchMaking('received matchmake request: %s', req.url);\n this.handleMatchMakeRequest(req, res);\n\n } else {\n for (let i = 0, l = listeners.length; i < l; i++) {\n listeners[i].call(server, req, res);\n }\n }\n });\n }\n\n protected async handleMatchMakeRequest(req: IncomingMessage, res: ServerResponse) {\n // do not accept matchmaking requests if already shutting down\n if (matchMaker.isGracefullyShuttingDown) {\n res.writeHead(503, {});\n res.end();\n return;\n }\n\n const headers = Object.assign(\n {},\n matchMaker.controller.DEFAULT_CORS_HEADERS,\n matchMaker.controller.getCorsHeaders.call(undefined, req)\n );\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204, headers);\n res.end();\n\n } else if (req.method === 'POST') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const matchmakeIndex = matchedParams.indexOf(matchMaker.controller.matchmakeRoute);\n const method = matchedParams[matchmakeIndex + 1];\n const roomName = matchedParams[matchmakeIndex + 2] || '';\n\n const data = [];\n req.on('data', (chunk) => data.push(chunk));\n req.on('end', async () => {\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n\n try {\n const clientOptions = JSON.parse(Buffer.concat(data).toString());\n const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);\n res.write(JSON.stringify(response));\n\n } catch (e) {\n res.write(JSON.stringify({ code: e.code, error: e.message, }));\n }\n\n res.end();\n });\n\n } else if (req.method === 'GET') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const roomName = matchedParams.length > 1 ? matchedParams[matchedParams.length - 1] : \"\";\n\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n res.write(JSON.stringify(await matchMaker.controller.getAvailableRooms(roomName)));\n res.end();\n }\n\n }\n\n\n}\n"],
|
|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AAGF;",
|
|
6
6
|
"names": ["greeting"]
|
|
7
7
|
}
|
package/build/Server.mjs
CHANGED
|
@@ -20,7 +20,8 @@ class Server {
|
|
|
20
20
|
matchMaker.setup(
|
|
21
21
|
this.presence,
|
|
22
22
|
this.driver,
|
|
23
|
-
options.publicAddress
|
|
23
|
+
options.publicAddress,
|
|
24
|
+
options.selectProcessIdToCreateRoom
|
|
24
25
|
);
|
|
25
26
|
if (gracefullyShutdown) {
|
|
26
27
|
registerGracefulShutdown((err) => this.gracefullyShutdown(true, err));
|
|
@@ -76,11 +77,8 @@ class Server {
|
|
|
76
77
|
processId: matchMaker.processId
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
define(
|
|
80
|
-
|
|
81
|
-
const roomClass = typeof nameOrHandler === "string" ? handlerOrOptions : nameOrHandler;
|
|
82
|
-
const options = typeof nameOrHandler === "string" ? defaultOptions : handlerOrOptions;
|
|
83
|
-
return matchMaker.defineRoomType(name, roomClass, options);
|
|
80
|
+
define(name, handler, defaultOptions) {
|
|
81
|
+
return matchMaker.defineRoomType(name, handler, defaultOptions);
|
|
84
82
|
}
|
|
85
83
|
removeRoomType(name) {
|
|
86
84
|
matchMaker.removeRoomType(name);
|
|
@@ -163,12 +161,6 @@ class Server {
|
|
|
163
161
|
res.writeHead(200, headers);
|
|
164
162
|
try {
|
|
165
163
|
const clientOptions = JSON.parse(Buffer.concat(data).toString());
|
|
166
|
-
const roomClass = matchMaker.getRoomClass(roomName);
|
|
167
|
-
if (roomClass["onAuth"] !== Room["onAuth"]) {
|
|
168
|
-
const authHeader = req.headers["authorization"];
|
|
169
|
-
const authToken = authHeader && authHeader.startsWith("Bearer ") && authHeader.substring(7, authHeader.length) || void 0;
|
|
170
|
-
clientOptions["$auth"] = await roomClass["onAuth"](authToken, req);
|
|
171
|
-
}
|
|
172
164
|
const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);
|
|
173
165
|
res.write(JSON.stringify(response));
|
|
174
166
|
} catch (e) {
|
package/build/Server.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Server.ts"],
|
|
4
|
-
"sourcesContent": ["import http, { IncomingMessage, ServerResponse } from 'http';\nimport greeting from \"@colyseus/greeting-banner\";\n\nimport { debugAndPrintError, debugMatchMaking } from './Debug';\nimport * as matchMaker from './MatchMaker';\nimport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nimport { Presence } from './presence/Presence';\n\nimport { Room } from './Room';\nimport { Type } from './types';\nimport { registerGracefulShutdown } from './utils/Utils';\n\nimport { registerNode, unregisterNode} from './discovery';\n\nimport { LocalPresence } from './presence/LocalPresence';\nimport { LocalDriver } from './matchmaker/driver';\n\nimport { Transport } from './Transport';\nimport { logger, setLogger } from './Logger';\nimport { setDevMode, isDevMode } from './utils/DevMode';\n\nexport type ServerOptions = {\n publicAddress?: string,\n presence?: Presence,\n driver?: matchMaker.MatchMakerDriver,\n transport?: Transport,\n gracefullyShutdown?: boolean,\n logger?: any;\n\n /**\n * If enabled, rooms are going to be restored in the server-side upon restart,\n * clients are going to automatically re-connect when server reboots.\n *\n * Beware of \"schema mismatch\" issues. When updating Schema structures and\n * reloading existing data, you may see \"schema mismatch\" errors in the\n * client-side.\n *\n * (This operation is costly and should not be used in a production\n * environment)\n */\n devMode?: boolean,\n\n /**\n * Display greeting message on server start.\n * Default: true\n */\n greet?: boolean,\n\n /**\n * Options below are now part of WebSocketTransport (@colyseus/ws-transport)\n * TODO: remove me on 0.15.0\n */\n /** @deprecated */\n pingInterval?: number,\n\n /** @deprecated */\n pingMaxRetries?: number,\n\n /** @deprecated */\n verifyClient?: any,\n\n /** @deprecated */\n server?: http.Server,\n};\n\nexport class Server {\n public transport: Transport;\n\n protected presence: Presence;\n protected driver: matchMaker.MatchMakerDriver;\n\n protected port: number;\n protected greet: boolean;\n\n constructor(options: ServerOptions = {}) {\n const { gracefullyShutdown = true, greet = true } = options;\n\n setDevMode(options.devMode === true);\n\n this.presence = options.presence || new LocalPresence();\n this.driver = options.driver || new LocalDriver();\n this.greet = greet;\n\n this.attach(options);\n\n matchMaker.setup(\n this.presence,\n this.driver,\n options.publicAddress,\n );\n\n if (gracefullyShutdown) {\n registerGracefulShutdown((err) => this.gracefullyShutdown(true, err));\n }\n\n if (options.logger) {\n setLogger(options.logger);\n }\n }\n\n public attach(options: ServerOptions) {\n /**\n * Display deprecation warnings for moved Transport options.\n * TODO: Remove me on 0.15\n */\n if (\n options.pingInterval !== undefined ||\n options.pingMaxRetries !== undefined ||\n options.server !== undefined ||\n options.verifyClient !== undefined\n ) {\n logger.warn(\"DEPRECATION WARNING: 'pingInterval', 'pingMaxRetries', 'server', and 'verifyClient' Server options will be permanently moved to WebSocketTransport on v0.15\");\n logger.warn(`new Server({\n transport: new WebSocketTransport({\n pingInterval: ...,\n pingMaxRetries: ...,\n server: ...,\n verifyClient: ...\n })\n})`);\n logger.warn(\"\uD83D\uDC49 Documentation: https://docs.colyseus.io/server/transport/\")\n }\n\n const transport = options.transport || this.getDefaultTransport(options);\n delete options.transport;\n\n this.transport = transport;\n\n if (this.transport.server) {\n this.transport.server.once('listening', () => this.registerProcessForDiscovery());\n this.attachMatchMakingRoutes(this.transport.server as http.Server);\n }\n }\n\n /**\n * Bind the server into the port specified.\n *\n * @param port\n * @param hostname\n * @param backlog\n * @param listeningListener\n */\n public async listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function) {\n this.port = port;\n\n //\n // Make sure matchmaker is ready before accepting connections\n // (isDevMode: matchmaker may take extra milliseconds to restore the rooms)\n //\n await matchMaker.onReady;\n\n /**\n * Greetings!\n */\n if (this.greet) {\n console.log(greeting);\n }\n\n return new Promise<void>((resolve, reject) => {\n this.transport.server?.on('error', (err) => reject(err));\n this.transport.listen(port, hostname, backlog, (err) => {\n if (listeningListener) {\n listeningListener(err);\n }\n\n if (err) {\n reject(err);\n\n } else {\n resolve();\n }\n });\n });\n }\n\n public async registerProcessForDiscovery() {\n // register node for proxy/service discovery\n await registerNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n }\n\n /**\n * Define a new type of room for matchmaking.\n *\n * @param name public room identifier for match-making.\n * @param roomClass Room class definition\n * @param defaultOptions default options for `onCreate`\n */\n public define<T extends Type<Room>>(\n roomClass: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler\n public define<T extends Type<Room>>(\n name: string,\n roomClass: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler\n public define<T extends Type<Room>>(\n nameOrHandler: string | T,\n handlerOrOptions: T | Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler {\n const name = (typeof(nameOrHandler) === \"string\")\n ? nameOrHandler\n : nameOrHandler.name;\n\n const roomClass = (typeof(nameOrHandler) === \"string\")\n ? handlerOrOptions\n : nameOrHandler;\n\n const options = (typeof(nameOrHandler) === \"string\")\n ? defaultOptions\n : handlerOrOptions;\n\n return matchMaker.defineRoomType(name, roomClass, options);\n }\n\n /**\n * Remove a room definition from matchmaking.\n * This method does not destroy any room. It only dissallows matchmaking\n */\n public removeRoomType(name: string): void {\n matchMaker.removeRoomType(name);\n }\n\n public async gracefullyShutdown(exit: boolean = true, err?: Error) {\n if (matchMaker.isGracefullyShuttingDown) {\n return;\n }\n\n await unregisterNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n\n try {\n await matchMaker.gracefullyShutdown();\n this.transport.shutdown();\n this.presence.shutdown();\n this.driver.shutdown();\n await this.onShutdownCallback();\n\n } catch (e) {\n debugAndPrintError(`error during shutdown: ${e}`);\n\n } finally {\n if (exit) {\n process.exit((err && !isDevMode) ? 1 : 0);\n }\n }\n }\n\n /**\n * Add simulated latency between client and server.\n * @param milliseconds round trip latency in milliseconds.\n */\n public simulateLatency(milliseconds: number) {\n logger.warn(`\uD83D\uDCF6\uFE0F\u2757 Colyseus latency simulation enabled \u2192 ${milliseconds}ms latency for round trip.`);\n\n const halfwayMS = (milliseconds / 2);\n this.transport.simulateLatency(halfwayMS);\n\n /* tslint:disable:no-string-literal */\n const _onMessage = Room.prototype['_onMessage'];\n /* tslint:disable:no-string-literal */\n Room.prototype['_onMessage'] = function (client, buffer) {\n // uWebSockets.js: duplicate buffer because it is cleared at native layer before the timeout.\n const cachedBuffer = Buffer.from(buffer);\n setTimeout(() => _onMessage.call(this, client, cachedBuffer), halfwayMS);\n };\n }\n\n /**\n * Register a callback that is going to be executed before the server shuts down.\n * @param callback\n */\n public onShutdown(callback: () => void | Promise<any>) {\n this.onShutdownCallback = callback;\n }\n\n protected getDefaultTransport(_: any): Transport {\n throw new Error(\"Please provide a 'transport' layer. Default transport not set.\");\n }\n\n protected onShutdownCallback: () => void | Promise<any> =\n () => Promise.resolve()\n\n protected attachMatchMakingRoutes(server: http.Server) {\n const listeners = server.listeners('request').slice(0);\n server.removeAllListeners('request');\n\n server.on('request', (req, res) => {\n if (req.url.indexOf(`/${matchMaker.controller.matchmakeRoute}`) !== -1) {\n debugMatchMaking('received matchmake request: %s', req.url);\n this.handleMatchMakeRequest(req, res);\n\n } else {\n for (let i = 0, l = listeners.length; i < l; i++) {\n listeners[i].call(server, req, res);\n }\n }\n });\n }\n\n protected async handleMatchMakeRequest(req: IncomingMessage, res: ServerResponse) {\n // do not accept matchmaking requests if already shutting down\n if (matchMaker.isGracefullyShuttingDown) {\n res.writeHead(503, {});\n res.end();\n return;\n }\n\n const headers = Object.assign(\n {},\n matchMaker.controller.DEFAULT_CORS_HEADERS,\n matchMaker.controller.getCorsHeaders.call(undefined, req)\n );\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204, headers);\n res.end();\n\n } else if (req.method === 'POST') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const matchmakeIndex = matchedParams.indexOf(matchMaker.controller.matchmakeRoute);\n const method = matchedParams[matchmakeIndex + 1];\n const roomName = matchedParams[matchmakeIndex + 2] || '';\n\n const data = [];\n req.on('data', (chunk) => data.push(chunk));\n req.on('end', async () => {\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n\n try {\n const clientOptions = JSON.parse(Buffer.concat(data).toString());\n const roomClass = matchMaker.getRoomClass(roomName);\n\n // check if static onAuth is implemented\n // (default implementation is just to satisfy TypeScript )\n if (roomClass['onAuth'] !== Room['onAuth']) {\n const authHeader = req.headers['authorization'];\n const authToken = (authHeader && authHeader.startsWith(\"Bearer \") && authHeader.substring(7, authHeader.length)) || undefined;\n clientOptions['$auth'] = await roomClass['onAuth'](authToken, req);\n }\n\n const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);\n res.write(JSON.stringify(response));\n\n } catch (e) {\n res.write(JSON.stringify({ code: e.code, error: e.message, }));\n }\n\n res.end();\n });\n\n } else if (req.method === 'GET') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const roomName = matchedParams.length > 1 ? matchedParams[matchedParams.length - 1] : \"\";\n\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n res.write(JSON.stringify(await matchMaker.controller.getAvailableRooms(roomName)));\n res.end();\n }\n\n }\n\n\n}\n"],
|
|
5
|
-
"mappings": "AACA,OAAO,cAAc;AAErB,SAAS,oBAAoB,wBAAwB;AACrD,YAAY,gBAAgB;AAI5B,SAAS,YAAY;AAErB,SAAS,gCAAgC;AAEzC,SAAS,cAAc,sBAAqB;AAE5C,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAG5B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import http, { IncomingMessage, ServerResponse } from 'http';\nimport greeting from \"@colyseus/greeting-banner\";\n\nimport { debugAndPrintError, debugMatchMaking } from './Debug';\nimport * as matchMaker from './MatchMaker';\nimport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nimport { Presence } from './presence/Presence';\n\nimport { Room } from './Room';\nimport { Type } from './utils/types';\nimport { registerGracefulShutdown } from './utils/Utils';\n\nimport { registerNode, unregisterNode} from './discovery';\n\nimport { LocalPresence } from './presence/LocalPresence';\nimport { LocalDriver } from './matchmaker/driver';\n\nimport { Transport } from './Transport';\nimport { logger, setLogger } from './Logger';\nimport { setDevMode, isDevMode } from './utils/DevMode';\n\n// IServerOptions &\nexport type ServerOptions = {\n publicAddress?: string,\n presence?: Presence,\n driver?: matchMaker.MatchMakerDriver,\n transport?: Transport,\n gracefullyShutdown?: boolean,\n logger?: any;\n\n /**\n * Custom function to determine which process should handle room creation.\n * Default: assign new rooms the process with least amount of rooms created\n */\n selectProcessIdToCreateRoom?: matchMaker.SelectProcessIdCallback;\n\n /**\n * If enabled, rooms are going to be restored in the server-side upon restart,\n * clients are going to automatically re-connect when server reboots.\n *\n * Beware of \"schema mismatch\" issues. When updating Schema structures and\n * reloading existing data, you may see \"schema mismatch\" errors in the\n * client-side.\n *\n * (This operation is costly and should never be used in a production\n * environment)\n */\n devMode?: boolean,\n\n /**\n * Display greeting message on server start.\n * Default: true\n */\n greet?: boolean,\n\n /**\n * Options below are now part of WebSocketTransport (@colyseus/ws-transport)\n * TODO: remove me on 0.15.0\n */\n /** @deprecated */\n pingInterval?: number,\n\n /** @deprecated */\n pingMaxRetries?: number,\n\n /** @deprecated */\n verifyClient?: any,\n\n /** @deprecated */\n server?: http.Server,\n};\n\nexport class Server {\n public transport: Transport;\n\n protected presence: Presence;\n protected driver: matchMaker.MatchMakerDriver;\n\n protected port: number;\n protected greet: boolean;\n\n constructor(options: ServerOptions = {}) {\n const { gracefullyShutdown = true, greet = true } = options;\n\n setDevMode(options.devMode === true);\n\n this.presence = options.presence || new LocalPresence();\n this.driver = options.driver || new LocalDriver();\n this.greet = greet;\n\n this.attach(options);\n\n matchMaker.setup(\n this.presence,\n this.driver,\n options.publicAddress,\n options.selectProcessIdToCreateRoom,\n );\n\n if (gracefullyShutdown) {\n registerGracefulShutdown((err) => this.gracefullyShutdown(true, err));\n }\n\n if (options.logger) {\n setLogger(options.logger);\n }\n }\n\n public attach(options: ServerOptions) {\n /**\n * Display deprecation warnings for moved Transport options.\n * TODO: Remove me on 0.15\n */\n if (\n options.pingInterval !== undefined ||\n options.pingMaxRetries !== undefined ||\n options.server !== undefined ||\n options.verifyClient !== undefined\n ) {\n logger.warn(\"DEPRECATION WARNING: 'pingInterval', 'pingMaxRetries', 'server', and 'verifyClient' Server options will be permanently moved to WebSocketTransport on v0.15\");\n logger.warn(`new Server({\n transport: new WebSocketTransport({\n pingInterval: ...,\n pingMaxRetries: ...,\n server: ...,\n verifyClient: ...\n })\n})`);\n logger.warn(\"\uD83D\uDC49 Documentation: https://docs.colyseus.io/server/transport/\")\n }\n\n const transport = options.transport || this.getDefaultTransport(options);\n delete options.transport;\n\n this.transport = transport;\n\n if (this.transport.server) {\n this.transport.server.once('listening', () => this.registerProcessForDiscovery());\n this.attachMatchMakingRoutes(this.transport.server as http.Server);\n }\n }\n\n /**\n * Bind the server into the port specified.\n *\n * @param port\n * @param hostname\n * @param backlog\n * @param listeningListener\n */\n public async listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function) {\n this.port = port;\n\n //\n // Make sure matchmaker is ready before accepting connections\n // (isDevMode: matchmaker may take extra milliseconds to restore the rooms)\n //\n await matchMaker.onReady;\n\n /**\n * Greetings!\n */\n if (this.greet) {\n console.log(greeting);\n }\n\n return new Promise<void>((resolve, reject) => {\n this.transport.server?.on('error', (err) => reject(err));\n this.transport.listen(port, hostname, backlog, (err) => {\n if (listeningListener) {\n listeningListener(err);\n }\n\n if (err) {\n reject(err);\n\n } else {\n resolve();\n }\n });\n });\n }\n\n public async registerProcessForDiscovery() {\n // register node for proxy/service discovery\n await registerNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n }\n\n /**\n * Define a new type of room for matchmaking.\n *\n * @param name public room identifier for match-making.\n * @param handler Room class definition\n * @param defaultOptions default options for `onCreate`\n */\n public define<T extends Type<Room>>(\n name: string,\n handler: T,\n defaultOptions?: Parameters<NonNullable<InstanceType<T>['onCreate']>>[0],\n ): RegisteredHandler {\n return matchMaker.defineRoomType(name, handler, defaultOptions);\n }\n\n /**\n * Remove a room definition from matchmaking.\n * This method does not destroy any room. It only dissallows matchmaking\n */\n public removeRoomType(name: string): void {\n matchMaker.removeRoomType(name);\n }\n\n public async gracefullyShutdown(exit: boolean = true, err?: Error) {\n if (matchMaker.isGracefullyShuttingDown) {\n return;\n }\n\n await unregisterNode(this.presence, {\n port: this.port,\n processId: matchMaker.processId,\n });\n\n try {\n await matchMaker.gracefullyShutdown();\n this.transport.shutdown();\n this.presence.shutdown();\n this.driver.shutdown();\n await this.onShutdownCallback();\n\n } catch (e) {\n debugAndPrintError(`error during shutdown: ${e}`);\n\n } finally {\n if (exit) {\n process.exit((err && !isDevMode) ? 1 : 0);\n }\n }\n }\n\n /**\n * Add simulated latency between client and server.\n * @param milliseconds round trip latency in milliseconds.\n */\n public simulateLatency(milliseconds: number) {\n logger.warn(`\uD83D\uDCF6\uFE0F\u2757 Colyseus latency simulation enabled \u2192 ${milliseconds}ms latency for round trip.`);\n\n const halfwayMS = (milliseconds / 2);\n this.transport.simulateLatency(halfwayMS);\n\n /* tslint:disable:no-string-literal */\n const _onMessage = Room.prototype['_onMessage'];\n /* tslint:disable:no-string-literal */\n Room.prototype['_onMessage'] = function (client, buffer) {\n // uWebSockets.js: duplicate buffer because it is cleared at native layer before the timeout.\n const cachedBuffer = Buffer.from(buffer);\n setTimeout(() => _onMessage.call(this, client, cachedBuffer), halfwayMS);\n };\n }\n\n /**\n * Register a callback that is going to be executed before the server shuts down.\n * @param callback\n */\n public onShutdown(callback: () => void | Promise<any>) {\n this.onShutdownCallback = callback;\n }\n\n protected getDefaultTransport(_: any): Transport {\n throw new Error(\"Please provide a 'transport' layer. Default transport not set.\");\n }\n\n protected onShutdownCallback: () => void | Promise<any> =\n () => Promise.resolve()\n\n protected attachMatchMakingRoutes(server: http.Server) {\n const listeners = server.listeners('request').slice(0);\n server.removeAllListeners('request');\n\n server.on('request', (req, res) => {\n if (req.url.indexOf(`/${matchMaker.controller.matchmakeRoute}`) !== -1) {\n debugMatchMaking('received matchmake request: %s', req.url);\n this.handleMatchMakeRequest(req, res);\n\n } else {\n for (let i = 0, l = listeners.length; i < l; i++) {\n listeners[i].call(server, req, res);\n }\n }\n });\n }\n\n protected async handleMatchMakeRequest(req: IncomingMessage, res: ServerResponse) {\n // do not accept matchmaking requests if already shutting down\n if (matchMaker.isGracefullyShuttingDown) {\n res.writeHead(503, {});\n res.end();\n return;\n }\n\n const headers = Object.assign(\n {},\n matchMaker.controller.DEFAULT_CORS_HEADERS,\n matchMaker.controller.getCorsHeaders.call(undefined, req)\n );\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204, headers);\n res.end();\n\n } else if (req.method === 'POST') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const matchmakeIndex = matchedParams.indexOf(matchMaker.controller.matchmakeRoute);\n const method = matchedParams[matchmakeIndex + 1];\n const roomName = matchedParams[matchmakeIndex + 2] || '';\n\n const data = [];\n req.on('data', (chunk) => data.push(chunk));\n req.on('end', async () => {\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n\n try {\n const clientOptions = JSON.parse(Buffer.concat(data).toString());\n const response = await matchMaker.controller.invokeMethod(method, roomName, clientOptions);\n res.write(JSON.stringify(response));\n\n } catch (e) {\n res.write(JSON.stringify({ code: e.code, error: e.message, }));\n }\n\n res.end();\n });\n\n } else if (req.method === 'GET') {\n const matchedParams = req.url.match(matchMaker.controller.allowedRoomNameChars);\n const roomName = matchedParams.length > 1 ? matchedParams[matchedParams.length - 1] : \"\";\n\n headers['Content-Type'] = 'application/json';\n res.writeHead(200, headers);\n res.write(JSON.stringify(await matchMaker.controller.getAvailableRooms(roomName)));\n res.end();\n }\n\n }\n\n\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,cA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|
|
7
7
|
}
|
package/build/Stats.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Stats = {
|
|
2
|
+
roomCount: number;
|
|
3
|
+
ccu: number;
|
|
4
|
+
};
|
|
5
|
+
export declare let local: Stats;
|
|
6
|
+
export declare function fetchAll(): Promise<(Stats & {
|
|
7
|
+
processId: string;
|
|
8
|
+
})[]>;
|
|
9
|
+
export declare function persist(): any;
|
|
10
|
+
export declare function reset(): any;
|
|
11
|
+
export declare function excludeProcess(_processId: string): any;
|
|
12
|
+
export declare function getGlobalCCU(): Promise<number>;
|
package/build/Stats.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var Stats_exports = {};
|
|
19
|
+
__export(Stats_exports, {
|
|
20
|
+
excludeProcess: () => excludeProcess,
|
|
21
|
+
fetchAll: () => fetchAll,
|
|
22
|
+
getGlobalCCU: () => getGlobalCCU,
|
|
23
|
+
local: () => local,
|
|
24
|
+
persist: () => persist,
|
|
25
|
+
reset: () => reset
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(Stats_exports);
|
|
28
|
+
var import_MatchMaker = require("./MatchMaker");
|
|
29
|
+
let local = {
|
|
30
|
+
roomCount: 0,
|
|
31
|
+
ccu: 0
|
|
32
|
+
};
|
|
33
|
+
async function fetchAll() {
|
|
34
|
+
const allStats = [];
|
|
35
|
+
const allProcesses = await import_MatchMaker.presence.hgetall(getRoomCountKey());
|
|
36
|
+
for (let remoteProcessId in allProcesses) {
|
|
37
|
+
if (remoteProcessId === import_MatchMaker.processId) {
|
|
38
|
+
allStats.push({ processId: import_MatchMaker.processId, roomCount: local.roomCount, ccu: local.ccu });
|
|
39
|
+
} else {
|
|
40
|
+
const [roomCount, ccu] = allProcesses[remoteProcessId].split(",").map(Number);
|
|
41
|
+
allStats.push({ processId: remoteProcessId, roomCount, ccu });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return allStats;
|
|
45
|
+
}
|
|
46
|
+
let lastPersisted = 0;
|
|
47
|
+
let persistTimeout = void 0;
|
|
48
|
+
const persistInterval = 1e3;
|
|
49
|
+
function persist() {
|
|
50
|
+
const now = Date.now();
|
|
51
|
+
if (now - lastPersisted > persistInterval) {
|
|
52
|
+
lastPersisted = now;
|
|
53
|
+
return import_MatchMaker.presence.hset(getRoomCountKey(), import_MatchMaker.processId, `${local.roomCount},${local.ccu}`);
|
|
54
|
+
} else {
|
|
55
|
+
clearTimeout(persistTimeout);
|
|
56
|
+
persistTimeout = setTimeout(persist, persistInterval);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function reset() {
|
|
60
|
+
lastPersisted = 0;
|
|
61
|
+
clearTimeout(persistTimeout);
|
|
62
|
+
local.roomCount = 0;
|
|
63
|
+
local.ccu = 0;
|
|
64
|
+
return persist();
|
|
65
|
+
}
|
|
66
|
+
function excludeProcess(_processId) {
|
|
67
|
+
return import_MatchMaker.presence.hdel(getRoomCountKey(), _processId);
|
|
68
|
+
}
|
|
69
|
+
async function getGlobalCCU() {
|
|
70
|
+
const allStats = await fetchAll();
|
|
71
|
+
return allStats.reduce((prev, next) => prev + next.ccu, 0);
|
|
72
|
+
}
|
|
73
|
+
function getRoomCountKey() {
|
|
74
|
+
return "roomcount";
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
excludeProcess,
|
|
79
|
+
fetchAll,
|
|
80
|
+
getGlobalCCU,
|
|
81
|
+
local,
|
|
82
|
+
persist,
|
|
83
|
+
reset
|
|
84
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Stats.ts"],
|
|
4
|
+
"sourcesContent": ["import { presence, processId } from \"./MatchMaker\";\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist() {\n /**\n * Avoid persisting too often.\n */\n const now = Date.now();\n\n if (now - lastPersisted > persistInterval) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset() {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n local.roomCount = 0;\n local.ccu = 0;\n return persist();\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAoC;AAO7B,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAEA,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,2BAAS,QAAQ,gBAAgB,CAAC;AAC7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,6BAAW;AACjC,eAAS,KAAK,EAAE,wCAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,iBAAiB,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,MAAM,kBAAkB;AAEjB,SAAS,UAAU;AAIxB,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,MAAM,gBAAgB,iBAAiB;AACzC,oBAAgB;AAChB,WAAO,2BAAS,KAAK,gBAAgB,GAAG,6BAAW,GAAG,MAAM,aAAa,MAAM,KAAK;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,QAAQ;AACtB,kBAAgB;AAChB,eAAa,cAAc;AAC3B,QAAM,YAAY;AAClB,QAAM,MAAM;AACZ,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,2BAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/Stats.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { presence, processId } from "./MatchMaker";
|
|
2
|
+
let local = {
|
|
3
|
+
roomCount: 0,
|
|
4
|
+
ccu: 0
|
|
5
|
+
};
|
|
6
|
+
async function fetchAll() {
|
|
7
|
+
const allStats = [];
|
|
8
|
+
const allProcesses = await presence.hgetall(getRoomCountKey());
|
|
9
|
+
for (let remoteProcessId in allProcesses) {
|
|
10
|
+
if (remoteProcessId === processId) {
|
|
11
|
+
allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu });
|
|
12
|
+
} else {
|
|
13
|
+
const [roomCount, ccu] = allProcesses[remoteProcessId].split(",").map(Number);
|
|
14
|
+
allStats.push({ processId: remoteProcessId, roomCount, ccu });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return allStats;
|
|
18
|
+
}
|
|
19
|
+
let lastPersisted = 0;
|
|
20
|
+
let persistTimeout = void 0;
|
|
21
|
+
const persistInterval = 1e3;
|
|
22
|
+
function persist() {
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
if (now - lastPersisted > persistInterval) {
|
|
25
|
+
lastPersisted = now;
|
|
26
|
+
return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);
|
|
27
|
+
} else {
|
|
28
|
+
clearTimeout(persistTimeout);
|
|
29
|
+
persistTimeout = setTimeout(persist, persistInterval);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function reset() {
|
|
33
|
+
lastPersisted = 0;
|
|
34
|
+
clearTimeout(persistTimeout);
|
|
35
|
+
local.roomCount = 0;
|
|
36
|
+
local.ccu = 0;
|
|
37
|
+
return persist();
|
|
38
|
+
}
|
|
39
|
+
function excludeProcess(_processId) {
|
|
40
|
+
return presence.hdel(getRoomCountKey(), _processId);
|
|
41
|
+
}
|
|
42
|
+
async function getGlobalCCU() {
|
|
43
|
+
const allStats = await fetchAll();
|
|
44
|
+
return allStats.reduce((prev, next) => prev + next.ccu, 0);
|
|
45
|
+
}
|
|
46
|
+
function getRoomCountKey() {
|
|
47
|
+
return "roomcount";
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
excludeProcess,
|
|
51
|
+
fetchAll,
|
|
52
|
+
getGlobalCCU,
|
|
53
|
+
local,
|
|
54
|
+
persist,
|
|
55
|
+
reset
|
|
56
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Stats.ts"],
|
|
4
|
+
"sourcesContent": ["import { presence, processId } from \"./MatchMaker\";\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist() {\n /**\n * Avoid persisting too often.\n */\n const now = Date.now();\n\n if (now - lastPersisted > persistInterval) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset() {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n local.roomCount = 0;\n local.ccu = 0;\n return persist();\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,iBAAiB;AAO7B,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAEA,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,SAAS,QAAQ,gBAAgB,CAAC;AAC7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,WAAW;AACjC,eAAS,KAAK,EAAE,WAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,iBAAiB,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,MAAM,kBAAkB;AAEjB,SAAS,UAAU;AAIxB,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,MAAM,gBAAgB,iBAAiB;AACzC,oBAAgB;AAChB,WAAO,SAAS,KAAK,gBAAgB,GAAG,WAAW,GAAG,MAAM,aAAa,MAAM,KAAK;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,QAAQ;AACtB,kBAAgB;AAChB,eAAa,cAAc;AAC3B,QAAM,YAAY;AAClB,QAAM,MAAM;AACZ,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,SAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Clock, { Delayed } from '@gamestdio/timer';
|
|
2
|
-
export { Server, ServerOptions } from './Server';
|
|
2
|
+
export { Server, type ServerOptions } from './Server';
|
|
3
3
|
export { Room, RoomInternalState } from './Room';
|
|
4
4
|
export { Protocol, ErrorCode, getMessageBytes } from './Protocol';
|
|
5
5
|
export { RegisteredHandler } from './matchmaker/RegisteredHandler';
|
|
@@ -8,10 +8,10 @@ import * as matchMaker from './MatchMaker';
|
|
|
8
8
|
export { matchMaker };
|
|
9
9
|
export { updateLobby, subscribeLobby } from './matchmaker/Lobby';
|
|
10
10
|
export * from './matchmaker/driver';
|
|
11
|
-
export { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';
|
|
12
|
-
export { Presence } from './presence/Presence';
|
|
11
|
+
export { type Client, ClientState, ClientArray, Transport, type ISendOptions } from './Transport';
|
|
12
|
+
export { type Presence } from './presence/Presence';
|
|
13
13
|
export { LocalPresence } from './presence/LocalPresence';
|
|
14
|
-
export { Serializer } from './serializer/Serializer';
|
|
14
|
+
export { type Serializer } from './serializer/Serializer';
|
|
15
15
|
export { SchemaSerializer } from './serializer/SchemaSerializer';
|
|
16
16
|
export { Clock, Delayed };
|
|
17
17
|
export { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';
|
package/build/index.js
CHANGED
|
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var src_exports = {};
|
|
26
26
|
__export(src_exports, {
|
|
27
|
-
Client: () => import_Transport.Client,
|
|
28
27
|
ClientArray: () => import_Transport.ClientArray,
|
|
29
28
|
ClientState: () => import_Transport.ClientState,
|
|
30
29
|
Clock: () => import_timer.default,
|
|
@@ -32,20 +31,16 @@ __export(src_exports, {
|
|
|
32
31
|
Delayed: () => import_timer.Delayed,
|
|
33
32
|
DummyServer: () => import_Utils.DummyServer,
|
|
34
33
|
ErrorCode: () => import_Protocol.ErrorCode,
|
|
35
|
-
ISendOptions: () => import_Transport.ISendOptions,
|
|
36
34
|
LobbyRoom: () => import_LobbyRoom.LobbyRoom,
|
|
37
35
|
LocalPresence: () => import_LocalPresence.LocalPresence,
|
|
38
|
-
Presence: () => import_Presence.Presence,
|
|
39
36
|
Protocol: () => import_Protocol.Protocol,
|
|
40
37
|
RegisteredHandler: () => import_RegisteredHandler.RegisteredHandler,
|
|
41
38
|
RelayRoom: () => import_RelayRoom.RelayRoom,
|
|
42
39
|
Room: () => import_Room.Room,
|
|
43
40
|
RoomInternalState: () => import_Room.RoomInternalState,
|
|
44
41
|
SchemaSerializer: () => import_SchemaSerializer.SchemaSerializer,
|
|
45
|
-
Serializer: () => import_Serializer.Serializer,
|
|
46
42
|
Server: () => import_Server.Server,
|
|
47
43
|
ServerError: () => import_ServerError.ServerError,
|
|
48
|
-
ServerOptions: () => import_Server.ServerOptions,
|
|
49
44
|
Transport: () => import_Transport.Transport,
|
|
50
45
|
debugAndPrintError: () => import_Debug.debugAndPrintError,
|
|
51
46
|
debugConnection: () => import_Debug.debugConnection,
|
|
@@ -87,7 +82,6 @@ var import_RelayRoom = require("./rooms/RelayRoom");
|
|
|
87
82
|
var import_Logger = require("./Logger");
|
|
88
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
84
|
0 && (module.exports = {
|
|
90
|
-
Client,
|
|
91
85
|
ClientArray,
|
|
92
86
|
ClientState,
|
|
93
87
|
Clock,
|
|
@@ -95,20 +89,16 @@ var import_Logger = require("./Logger");
|
|
|
95
89
|
Delayed,
|
|
96
90
|
DummyServer,
|
|
97
91
|
ErrorCode,
|
|
98
|
-
ISendOptions,
|
|
99
92
|
LobbyRoom,
|
|
100
93
|
LocalPresence,
|
|
101
|
-
Presence,
|
|
102
94
|
Protocol,
|
|
103
95
|
RegisteredHandler,
|
|
104
96
|
RelayRoom,
|
|
105
97
|
Room,
|
|
106
98
|
RoomInternalState,
|
|
107
99
|
SchemaSerializer,
|
|
108
|
-
Serializer,
|
|
109
100
|
Server,
|
|
110
101
|
ServerError,
|
|
111
|
-
ServerOptions,
|
|
112
102
|
Transport,
|
|
113
103
|
debugAndPrintError,
|
|
114
104
|
debugConnection,
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, type ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { type Client, ClientState, ClientArray, Transport, type ISendOptions } from './Transport';\n\n// Presence\nexport { type Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { type Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAG/B,oBAA2C;AAC3C,kBAAwC;AACxC,sBAAqD;AACrD,+BAAkC;AAClC,yBAA4B;AAG5B,iBAA4B;AAE5B,mBAA4C;AAG5C,wBAAc,gCAfd;AAkBA,uBAAoF;AAGpF,sBAA8B;AAC9B,2BAA8B;AAG9B,wBAAgC;AAChC,8BAAiC;AAIjC,mBAA6D;AAC7D,qBAA0B;AAG1B,mBASO;AAGP,uBAA0B;AAC1B,uBAA0B;AAG1B,oBAAuB;",
|
|
6
6
|
"names": ["Clock"]
|
|
7
7
|
}
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Clock, { Delayed } from "@gamestdio/timer";
|
|
2
|
-
import { Server
|
|
2
|
+
import { Server } from "./Server";
|
|
3
3
|
import { Room, RoomInternalState } from "./Room";
|
|
4
4
|
import { Protocol, ErrorCode, getMessageBytes } from "./Protocol";
|
|
5
5
|
import { RegisteredHandler } from "./matchmaker/RegisteredHandler";
|
|
@@ -7,10 +7,10 @@ import { ServerError } from "./errors/ServerError";
|
|
|
7
7
|
import * as matchMaker from "./MatchMaker";
|
|
8
8
|
import { updateLobby, subscribeLobby } from "./matchmaker/Lobby";
|
|
9
9
|
export * from "./matchmaker/driver";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { ClientState, ClientArray, Transport } from "./Transport";
|
|
11
|
+
import {} from "./presence/Presence";
|
|
12
12
|
import { LocalPresence } from "./presence/LocalPresence";
|
|
13
|
-
import {
|
|
13
|
+
import {} from "./serializer/Serializer";
|
|
14
14
|
import { SchemaSerializer } from "./serializer/SchemaSerializer";
|
|
15
15
|
import { generateId, Deferred, DummyServer, spliceOne } from "./utils/Utils";
|
|
16
16
|
import { isDevMode } from "./utils/DevMode";
|
|
@@ -28,7 +28,6 @@ import { LobbyRoom } from "./rooms/LobbyRoom";
|
|
|
28
28
|
import { RelayRoom } from "./rooms/RelayRoom";
|
|
29
29
|
import { logger } from "./Logger";
|
|
30
30
|
export {
|
|
31
|
-
Client,
|
|
32
31
|
ClientArray,
|
|
33
32
|
ClientState,
|
|
34
33
|
Clock,
|
|
@@ -36,20 +35,16 @@ export {
|
|
|
36
35
|
Delayed,
|
|
37
36
|
DummyServer,
|
|
38
37
|
ErrorCode,
|
|
39
|
-
ISendOptions,
|
|
40
38
|
LobbyRoom,
|
|
41
39
|
LocalPresence,
|
|
42
|
-
Presence,
|
|
43
40
|
Protocol,
|
|
44
41
|
RegisteredHandler,
|
|
45
42
|
RelayRoom,
|
|
46
43
|
Room,
|
|
47
44
|
RoomInternalState,
|
|
48
45
|
SchemaSerializer,
|
|
49
|
-
Serializer,
|
|
50
46
|
Server,
|
|
51
47
|
ServerError,
|
|
52
|
-
ServerOptions,
|
|
53
48
|
Transport,
|
|
54
49
|
debugAndPrintError,
|
|
55
50
|
debugConnection,
|
package/build/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,eAAe;AAG/B,SAAS,
|
|
4
|
+
"sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, type ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { type Client, ClientState, ClientArray, Transport, type ISendOptions } from './Transport';\n\n// Presence\nexport { type Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { type Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,eAAe;AAG/B,SAAS,cAAkC;AAC3C,SAAS,MAAM,yBAAyB;AACxC,SAAS,UAAU,WAAW,uBAAuB;AACrD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAG5B,YAAY,gBAAgB;AAE5B,SAAS,aAAa,sBAAsB;AAG5C,cAAc;AAGd,SAAsB,aAAa,aAAa,iBAAoC;AAGpF,eAA8B;AAC9B,SAAS,qBAAqB;AAG9B,eAAgC;AAChC,SAAS,wBAAwB;AAIjC,SAAS,YAAY,UAAU,aAAa,iBAAiB;AAC7D,SAAS,iBAAiB;AAG1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAG1B,SAAS,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { IncomingMessage } from 'http';
|
|
4
2
|
import { EventEmitter } from 'events';
|
|
5
3
|
import { RoomListingData, SortOptions } from './driver/interfaces';
|
|
6
|
-
import {
|
|
7
|
-
import { Type } from '../types';
|
|
4
|
+
import { RoomConstructor } from './../Room';
|
|
8
5
|
export declare const INVALID_OPTION_KEYS: Array<keyof RoomListingData>;
|
|
9
|
-
export type ValidateAuthTokenCallback = (token: string, request?: IncomingMessage) => Promise<any>;
|
|
10
6
|
export declare class RegisteredHandler extends EventEmitter {
|
|
11
|
-
klass:
|
|
7
|
+
klass: RoomConstructor;
|
|
12
8
|
options: any;
|
|
13
9
|
filterOptions: string[];
|
|
14
10
|
sortOptions?: SortOptions;
|
|
15
|
-
constructor(klass:
|
|
11
|
+
constructor(klass: RoomConstructor, options: any);
|
|
16
12
|
enableRealtimeListing(): this;
|
|
17
13
|
filterBy(options: string[]): this;
|
|
18
14
|
sortBy(options: SortOptions): this;
|
|
@@ -24,11 +24,6 @@ module.exports = __toCommonJS(RegisteredHandler_exports);
|
|
|
24
24
|
var import_events = require("events");
|
|
25
25
|
var import_Logger = require("../Logger");
|
|
26
26
|
var import_Lobby = require("./Lobby");
|
|
27
|
-
let ColyseusAuth = void 0;
|
|
28
|
-
try {
|
|
29
|
-
ColyseusAuth = require("@colyseus/auth");
|
|
30
|
-
} catch (e) {
|
|
31
|
-
}
|
|
32
27
|
const INVALID_OPTION_KEYS = [
|
|
33
28
|
"clients",
|
|
34
29
|
"locked",
|