@colyseus/sdk 0.17.16 → 0.17.18
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 +20 -26
- package/build/Client.cjs.map +1 -1
- package/build/Client.d.ts +0 -4
- package/build/Client.mjs +22 -28
- package/build/Client.mjs.map +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +20 -19
- package/build/HTTP.cjs.map +1 -1
- package/build/HTTP.d.ts +2 -18
- package/build/HTTP.mjs +19 -18
- package/build/HTTP.mjs.map +1 -1
- package/build/Protocol.cjs +1 -1
- package/build/Protocol.mjs +1 -1
- package/build/Room.cjs +1 -1
- package/build/Room.cjs.map +1 -1
- package/build/Room.d.ts +6 -5
- package/build/Room.mjs +1 -1
- package/build/Room.mjs.map +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 +17 -2
- package/build/errors/Errors.cjs.map +1 -1
- package/build/errors/Errors.d.ts +15 -2
- package/build/errors/Errors.mjs +22 -3
- package/build/errors/Errors.mjs.map +1 -1
- package/build/index.cjs +3 -2
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.mjs +3 -3
- package/build/index.mjs.map +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 +1 -1
- package/build/transport/H3Transport.mjs +1 -1
- package/build/transport/WebSocketTransport.cjs +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus-cocos-creator.js +61 -44
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +61 -44
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +54 -44
- package/dist/debug.js.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +20 -28
- package/src/HTTP.ts +20 -40
- package/src/Room.ts +11 -10
- package/src/errors/Errors.ts +33 -11
- package/src/index.ts +2 -2
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.18
|
|
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.18
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
@@ -17,14 +17,6 @@ var Connection = require('./Connection.cjs');
|
|
|
17
17
|
var discord = require('./3rd_party/discord.cjs');
|
|
18
18
|
|
|
19
19
|
var _a;
|
|
20
|
-
class MatchMakeError extends Error {
|
|
21
|
-
constructor(message, code) {
|
|
22
|
-
super(message);
|
|
23
|
-
this.code = code;
|
|
24
|
-
this.name = "MatchMakeError";
|
|
25
|
-
Object.setPrototypeOf(this, MatchMakeError.prototype);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
20
|
// - React Native does not provide `window.location`
|
|
29
21
|
// - Cocos Creator (Native) does not provide `window.location.hostname`
|
|
30
22
|
const DEFAULT_ENDPOINT = (typeof (window) !== "undefined" && typeof ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) !== "undefined")
|
|
@@ -204,24 +196,27 @@ class ColyseusSDK {
|
|
|
204
196
|
}
|
|
205
197
|
createMatchMakeRequest(method_1, roomName_1) {
|
|
206
198
|
return tslib.__awaiter(this, arguments, void 0, function* (method, roomName, options = {}, rootSchema) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
//
|
|
217
|
-
|
|
199
|
+
try {
|
|
200
|
+
const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
|
|
201
|
+
headers: {
|
|
202
|
+
'Accept': 'application/json',
|
|
203
|
+
'Content-Type': 'application/json'
|
|
204
|
+
},
|
|
205
|
+
body: options
|
|
206
|
+
});
|
|
207
|
+
const response = httpResponse.data;
|
|
208
|
+
// forward reconnection token during "reconnect" methods.
|
|
209
|
+
if (method === "reconnect") {
|
|
210
|
+
response.reconnectionToken = options.reconnectionToken;
|
|
211
|
+
}
|
|
212
|
+
return yield this.consumeSeatReservation(response, rootSchema);
|
|
218
213
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error instanceof Errors.ServerError) {
|
|
216
|
+
throw new Errors.MatchMakeError(error.message, error.code);
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
223
219
|
}
|
|
224
|
-
return yield this.consumeSeatReservation(response, rootSchema);
|
|
225
220
|
});
|
|
226
221
|
}
|
|
227
222
|
createRoom(roomName, rootSchema) {
|
|
@@ -279,5 +274,4 @@ const Client = ColyseusSDK;
|
|
|
279
274
|
|
|
280
275
|
exports.Client = Client;
|
|
281
276
|
exports.ColyseusSDK = ColyseusSDK;
|
|
282
|
-
exports.MatchMakeError = MatchMakeError;
|
|
283
277
|
//# sourceMappingURL=Client.cjs.map
|
package/build/Client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.cjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Protocol } from './Protocol.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\nexport class MatchMakeError extends Error {\n code: number;\n constructor(message: string, code: number) {\n super(message);\n this.code = code;\n this.name = \"MatchMakeError\";\n Object.setPrototypeOf(this, MatchMakeError.prototype);\n }\n}\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}\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 });\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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<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 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 // Handle HTTP error responses\n if (!httpResponse.ok) {\n // @ts-ignore\n throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);\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 }\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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["import { CloseCode, 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 } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Protocol } from './Protocol.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\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}\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 });\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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<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 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":";;;;;;;;;;;;;;;;;;;AAeA;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,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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;;AAlZO,WAAA,CAAA,OAAO,GAAG,MAAM;AAqZpB,MAAM,MAAM,GAAG;;;;;"}
|
package/build/Client.d.ts
CHANGED
|
@@ -5,10 +5,6 @@ import { HTTP } from './HTTP.ts';
|
|
|
5
5
|
import { Auth } from './Auth.ts';
|
|
6
6
|
export type JoinOptions = any;
|
|
7
7
|
export type { ISeatReservation };
|
|
8
|
-
export declare class MatchMakeError extends Error {
|
|
9
|
-
code: number;
|
|
10
|
-
constructor(message: string, code: number);
|
|
11
|
-
}
|
|
12
8
|
export interface EndpointSettings {
|
|
13
9
|
hostname: string;
|
|
14
10
|
secure: boolean;
|
package/build/Client.mjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
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.18
|
|
7
7
|
import { CloseCode } from '@colyseus/shared-types';
|
|
8
|
-
import { ServerError } from './errors/Errors.mjs';
|
|
8
|
+
import { ServerError, MatchMakeError } from './errors/Errors.mjs';
|
|
9
9
|
import { Room } from './Room.mjs';
|
|
10
10
|
import { HTTP } from './HTTP.mjs';
|
|
11
11
|
import { Auth } from './Auth.mjs';
|
|
@@ -13,15 +13,6 @@ import { Protocol } from './Protocol.mjs';
|
|
|
13
13
|
import { Connection } from './Connection.mjs';
|
|
14
14
|
import { discordURLBuilder } from './3rd_party/discord.mjs';
|
|
15
15
|
|
|
16
|
-
class MatchMakeError extends Error {
|
|
17
|
-
code;
|
|
18
|
-
constructor(message, code) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.code = code;
|
|
21
|
-
this.name = "MatchMakeError";
|
|
22
|
-
Object.setPrototypeOf(this, MatchMakeError.prototype);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
16
|
// - React Native does not provide `window.location`
|
|
26
17
|
// - Cocos Creator (Native) does not provide `window.location.hostname`
|
|
27
18
|
const DEFAULT_ENDPOINT = (typeof (window) !== "undefined" && typeof (window?.location?.hostname) !== "undefined")
|
|
@@ -198,24 +189,27 @@ class ColyseusSDK {
|
|
|
198
189
|
});
|
|
199
190
|
}
|
|
200
191
|
async createMatchMakeRequest(method, roomName, options = {}, rootSchema) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
//
|
|
211
|
-
|
|
192
|
+
try {
|
|
193
|
+
const httpResponse = await this.http.post(`/matchmake/${method}/${roomName}`, {
|
|
194
|
+
headers: {
|
|
195
|
+
'Accept': 'application/json',
|
|
196
|
+
'Content-Type': 'application/json'
|
|
197
|
+
},
|
|
198
|
+
body: options
|
|
199
|
+
});
|
|
200
|
+
const response = httpResponse.data;
|
|
201
|
+
// forward reconnection token during "reconnect" methods.
|
|
202
|
+
if (method === "reconnect") {
|
|
203
|
+
response.reconnectionToken = options.reconnectionToken;
|
|
204
|
+
}
|
|
205
|
+
return await this.consumeSeatReservation(response, rootSchema);
|
|
212
206
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (error instanceof ServerError) {
|
|
209
|
+
throw new MatchMakeError(error.message, error.code);
|
|
210
|
+
}
|
|
211
|
+
throw error;
|
|
217
212
|
}
|
|
218
|
-
return await this.consumeSeatReservation(response, rootSchema);
|
|
219
213
|
}
|
|
220
214
|
createRoom(roomName, rootSchema) {
|
|
221
215
|
return new Room(roomName, rootSchema);
|
|
@@ -269,5 +263,5 @@ class ColyseusSDK {
|
|
|
269
263
|
}
|
|
270
264
|
const Client = ColyseusSDK;
|
|
271
265
|
|
|
272
|
-
export { Client, ColyseusSDK
|
|
266
|
+
export { Client, ColyseusSDK };
|
|
273
267
|
//# sourceMappingURL=Client.mjs.map
|
package/build/Client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.mjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';\n\nimport { ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Protocol } from './Protocol.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\nexport class MatchMakeError extends Error {\n code: number;\n constructor(message: string, code: number) {\n super(message);\n this.code = code;\n this.name = \"MatchMakeError\";\n Object.setPrototypeOf(this, MatchMakeError.prototype);\n }\n}\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}\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 });\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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<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 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 // Handle HTTP error responses\n if (!httpResponse.ok) {\n // @ts-ignore\n throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);\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 }\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":";;;;;;;;;;;;;;;AAcM,MAAO,cAAe,SAAQ,KAAK,CAAA;AACrC,IAAA,IAAI;IACJ,WAAA,CAAY,OAAe,EAAE,IAAY,EAAA;QACrC,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,IAAI,GAAG,gBAAgB;QAC5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC;IACzD;AACH;AAED;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,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA,CAAA,EAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE,EAAC;MACrI,qBAAqB;MAwBd,WAAW,CAAA;AACpB,IAAA,OAAO,OAAO,GAAG,MAAM;AAEvB;;AAEG;AACI,IAAA,IAAI;AAEX;;AAEG;AACI,IAAA,IAAI;AAEX;;AAEG;AACI,IAAA,QAAQ;AAEL,IAAA,UAAU;IAEpB,WAAA,CACI,QAAA,GAAsC,gBAAgB,EACtD,OAAuB,EAAA;AAEvB,QAAA,IAAI,QAAQ,QAAQ,CAAC,KAAK,QAAQ,EAAE;;;;YAKhC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,C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.mjs","sources":["../src/Client.ts"],"sourcesContent":["import { CloseCode, 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 } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Protocol } from './Protocol.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type { ISeatReservation };\n\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}\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 });\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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends ServerRoomLike>(\n roomName: string,\n options?: Parameters<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']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends ServerRoomLike>(\n roomId: string,\n options?: Parameters<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 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":";;;;;;;;;;;;;;;AAeA;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,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA,CAAA,EAAI,MAAM,CAAC,QAAQ,CA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AAA,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.18
|
|
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
|
@@ -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.18
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
@@ -111,7 +111,7 @@ class HTTP {
|
|
|
111
111
|
}
|
|
112
112
|
executeRequest(method, path, requestOptions) {
|
|
113
113
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
var _a;
|
|
114
|
+
var _a, _b, _c;
|
|
115
115
|
//
|
|
116
116
|
// FIXME: if FormData is provided, merging "baseOptions.body" with
|
|
117
117
|
// "options.body" will not work as intended
|
|
@@ -146,9 +146,9 @@ class HTTP {
|
|
|
146
146
|
body,
|
|
147
147
|
method });
|
|
148
148
|
const url = getURLWithQueryParams(this.sdk['getHttpEndpoint'](path.toString()), mergedOptions);
|
|
149
|
-
let
|
|
149
|
+
let raw;
|
|
150
150
|
try {
|
|
151
|
-
|
|
151
|
+
raw = yield fetch(url, mergedOptions);
|
|
152
152
|
}
|
|
153
153
|
catch (err) {
|
|
154
154
|
// If it's an AbortError, re-throw as-is
|
|
@@ -157,35 +157,36 @@ class HTTP {
|
|
|
157
157
|
}
|
|
158
158
|
// Re-throw with network error code at top level (e.g. ECONNREFUSED)
|
|
159
159
|
const networkError = new Errors.ServerError(((_a = err.cause) === null || _a === void 0 ? void 0 : _a.code) || err.code, err.message);
|
|
160
|
+
networkError.response = raw;
|
|
160
161
|
networkError.cause = err.cause;
|
|
161
162
|
throw networkError;
|
|
162
163
|
}
|
|
163
|
-
const contentType =
|
|
164
|
+
const contentType = raw.headers.get("content-type");
|
|
164
165
|
let data;
|
|
165
|
-
let error = null;
|
|
166
166
|
// TODO: improve content-type detection here!
|
|
167
167
|
if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("json")) {
|
|
168
|
-
data = yield
|
|
168
|
+
data = yield raw.json();
|
|
169
169
|
}
|
|
170
170
|
else if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("text")) {
|
|
171
|
-
data = yield
|
|
171
|
+
data = yield raw.text();
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
data = yield
|
|
174
|
+
data = yield raw.blob();
|
|
175
175
|
}
|
|
176
|
-
if (!
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
if (!raw.ok) {
|
|
177
|
+
throw new Errors.ServerError((_b = data.code) !== null && _b !== void 0 ? _b : raw.status, (_c = data.message) !== null && _c !== void 0 ? _c : raw.statusText, {
|
|
178
|
+
headers: raw.headers,
|
|
179
|
+
status: raw.status,
|
|
180
|
+
response: raw,
|
|
181
|
+
data
|
|
182
|
+
});
|
|
180
183
|
}
|
|
181
184
|
return {
|
|
182
|
-
|
|
183
|
-
headers: response.headers,
|
|
185
|
+
raw,
|
|
184
186
|
data,
|
|
185
|
-
|
|
186
|
-
status:
|
|
187
|
-
statusText:
|
|
188
|
-
response,
|
|
187
|
+
headers: raw.headers,
|
|
188
|
+
status: raw.status,
|
|
189
|
+
statusText: raw.statusText,
|
|
189
190
|
};
|
|
190
191
|
});
|
|
191
192
|
}
|