@colyseus/sdk 0.17.11 → 0.17.13
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.cjs.map +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +1 -1
- package/build/Auth.cjs.map +1 -1
- package/build/Auth.mjs +1 -1
- package/build/Client.cjs +1 -1
- package/build/Client.cjs.map +1 -1
- package/build/Client.d.ts +7 -7
- package/build/Client.mjs +1 -1
- package/build/Client.mjs.map +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +23 -1
- package/build/HTTP.cjs.map +1 -1
- package/build/HTTP.mjs +23 -2
- 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 +3 -19
- 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.cjs.map +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +2 -1
- package/build/core/signal.cjs.map +1 -1
- package/build/core/signal.mjs +2 -1
- package/build/core/signal.mjs.map +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +2461 -0
- package/build/debug.cjs.map +1 -0
- package/build/debug.mjs +2452 -0
- package/build/debug.mjs.map +1 -0
- package/build/errors/Errors.cjs +8 -1
- package/build/errors/Errors.cjs.map +1 -1
- package/build/errors/Errors.mjs +8 -2
- package/build/errors/Errors.mjs.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +2 -2
- 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.cjs.map +1 -1
- package/build/transport/H3Transport.mjs +1 -1
- package/build/transport/H3Transport.mjs.map +1 -1
- package/build/transport/WebSocketTransport.cjs +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus-cocos-creator.js +1 -1
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +1 -1
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +4277 -2394
- package/dist/debug.js.map +1 -1
- package/package.json +4 -3
- package/src/Client.ts +7 -7
- package/src/Room.ts +6 -25
- package/src/debug.ts +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/sdk",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.13",
|
|
4
4
|
"description": "Colyseus Multiplayer SDK for JavaScript/TypeScript",
|
|
5
5
|
"author": "Endel Dreyer",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"./*": {
|
|
27
27
|
"@source": "./src/*.ts",
|
|
28
28
|
"types": "./build/*.d.ts",
|
|
29
|
-
"import": "./build
|
|
29
|
+
"import": "./build/*.mjs",
|
|
30
30
|
"require": "./build/*.cjs"
|
|
31
31
|
},
|
|
32
32
|
"./package.json": "./package.json"
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"@colyseus/schema": "^4.0.1",
|
|
56
56
|
"tslib": "^2.1.0",
|
|
57
57
|
"ws": "^8.13.0",
|
|
58
|
+
"@colyseus/shared-types": "^0.17.0",
|
|
58
59
|
"@colyseus/better-call": "^1.0.26"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"typescript": "^5.9.3",
|
|
82
83
|
"vite": "^5.0.11",
|
|
83
84
|
"vitest": "^2.1.1",
|
|
84
|
-
"@colyseus/core": "^0.17.
|
|
85
|
+
"@colyseus/core": "^0.17.10"
|
|
85
86
|
},
|
|
86
87
|
"peerDependencies": {
|
|
87
88
|
"@colyseus/core": "0.17.x"
|
package/src/Client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SDKTypes, ServerRoomLike, ISeatReservation } from '@colyseus/shared-types';
|
|
2
2
|
|
|
3
3
|
import { CloseCode, ServerError } from './errors/Errors.ts';
|
|
4
4
|
import { Room } from './Room.ts';
|
|
@@ -10,7 +10,7 @@ import { Connection } from './Connection.ts';
|
|
|
10
10
|
import { discordURLBuilder } from './3rd_party/discord.ts';
|
|
11
11
|
|
|
12
12
|
export type JoinOptions = any;
|
|
13
|
-
export type ISeatReservation
|
|
13
|
+
export type { ISeatReservation };
|
|
14
14
|
|
|
15
15
|
export class MatchMakeError extends Error {
|
|
16
16
|
code: number;
|
|
@@ -173,7 +173,7 @@ export class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
|
173
173
|
rootSchema?: SchemaConstructor<ServerType>
|
|
174
174
|
): Promise<Room<ServerType['~rooms'][R]['~room']>>
|
|
175
175
|
// Overload: Pass RoomType directly to extract state
|
|
176
|
-
public async joinOrCreate<RoomType extends
|
|
176
|
+
public async joinOrCreate<RoomType extends ServerRoomLike>(
|
|
177
177
|
roomName: string,
|
|
178
178
|
options?: Parameters<RoomType['onJoin']>[1],
|
|
179
179
|
rootSchema?: SchemaConstructor<RoomType['state']>
|
|
@@ -196,7 +196,7 @@ export class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
|
196
196
|
rootSchema?: SchemaConstructor<ServerType>
|
|
197
197
|
): Promise<Room<ServerType['~rooms'][R]['~room']>>
|
|
198
198
|
// Overload: Pass RoomType directly to extract state
|
|
199
|
-
public async create<RoomType extends
|
|
199
|
+
public async create<RoomType extends ServerRoomLike>(
|
|
200
200
|
roomName: string,
|
|
201
201
|
options?: Parameters<RoomType['onJoin']>[1],
|
|
202
202
|
rootSchema?: SchemaConstructor<RoomType['state']>
|
|
@@ -219,7 +219,7 @@ export class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
|
219
219
|
rootSchema?: SchemaConstructor<ServerType>
|
|
220
220
|
): Promise<Room<ServerType['~rooms'][R]['~room']>>
|
|
221
221
|
// Overload: Pass RoomType directly to extract state
|
|
222
|
-
public async join<RoomType extends
|
|
222
|
+
public async join<RoomType extends ServerRoomLike>(
|
|
223
223
|
roomName: string,
|
|
224
224
|
options?: Parameters<RoomType['onJoin']>[1],
|
|
225
225
|
rootSchema?: SchemaConstructor<RoomType['state']>
|
|
@@ -242,7 +242,7 @@ export class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
|
242
242
|
rootSchema?: SchemaConstructor<ServerType>
|
|
243
243
|
): Promise<Room<ServerType['~rooms'][R]['~room']>>
|
|
244
244
|
// Overload: Pass RoomType directly to extract state
|
|
245
|
-
public async joinById<RoomType extends
|
|
245
|
+
public async joinById<RoomType extends ServerRoomLike>(
|
|
246
246
|
roomId: string,
|
|
247
247
|
options?: Parameters<RoomType['onJoin']>[1],
|
|
248
248
|
rootSchema?: SchemaConstructor<RoomType['state']>
|
|
@@ -268,7 +268,7 @@ export class ColyseusSDK<ServerType extends SDKTypes = any, UserData = any> {
|
|
|
268
268
|
// Overload: Use room name from ServerType to infer room type
|
|
269
269
|
public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>
|
|
270
270
|
// Overload: Pass RoomType directly to extract state
|
|
271
|
-
public async reconnect<RoomType extends
|
|
271
|
+
public async reconnect<RoomType extends ServerRoomLike>(
|
|
272
272
|
reconnectionToken: string,
|
|
273
273
|
rootSchema?: SchemaConstructor<RoomType['state']>
|
|
274
274
|
): Promise<Room<RoomType, RoomType['state']>>
|
package/src/Room.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { decode,
|
|
1
|
+
import { type InferState, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';
|
|
2
|
+
import { decode, encode, Iterator, Schema } from '@colyseus/schema';
|
|
3
3
|
|
|
4
4
|
import { Packr, unpack } from '@colyseus/msgpackr';
|
|
5
5
|
|
|
@@ -22,25 +22,6 @@ export type InferSerializer<State> = [State] extends [Schema]
|
|
|
22
22
|
? SchemaSerializer<State>
|
|
23
23
|
: Serializer<State>;
|
|
24
24
|
|
|
25
|
-
// Helper types for flexible Room generics
|
|
26
|
-
// Allows: Room<State>, Room<ServerRoom>, or Room<ServerRoom, State>
|
|
27
|
-
type InferState<T, S> = [S] extends [never]
|
|
28
|
-
? (T extends typeof ServerRoom ? T['prototype']['state'] : T)
|
|
29
|
-
: S;
|
|
30
|
-
|
|
31
|
-
// Supports both constructor types (typeof MyRoom) and instance types (MyRoom)
|
|
32
|
-
type RoomMessages<T> = T extends abstract new (...args: any) => { messages: infer M }
|
|
33
|
-
? M
|
|
34
|
-
: T extends { messages: infer M }
|
|
35
|
-
? M
|
|
36
|
-
: {};
|
|
37
|
-
|
|
38
|
-
type RoomClientMessages<T> = T extends abstract new (...args: any) => { '~client': { '~messages': infer M } }
|
|
39
|
-
? M
|
|
40
|
-
: T extends { '~client': { '~messages': infer M } }
|
|
41
|
-
? M
|
|
42
|
-
: {};
|
|
43
|
-
|
|
44
25
|
export interface RoomAvailable<Metadata = any> {
|
|
45
26
|
name: string;
|
|
46
27
|
roomId: string;
|
|
@@ -235,9 +216,9 @@ export class Room<
|
|
|
235
216
|
});
|
|
236
217
|
}
|
|
237
218
|
|
|
238
|
-
public onMessage<MessageType extends keyof
|
|
219
|
+
public onMessage<MessageType extends keyof ExtractRoomClientMessages<T>>(
|
|
239
220
|
message: MessageType,
|
|
240
|
-
callback: (payload:
|
|
221
|
+
callback: (payload: ExtractRoomClientMessages<T>[MessageType]) => void
|
|
241
222
|
)
|
|
242
223
|
public onMessage<T = any>(type: "*", callback: (messageType: string | number, payload: T) => void)
|
|
243
224
|
public onMessage<T = any>(type: string | number, callback: (payload: T) => void)
|
|
@@ -252,9 +233,9 @@ export class Room<
|
|
|
252
233
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
253
234
|
}
|
|
254
235
|
|
|
255
|
-
public send<MessageType extends keyof
|
|
236
|
+
public send<MessageType extends keyof ExtractRoomMessages<T>>(
|
|
256
237
|
messageType: MessageType,
|
|
257
|
-
payload?: ExtractMessageType<
|
|
238
|
+
payload?: ExtractMessageType<ExtractRoomMessages<T>[MessageType]>
|
|
258
239
|
)
|
|
259
240
|
public send<T = any>(messageType: string | number, payload?: T): void {
|
|
260
241
|
const it: Iterator = { offset: 1 };
|
package/src/debug.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Client } from "./Client";
|
|
2
|
-
import type { Room } from "./Room";
|
|
3
|
-
import type { WebSocketTransport } from "./transport/WebSocketTransport";
|
|
1
|
+
import { Client } from "./Client.ts";
|
|
2
|
+
import type { Room } from "./Room.ts";
|
|
3
|
+
import type { WebSocketTransport } from "./transport/WebSocketTransport.ts";
|
|
4
4
|
|
|
5
5
|
const logoIcon = `<svg viewBox="0 0 488.94 541.2" style="width: 100%; height: 100%;">
|
|
6
6
|
<g>
|
|
@@ -1431,7 +1431,6 @@ function openStateInspectorModal(uniquePanelId) {
|
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
var room = debugInfo.room;
|
|
1434
|
-
var refIds = room.serializer.decoder.root.refIds;
|
|
1435
1434
|
|
|
1436
1435
|
// Remove existing modal if present
|
|
1437
1436
|
var existingModal = document.getElementById('debug-state-inspector-modal');
|
|
@@ -1671,7 +1670,7 @@ function openStateInspectorModal(uniquePanelId) {
|
|
|
1671
1670
|
|
|
1672
1671
|
var type = typeof obj;
|
|
1673
1672
|
var indent = depth * 6;
|
|
1674
|
-
var refId =
|
|
1673
|
+
var refId = obj["~refId"];
|
|
1675
1674
|
var nodeId = 'state-node-' + refId;
|
|
1676
1675
|
var currentPath = path ? path + '.' + (parentKey || '') : (parentKey || 'root');
|
|
1677
1676
|
var isPathExpanded = expandedPaths.has(currentPath);
|
|
@@ -1747,6 +1746,7 @@ function openStateInspectorModal(uniquePanelId) {
|
|
|
1747
1746
|
|
|
1748
1747
|
for (var i = 0; i < keys.length; i++) {
|
|
1749
1748
|
var key = keys[i];
|
|
1749
|
+
if (key === "~refId") continue;// skip refId
|
|
1750
1750
|
html += renderKeyValue(key, obj[key], depth + 1, currentPath, key, false);
|
|
1751
1751
|
}
|
|
1752
1752
|
|