@colyseus/core 0.17.30 → 0.17.32
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/Room.cjs +21 -3
- package/build/Room.cjs.map +2 -2
- package/build/Room.mjs +22 -4
- package/build/Room.mjs.map +2 -2
- package/build/Transport.cjs +8 -1
- package/build/Transport.cjs.map +2 -2
- package/build/Transport.d.ts +4 -3
- package/build/Transport.mjs +8 -1
- package/build/Transport.mjs.map +2 -2
- package/build/errors/RoomExceptions.cjs +19 -0
- package/build/errors/RoomExceptions.cjs.map +2 -2
- package/build/errors/RoomExceptions.d.ts +11 -2
- package/build/errors/RoomExceptions.mjs +17 -0
- package/build/errors/RoomExceptions.mjs.map +2 -2
- package/package.json +2 -2
- package/src/Room.ts +36 -8
- package/src/Transport.ts +8 -1
- package/src/errors/RoomExceptions.ts +33 -0
|
@@ -23,9 +23,11 @@ __export(RoomExceptions_exports, {
|
|
|
23
23
|
OnAuthException: () => OnAuthException,
|
|
24
24
|
OnCreateException: () => OnCreateException,
|
|
25
25
|
OnDisposeException: () => OnDisposeException,
|
|
26
|
+
OnDropException: () => OnDropException,
|
|
26
27
|
OnJoinException: () => OnJoinException,
|
|
27
28
|
OnLeaveException: () => OnLeaveException,
|
|
28
29
|
OnMessageException: () => OnMessageException,
|
|
30
|
+
OnReconnectException: () => OnReconnectException,
|
|
29
31
|
SimulationIntervalException: () => SimulationIntervalException,
|
|
30
32
|
TimedEventException: () => TimedEventException
|
|
31
33
|
});
|
|
@@ -62,6 +64,21 @@ var OnLeaveException = class extends Error {
|
|
|
62
64
|
this.consented = consented;
|
|
63
65
|
}
|
|
64
66
|
};
|
|
67
|
+
var OnDropException = class extends Error {
|
|
68
|
+
constructor(cause, message, client, code) {
|
|
69
|
+
super(message, { cause });
|
|
70
|
+
this.name = "OnDropException";
|
|
71
|
+
this.client = client;
|
|
72
|
+
this.code = code;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var OnReconnectException = class extends Error {
|
|
76
|
+
constructor(cause, message, client) {
|
|
77
|
+
super(message, { cause });
|
|
78
|
+
this.name = "OnReconnectException";
|
|
79
|
+
this.client = client;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
65
82
|
var OnDisposeException = class extends Error {
|
|
66
83
|
constructor(cause, message) {
|
|
67
84
|
super(message, { cause });
|
|
@@ -98,9 +115,11 @@ var TimedEventException = class extends Error {
|
|
|
98
115
|
OnAuthException,
|
|
99
116
|
OnCreateException,
|
|
100
117
|
OnDisposeException,
|
|
118
|
+
OnDropException,
|
|
101
119
|
OnJoinException,
|
|
102
120
|
OnLeaveException,
|
|
103
121
|
OnMessageException,
|
|
122
|
+
OnReconnectException,
|
|
104
123
|
SimulationIntervalException,
|
|
105
124
|
TimedEventException
|
|
106
125
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/errors/RoomExceptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtractMessageType } from '@colyseus/shared-types';\nimport type { Room } from '../Room.ts';\n\nexport type RoomMethodName = 'onCreate'\n | 'onAuth'\n | 'onJoin'\n | 'onLeave'\n | 'onDispose'\n | 'onMessage'\n | 'setSimulationInterval'\n | 'setInterval'\n | 'setTimeout';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n options: Parameters<R['onCreate']>[0];\n constructor(\n cause: Error,\n message: string,\n options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n this.options = options;\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n client: Parameters<R['onAuth']>[0];\n options: Parameters<R['onAuth']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onAuth']>[0],\n options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n this.client = client;\n this.options = options;\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n client: Parameters<R['onJoin']>[0];\n options: Parameters<R['onJoin']>[1];\n auth: Parameters<R['onJoin']>[2];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onJoin']>[0],\n options: Parameters<R['onJoin']>[1],\n auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n this.client = client;\n this.options = options;\n this.auth = auth;\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n client: Parameters<R['onLeave']>[0];\n consented: Parameters<R['onLeave']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onLeave']>[0],\n consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n this.client = client;\n this.consented = consented;\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room, MessageType extends keyof R['messages'] = keyof R['messages']> extends Error {\n client: R['~client'];\n payload: ExtractMessageType<R['messages'][MessageType]>;\n type: MessageType;\n constructor(\n cause: Error,\n message: string,\n client: R['~client'],\n payload: ExtractMessageType<R['messages'][MessageType]>,\n type: MessageType,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n this.client = client;\n this.payload = payload;\n this.type = type;\n }\n\n public isType<T extends keyof R['messages']>(type: T): this is OnMessageException<R, T> {\n return (this.type as string) === type;\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type { ExtractMessageType } from '@colyseus/shared-types';\nimport type { Room } from '../Room.ts';\n\nexport type RoomMethodName = 'onCreate'\n | 'onAuth'\n | 'onJoin'\n | 'onLeave'\n | 'onDrop'\n | 'onReconnect'\n | 'onDispose'\n | 'onMessage'\n | 'setSimulationInterval'\n | 'setInterval'\n | 'setTimeout';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDropException<R> |\n OnReconnectException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n options: Parameters<R['onCreate']>[0];\n constructor(\n cause: Error,\n message: string,\n options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n this.options = options;\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n client: Parameters<R['onAuth']>[0];\n options: Parameters<R['onAuth']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onAuth']>[0],\n options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n this.client = client;\n this.options = options;\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n client: Parameters<R['onJoin']>[0];\n options: Parameters<R['onJoin']>[1];\n auth: Parameters<R['onJoin']>[2];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onJoin']>[0],\n options: Parameters<R['onJoin']>[1],\n auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n this.client = client;\n this.options = options;\n this.auth = auth;\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n client: Parameters<R['onLeave']>[0];\n consented: Parameters<R['onLeave']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onLeave']>[0],\n consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n this.client = client;\n this.consented = consented;\n }\n}\n\nexport class OnDropException<R extends Room = Room> extends Error {\n client: Parameters<R['onDrop']>[0];\n code: Parameters<R['onDrop']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onDrop']>[0],\n code: Parameters<R['onDrop']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnDropException';\n this.client = client;\n this.code = code;\n }\n}\n\nexport class OnReconnectException<R extends Room = Room> extends Error {\n client: Parameters<R['onReconnect']>[0];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onReconnect']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnReconnectException';\n this.client = client;\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room, MessageType extends keyof R['messages'] = keyof R['messages']> extends Error {\n client: R['~client'];\n payload: ExtractMessageType<R['messages'][MessageType]>;\n type: MessageType;\n constructor(\n cause: Error,\n message: string,\n client: R['~client'],\n payload: ExtractMessageType<R['messages'][MessageType]>,\n type: MessageType,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n this.client = client;\n this.payload = payload;\n this.type = type;\n }\n\n public isType<T extends keyof R['messages']>(type: T): this is OnMessageException<R, T> {\n return (this.type as string) === type;\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;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EACd;AACF;AAEO,IAAM,qBAAN,cAAgH,MAAM;AAAA,EAI3H,YACE,OACA,SACA,QACA,SACA,MACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEO,OAAsC,MAA2C;AACtF,WAAQ,KAAK,SAAoB;AAAA,EACnC;AACF;AAEO,IAAM,8BAAN,cAA0C,MAAM;AAAA,EACrD,YACE,OACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAE7C,YACE,OACA,YACG,MACH;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtractMessageType } from '@colyseus/shared-types';
|
|
2
2
|
import type { Room } from '../Room.ts';
|
|
3
|
-
export type RoomMethodName = 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout';
|
|
4
|
-
export type RoomException<R extends Room = Room> = OnCreateException<R> | OnAuthException<R> | OnJoinException<R> | OnLeaveException<R> | OnDisposeException | OnMessageException<R> | SimulationIntervalException | TimedEventException;
|
|
3
|
+
export type RoomMethodName = 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDrop' | 'onReconnect' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout';
|
|
4
|
+
export type RoomException<R extends Room = Room> = OnCreateException<R> | OnAuthException<R> | OnJoinException<R> | OnLeaveException<R> | OnDropException<R> | OnReconnectException<R> | OnDisposeException | OnMessageException<R> | SimulationIntervalException | TimedEventException;
|
|
5
5
|
export declare class OnCreateException<R extends Room = Room> extends Error {
|
|
6
6
|
options: Parameters<R['onCreate']>[0];
|
|
7
7
|
constructor(cause: Error, message: string, options: Parameters<R['onCreate']>[0]);
|
|
@@ -22,6 +22,15 @@ export declare class OnLeaveException<R extends Room = Room> extends Error {
|
|
|
22
22
|
consented: Parameters<R['onLeave']>[1];
|
|
23
23
|
constructor(cause: Error, message: string, client: Parameters<R['onLeave']>[0], consented: Parameters<R['onLeave']>[1]);
|
|
24
24
|
}
|
|
25
|
+
export declare class OnDropException<R extends Room = Room> extends Error {
|
|
26
|
+
client: Parameters<R['onDrop']>[0];
|
|
27
|
+
code: Parameters<R['onDrop']>[1];
|
|
28
|
+
constructor(cause: Error, message: string, client: Parameters<R['onDrop']>[0], code: Parameters<R['onDrop']>[1]);
|
|
29
|
+
}
|
|
30
|
+
export declare class OnReconnectException<R extends Room = Room> extends Error {
|
|
31
|
+
client: Parameters<R['onReconnect']>[0];
|
|
32
|
+
constructor(cause: Error, message: string, client: Parameters<R['onReconnect']>[0]);
|
|
33
|
+
}
|
|
25
34
|
export declare class OnDisposeException extends Error {
|
|
26
35
|
constructor(cause: Error, message: string);
|
|
27
36
|
}
|
|
@@ -31,6 +31,21 @@ var OnLeaveException = class extends Error {
|
|
|
31
31
|
this.consented = consented;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
+
var OnDropException = class extends Error {
|
|
35
|
+
constructor(cause, message, client, code) {
|
|
36
|
+
super(message, { cause });
|
|
37
|
+
this.name = "OnDropException";
|
|
38
|
+
this.client = client;
|
|
39
|
+
this.code = code;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var OnReconnectException = class extends Error {
|
|
43
|
+
constructor(cause, message, client) {
|
|
44
|
+
super(message, { cause });
|
|
45
|
+
this.name = "OnReconnectException";
|
|
46
|
+
this.client = client;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
34
49
|
var OnDisposeException = class extends Error {
|
|
35
50
|
constructor(cause, message) {
|
|
36
51
|
super(message, { cause });
|
|
@@ -66,9 +81,11 @@ export {
|
|
|
66
81
|
OnAuthException,
|
|
67
82
|
OnCreateException,
|
|
68
83
|
OnDisposeException,
|
|
84
|
+
OnDropException,
|
|
69
85
|
OnJoinException,
|
|
70
86
|
OnLeaveException,
|
|
71
87
|
OnMessageException,
|
|
88
|
+
OnReconnectException,
|
|
72
89
|
SimulationIntervalException,
|
|
73
90
|
TimedEventException
|
|
74
91
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/errors/RoomExceptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtractMessageType } from '@colyseus/shared-types';\nimport type { Room } from '../Room.ts';\n\nexport type RoomMethodName = 'onCreate'\n | 'onAuth'\n | 'onJoin'\n | 'onLeave'\n | 'onDispose'\n | 'onMessage'\n | 'setSimulationInterval'\n | 'setInterval'\n | 'setTimeout';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n options: Parameters<R['onCreate']>[0];\n constructor(\n cause: Error,\n message: string,\n options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n this.options = options;\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n client: Parameters<R['onAuth']>[0];\n options: Parameters<R['onAuth']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onAuth']>[0],\n options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n this.client = client;\n this.options = options;\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n client: Parameters<R['onJoin']>[0];\n options: Parameters<R['onJoin']>[1];\n auth: Parameters<R['onJoin']>[2];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onJoin']>[0],\n options: Parameters<R['onJoin']>[1],\n auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n this.client = client;\n this.options = options;\n this.auth = auth;\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n client: Parameters<R['onLeave']>[0];\n consented: Parameters<R['onLeave']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onLeave']>[0],\n consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n this.client = client;\n this.consented = consented;\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room, MessageType extends keyof R['messages'] = keyof R['messages']> extends Error {\n client: R['~client'];\n payload: ExtractMessageType<R['messages'][MessageType]>;\n type: MessageType;\n constructor(\n cause: Error,\n message: string,\n client: R['~client'],\n payload: ExtractMessageType<R['messages'][MessageType]>,\n type: MessageType,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n this.client = client;\n this.payload = payload;\n this.type = type;\n }\n\n public isType<T extends keyof R['messages']>(type: T): this is OnMessageException<R, T> {\n return (this.type as string) === type;\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { ExtractMessageType } from '@colyseus/shared-types';\nimport type { Room } from '../Room.ts';\n\nexport type RoomMethodName = 'onCreate'\n | 'onAuth'\n | 'onJoin'\n | 'onLeave'\n | 'onDrop'\n | 'onReconnect'\n | 'onDispose'\n | 'onMessage'\n | 'setSimulationInterval'\n | 'setInterval'\n | 'setTimeout';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDropException<R> |\n OnReconnectException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n options: Parameters<R['onCreate']>[0];\n constructor(\n cause: Error,\n message: string,\n options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n this.options = options;\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n client: Parameters<R['onAuth']>[0];\n options: Parameters<R['onAuth']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onAuth']>[0],\n options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n this.client = client;\n this.options = options;\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n client: Parameters<R['onJoin']>[0];\n options: Parameters<R['onJoin']>[1];\n auth: Parameters<R['onJoin']>[2];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onJoin']>[0],\n options: Parameters<R['onJoin']>[1],\n auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n this.client = client;\n this.options = options;\n this.auth = auth;\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n client: Parameters<R['onLeave']>[0];\n consented: Parameters<R['onLeave']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onLeave']>[0],\n consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n this.client = client;\n this.consented = consented;\n }\n}\n\nexport class OnDropException<R extends Room = Room> extends Error {\n client: Parameters<R['onDrop']>[0];\n code: Parameters<R['onDrop']>[1];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onDrop']>[0],\n code: Parameters<R['onDrop']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnDropException';\n this.client = client;\n this.code = code;\n }\n}\n\nexport class OnReconnectException<R extends Room = Room> extends Error {\n client: Parameters<R['onReconnect']>[0];\n constructor(\n cause: Error,\n message: string,\n client: Parameters<R['onReconnect']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnReconnectException';\n this.client = client;\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room, MessageType extends keyof R['messages'] = keyof R['messages']> extends Error {\n client: R['~client'];\n payload: ExtractMessageType<R['messages'][MessageType]>;\n type: MessageType;\n constructor(\n cause: Error,\n message: string,\n client: R['~client'],\n payload: ExtractMessageType<R['messages'][MessageType]>,\n type: MessageType,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n this.client = client;\n this.payload = payload;\n this.type = type;\n }\n\n public isType<T extends keyof R['messages']>(type: T): this is OnMessageException<R, T> {\n return (this.type as string) === type;\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
|
|
5
|
+
"mappings": ";AA2BO,IAAM,oBAAN,cAAuD,MAAM;AAAA,EAElE,YACE,OACA,SACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,UAAU;AAAA,EACjB;AACF;AAEO,IAAM,kBAAN,cAAqD,MAAM;AAAA,EAGhE,YACE,OACA,SACA,QACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AACF;AAEO,IAAM,kBAA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EAE7C,YACE,OACA,YACG,MACH;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/core",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.32",
|
|
4
4
|
"description": "Multiplayer Framework for Node.js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"input": "./src/index.ts",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@colyseus/schema": "^4.0.7",
|
|
60
60
|
"express": "^5.0.0",
|
|
61
|
-
"@colyseus/redis-driver": "^0.17.6",
|
|
62
61
|
"@colyseus/redis-presence": "^0.17.6",
|
|
62
|
+
"@colyseus/redis-driver": "^0.17.6",
|
|
63
63
|
"@colyseus/tools": "^0.17.18"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
package/src/Room.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { isDevMode } from './utils/DevMode.ts';
|
|
|
20
20
|
import { debugAndPrintError, debugMatchMaking, debugMessage } from './Debug.ts';
|
|
21
21
|
import { ServerError } from './errors/ServerError.ts';
|
|
22
22
|
import { ClientState, type AuthContext, type Client, type ClientPrivate, ClientArray, type ISendOptions, type MessageArgs } from './Transport.ts';
|
|
23
|
-
import { type RoomMethodName, OnAuthException, OnCreateException, OnDisposeException, OnJoinException, OnLeaveException, OnMessageException, type RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.ts';
|
|
23
|
+
import { type RoomMethodName, OnAuthException, OnCreateException, OnDisposeException, OnDropException, OnJoinException, OnLeaveException, OnMessageException, OnReconnectException, type RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.ts';
|
|
24
24
|
|
|
25
25
|
import { standardValidate, type StandardSchemaV1 } from './utils/StandardSchema.ts';
|
|
26
26
|
import { matchMaker } from '@colyseus/core';
|
|
@@ -1164,14 +1164,33 @@ export class Room<T extends RoomOptions = RoomOptions> {
|
|
|
1164
1164
|
const reconnectionToken = connectionOptions?.reconnectionToken;
|
|
1165
1165
|
if (reconnectionToken && this._reconnections[reconnectionToken]?.[0] === sessionId) {
|
|
1166
1166
|
this.clients.push(client);
|
|
1167
|
+
|
|
1167
1168
|
//
|
|
1168
1169
|
// await for reconnection:
|
|
1169
1170
|
// (end user may customize the reconnection token at this step)
|
|
1170
1171
|
//
|
|
1171
1172
|
await this._reconnections[reconnectionToken]?.[1].resolve(client);
|
|
1172
1173
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1174
|
+
try {
|
|
1175
|
+
if (this.onReconnect) {
|
|
1176
|
+
await this.onReconnect(client);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// FIXME: we shouldn't rely on WebSocket specific API here (make it transport agnostic)
|
|
1180
|
+
if (client.readyState !== WebSocket.OPEN) {
|
|
1181
|
+
throw new Error("reconnection denied");
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// client.leave() may have been called during onReconnect()
|
|
1185
|
+
if (client.state === ClientState.RECONNECTING) {
|
|
1186
|
+
// switch client state from RECONNECTING to JOINING
|
|
1187
|
+
// (to allow to attach messages to the client again)
|
|
1188
|
+
client.state = ClientState.JOINING;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
} catch (e) {
|
|
1192
|
+
await this._onLeave(client, CloseCode.FAILED_TO_RECONNECT);
|
|
1193
|
+
throw e;
|
|
1175
1194
|
}
|
|
1176
1195
|
|
|
1177
1196
|
} else {
|
|
@@ -1356,6 +1375,7 @@ export class Room<T extends RoomOptions = RoomOptions> {
|
|
|
1356
1375
|
newClient.auth = previousClient.auth;
|
|
1357
1376
|
newClient.userData = previousClient.userData;
|
|
1358
1377
|
newClient.view = previousClient.view;
|
|
1378
|
+
newClient.state = ClientState.RECONNECTING;
|
|
1359
1379
|
|
|
1360
1380
|
// for convenience: populate previous client reference with new client
|
|
1361
1381
|
previousClient.state = ClientState.RECONNECTED;
|
|
@@ -1677,7 +1697,11 @@ export class Room<T extends RoomOptions = RoomOptions> {
|
|
|
1677
1697
|
}
|
|
1678
1698
|
|
|
1679
1699
|
private async _onLeave(client: ExtractRoomClient<T>, code?: number): Promise<any> {
|
|
1680
|
-
//
|
|
1700
|
+
// reconnecting check is required here to allow user to deny reconnection via onReconnect()
|
|
1701
|
+
const method = (code === CloseCode.CONSENTED || client.state === ClientState.RECONNECTING)
|
|
1702
|
+
? this.onLeave
|
|
1703
|
+
: (this.onDrop || this.onLeave);
|
|
1704
|
+
|
|
1681
1705
|
client.state = ClientState.LEAVING;
|
|
1682
1706
|
|
|
1683
1707
|
if (!this.clients.delete(client)) {
|
|
@@ -1685,10 +1709,6 @@ export class Room<T extends RoomOptions = RoomOptions> {
|
|
|
1685
1709
|
return;
|
|
1686
1710
|
}
|
|
1687
1711
|
|
|
1688
|
-
const method = (code === CloseCode.CONSENTED)
|
|
1689
|
-
? this.onLeave
|
|
1690
|
-
: (this.onDrop || this.onLeave);
|
|
1691
|
-
|
|
1692
1712
|
if (method) {
|
|
1693
1713
|
debugMatchMaking(`${method.name}, sessionId: \'%s\' (close code: %d, roomId: %s)`, client.sessionId, code, this.roomId);
|
|
1694
1714
|
|
|
@@ -1800,6 +1820,14 @@ export class Room<T extends RoomOptions = RoomOptions> {
|
|
|
1800
1820
|
this.onLeave = wrapTryCatch(this.onLeave.bind(this), onUncaughtException, OnLeaveException, 'onLeave', true);
|
|
1801
1821
|
}
|
|
1802
1822
|
|
|
1823
|
+
if (this.onDrop !== undefined) {
|
|
1824
|
+
this.onDrop = wrapTryCatch(this.onDrop.bind(this), onUncaughtException, OnDropException, 'onDrop', true);
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
if (this.onReconnect !== undefined) {
|
|
1828
|
+
this.onReconnect = wrapTryCatch(this.onReconnect.bind(this), onUncaughtException, OnReconnectException, 'onReconnect', true);
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1803
1831
|
if (this.onDispose !== undefined) {
|
|
1804
1832
|
this.onDispose = wrapTryCatch(this.onDispose.bind(this), onUncaughtException, OnDisposeException, 'onDispose');
|
|
1805
1833
|
}
|
package/src/Transport.ts
CHANGED
|
@@ -53,7 +53,14 @@ export interface ISendOptions {
|
|
|
53
53
|
afterNextPatch?: boolean;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export const ClientState = {
|
|
56
|
+
export const ClientState = {
|
|
57
|
+
JOINING: 0,
|
|
58
|
+
JOINED: 1,
|
|
59
|
+
RECONNECTING: 2,
|
|
60
|
+
RECONNECTED: 3,
|
|
61
|
+
LEAVING: 4,
|
|
62
|
+
CLOSED: 5
|
|
63
|
+
} as const;
|
|
57
64
|
export type ClientState = (typeof ClientState)[keyof typeof ClientState];
|
|
58
65
|
|
|
59
66
|
// Helper types to extract properties from the Client type parameter
|
|
@@ -5,6 +5,8 @@ export type RoomMethodName = 'onCreate'
|
|
|
5
5
|
| 'onAuth'
|
|
6
6
|
| 'onJoin'
|
|
7
7
|
| 'onLeave'
|
|
8
|
+
| 'onDrop'
|
|
9
|
+
| 'onReconnect'
|
|
8
10
|
| 'onDispose'
|
|
9
11
|
| 'onMessage'
|
|
10
12
|
| 'setSimulationInterval'
|
|
@@ -16,6 +18,8 @@ export type RoomException<R extends Room = Room> =
|
|
|
16
18
|
OnAuthException<R> |
|
|
17
19
|
OnJoinException<R> |
|
|
18
20
|
OnLeaveException<R> |
|
|
21
|
+
OnDropException<R> |
|
|
22
|
+
OnReconnectException<R> |
|
|
19
23
|
OnDisposeException |
|
|
20
24
|
OnMessageException<R> |
|
|
21
25
|
SimulationIntervalException |
|
|
@@ -85,6 +89,35 @@ export class OnLeaveException<R extends Room = Room> extends Error {
|
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
92
|
+
export class OnDropException<R extends Room = Room> extends Error {
|
|
93
|
+
client: Parameters<R['onDrop']>[0];
|
|
94
|
+
code: Parameters<R['onDrop']>[1];
|
|
95
|
+
constructor(
|
|
96
|
+
cause: Error,
|
|
97
|
+
message: string,
|
|
98
|
+
client: Parameters<R['onDrop']>[0],
|
|
99
|
+
code: Parameters<R['onDrop']>[1],
|
|
100
|
+
) {
|
|
101
|
+
super(message, { cause });
|
|
102
|
+
this.name = 'OnDropException';
|
|
103
|
+
this.client = client;
|
|
104
|
+
this.code = code;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class OnReconnectException<R extends Room = Room> extends Error {
|
|
109
|
+
client: Parameters<R['onReconnect']>[0];
|
|
110
|
+
constructor(
|
|
111
|
+
cause: Error,
|
|
112
|
+
message: string,
|
|
113
|
+
client: Parameters<R['onReconnect']>[0],
|
|
114
|
+
) {
|
|
115
|
+
super(message, { cause });
|
|
116
|
+
this.name = 'OnReconnectException';
|
|
117
|
+
this.client = client;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
88
121
|
export class OnDisposeException extends Error {
|
|
89
122
|
constructor(
|
|
90
123
|
cause: Error,
|