@colyseus/sdk 0.17.13 → 0.17.14

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.
Files changed (62) hide show
  1. package/build/3rd_party/discord.cjs +1 -1
  2. package/build/3rd_party/discord.mjs +1 -1
  3. package/build/Auth.cjs +1 -1
  4. package/build/Auth.mjs +1 -1
  5. package/build/Client.cjs +3 -2
  6. package/build/Client.cjs.map +1 -1
  7. package/build/Client.d.ts +1 -1
  8. package/build/Client.mjs +3 -2
  9. package/build/Client.mjs.map +1 -1
  10. package/build/Connection.cjs +1 -1
  11. package/build/Connection.mjs +1 -1
  12. package/build/HTTP.cjs +1 -1
  13. package/build/HTTP.mjs +1 -1
  14. package/build/Protocol.cjs +1 -1
  15. package/build/Protocol.mjs +1 -1
  16. package/build/Room.cjs +7 -7
  17. package/build/Room.cjs.map +1 -1
  18. package/build/Room.mjs +2 -2
  19. package/build/Room.mjs.map +1 -1
  20. package/build/Storage.cjs +1 -1
  21. package/build/Storage.mjs +1 -1
  22. package/build/core/nanoevents.cjs +1 -1
  23. package/build/core/nanoevents.mjs +1 -1
  24. package/build/core/signal.cjs +1 -1
  25. package/build/core/signal.mjs +1 -1
  26. package/build/core/utils.cjs +1 -1
  27. package/build/core/utils.mjs +1 -1
  28. package/build/debug.cjs +1 -1
  29. package/build/debug.mjs +1 -1
  30. package/build/errors/Errors.cjs +1 -12
  31. package/build/errors/Errors.cjs.map +1 -1
  32. package/build/errors/Errors.d.ts +0 -10
  33. package/build/errors/Errors.mjs +2 -13
  34. package/build/errors/Errors.mjs.map +1 -1
  35. package/build/index.cjs +11 -11
  36. package/build/index.cjs.map +1 -1
  37. package/build/index.d.ts +2 -2
  38. package/build/index.mjs +3 -3
  39. package/build/index.mjs.map +1 -1
  40. package/build/legacy.cjs +1 -1
  41. package/build/legacy.mjs +1 -1
  42. package/build/serializer/NoneSerializer.cjs +1 -1
  43. package/build/serializer/NoneSerializer.mjs +1 -1
  44. package/build/serializer/SchemaSerializer.cjs +1 -1
  45. package/build/serializer/SchemaSerializer.mjs +1 -1
  46. package/build/serializer/Serializer.cjs +1 -1
  47. package/build/serializer/Serializer.mjs +1 -1
  48. package/build/transport/H3Transport.cjs +1 -1
  49. package/build/transport/H3Transport.mjs +1 -1
  50. package/build/transport/WebSocketTransport.cjs +1 -1
  51. package/build/transport/WebSocketTransport.mjs +1 -1
  52. package/dist/colyseus-cocos-creator.js +67 -38
  53. package/dist/colyseus-cocos-creator.js.map +1 -1
  54. package/dist/colyseus.js +67 -38
  55. package/dist/colyseus.js.map +1 -1
  56. package/dist/debug.js +9 -20
  57. package/dist/debug.js.map +1 -1
  58. package/package.json +3 -3
  59. package/src/Client.ts +2 -2
  60. package/src/Room.ts +1 -2
  61. package/src/errors/Errors.ts +0 -11
  62. package/src/index.ts +2 -2
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  /**
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  /**
8
8
  * Discord Embedded App SDK
9
9
  * https://github.com/colyseus/colyseus/issues/707
package/build/Auth.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.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
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.13
6
+ // colyseus.js@0.17.14
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,10 +3,11 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
10
+ var sharedTypes = require('@colyseus/shared-types');
10
11
  var Errors = require('./errors/Errors.cjs');
11
12
  var Room = require('./Room.cjs');
12
13
  var HTTP = require('./HTTP.cjs');
@@ -196,7 +197,7 @@ class ColyseusSDK {
196
197
  }
197
198
  };
198
199
  conn.events.onerror = (event) => {
199
- reject(new Errors.ServerError(Errors.CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
200
+ reject(new Errors.ServerError(sharedTypes.CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
200
201
  };
201
202
  conn.connect(this.getHttpEndpoint());
202
203
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Client.cjs","sources":["../src/Client.ts"],"sourcesContent":["import type { SDKTypes, ServerRoomLike, ISeatReservation } from '@colyseus/shared-types';\n\nimport { CloseCode, 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":["HTTP","Auth","discordURLBuilder","__awaiter","ServerError","Connection","Protocol","CloseCode","Room"],"mappings":";;;;;;;;;;;;;;;;;;AAcM,MAAO,cAAe,SAAQ,KAAK,CAAA;IAErC,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,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,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AAC,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;;AAjZO,WAAA,CAAA,OAAO,GAAG,MAAM;AAoZpB,MAAM,MAAM,GAAG;;;;;;"}
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<typ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ServerRoomLike, ISeatReservation } from '@colyseus/shared-types';
1
+ import { type SDKTypes, type ServerRoomLike, type ISeatReservation } from '@colyseus/shared-types';
2
2
  import { Room } from './Room.ts';
3
3
  import { SchemaConstructor } from './serializer/SchemaSerializer.ts';
4
4
  import { HTTP } from './HTTP.ts';
package/build/Client.mjs CHANGED
@@ -3,8 +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.13
7
- import { ServerError, CloseCode } from './errors/Errors.mjs';
6
+ // colyseus.js@0.17.14
7
+ import { CloseCode } from '@colyseus/shared-types';
8
+ import { ServerError } from './errors/Errors.mjs';
8
9
  import { Room } from './Room.mjs';
9
10
  import { HTTP } from './HTTP.mjs';
10
11
  import { Auth } from './Auth.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"Client.mjs","sources":["../src/Client.ts"],"sourcesContent":["import type { SDKTypes, ServerRoomLike, ISeatReservation } from '@colyseus/shared-types';\n\nimport { CloseCode, 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,EAA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A,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, 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;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C,WAAW;IACrB;IAEU,eAAe,CAAC,WAAmB,EAAE,EAAA;AAC3C,QAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,GAAG,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;;AAGG,MAAM,MAAM,GAAG;;;;"}
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  var H3Transport = require('./transport/H3Transport.cjs');
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  import { H3TransportTransport } from './transport/H3Transport.mjs';
8
8
  import { WebSocketTransport } from './transport/WebSocketTransport.mjs';
9
9
 
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.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
package/build/HTTP.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.13
6
+ // colyseus.js@0.17.14
7
7
  import { ServerError } from './errors/Errors.mjs';
8
8
 
9
9
  function isJSONSerializable(value) {
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  // Use codes between 0~127 for lesser throughput (1 byte)
@@ -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.13
6
+ // colyseus.js@0.17.14
7
7
  // Use codes between 0~127 for lesser throughput (1 byte)
8
8
  var Protocol;
9
9
  (function (Protocol) {
package/build/Room.cjs CHANGED
@@ -3,10 +3,11 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.13
6
+ // colyseus.js@0.17.14
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
10
+ var sharedTypes = require('@colyseus/shared-types');
10
11
  var schema = require('@colyseus/schema');
11
12
  var msgpackr = require('@colyseus/msgpackr');
12
13
  var Connection = require('./Connection.cjs');
@@ -15,7 +16,6 @@ var Serializer = require('./serializer/Serializer.cjs');
15
16
  var nanoevents = require('./core/nanoevents.cjs');
16
17
  var signal = require('./core/signal.cjs');
17
18
  var SchemaSerializer = require('./serializer/SchemaSerializer.cjs');
18
- var Errors = require('./errors/Errors.cjs');
19
19
  var utils = require('./core/utils.cjs');
20
20
 
21
21
  var _Room_lastPingTime, _Room_pingCallback;
@@ -67,10 +67,10 @@ class Room {
67
67
  this.onError.invoke(e.code, e.reason);
68
68
  return;
69
69
  }
70
- if (e.code === Errors.CloseCode.NO_STATUS_RECEIVED ||
71
- e.code === Errors.CloseCode.ABNORMAL_CLOSURE ||
72
- e.code === Errors.CloseCode.GOING_AWAY ||
73
- e.code === Errors.CloseCode.DEVMODE_RESTART) {
70
+ if (e.code === sharedTypes.CloseCode.NO_STATUS_RECEIVED ||
71
+ e.code === sharedTypes.CloseCode.ABNORMAL_CLOSURE ||
72
+ e.code === sharedTypes.CloseCode.GOING_AWAY ||
73
+ e.code === sharedTypes.CloseCode.DEVMODE_RESTART) {
74
74
  this.onDrop.invoke(e.code, e.reason);
75
75
  this.handleReconnection();
76
76
  }
@@ -111,7 +111,7 @@ class Room {
111
111
  }
112
112
  }
113
113
  else {
114
- this.onLeave.invoke(Errors.CloseCode.CONSENTED);
114
+ this.onLeave.invoke(sharedTypes.CloseCode.CONSENTED);
115
115
  }
116
116
  });
117
117
  }