@colyseus/sdk 0.17.41 → 0.17.43
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/3rd_party/discord.cjs +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +1 -1
- package/build/Auth.mjs +1 -1
- package/build/Client.cjs +39 -10
- package/build/Client.cjs.map +1 -1
- package/build/Client.d.ts +11 -2
- package/build/Client.mjs +38 -10
- package/build/Client.mjs.map +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Room.cjs +1 -1
- package/build/Room.mjs +1 -1
- package/build/Storage.cjs +1 -1
- package/build/Storage.mjs +1 -1
- package/build/core/nanoevents.cjs +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +1 -1
- package/build/core/signal.mjs +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +1 -1
- package/build/debug.mjs +1 -1
- package/build/errors/Errors.cjs +1 -1
- package/build/errors/Errors.mjs +1 -1
- package/build/fetchXHR.cjs +1 -1
- package/build/fetchXHR.mjs +1 -1
- package/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +1 -1
- package/build/serializer/Serializer.cjs +1 -1
- package/build/serializer/Serializer.mjs +1 -1
- package/build/transport/H3Transport.cjs +70 -21
- package/build/transport/H3Transport.cjs.map +1 -1
- package/build/transport/H3Transport.d.ts +16 -0
- package/build/transport/H3Transport.mjs +69 -23
- package/build/transport/H3Transport.mjs.map +1 -1
- package/build/transport/WebSocketTransport.cjs +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus.js +107 -30
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +1 -1
- package/package.json +2 -2
- package/src/Client.ts +41 -8
- package/src/transport/H3Transport.ts +74 -24
package/build/Auth.cjs
CHANGED
package/build/Auth.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.43
|
|
7
7
|
import { getItem, removeItem, setItem } from './Storage.mjs';
|
|
8
8
|
import { createNanoEvents } from './core/nanoevents.mjs';
|
|
9
9
|
|
package/build/Client.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.43
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
@@ -80,7 +80,7 @@ class ColyseusSDK {
|
|
|
80
80
|
* Select the endpoint with the lowest latency.
|
|
81
81
|
* @param endpoints Array of endpoints to select from.
|
|
82
82
|
* @param options Client options.
|
|
83
|
-
* @param latencyOptions Latency measurement options (protocol, pingCount).
|
|
83
|
+
* @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.
|
|
84
84
|
* @returns The client with the lowest latency.
|
|
85
85
|
*/
|
|
86
86
|
static selectByLatency(endpoints_1, options_1) {
|
|
@@ -159,16 +159,41 @@ class ColyseusSDK {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Create a new connection with the server, and measure the latency.
|
|
162
|
-
*
|
|
162
|
+
*
|
|
163
|
+
* Always settles: resolves with the (average) round-trip time, or rejects on
|
|
164
|
+
* connection error, server-side close before all pongs arrive, or timeout.
|
|
165
|
+
*
|
|
166
|
+
* @param options Latency measurement options (protocol, pingCount, timeout).
|
|
163
167
|
*/
|
|
164
168
|
getLatency(options = {}) {
|
|
165
|
-
var _a, _b;
|
|
169
|
+
var _a, _b, _c;
|
|
166
170
|
const protocol = (_a = options.protocol) !== null && _a !== void 0 ? _a : "ws";
|
|
167
171
|
const pingCount = (_b = options.pingCount) !== null && _b !== void 0 ? _b : 1;
|
|
172
|
+
const timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : 1500;
|
|
168
173
|
return new Promise((resolve, reject) => {
|
|
174
|
+
var _a;
|
|
169
175
|
const conn = new Connection.Connection(protocol);
|
|
170
176
|
const latencies = [];
|
|
171
177
|
let pingStart = 0;
|
|
178
|
+
let settled = false;
|
|
179
|
+
let timeoutId;
|
|
180
|
+
// run exactly once — guards against late events after resolve/reject
|
|
181
|
+
// (e.g. our own conn.close() firing onclose, or a stray onclose/onerror pair)
|
|
182
|
+
const settle = (run) => {
|
|
183
|
+
if (settled) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
settled = true;
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
try {
|
|
189
|
+
conn.close();
|
|
190
|
+
}
|
|
191
|
+
catch (e) { /* socket may never have opened */ }
|
|
192
|
+
run();
|
|
193
|
+
};
|
|
194
|
+
const fail = (message) => settle(() => reject(new Errors.ServerError(sharedTypes.CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${message}`)));
|
|
195
|
+
// bound blackholed/filtered hosts that never fire onopen/onerror within the OS TCP timeout
|
|
196
|
+
timeoutId = setTimeout(() => fail(`timed out after ${timeout}ms`), timeout);
|
|
172
197
|
conn.events.onopen = () => {
|
|
173
198
|
pingStart = Date.now();
|
|
174
199
|
conn.send(new Uint8Array([sharedTypes.Protocol.PING]));
|
|
@@ -182,15 +207,19 @@ class ColyseusSDK {
|
|
|
182
207
|
}
|
|
183
208
|
else {
|
|
184
209
|
// Done, calculate average and close
|
|
185
|
-
conn.close();
|
|
186
210
|
const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;
|
|
187
|
-
resolve(average);
|
|
211
|
+
settle(() => resolve(average));
|
|
188
212
|
}
|
|
189
213
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
214
|
+
// server closed the socket before all pongs arrived — fires without onerror on a clean close
|
|
215
|
+
conn.events.onclose = (event) => fail(`connection closed${(event === null || event === void 0 ? void 0 : event.code) ? ` (${event.code})` : ""}${(event === null || event === void 0 ? void 0 : event.reason) ? `: ${event.reason}` : ""}`);
|
|
216
|
+
conn.events.onerror = (event) => fail(event.message);
|
|
217
|
+
try {
|
|
218
|
+
conn.connect(this.getHttpEndpoint());
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
fail((_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : "failed to connect");
|
|
222
|
+
}
|
|
194
223
|
});
|
|
195
224
|
}
|
|
196
225
|
createMatchMakeRequest(method_1, roomName_1) {
|
package/build/Client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.cjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { MatchMakeError, ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP, type FetchFn } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\n// - React Native does not provide `window.location`\n// - Cocos Creator (Native) does not provide `window.location.hostname`\nconst DEFAULT_ENDPOINT = (typeof (window) !== \"undefined\" && typeof (window?.location?.hostname) !== \"undefined\")\n ? `${window.location.protocol.replace(\"http\", \"ws\")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`\n : \"ws://127.0.0.1:2567\";\n\nexport interface EndpointSettings {\n hostname: string,\n secure: boolean,\n port?: number,\n pathname?: string,\n searchParams?: string,\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface ClientOptions {\n headers?: { [id: string]: string };\n urlBuilder?: (url: URL) => string;\n protocol?: \"ws\" | \"h3\";\n fetchFn?: FetchFn;\n}\n\nexport interface LatencyOptions {\n /** \"ws\" for WebSocket, \"h3\" for WebTransport (default: \"ws\") */\n protocol?: \"ws\" | \"h3\";\n /** Number of pings to send (default: 1). Returns the average latency when > 1. */\n pingCount?: number;\n}\n\nexport class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {\n static VERSION = \"0.17\";\n\n /**\n * The HTTP client to make requests to the server.\n */\n public http: HTTP<ServerType['~routes']>;\n\n /**\n * The authentication module to authenticate into requests and rooms.\n */\n public auth: Auth<UserData>;\n\n /**\n * The settings used to connect to the server.\n */\n public settings: EndpointSettings;\n\n protected urlBuilder: (url: URL) => string;\n\n constructor(\n settings: string | EndpointSettings = DEFAULT_ENDPOINT,\n options?: ClientOptions,\n ) {\n if (typeof (settings) === \"string\") {\n\n //\n // endpoint by url\n //\n const url = (settings.startsWith(\"/\"))\n ? new URL(settings, DEFAULT_ENDPOINT)\n : new URL(settings);\n\n const secure = (url.protocol === \"https:\" || url.protocol === \"wss:\");\n const port = Number(url.port || (secure ? 443 : 80));\n\n this.settings = {\n hostname: url.hostname,\n pathname: url.pathname,\n port,\n secure,\n searchParams: url.searchParams.toString() || undefined,\n };\n\n } else {\n //\n // endpoint by settings\n //\n if (settings.port === undefined) {\n settings.port = (settings.secure) ? 443 : 80;\n }\n if (settings.pathname === undefined) {\n settings.pathname = \"\";\n }\n this.settings = settings;\n }\n\n // make sure pathname does not end with \"/\"\n if (this.settings.pathname.endsWith(\"/\")) {\n this.settings.pathname = this.settings.pathname.slice(0, -1);\n }\n\n // specify room connection protocol if provided\n if (options?.protocol) {\n this.settings.protocol = options.protocol;\n }\n\n this.http = new HTTP(this, {\n headers: options?.headers || {},\n }, options?.fetchFn);\n this.auth = new Auth(this.http);\n\n this.urlBuilder = options?.urlBuilder;\n\n //\n // Discord Embedded SDK requires a custom URL builder\n //\n if (\n !this.urlBuilder &&\n typeof (window) !== \"undefined\" &&\n window?.location?.hostname?.includes(\"discordsays.com\")\n ) {\n this.urlBuilder = discordURLBuilder;\n console.log(\"Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.\");\n }\n }\n\n /**\n * Select the endpoint with the lowest latency.\n * @param endpoints Array of endpoints to select from.\n * @param options Client options.\n * @param latencyOptions Latency measurement options (protocol, pingCount).\n * @returns The client with the lowest latency.\n */\n static async selectByLatency<ServerType extends SDKTypes = any, UserData = any>(\n endpoints: Array<string | EndpointSettings>,\n options?: ClientOptions,\n latencyOptions: LatencyOptions = {}\n ) {\n const clients = endpoints.map(endpoint => new ColyseusSDK<ServerType, UserData>(endpoint, options));\n\n const latencies = (await Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {\n const settings = clients[index].settings;\n console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);\n return [index, latency]\n }))))\n .filter((result) => result.status === 'fulfilled')\n .map(result => result.value);\n\n if (latencies.length === 0) {\n throw new Error('All endpoints failed to respond');\n }\n\n return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinOrCreate<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinOrCreate<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinOrCreate<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinOrCreate', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async create<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async create<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async create<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('create', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async join<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async join<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async join<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('join', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinById<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinById<State = any>(\n roomId: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinById<T = any>(roomId: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinById', roomId, options, rootSchema);\n }\n\n /**\n * Re-establish connection with a room this client was previously connected to.\n *\n * @param reconnectionToken The `room.reconnectionToken` from previously connected room.\n * @param rootSchema (optional) Concrete root schema definition\n * @returns Promise<Room>\n */\n // Overload: Use room name from ServerType to infer room type\n public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async reconnect<RoomType extends ServerRoomLike>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async reconnect<State = any>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async reconnect<T = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<T>) {\n if (typeof (reconnectionToken) === \"string\" && typeof (rootSchema) === \"string\") {\n throw new Error(\"DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\\nYou can get this token from previously connected `room.reconnectionToken`\");\n }\n const [roomId, token] = reconnectionToken.split(\":\");\n\t\tif (!roomId || !token) {\n\t\t\tthrow new Error(\"Invalid reconnection token format.\\nThe format should be roomId:reconnectionToken\");\n\t\t}\n return await this.createMatchMakeRequest<T>('reconnect', roomId, { reconnectionToken: token }, rootSchema);\n }\n\n public async consumeSeatReservation<T>(\n response: ISeatReservation,\n rootSchema?: SchemaConstructor<T>\n ): Promise<Room<any, T>> {\n const room = this.createRoom<T>(response.name, rootSchema);\n room.roomId = response.roomId;\n room.sessionId = response.sessionId;\n\n const options: any = { sessionId: room.sessionId };\n\n // forward \"reconnection token\" in case of reconnection.\n if (response.reconnectionToken) {\n options.reconnectionToken = response.reconnectionToken;\n }\n\n room.connect(\n this.buildEndpoint(response, options),\n response,\n this.http.options.headers\n );\n\n return new Promise((resolve, reject) => {\n const onError = (code, message) => reject(new ServerError(code, message));\n room.onError.once(onError);\n\n room['onJoin'].once(() => {\n room.onError.remove(onError);\n resolve(room);\n });\n });\n }\n\n /**\n * Create a new connection with the server, and measure the latency.\n * @param options Latency measurement options (protocol, pingCount).\n */\n public getLatency(options: LatencyOptions = {}): Promise<number> {\n const protocol = options.protocol ?? \"ws\";\n const pingCount = options.pingCount ?? 1;\n\n return new Promise<number>((resolve, reject) => {\n const conn = new Connection(protocol);\n const latencies: number[] = [];\n let pingStart = 0;\n\n conn.events.onopen = () => {\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n };\n\n conn.events.onmessage = (_: MessageEvent) => {\n latencies.push(Date.now() - pingStart);\n\n if (latencies.length < pingCount) {\n // Send another ping\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n } else {\n // Done, calculate average and close\n conn.close();\n const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;\n resolve(average);\n }\n };\n\n conn.events.onerror = (event: ErrorEvent) => {\n reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));\n };\n\n conn.connect(this.getHttpEndpoint());\n });\n }\n\n protected async createMatchMakeRequest<T>(\n method: string,\n roomName: string,\n options: JoinOptions = {},\n rootSchema?: SchemaConstructor<T>,\n ) {\n try {\n if (!roomName) {\n throw new Error(\"Must provide a room name\");\n }\n\n const httpResponse = await (this.http as HTTP<any>).post(`/matchmake/${method}/${roomName}`, {\n headers: {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: options\n });\n\n const response = httpResponse.data as unknown as ISeatReservation;\n\n // forward reconnection token during \"reconnect\" methods.\n if (method === \"reconnect\") {\n response.reconnectionToken = options.reconnectionToken;\n }\n\n return await this.consumeSeatReservation<T>(response, rootSchema);\n } catch (error) {\n if (error instanceof ServerError) {\n throw new MatchMakeError(error.message, error.code);\n }\n throw error;\n }\n }\n\n protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {\n return new Room<any, T>(roomName, rootSchema);\n }\n\n protected buildEndpoint(seatReservation: ISeatReservation, options: any = {}) {\n let protocol: string = this.settings.protocol || \"ws\";\n let searchParams = this.settings.searchParams || \"\";\n\n // forward authentication token\n if (this.http.authToken) {\n options['_authToken'] = this.http.authToken;\n }\n\n // append provided options\n for (const name in options) {\n if (!options.hasOwnProperty(name)) {\n continue;\n }\n searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;\n }\n\n if (protocol === \"h3\") {\n protocol = \"http\";\n }\n\n let endpoint = (this.settings.secure)\n ? `${protocol}s://`\n : `${protocol}://`;\n\n if (seatReservation.publicAddress) {\n endpoint += `${seatReservation.publicAddress}`;\n\n } else {\n endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;\n }\n\n const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getHttpEndpoint(segments: string = '') {\n const path = segments.startsWith(\"/\") ? segments : `/${segments}`;\n\n let endpointURL = `${(this.settings.secure) ? \"https\" : \"http\"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;\n\n if (this.settings.searchParams) {\n endpointURL += `?${this.settings.searchParams}`;\n }\n\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getEndpointPort() {\n return (this.settings.port !== 80 && this.settings.port !== 443)\n ? `:${this.settings.port}`\n : \"\";\n }\n}\n\nexport const Client = ColyseusSDK;\nexport type Client<ServerType extends SDKTypes = any, UserData = any> = InstanceType<typeof ColyseusSDK<ServerType, UserData>>;"],"names":["HTTP","Auth","discordURLBuilder","__awaiter","ServerError","Connection","Protocol","CloseCode","MatchMakeError","Room"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,QAAQ,MAAM,CAAC,KAAK,WAAW,IAAK,QAAQ,MAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAN,MAAM,CAAE,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,QAAQ,CAAC,KAAK,WAAW;AAC7G,MAAE,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA,EAAA,EAAK,MAAM,CAAC,QAAQ,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA,CAAA,EAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE,EAAC;MACrI,qBAAqB;MAyBd,WAAW,CAAA;IAoBpB,WAAA,CACI,QAAA,GAAsC,gBAAgB,EACtD,OAAuB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,WAAW,CAAC;cACpC,WAAW;IACrB;IAEU,eAAe,GAAA;AACrB,QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG;AAC3D,cAAE,CAAA,CAAA,EAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;cACtB,EAAE;IACZ;;AAtZO,WAAA,CAAA,OAAO,GAAG,MAAM;AAyZpB,MAAM,MAAM,GAAG;;;;;"}
|
|
1
|
+
{"version":3,"file":"Client.cjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { MatchMakeError, ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP, type FetchFn } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\n// - React Native does not provide `window.location`\n// - Cocos Creator (Native) does not provide `window.location.hostname`\nconst DEFAULT_ENDPOINT = (typeof (window) !== \"undefined\" && typeof (window?.location?.hostname) !== \"undefined\")\n ? `${window.location.protocol.replace(\"http\", \"ws\")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`\n : \"ws://127.0.0.1:2567\";\n\nexport interface EndpointSettings {\n hostname: string,\n secure: boolean,\n port?: number,\n pathname?: string,\n searchParams?: string,\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface ClientOptions {\n headers?: { [id: string]: string };\n urlBuilder?: (url: URL) => string;\n protocol?: \"ws\" | \"h3\";\n fetchFn?: FetchFn;\n}\n\nexport interface LatencyOptions {\n /** \"ws\" for WebSocket, \"h3\" for WebTransport (default: \"ws\") */\n protocol?: \"ws\" | \"h3\";\n /** Number of pings to send (default: 1). Returns the average latency when > 1. */\n pingCount?: number;\n /**\n * Milliseconds to wait for the measurement before rejecting (default: 1500).\n * Bounds unreachable/blackholed endpoints so they can't stall selection.\n */\n timeout?: number;\n}\n\nexport class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {\n static VERSION = \"0.17\";\n\n /**\n * The HTTP client to make requests to the server.\n */\n public http: HTTP<ServerType['~routes']>;\n\n /**\n * The authentication module to authenticate into requests and rooms.\n */\n public auth: Auth<UserData>;\n\n /**\n * The settings used to connect to the server.\n */\n public settings: EndpointSettings;\n\n protected urlBuilder: (url: URL) => string;\n\n constructor(\n settings: string | EndpointSettings = DEFAULT_ENDPOINT,\n options?: ClientOptions,\n ) {\n if (typeof (settings) === \"string\") {\n\n //\n // endpoint by url\n //\n const url = (settings.startsWith(\"/\"))\n ? new URL(settings, DEFAULT_ENDPOINT)\n : new URL(settings);\n\n const secure = (url.protocol === \"https:\" || url.protocol === \"wss:\");\n const port = Number(url.port || (secure ? 443 : 80));\n\n this.settings = {\n hostname: url.hostname,\n pathname: url.pathname,\n port,\n secure,\n searchParams: url.searchParams.toString() || undefined,\n };\n\n } else {\n //\n // endpoint by settings\n //\n if (settings.port === undefined) {\n settings.port = (settings.secure) ? 443 : 80;\n }\n if (settings.pathname === undefined) {\n settings.pathname = \"\";\n }\n this.settings = settings;\n }\n\n // make sure pathname does not end with \"/\"\n if (this.settings.pathname.endsWith(\"/\")) {\n this.settings.pathname = this.settings.pathname.slice(0, -1);\n }\n\n // specify room connection protocol if provided\n if (options?.protocol) {\n this.settings.protocol = options.protocol;\n }\n\n this.http = new HTTP(this, {\n headers: options?.headers || {},\n }, options?.fetchFn);\n this.auth = new Auth(this.http);\n\n this.urlBuilder = options?.urlBuilder;\n\n //\n // Discord Embedded SDK requires a custom URL builder\n //\n if (\n !this.urlBuilder &&\n typeof (window) !== \"undefined\" &&\n window?.location?.hostname?.includes(\"discordsays.com\")\n ) {\n this.urlBuilder = discordURLBuilder;\n console.log(\"Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.\");\n }\n }\n\n /**\n * Select the endpoint with the lowest latency.\n * @param endpoints Array of endpoints to select from.\n * @param options Client options.\n * @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.\n * @returns The client with the lowest latency.\n */\n static async selectByLatency<ServerType extends SDKTypes = any, UserData = any>(\n endpoints: Array<string | EndpointSettings>,\n options?: ClientOptions,\n latencyOptions: LatencyOptions = {}\n ) {\n const clients = endpoints.map(endpoint => new ColyseusSDK<ServerType, UserData>(endpoint, options));\n\n const latencies = (await Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {\n const settings = clients[index].settings;\n console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);\n return [index, latency]\n }))))\n .filter((result) => result.status === 'fulfilled')\n .map(result => result.value);\n\n if (latencies.length === 0) {\n throw new Error('All endpoints failed to respond');\n }\n\n return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinOrCreate<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinOrCreate<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinOrCreate<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinOrCreate', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async create<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async create<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async create<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('create', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async join<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async join<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async join<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('join', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinById<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinById<State = any>(\n roomId: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinById<T = any>(roomId: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinById', roomId, options, rootSchema);\n }\n\n /**\n * Re-establish connection with a room this client was previously connected to.\n *\n * @param reconnectionToken The `room.reconnectionToken` from previously connected room.\n * @param rootSchema (optional) Concrete root schema definition\n * @returns Promise<Room>\n */\n // Overload: Use room name from ServerType to infer room type\n public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async reconnect<RoomType extends ServerRoomLike>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async reconnect<State = any>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async reconnect<T = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<T>) {\n if (typeof (reconnectionToken) === \"string\" && typeof (rootSchema) === \"string\") {\n throw new Error(\"DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\\nYou can get this token from previously connected `room.reconnectionToken`\");\n }\n const [roomId, token] = reconnectionToken.split(\":\");\n\t\tif (!roomId || !token) {\n\t\t\tthrow new Error(\"Invalid reconnection token format.\\nThe format should be roomId:reconnectionToken\");\n\t\t}\n return await this.createMatchMakeRequest<T>('reconnect', roomId, { reconnectionToken: token }, rootSchema);\n }\n\n public async consumeSeatReservation<T>(\n response: ISeatReservation,\n rootSchema?: SchemaConstructor<T>\n ): Promise<Room<any, T>> {\n const room = this.createRoom<T>(response.name, rootSchema);\n room.roomId = response.roomId;\n room.sessionId = response.sessionId;\n\n const options: any = { sessionId: room.sessionId };\n\n // forward \"reconnection token\" in case of reconnection.\n if (response.reconnectionToken) {\n options.reconnectionToken = response.reconnectionToken;\n }\n\n room.connect(\n this.buildEndpoint(response, options),\n response,\n this.http.options.headers\n );\n\n return new Promise((resolve, reject) => {\n const onError = (code, message) => reject(new ServerError(code, message));\n room.onError.once(onError);\n\n room['onJoin'].once(() => {\n room.onError.remove(onError);\n resolve(room);\n });\n });\n }\n\n /**\n * Create a new connection with the server, and measure the latency.\n *\n * Always settles: resolves with the (average) round-trip time, or rejects on\n * connection error, server-side close before all pongs arrive, or timeout.\n *\n * @param options Latency measurement options (protocol, pingCount, timeout).\n */\n public getLatency(options: LatencyOptions = {}): Promise<number> {\n const protocol = options.protocol ?? \"ws\";\n const pingCount = options.pingCount ?? 1;\n const timeout = options.timeout ?? 1500;\n\n return new Promise<number>((resolve, reject) => {\n const conn = new Connection(protocol);\n const latencies: number[] = [];\n let pingStart = 0;\n let settled = false;\n let timeoutId: ReturnType<typeof setTimeout>;\n\n // run exactly once — guards against late events after resolve/reject\n // (e.g. our own conn.close() firing onclose, or a stray onclose/onerror pair)\n const settle = (run: () => void) => {\n if (settled) { return; }\n settled = true;\n clearTimeout(timeoutId);\n try { conn.close(); } catch (e) { /* socket may never have opened */ }\n run();\n };\n\n const fail = (message: string) =>\n settle(() => reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${message}`)));\n\n // bound blackholed/filtered hosts that never fire onopen/onerror within the OS TCP timeout\n timeoutId = setTimeout(() => fail(`timed out after ${timeout}ms`), timeout);\n\n conn.events.onopen = () => {\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n };\n\n conn.events.onmessage = (_: MessageEvent) => {\n latencies.push(Date.now() - pingStart);\n\n if (latencies.length < pingCount) {\n // Send another ping\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n } else {\n // Done, calculate average and close\n const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;\n settle(() => resolve(average));\n }\n };\n\n // server closed the socket before all pongs arrived — fires without onerror on a clean close\n conn.events.onclose = (event: any) =>\n fail(`connection closed${event?.code ? ` (${event.code})` : \"\"}${event?.reason ? `: ${event.reason}` : \"\"}`);\n\n conn.events.onerror = (event: ErrorEvent) => fail(event.message);\n\n try {\n conn.connect(this.getHttpEndpoint());\n } catch (e: any) {\n fail(e?.message ?? \"failed to connect\");\n }\n });\n }\n\n protected async createMatchMakeRequest<T>(\n method: string,\n roomName: string,\n options: JoinOptions = {},\n rootSchema?: SchemaConstructor<T>,\n ) {\n try {\n if (!roomName) {\n throw new Error(\"Must provide a room name\");\n }\n\n const httpResponse = await (this.http as HTTP<any>).post(`/matchmake/${method}/${roomName}`, {\n headers: {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: options\n });\n\n const response = httpResponse.data as unknown as ISeatReservation;\n\n // forward reconnection token during \"reconnect\" methods.\n if (method === \"reconnect\") {\n response.reconnectionToken = options.reconnectionToken;\n }\n\n return await this.consumeSeatReservation<T>(response, rootSchema);\n } catch (error) {\n if (error instanceof ServerError) {\n throw new MatchMakeError(error.message, error.code);\n }\n throw error;\n }\n }\n\n protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {\n return new Room<any, T>(roomName, rootSchema);\n }\n\n protected buildEndpoint(seatReservation: ISeatReservation, options: any = {}) {\n let protocol: string = this.settings.protocol || \"ws\";\n let searchParams = this.settings.searchParams || \"\";\n\n // forward authentication token\n if (this.http.authToken) {\n options['_authToken'] = this.http.authToken;\n }\n\n // append provided options\n for (const name in options) {\n if (!options.hasOwnProperty(name)) {\n continue;\n }\n searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;\n }\n\n if (protocol === \"h3\") {\n protocol = \"http\";\n }\n\n let endpoint = (this.settings.secure)\n ? `${protocol}s://`\n : `${protocol}://`;\n\n if (seatReservation.publicAddress) {\n endpoint += `${seatReservation.publicAddress}`;\n\n } else {\n endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;\n }\n\n const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getHttpEndpoint(segments: string = '') {\n const path = segments.startsWith(\"/\") ? segments : `/${segments}`;\n\n let endpointURL = `${(this.settings.secure) ? \"https\" : \"http\"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;\n\n if (this.settings.searchParams) {\n endpointURL += `?${this.settings.searchParams}`;\n }\n\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getEndpointPort() {\n return (this.settings.port !== 80 && this.settings.port !== 443)\n ? `:${this.settings.port}`\n : \"\";\n }\n}\n\nexport const Client = ColyseusSDK;\nexport type Client<ServerType extends SDKTypes = any, UserData = any> = InstanceType<typeof ColyseusSDK<ServerType, UserData>>;"],"names":["HTTP","Auth","discordURLBuilder","__awaiter","ServerError","Connection","CloseCode","Protocol","MatchMakeError","Room"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,QAAQ,MAAM,CAAC,KAAK,WAAW,IAAK,QAAQ,MAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAN,MAAM,CAAE,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,QAA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G,CAAA,CAAA,EAAI,QAAQ,EAAE;AAEjE,QAAA,IAAI,WAAW,GAAG,CAAA,EAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,OAAO,GAAG,MAAM,CAAA,GAAA,EAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAA,EAAG,IAAI,CAAC,eAAe,EAAE,CAAA,EAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAA,EAAG,IAAI,EAAE;AAErJ,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC5B,WAAW,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;QACnD;AAEA,QAAA,OAAO,CAAC,IAAI,CAAC,UAAU;cACjB,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC;cACpC,WAAW;IACrB;IAEU,eAAe,GAAA;AACrB,QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG;AAC3D,cAAE,CAAA,CAAA,EAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;cACtB,EAAE;IACZ;;AAlbO,WAAA,CAAA,OAAO,GAAG,MAAM;AAqbpB,MAAM,MAAM,GAAG;;;;;"}
|
package/build/Client.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface LatencyOptions {
|
|
|
26
26
|
protocol?: "ws" | "h3";
|
|
27
27
|
/** Number of pings to send (default: 1). Returns the average latency when > 1. */
|
|
28
28
|
pingCount?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Milliseconds to wait for the measurement before rejecting (default: 1500).
|
|
31
|
+
* Bounds unreachable/blackholed endpoints so they can't stall selection.
|
|
32
|
+
*/
|
|
33
|
+
timeout?: number;
|
|
29
34
|
}
|
|
30
35
|
export declare class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
31
36
|
static VERSION: string;
|
|
@@ -47,7 +52,7 @@ export declare class ColyseusSDK<ServerType extends SDKTypes = any, UserData = a
|
|
|
47
52
|
* Select the endpoint with the lowest latency.
|
|
48
53
|
* @param endpoints Array of endpoints to select from.
|
|
49
54
|
* @param options Client options.
|
|
50
|
-
* @param latencyOptions Latency measurement options (protocol, pingCount).
|
|
55
|
+
* @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.
|
|
51
56
|
* @returns The client with the lowest latency.
|
|
52
57
|
*/
|
|
53
58
|
static selectByLatency<ServerType extends SDKTypes = any, UserData = any>(endpoints: Array<string | EndpointSettings>, options?: ClientOptions, latencyOptions?: LatencyOptions): Promise<ColyseusSDK<ServerType, UserData>>;
|
|
@@ -76,7 +81,11 @@ export declare class ColyseusSDK<ServerType extends SDKTypes = any, UserData = a
|
|
|
76
81
|
consumeSeatReservation<T>(response: ISeatReservation, rootSchema?: SchemaConstructor<T>): Promise<Room<any, T>>;
|
|
77
82
|
/**
|
|
78
83
|
* Create a new connection with the server, and measure the latency.
|
|
79
|
-
*
|
|
84
|
+
*
|
|
85
|
+
* Always settles: resolves with the (average) round-trip time, or rejects on
|
|
86
|
+
* connection error, server-side close before all pongs arrive, or timeout.
|
|
87
|
+
*
|
|
88
|
+
* @param options Latency measurement options (protocol, pingCount, timeout).
|
|
80
89
|
*/
|
|
81
90
|
getLatency(options?: LatencyOptions): Promise<number>;
|
|
82
91
|
protected createMatchMakeRequest<T>(method: string, roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor<T>): Promise<Room<any, T>>;
|
package/build/Client.mjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
7
|
-
import {
|
|
6
|
+
// colyseus.js@0.17.43
|
|
7
|
+
import { CloseCode, Protocol } from '@colyseus/shared-types';
|
|
8
8
|
import { ServerError, MatchMakeError } from './errors/Errors.mjs';
|
|
9
9
|
import { Room } from './Room.mjs';
|
|
10
10
|
import { HTTP } from './HTTP.mjs';
|
|
@@ -89,7 +89,7 @@ class ColyseusSDK {
|
|
|
89
89
|
* Select the endpoint with the lowest latency.
|
|
90
90
|
* @param endpoints Array of endpoints to select from.
|
|
91
91
|
* @param options Client options.
|
|
92
|
-
* @param latencyOptions Latency measurement options (protocol, pingCount).
|
|
92
|
+
* @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.
|
|
93
93
|
* @returns The client with the lowest latency.
|
|
94
94
|
*/
|
|
95
95
|
static async selectByLatency(endpoints, options, latencyOptions = {}) {
|
|
@@ -154,15 +154,39 @@ class ColyseusSDK {
|
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Create a new connection with the server, and measure the latency.
|
|
157
|
-
*
|
|
157
|
+
*
|
|
158
|
+
* Always settles: resolves with the (average) round-trip time, or rejects on
|
|
159
|
+
* connection error, server-side close before all pongs arrive, or timeout.
|
|
160
|
+
*
|
|
161
|
+
* @param options Latency measurement options (protocol, pingCount, timeout).
|
|
158
162
|
*/
|
|
159
163
|
getLatency(options = {}) {
|
|
160
164
|
const protocol = options.protocol ?? "ws";
|
|
161
165
|
const pingCount = options.pingCount ?? 1;
|
|
166
|
+
const timeout = options.timeout ?? 1500;
|
|
162
167
|
return new Promise((resolve, reject) => {
|
|
163
168
|
const conn = new Connection(protocol);
|
|
164
169
|
const latencies = [];
|
|
165
170
|
let pingStart = 0;
|
|
171
|
+
let settled = false;
|
|
172
|
+
let timeoutId;
|
|
173
|
+
// run exactly once — guards against late events after resolve/reject
|
|
174
|
+
// (e.g. our own conn.close() firing onclose, or a stray onclose/onerror pair)
|
|
175
|
+
const settle = (run) => {
|
|
176
|
+
if (settled) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
settled = true;
|
|
180
|
+
clearTimeout(timeoutId);
|
|
181
|
+
try {
|
|
182
|
+
conn.close();
|
|
183
|
+
}
|
|
184
|
+
catch (e) { /* socket may never have opened */ }
|
|
185
|
+
run();
|
|
186
|
+
};
|
|
187
|
+
const fail = (message) => settle(() => reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${message}`)));
|
|
188
|
+
// bound blackholed/filtered hosts that never fire onopen/onerror within the OS TCP timeout
|
|
189
|
+
timeoutId = setTimeout(() => fail(`timed out after ${timeout}ms`), timeout);
|
|
166
190
|
conn.events.onopen = () => {
|
|
167
191
|
pingStart = Date.now();
|
|
168
192
|
conn.send(new Uint8Array([Protocol.PING]));
|
|
@@ -176,15 +200,19 @@ class ColyseusSDK {
|
|
|
176
200
|
}
|
|
177
201
|
else {
|
|
178
202
|
// Done, calculate average and close
|
|
179
|
-
conn.close();
|
|
180
203
|
const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;
|
|
181
|
-
resolve(average);
|
|
204
|
+
settle(() => resolve(average));
|
|
182
205
|
}
|
|
183
206
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
207
|
+
// server closed the socket before all pongs arrived — fires without onerror on a clean close
|
|
208
|
+
conn.events.onclose = (event) => fail(`connection closed${event?.code ? ` (${event.code})` : ""}${event?.reason ? `: ${event.reason}` : ""}`);
|
|
209
|
+
conn.events.onerror = (event) => fail(event.message);
|
|
210
|
+
try {
|
|
211
|
+
conn.connect(this.getHttpEndpoint());
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
fail(e?.message ?? "failed to connect");
|
|
215
|
+
}
|
|
188
216
|
});
|
|
189
217
|
}
|
|
190
218
|
async createMatchMakeRequest(method, roomName, options = {}, rootSchema) {
|
package/build/Client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.mjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { MatchMakeError, ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP, type FetchFn } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\n// - React Native does not provide `window.location`\n// - Cocos Creator (Native) does not provide `window.location.hostname`\nconst DEFAULT_ENDPOINT = (typeof (window) !== \"undefined\" && typeof (window?.location?.hostname) !== \"undefined\")\n ? `${window.location.protocol.replace(\"http\", \"ws\")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`\n : \"ws://127.0.0.1:2567\";\n\nexport interface EndpointSettings {\n hostname: string,\n secure: boolean,\n port?: number,\n pathname?: string,\n searchParams?: string,\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface ClientOptions {\n headers?: { [id: string]: string };\n urlBuilder?: (url: URL) => string;\n protocol?: \"ws\" | \"h3\";\n fetchFn?: FetchFn;\n}\n\nexport interface LatencyOptions {\n /** \"ws\" for WebSocket, \"h3\" for WebTransport (default: \"ws\") */\n protocol?: \"ws\" | \"h3\";\n /** Number of pings to send (default: 1). Returns the average latency when > 1. */\n pingCount?: number;\n}\n\nexport class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {\n static VERSION = \"0.17\";\n\n /**\n * The HTTP client to make requests to the server.\n */\n public http: HTTP<ServerType['~routes']>;\n\n /**\n * The authentication module to authenticate into requests and rooms.\n */\n public auth: Auth<UserData>;\n\n /**\n * The settings used to connect to the server.\n */\n public settings: EndpointSettings;\n\n protected urlBuilder: (url: URL) => string;\n\n constructor(\n settings: string | EndpointSettings = DEFAULT_ENDPOINT,\n options?: ClientOptions,\n ) {\n if (typeof (settings) === \"string\") {\n\n //\n // endpoint by url\n //\n const url = (settings.startsWith(\"/\"))\n ? new URL(settings, DEFAULT_ENDPOINT)\n : new URL(settings);\n\n const secure = (url.protocol === \"https:\" || url.protocol === \"wss:\");\n const port = Number(url.port || (secure ? 443 : 80));\n\n this.settings = {\n hostname: url.hostname,\n pathname: url.pathname,\n port,\n secure,\n searchParams: url.searchParams.toString() || undefined,\n };\n\n } else {\n //\n // endpoint by settings\n //\n if (settings.port === undefined) {\n settings.port = (settings.secure) ? 443 : 80;\n }\n if (settings.pathname === undefined) {\n settings.pathname = \"\";\n }\n this.settings = settings;\n }\n\n // make sure pathname does not end with \"/\"\n if (this.settings.pathname.endsWith(\"/\")) {\n this.settings.pathname = this.settings.pathname.slice(0, -1);\n }\n\n // specify room connection protocol if provided\n if (options?.protocol) {\n this.settings.protocol = options.protocol;\n }\n\n this.http = new HTTP(this, {\n headers: options?.headers || {},\n }, options?.fetchFn);\n this.auth = new Auth(this.http);\n\n this.urlBuilder = options?.urlBuilder;\n\n //\n // Discord Embedded SDK requires a custom URL builder\n //\n if (\n !this.urlBuilder &&\n typeof (window) !== \"undefined\" &&\n window?.location?.hostname?.includes(\"discordsays.com\")\n ) {\n this.urlBuilder = discordURLBuilder;\n console.log(\"Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.\");\n }\n }\n\n /**\n * Select the endpoint with the lowest latency.\n * @param endpoints Array of endpoints to select from.\n * @param options Client options.\n * @param latencyOptions Latency measurement options (protocol, pingCount).\n * @returns The client with the lowest latency.\n */\n static async selectByLatency<ServerType extends SDKTypes = any, UserData = any>(\n endpoints: Array<string | EndpointSettings>,\n options?: ClientOptions,\n latencyOptions: LatencyOptions = {}\n ) {\n const clients = endpoints.map(endpoint => new ColyseusSDK<ServerType, UserData>(endpoint, options));\n\n const latencies = (await Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {\n const settings = clients[index].settings;\n console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);\n return [index, latency]\n }))))\n .filter((result) => result.status === 'fulfilled')\n .map(result => result.value);\n\n if (latencies.length === 0) {\n throw new Error('All endpoints failed to respond');\n }\n\n return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinOrCreate<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinOrCreate<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinOrCreate<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinOrCreate', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async create<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async create<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async create<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('create', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async join<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async join<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async join<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('join', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinById<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinById<State = any>(\n roomId: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinById<T = any>(roomId: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinById', roomId, options, rootSchema);\n }\n\n /**\n * Re-establish connection with a room this client was previously connected to.\n *\n * @param reconnectionToken The `room.reconnectionToken` from previously connected room.\n * @param rootSchema (optional) Concrete root schema definition\n * @returns Promise<Room>\n */\n // Overload: Use room name from ServerType to infer room type\n public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async reconnect<RoomType extends ServerRoomLike>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async reconnect<State = any>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async reconnect<T = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<T>) {\n if (typeof (reconnectionToken) === \"string\" && typeof (rootSchema) === \"string\") {\n throw new Error(\"DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\\nYou can get this token from previously connected `room.reconnectionToken`\");\n }\n const [roomId, token] = reconnectionToken.split(\":\");\n\t\tif (!roomId || !token) {\n\t\t\tthrow new Error(\"Invalid reconnection token format.\\nThe format should be roomId:reconnectionToken\");\n\t\t}\n return await this.createMatchMakeRequest<T>('reconnect', roomId, { reconnectionToken: token }, rootSchema);\n }\n\n public async consumeSeatReservation<T>(\n response: ISeatReservation,\n rootSchema?: SchemaConstructor<T>\n ): Promise<Room<any, T>> {\n const room = this.createRoom<T>(response.name, rootSchema);\n room.roomId = response.roomId;\n room.sessionId = response.sessionId;\n\n const options: any = { sessionId: room.sessionId };\n\n // forward \"reconnection token\" in case of reconnection.\n if (response.reconnectionToken) {\n options.reconnectionToken = response.reconnectionToken;\n }\n\n room.connect(\n this.buildEndpoint(response, options),\n response,\n this.http.options.headers\n );\n\n return new Promise((resolve, reject) => {\n const onError = (code, message) => reject(new ServerError(code, message));\n room.onError.once(onError);\n\n room['onJoin'].once(() => {\n room.onError.remove(onError);\n resolve(room);\n });\n });\n }\n\n /**\n * Create a new connection with the server, and measure the latency.\n * @param options Latency measurement options (protocol, pingCount).\n */\n public getLatency(options: LatencyOptions = {}): Promise<number> {\n const protocol = options.protocol ?? \"ws\";\n const pingCount = options.pingCount ?? 1;\n\n return new Promise<number>((resolve, reject) => {\n const conn = new Connection(protocol);\n const latencies: number[] = [];\n let pingStart = 0;\n\n conn.events.onopen = () => {\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n };\n\n conn.events.onmessage = (_: MessageEvent) => {\n latencies.push(Date.now() - pingStart);\n\n if (latencies.length < pingCount) {\n // Send another ping\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n } else {\n // Done, calculate average and close\n conn.close();\n const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;\n resolve(average);\n }\n };\n\n conn.events.onerror = (event: ErrorEvent) => {\n reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));\n };\n\n conn.connect(this.getHttpEndpoint());\n });\n }\n\n protected async createMatchMakeRequest<T>(\n method: string,\n roomName: string,\n options: JoinOptions = {},\n rootSchema?: SchemaConstructor<T>,\n ) {\n try {\n if (!roomName) {\n throw new Error(\"Must provide a room name\");\n }\n\n const httpResponse = await (this.http as HTTP<any>).post(`/matchmake/${method}/${roomName}`, {\n headers: {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: options\n });\n\n const response = httpResponse.data as unknown as ISeatReservation;\n\n // forward reconnection token during \"reconnect\" methods.\n if (method === \"reconnect\") {\n response.reconnectionToken = options.reconnectionToken;\n }\n\n return await this.consumeSeatReservation<T>(response, rootSchema);\n } catch (error) {\n if (error instanceof ServerError) {\n throw new MatchMakeError(error.message, error.code);\n }\n throw error;\n }\n }\n\n protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {\n return new Room<any, T>(roomName, rootSchema);\n }\n\n protected buildEndpoint(seatReservation: ISeatReservation, options: any = {}) {\n let protocol: string = this.settings.protocol || \"ws\";\n let searchParams = this.settings.searchParams || \"\";\n\n // forward authentication token\n if (this.http.authToken) {\n options['_authToken'] = this.http.authToken;\n }\n\n // append provided options\n for (const name in options) {\n if (!options.hasOwnProperty(name)) {\n continue;\n }\n searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;\n }\n\n if (protocol === \"h3\") {\n protocol = \"http\";\n }\n\n let endpoint = (this.settings.secure)\n ? `${protocol}s://`\n : `${protocol}://`;\n\n if (seatReservation.publicAddress) {\n endpoint += `${seatReservation.publicAddress}`;\n\n } else {\n endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;\n }\n\n const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getHttpEndpoint(segments: string = '') {\n const path = segments.startsWith(\"/\") ? segments : `/${segments}`;\n\n let endpointURL = `${(this.settings.secure) ? \"https\" : \"http\"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;\n\n if (this.settings.searchParams) {\n endpointURL += `?${this.settings.searchParams}`;\n }\n\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getEndpointPort() {\n return (this.settings.port !== 80 && this.settings.port !== 443)\n ? `:${this.settings.port}`\n : \"\";\n }\n}\n\nexport const Client = ColyseusSDK;\nexport type Client<ServerType extends SDKTypes = any, UserData = any> = InstanceType<typeof ColyseusSDK<ServerType, UserData>>;"],"names":[],"mappings":";;;;;;;;;;;;;;AAaA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,QAAQ,MAAM,CAAC,KAAK,WAAW,IAAK,QAAQ,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,WAAW;AAC7G,MAAE,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA,EAAA,EAAK,MAAM,CAAC,QAAQ,CAAC,QAA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CAAA,EAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAA,EAAG,IAAI,EAAE;AAErJ,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC5B,WAAW,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;QACnD;AAEA,QAAA,OAAO,CAAC,IAAI,CAAC,UAAU;cACjB,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC;cACpC,WAAW;IACrB;IAEU,eAAe,GAAA;AACrB,QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG;AAC3D,cAAE,CAAA,CAAA,EAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;cACtB,EAAE;IACZ;;AAGG,MAAM,MAAM,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"Client.mjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { MatchMakeError, ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP, type FetchFn } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\n// - React Native does not provide `window.location`\n// - Cocos Creator (Native) does not provide `window.location.hostname`\nconst DEFAULT_ENDPOINT = (typeof (window) !== \"undefined\" && typeof (window?.location?.hostname) !== \"undefined\")\n ? `${window.location.protocol.replace(\"http\", \"ws\")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`\n : \"ws://127.0.0.1:2567\";\n\nexport interface EndpointSettings {\n hostname: string,\n secure: boolean,\n port?: number,\n pathname?: string,\n searchParams?: string,\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface ClientOptions {\n headers?: { [id: string]: string };\n urlBuilder?: (url: URL) => string;\n protocol?: \"ws\" | \"h3\";\n fetchFn?: FetchFn;\n}\n\nexport interface LatencyOptions {\n /** \"ws\" for WebSocket, \"h3\" for WebTransport (default: \"ws\") */\n protocol?: \"ws\" | \"h3\";\n /** Number of pings to send (default: 1). Returns the average latency when > 1. */\n pingCount?: number;\n /**\n * Milliseconds to wait for the measurement before rejecting (default: 1500).\n * Bounds unreachable/blackholed endpoints so they can't stall selection.\n */\n timeout?: number;\n}\n\nexport class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {\n static VERSION = \"0.17\";\n\n /**\n * The HTTP client to make requests to the server.\n */\n public http: HTTP<ServerType['~routes']>;\n\n /**\n * The authentication module to authenticate into requests and rooms.\n */\n public auth: Auth<UserData>;\n\n /**\n * The settings used to connect to the server.\n */\n public settings: EndpointSettings;\n\n protected urlBuilder: (url: URL) => string;\n\n constructor(\n settings: string | EndpointSettings = DEFAULT_ENDPOINT,\n options?: ClientOptions,\n ) {\n if (typeof (settings) === \"string\") {\n\n //\n // endpoint by url\n //\n const url = (settings.startsWith(\"/\"))\n ? new URL(settings, DEFAULT_ENDPOINT)\n : new URL(settings);\n\n const secure = (url.protocol === \"https:\" || url.protocol === \"wss:\");\n const port = Number(url.port || (secure ? 443 : 80));\n\n this.settings = {\n hostname: url.hostname,\n pathname: url.pathname,\n port,\n secure,\n searchParams: url.searchParams.toString() || undefined,\n };\n\n } else {\n //\n // endpoint by settings\n //\n if (settings.port === undefined) {\n settings.port = (settings.secure) ? 443 : 80;\n }\n if (settings.pathname === undefined) {\n settings.pathname = \"\";\n }\n this.settings = settings;\n }\n\n // make sure pathname does not end with \"/\"\n if (this.settings.pathname.endsWith(\"/\")) {\n this.settings.pathname = this.settings.pathname.slice(0, -1);\n }\n\n // specify room connection protocol if provided\n if (options?.protocol) {\n this.settings.protocol = options.protocol;\n }\n\n this.http = new HTTP(this, {\n headers: options?.headers || {},\n }, options?.fetchFn);\n this.auth = new Auth(this.http);\n\n this.urlBuilder = options?.urlBuilder;\n\n //\n // Discord Embedded SDK requires a custom URL builder\n //\n if (\n !this.urlBuilder &&\n typeof (window) !== \"undefined\" &&\n window?.location?.hostname?.includes(\"discordsays.com\")\n ) {\n this.urlBuilder = discordURLBuilder;\n console.log(\"Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.\");\n }\n }\n\n /**\n * Select the endpoint with the lowest latency.\n * @param endpoints Array of endpoints to select from.\n * @param options Client options.\n * @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.\n * @returns The client with the lowest latency.\n */\n static async selectByLatency<ServerType extends SDKTypes = any, UserData = any>(\n endpoints: Array<string | EndpointSettings>,\n options?: ClientOptions,\n latencyOptions: LatencyOptions = {}\n ) {\n const clients = endpoints.map(endpoint => new ColyseusSDK<ServerType, UserData>(endpoint, options));\n\n const latencies = (await Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {\n const settings = clients[index].settings;\n console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);\n return [index, latency]\n }))))\n .filter((result) => result.status === 'fulfilled')\n .map(result => result.value);\n\n if (latencies.length === 0) {\n throw new Error('All endpoints failed to respond');\n }\n\n return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinOrCreate<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinOrCreate<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinOrCreate<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinOrCreate', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async create<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async create<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async create<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('create', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async join<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async join<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async join<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('join', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinById<R extends keyof ServerType['~rooms'], State = InferState<ServerType['~rooms'][R]['~room'], never>>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['onJoin']>[1],\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<ServerType['~rooms'][R]['~room'], State>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<NonNullable<RoomType['onJoin']>>[1],\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async joinById<State = any>(\n roomId: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinById<T = any>(roomId: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinById', roomId, options, rootSchema);\n }\n\n /**\n * Re-establish connection with a room this client was previously connected to.\n *\n * @param reconnectionToken The `room.reconnectionToken` from previously connected room.\n * @param rootSchema (optional) Concrete root schema definition\n * @returns Promise<Room>\n */\n // Overload: Use room name from ServerType to infer room type\n public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async reconnect<RoomType extends ServerRoomLike>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<RoomType['state']>\n ): Promise<Room<RoomType, RoomType['state']>>\n // Overload: Pass State type directly\n public async reconnect<State = any>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async reconnect<T = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<T>) {\n if (typeof (reconnectionToken) === \"string\" && typeof (rootSchema) === \"string\") {\n throw new Error(\"DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\\nYou can get this token from previously connected `room.reconnectionToken`\");\n }\n const [roomId, token] = reconnectionToken.split(\":\");\n\t\tif (!roomId || !token) {\n\t\t\tthrow new Error(\"Invalid reconnection token format.\\nThe format should be roomId:reconnectionToken\");\n\t\t}\n return await this.createMatchMakeRequest<T>('reconnect', roomId, { reconnectionToken: token }, rootSchema);\n }\n\n public async consumeSeatReservation<T>(\n response: ISeatReservation,\n rootSchema?: SchemaConstructor<T>\n ): Promise<Room<any, T>> {\n const room = this.createRoom<T>(response.name, rootSchema);\n room.roomId = response.roomId;\n room.sessionId = response.sessionId;\n\n const options: any = { sessionId: room.sessionId };\n\n // forward \"reconnection token\" in case of reconnection.\n if (response.reconnectionToken) {\n options.reconnectionToken = response.reconnectionToken;\n }\n\n room.connect(\n this.buildEndpoint(response, options),\n response,\n this.http.options.headers\n );\n\n return new Promise((resolve, reject) => {\n const onError = (code, message) => reject(new ServerError(code, message));\n room.onError.once(onError);\n\n room['onJoin'].once(() => {\n room.onError.remove(onError);\n resolve(room);\n });\n });\n }\n\n /**\n * Create a new connection with the server, and measure the latency.\n *\n * Always settles: resolves with the (average) round-trip time, or rejects on\n * connection error, server-side close before all pongs arrive, or timeout.\n *\n * @param options Latency measurement options (protocol, pingCount, timeout).\n */\n public getLatency(options: LatencyOptions = {}): Promise<number> {\n const protocol = options.protocol ?? \"ws\";\n const pingCount = options.pingCount ?? 1;\n const timeout = options.timeout ?? 1500;\n\n return new Promise<number>((resolve, reject) => {\n const conn = new Connection(protocol);\n const latencies: number[] = [];\n let pingStart = 0;\n let settled = false;\n let timeoutId: ReturnType<typeof setTimeout>;\n\n // run exactly once — guards against late events after resolve/reject\n // (e.g. our own conn.close() firing onclose, or a stray onclose/onerror pair)\n const settle = (run: () => void) => {\n if (settled) { return; }\n settled = true;\n clearTimeout(timeoutId);\n try { conn.close(); } catch (e) { /* socket may never have opened */ }\n run();\n };\n\n const fail = (message: string) =>\n settle(() => reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${message}`)));\n\n // bound blackholed/filtered hosts that never fire onopen/onerror within the OS TCP timeout\n timeoutId = setTimeout(() => fail(`timed out after ${timeout}ms`), timeout);\n\n conn.events.onopen = () => {\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n };\n\n conn.events.onmessage = (_: MessageEvent) => {\n latencies.push(Date.now() - pingStart);\n\n if (latencies.length < pingCount) {\n // Send another ping\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n } else {\n // Done, calculate average and close\n const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;\n settle(() => resolve(average));\n }\n };\n\n // server closed the socket before all pongs arrived — fires without onerror on a clean close\n conn.events.onclose = (event: any) =>\n fail(`connection closed${event?.code ? ` (${event.code})` : \"\"}${event?.reason ? `: ${event.reason}` : \"\"}`);\n\n conn.events.onerror = (event: ErrorEvent) => fail(event.message);\n\n try {\n conn.connect(this.getHttpEndpoint());\n } catch (e: any) {\n fail(e?.message ?? \"failed to connect\");\n }\n });\n }\n\n protected async createMatchMakeRequest<T>(\n method: string,\n roomName: string,\n options: JoinOptions = {},\n rootSchema?: SchemaConstructor<T>,\n ) {\n try {\n if (!roomName) {\n throw new Error(\"Must provide a room name\");\n }\n\n const httpResponse = await (this.http as HTTP<any>).post(`/matchmake/${method}/${roomName}`, {\n headers: {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: options\n });\n\n const response = httpResponse.data as unknown as ISeatReservation;\n\n // forward reconnection token during \"reconnect\" methods.\n if (method === \"reconnect\") {\n response.reconnectionToken = options.reconnectionToken;\n }\n\n return await this.consumeSeatReservation<T>(response, rootSchema);\n } catch (error) {\n if (error instanceof ServerError) {\n throw new MatchMakeError(error.message, error.code);\n }\n throw error;\n }\n }\n\n protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {\n return new Room<any, T>(roomName, rootSchema);\n }\n\n protected buildEndpoint(seatReservation: ISeatReservation, options: any = {}) {\n let protocol: string = this.settings.protocol || \"ws\";\n let searchParams = this.settings.searchParams || \"\";\n\n // forward authentication token\n if (this.http.authToken) {\n options['_authToken'] = this.http.authToken;\n }\n\n // append provided options\n for (const name in options) {\n if (!options.hasOwnProperty(name)) {\n continue;\n }\n searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;\n }\n\n if (protocol === \"h3\") {\n protocol = \"http\";\n }\n\n let endpoint = (this.settings.secure)\n ? `${protocol}s://`\n : `${protocol}://`;\n\n if (seatReservation.publicAddress) {\n endpoint += `${seatReservation.publicAddress}`;\n\n } else {\n endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;\n }\n\n const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getHttpEndpoint(segments: string = '') {\n const path = segments.startsWith(\"/\") ? segments : `/${segments}`;\n\n let endpointURL = `${(this.settings.secure) ? \"https\" : \"http\"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;\n\n if (this.settings.searchParams) {\n endpointURL += `?${this.settings.searchParams}`;\n }\n\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getEndpointPort() {\n return (this.settings.port !== 80 && this.settings.port !== 443)\n ? `:${this.settings.port}`\n : \"\";\n }\n}\n\nexport const Client = ColyseusSDK;\nexport type Client<ServerType extends SDKTypes = any, UserData = any> = InstanceType<typeof ColyseusSDK<ServerType, UserData>>;"],"names":[],"mappings":";;;;;;;;;;;;;;AAaA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,QAAQ,MAAM,CAAC,KAAK,WAAW,IAAK,QAAQ,MAAM,EA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AAG,IAAI,EAAE;AAErJ,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC5B,WAAW,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;QACnD;AAEA,QAAA,OAAO,CAAC,IAAI,CAAC,UAAU;cACjB,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC;cACpC,WAAW;IACrB;IAEU,eAAe,GAAA;AACrB,QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG;AAC3D,cAAE,CAAA,CAAA,EAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;cACtB,EAAE;IACZ;;AAGG,MAAM,MAAM,GAAG;;;;"}
|
package/build/Connection.cjs
CHANGED
package/build/Connection.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.43
|
|
7
7
|
import { H3TransportTransport } from './transport/H3Transport.mjs';
|
|
8
8
|
import { WebSocketTransport } from './transport/WebSocketTransport.mjs';
|
|
9
9
|
import { CloseCode } from '@colyseus/shared-types';
|
package/build/HTTP.cjs
CHANGED
package/build/HTTP.mjs
CHANGED
package/build/Room.cjs
CHANGED
package/build/Room.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.43
|
|
7
7
|
import { CloseCode, Protocol } from '@colyseus/shared-types';
|
|
8
8
|
import { Decoder, encode, decode } from '@colyseus/schema';
|
|
9
9
|
import { Packr, unpack } from '@colyseus/msgpackr';
|