@colyseus/sdk 0.17.14 → 0.17.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/3rd_party/discord.cjs +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +1 -1
- package/build/Auth.mjs +1 -1
- package/build/Client.cjs +1 -1
- package/build/Client.mjs +1 -1
- package/build/Connection.cjs +30 -1
- package/build/Connection.cjs.map +1 -1
- package/build/Connection.d.ts +1 -0
- package/build/Connection.mjs +27 -1
- package/build/Connection.mjs.map +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Protocol.cjs +1 -1
- package/build/Protocol.mjs +1 -1
- package/build/Room.cjs +12 -9
- package/build/Room.cjs.map +1 -1
- package/build/Room.mjs +11 -8
- package/build/Room.mjs.map +1 -1
- package/build/Storage.cjs +1 -1
- package/build/Storage.mjs +1 -1
- package/build/core/nanoevents.cjs +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +1 -1
- package/build/core/signal.mjs +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +226 -113
- package/build/debug.cjs.map +1 -1
- package/build/debug.mjs +226 -113
- package/build/debug.mjs.map +1 -1
- package/build/errors/Errors.cjs +1 -1
- package/build/errors/Errors.mjs +1 -1
- package/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +1 -1
- package/build/serializer/Serializer.cjs +1 -1
- package/build/serializer/Serializer.mjs +1 -1
- package/build/transport/H3Transport.cjs +1 -1
- package/build/transport/H3Transport.mjs +1 -1
- package/build/transport/WebSocketTransport.cjs +16 -5
- package/build/transport/WebSocketTransport.cjs.map +1 -1
- package/build/transport/WebSocketTransport.mjs +16 -5
- package/build/transport/WebSocketTransport.mjs.map +1 -1
- package/dist/colyseus-cocos-creator.js +101 -87
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +101 -87
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +277 -125
- package/dist/debug.js.map +1 -1
- package/package.json +4 -4
- package/src/Connection.ts +30 -0
- package/src/Room.ts +12 -8
- package/src/debug.ts +246 -111
- package/src/transport/WebSocketTransport.ts +16 -4
package/build/Auth.cjs
CHANGED
package/build/Auth.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
import { getItem, removeItem, setItem } from './Storage.mjs';
|
|
8
8
|
import { createNanoEvents } from './core/nanoevents.mjs';
|
|
9
9
|
|
package/build/Client.cjs
CHANGED
package/build/Client.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
import { CloseCode } from '@colyseus/shared-types';
|
|
8
8
|
import { ServerError } from './errors/Errors.mjs';
|
|
9
9
|
import { Room } from './Room.mjs';
|
package/build/Connection.cjs
CHANGED
|
@@ -3,15 +3,31 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var tslib = require('tslib');
|
|
9
10
|
var H3Transport = require('./transport/H3Transport.cjs');
|
|
10
11
|
var WebSocketTransport = require('./transport/WebSocketTransport.cjs');
|
|
12
|
+
var sharedTypes = require('@colyseus/shared-types');
|
|
11
13
|
|
|
14
|
+
var _Connection__offlineListener;
|
|
15
|
+
const onOfflineListeners = [];
|
|
16
|
+
const hasGlobalEventListeners = typeof (addEventListener) === "function" && typeof (removeEventListener) === "function";
|
|
17
|
+
if (hasGlobalEventListeners) {
|
|
18
|
+
/**
|
|
19
|
+
* Detects when the network is offline and closes all connections.
|
|
20
|
+
* (When switching wifi networks, etc.)
|
|
21
|
+
*/
|
|
22
|
+
addEventListener("offline", () => {
|
|
23
|
+
console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${onOfflineListeners.length} connection(s)`);
|
|
24
|
+
onOfflineListeners.forEach((listener) => listener());
|
|
25
|
+
}, false);
|
|
26
|
+
}
|
|
12
27
|
class Connection {
|
|
13
28
|
constructor(protocol) {
|
|
14
29
|
this.events = {};
|
|
30
|
+
_Connection__offlineListener.set(this, (hasGlobalEventListeners) ? () => this.close(sharedTypes.CloseCode.MAY_TRY_RECONNECT) : null);
|
|
15
31
|
switch (protocol) {
|
|
16
32
|
case "h3":
|
|
17
33
|
this.transport = new H3Transport.H3TransportTransport(this.events);
|
|
@@ -22,6 +38,18 @@ class Connection {
|
|
|
22
38
|
}
|
|
23
39
|
}
|
|
24
40
|
connect(url, options) {
|
|
41
|
+
if (hasGlobalEventListeners) {
|
|
42
|
+
const onOpen = this.events.onopen;
|
|
43
|
+
this.events.onopen = (ev) => {
|
|
44
|
+
onOfflineListeners.push(tslib.__classPrivateFieldGet(this, _Connection__offlineListener, "f"));
|
|
45
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen(ev);
|
|
46
|
+
};
|
|
47
|
+
const onClose = this.events.onclose;
|
|
48
|
+
this.events.onclose = (ev) => {
|
|
49
|
+
onOfflineListeners.splice(onOfflineListeners.indexOf(tslib.__classPrivateFieldGet(this, _Connection__offlineListener, "f")), 1);
|
|
50
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(ev);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
25
53
|
this.url = url;
|
|
26
54
|
this.options = options;
|
|
27
55
|
this.transport.connect(url, options);
|
|
@@ -43,6 +71,7 @@ class Connection {
|
|
|
43
71
|
return this.transport.isOpen;
|
|
44
72
|
}
|
|
45
73
|
}
|
|
74
|
+
_Connection__offlineListener = new WeakMap();
|
|
46
75
|
|
|
47
76
|
exports.Connection = Connection;
|
|
48
77
|
//# sourceMappingURL=Connection.cjs.map
|
package/build/Connection.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.cjs","sources":["../src/Connection.ts"],"sourcesContent":["import type { ITransport, ITransportEventMap } from \"./transport/ITransport.ts\";\nimport { H3TransportTransport } from \"./transport/H3Transport.ts\";\nimport { WebSocketTransport } from \"./transport/WebSocketTransport.ts\";\n\nexport class Connection implements ITransport {\n transport: ITransport;\n events: ITransportEventMap = {};\n\n url?: string;\n options?: any;\n\n constructor(protocol?: string) {\n switch (protocol) {\n case \"h3\":\n this.transport = new H3TransportTransport(this.events);\n break;\n\n default:\n this.transport = new WebSocketTransport(this.events);\n break;\n }\n }\n\n connect(url: string, options?: any): void {\n this.url = url;\n this.options = options;\n this.transport.connect(url, options);\n }\n\n send(data: Buffer | Uint8Array): void {\n this.transport.send(data);\n }\n\n sendUnreliable(data: Buffer | Uint8Array): void {\n this.transport.sendUnreliable(data);\n }\n\n reconnect(queryParams: { reconnectionToken: string, skipHandshake?: boolean }): void {\n const queryString = new URLSearchParams(queryParams as unknown as Record<string, string>).toString();\n this.transport.connect(`${this.url}&${queryString}`, this.options);\n }\n\n close(code?: number, reason?: string): void {\n this.transport.close(code, reason);\n }\n\n get isOpen() {\n return this.transport.isOpen;\n }\n\n}\n"],"names":["H3TransportTransport","WebSocketTransport"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Connection.cjs","sources":["../src/Connection.ts"],"sourcesContent":["import type { ITransport, ITransportEventMap } from \"./transport/ITransport.ts\";\nimport { H3TransportTransport } from \"./transport/H3Transport.ts\";\nimport { WebSocketTransport } from \"./transport/WebSocketTransport.ts\";\nimport { CloseCode } from \"@colyseus/shared-types\";\n\nconst onOfflineListeners: (() => void)[] = [];\nconst hasGlobalEventListeners = typeof (addEventListener) === \"function\" && typeof (removeEventListener) === \"function\";\nif (hasGlobalEventListeners) {\n /**\n * Detects when the network is offline and closes all connections.\n * (When switching wifi networks, etc.)\n */\n addEventListener(\"offline\", () => {\n console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${onOfflineListeners.length} connection(s)`);\n onOfflineListeners.forEach((listener) => listener());\n }, false);\n}\n\nexport class Connection implements ITransport {\n transport: ITransport;\n events: ITransportEventMap = {};\n\n url?: string;\n options?: any;\n\n #_offlineListener = (hasGlobalEventListeners) ? () => this.close(CloseCode.MAY_TRY_RECONNECT) : null;\n\n constructor(protocol?: string) {\n switch (protocol) {\n case \"h3\":\n this.transport = new H3TransportTransport(this.events);\n break;\n\n default:\n this.transport = new WebSocketTransport(this.events);\n break;\n }\n }\n\n connect(url: string, options?: any): void {\n if (hasGlobalEventListeners) {\n const onOpen = this.events.onopen;\n this.events.onopen = (ev: any) => {\n onOfflineListeners.push(this.#_offlineListener);\n onOpen?.(ev);\n };\n\n const onClose = this.events.onclose;\n this.events.onclose = (ev: any) => {\n onOfflineListeners.splice(onOfflineListeners.indexOf(this.#_offlineListener), 1);\n onClose?.(ev);\n };\n }\n\n this.url = url;\n this.options = options;\n this.transport.connect(url, options);\n }\n\n send(data: Buffer | Uint8Array): void {\n this.transport.send(data);\n }\n\n sendUnreliable(data: Buffer | Uint8Array): void {\n this.transport.sendUnreliable(data);\n }\n\n reconnect(queryParams: { reconnectionToken: string, skipHandshake?: boolean }): void {\n const queryString = new URLSearchParams(queryParams as unknown as Record<string, string>).toString();\n this.transport.connect(`${this.url}&${queryString}`, this.options);\n }\n\n close(code?: number, reason?: string): void {\n this.transport.close(code, reason);\n }\n\n get isOpen() {\n return this.transport.isOpen;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,IAAI,EAAE,MAAM,CAAC;IACtC;AAEA,IAAA,IAAI,MAAM,GAAA;AACN,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM;IAChC;AAEH;;;;;"}
|
package/build/Connection.d.ts
CHANGED
package/build/Connection.mjs
CHANGED
|
@@ -3,15 +3,29 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
import { H3TransportTransport } from './transport/H3Transport.mjs';
|
|
8
8
|
import { WebSocketTransport } from './transport/WebSocketTransport.mjs';
|
|
9
|
+
import { CloseCode } from '@colyseus/shared-types';
|
|
9
10
|
|
|
11
|
+
const onOfflineListeners = [];
|
|
12
|
+
const hasGlobalEventListeners = typeof (addEventListener) === "function" && typeof (removeEventListener) === "function";
|
|
13
|
+
if (hasGlobalEventListeners) {
|
|
14
|
+
/**
|
|
15
|
+
* Detects when the network is offline and closes all connections.
|
|
16
|
+
* (When switching wifi networks, etc.)
|
|
17
|
+
*/
|
|
18
|
+
addEventListener("offline", () => {
|
|
19
|
+
console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${onOfflineListeners.length} connection(s)`);
|
|
20
|
+
onOfflineListeners.forEach((listener) => listener());
|
|
21
|
+
}, false);
|
|
22
|
+
}
|
|
10
23
|
class Connection {
|
|
11
24
|
transport;
|
|
12
25
|
events = {};
|
|
13
26
|
url;
|
|
14
27
|
options;
|
|
28
|
+
#_offlineListener = (hasGlobalEventListeners) ? () => this.close(CloseCode.MAY_TRY_RECONNECT) : null;
|
|
15
29
|
constructor(protocol) {
|
|
16
30
|
switch (protocol) {
|
|
17
31
|
case "h3":
|
|
@@ -23,6 +37,18 @@ class Connection {
|
|
|
23
37
|
}
|
|
24
38
|
}
|
|
25
39
|
connect(url, options) {
|
|
40
|
+
if (hasGlobalEventListeners) {
|
|
41
|
+
const onOpen = this.events.onopen;
|
|
42
|
+
this.events.onopen = (ev) => {
|
|
43
|
+
onOfflineListeners.push(this.#_offlineListener);
|
|
44
|
+
onOpen?.(ev);
|
|
45
|
+
};
|
|
46
|
+
const onClose = this.events.onclose;
|
|
47
|
+
this.events.onclose = (ev) => {
|
|
48
|
+
onOfflineListeners.splice(onOfflineListeners.indexOf(this.#_offlineListener), 1);
|
|
49
|
+
onClose?.(ev);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
26
52
|
this.url = url;
|
|
27
53
|
this.options = options;
|
|
28
54
|
this.transport.connect(url, options);
|
package/build/Connection.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.mjs","sources":["../src/Connection.ts"],"sourcesContent":["import type { ITransport, ITransportEventMap } from \"./transport/ITransport.ts\";\nimport { H3TransportTransport } from \"./transport/H3Transport.ts\";\nimport { WebSocketTransport } from \"./transport/WebSocketTransport.ts\";\n\nexport class Connection implements ITransport {\n transport: ITransport;\n events: ITransportEventMap = {};\n\n url?: string;\n options?: any;\n\n constructor(protocol?: string) {\n switch (protocol) {\n case \"h3\":\n this.transport = new H3TransportTransport(this.events);\n break;\n\n default:\n this.transport = new WebSocketTransport(this.events);\n break;\n }\n }\n\n connect(url: string, options?: any): void {\n this.url = url;\n this.options = options;\n this.transport.connect(url, options);\n }\n\n send(data: Buffer | Uint8Array): void {\n this.transport.send(data);\n }\n\n sendUnreliable(data: Buffer | Uint8Array): void {\n this.transport.sendUnreliable(data);\n }\n\n reconnect(queryParams: { reconnectionToken: string, skipHandshake?: boolean }): void {\n const queryString = new URLSearchParams(queryParams as unknown as Record<string, string>).toString();\n this.transport.connect(`${this.url}&${queryString}`, this.options);\n }\n\n close(code?: number, reason?: string): void {\n this.transport.close(code, reason);\n }\n\n get isOpen() {\n return this.transport.isOpen;\n }\n\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Connection.mjs","sources":["../src/Connection.ts"],"sourcesContent":["import type { ITransport, ITransportEventMap } from \"./transport/ITransport.ts\";\nimport { H3TransportTransport } from \"./transport/H3Transport.ts\";\nimport { WebSocketTransport } from \"./transport/WebSocketTransport.ts\";\nimport { CloseCode } from \"@colyseus/shared-types\";\n\nconst onOfflineListeners: (() => void)[] = [];\nconst hasGlobalEventListeners = typeof (addEventListener) === \"function\" && typeof (removeEventListener) === \"function\";\nif (hasGlobalEventListeners) {\n /**\n * Detects when the network is offline and closes all connections.\n * (When switching wifi networks, etc.)\n */\n addEventListener(\"offline\", () => {\n console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${onOfflineListeners.length} connection(s)`);\n onOfflineListeners.forEach((listener) => listener());\n }, false);\n}\n\nexport class Connection implements ITransport {\n transport: ITransport;\n events: ITransportEventMap = {};\n\n url?: string;\n options?: any;\n\n #_offlineListener = (hasGlobalEventListeners) ? () => this.close(CloseCode.MAY_TRY_RECONNECT) : null;\n\n constructor(protocol?: string) {\n switch (protocol) {\n case \"h3\":\n this.transport = new H3TransportTransport(this.events);\n break;\n\n default:\n this.transport = new WebSocketTransport(this.events);\n break;\n }\n }\n\n connect(url: string, options?: any): void {\n if (hasGlobalEventListeners) {\n const onOpen = this.events.onopen;\n this.events.onopen = (ev: any) => {\n onOfflineListeners.push(this.#_offlineListener);\n onOpen?.(ev);\n };\n\n const onClose = this.events.onclose;\n this.events.onclose = (ev: any) => {\n onOfflineListeners.splice(onOfflineListeners.indexOf(this.#_offlineListener), 1);\n onClose?.(ev);\n };\n }\n\n this.url = url;\n this.options = options;\n this.transport.connect(url, options);\n }\n\n send(data: Buffer | Uint8Array): void {\n this.transport.send(data);\n }\n\n sendUnreliable(data: Buffer | Uint8Array): void {\n this.transport.sendUnreliable(data);\n }\n\n reconnect(queryParams: { reconnectionToken: string, skipHandshake?: boolean }): void {\n const queryString = new URLSearchParams(queryParams as unknown as Record<string, string>).toString();\n this.transport.connect(`${this.url}&${queryString}`, this.options);\n }\n\n close(code?: number, reason?: string): void {\n this.transport.close(code, reason);\n }\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HANGED
package/build/Protocol.mjs
CHANGED
package/build/Room.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
@@ -31,7 +31,7 @@ class Room {
|
|
|
31
31
|
// reconnection logic
|
|
32
32
|
this.reconnection = {
|
|
33
33
|
retryCount: 0,
|
|
34
|
-
maxRetries:
|
|
34
|
+
maxRetries: 15,
|
|
35
35
|
delay: 100,
|
|
36
36
|
minDelay: 100,
|
|
37
37
|
maxDelay: 5000,
|
|
@@ -53,7 +53,6 @@ class Room {
|
|
|
53
53
|
this.serializer = new (Serializer.getSerializer("schema"));
|
|
54
54
|
this.serializer.state = new rootSchema();
|
|
55
55
|
}
|
|
56
|
-
this.onError((code, message) => { var _a; return (_a = console.warn) === null || _a === void 0 ? void 0 : _a.call(console, `colyseus.js - onError => (${code}) ${message}`); });
|
|
57
56
|
this.onLeave(() => this.removeAllListeners());
|
|
58
57
|
}
|
|
59
58
|
connect(endpoint, options, headers) {
|
|
@@ -70,7 +69,7 @@ class Room {
|
|
|
70
69
|
if (e.code === sharedTypes.CloseCode.NO_STATUS_RECEIVED ||
|
|
71
70
|
e.code === sharedTypes.CloseCode.ABNORMAL_CLOSURE ||
|
|
72
71
|
e.code === sharedTypes.CloseCode.GOING_AWAY ||
|
|
73
|
-
e.code === sharedTypes.CloseCode.
|
|
72
|
+
e.code === sharedTypes.CloseCode.MAY_TRY_RECONNECT) {
|
|
74
73
|
this.onDrop.invoke(e.code, e.reason);
|
|
75
74
|
this.handleReconnection();
|
|
76
75
|
}
|
|
@@ -80,8 +79,6 @@ class Room {
|
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
this.connection.events.onerror = (e) => {
|
|
83
|
-
var _a;
|
|
84
|
-
(_a = console.warn) === null || _a === void 0 ? void 0 : _a.call(console, `Room, onError (${e.code}): ${e.reason}`);
|
|
85
82
|
this.onError.invoke(e.code, e.reason);
|
|
86
83
|
};
|
|
87
84
|
/**
|
|
@@ -119,6 +116,11 @@ class Room {
|
|
|
119
116
|
return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);
|
|
120
117
|
}
|
|
121
118
|
ping(callback) {
|
|
119
|
+
var _a;
|
|
120
|
+
// skip if connection is not open
|
|
121
|
+
if (!((_a = this.connection) === null || _a === void 0 ? void 0 : _a.isOpen)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
122
124
|
tslib.__classPrivateFieldSet(this, _Room_lastPingTime, utils.now(), "f");
|
|
123
125
|
tslib.__classPrivateFieldSet(this, _Room_pingCallback, callback, "f");
|
|
124
126
|
this.packr.buffer[0] = Protocol.Protocol.PING;
|
|
@@ -276,7 +278,7 @@ class Room {
|
|
|
276
278
|
this.dispatchMessage(type, buffer.subarray(it.offset));
|
|
277
279
|
}
|
|
278
280
|
else if (code === Protocol.Protocol.PING) {
|
|
279
|
-
(_a = tslib.__classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, utils.now() - tslib.__classPrivateFieldGet(this, _Room_lastPingTime, "f"));
|
|
281
|
+
(_a = tslib.__classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, Math.round(utils.now() - tslib.__classPrivateFieldGet(this, _Room_lastPingTime, "f")));
|
|
280
282
|
tslib.__classPrivateFieldSet(this, _Room_pingCallback, undefined, "f");
|
|
281
283
|
}
|
|
282
284
|
}
|
|
@@ -313,7 +315,6 @@ class Room {
|
|
|
313
315
|
return;
|
|
314
316
|
}
|
|
315
317
|
if (!this.reconnection.isReconnecting) {
|
|
316
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing connection with roomId '${this.roomId}'...`); // 🔄
|
|
317
318
|
this.reconnection.retryCount = 0;
|
|
318
319
|
this.reconnection.isReconnecting = true;
|
|
319
320
|
}
|
|
@@ -322,16 +323,18 @@ class Room {
|
|
|
322
323
|
retryReconnection() {
|
|
323
324
|
this.reconnection.retryCount++;
|
|
324
325
|
const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
|
|
325
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(
|
|
326
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
|
|
326
327
|
// Wait before attempting reconnection
|
|
327
328
|
setTimeout(() => {
|
|
328
329
|
try {
|
|
330
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄
|
|
329
331
|
this.connection.reconnect({
|
|
330
332
|
reconnectionToken: this.reconnectionToken.split(":")[1],
|
|
331
333
|
skipHandshake: true, // we already applied the handshake on first join
|
|
332
334
|
});
|
|
333
335
|
}
|
|
334
336
|
catch (e) {
|
|
337
|
+
console.log(".reconnect() failed", e);
|
|
335
338
|
if (this.reconnection.retryCount < this.reconnection.maxRetries) {
|
|
336
339
|
this.retryReconnection();
|
|
337
340
|
}
|
package/build/Room.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Room.cjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, type InferState, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { Protocol } from './Protocol.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 8,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback: (ms: number) => void;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n this.serializer = new (getSerializer(\"schema\"));\n (this.serializer as SchemaSerializer).state = new rootSchema();\n }\n\n this.onError((code, message) => console.warn?.(`colyseus.js - onError => (${code}) ${message}`));\n this.onLeave(() => this.removeAllListeners());\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.DEVMODE_RESTART\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n this.destroy();\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n console.warn?.(`Room, onError (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"?skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<T>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<T>[MessageType]) => void\n )\n public onMessage<T = any>(type: \"*\", callback: (messageType: string | number, payload: T) => void)\n public onMessage<T = any>(type: string | number, callback: (payload: T) => void)\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<T>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<T>[MessageType]>\n )\n public send<T = any>(messageType: string | number, payload?: T): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(now() - this.#lastPingTime);\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing connection with roomId '${this.roomId}'...`); // 🔄\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} will retry in ${delay}ms... (${this.reconnection.retryCount} out of ${this.reconnection.maxRetries})`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n if (this.reconnection.retryCount < this.reconnection.maxRetries) {\n this.retryReconnection();\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌\n }\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":["createSignal","createNanoEvents","Packr","getSerializer","Connection","CloseCode","Protocol","__classPrivateFieldSet","now","encode","SchemaSerializer","decode","unpack","__classPrivateFieldGet"],"mappings":";;;;;;;;;;;;;;;;;;;;;MAuFa,IAAI,CAAA;IA+Cb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;QAnCxD,IAAA,CAAA,aAAa,GAAGA,mBAAY,EAA0B;QACtD,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA4C;QAClE,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA2C;QAEjE,IAAA,CAAA,WAAW,GAAGA,mBAAY,EAAc;QACxC,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAA2C;QAE7D,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAAE;;AAM1B,QAAA,IAAA,CAAA,YAAY,GAAwB;AACvC,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,QAAQ,EAAE,GAAG;AACb,YAAA,QAAQ,EAAE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CAAC,CAAC;oBACvD,aAAa,EAAE,IAAI;AACtB,iBAAA,CAAC;YAEN;YAAE,OAAO,CAAC,EAAE;AACR,gBAAA,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE;oBAC7D,IAAI,CAAC,iBAAiB,EAAE;gBAC5B;qBAAO;AACH,oBAAA,OAAO,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,uEAAA,CAAyE,CAAC,CAAC;gBACpJ;YACJ;QACJ,CAAC,EAAE,KAAK,CAAC;IACb;AACH;;AAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAa,KAAI;AAC1D,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAmB,EAAA;AACnD,IAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Room.cjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, type InferState, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { Protocol } from './Protocol.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 15,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback: (ms: number) => void;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n this.serializer = new (getSerializer(\"schema\"));\n (this.serializer as SchemaSerializer).state = new rootSchema();\n }\n\n this.onLeave(() => this.removeAllListeners());\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.MAY_TRY_RECONNECT\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n this.destroy();\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"?skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<T>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<T>[MessageType]) => void\n )\n public onMessage<T = any>(type: \"*\", callback: (messageType: string | number, payload: T) => void)\n public onMessage<T = any>(type: string | number, callback: (payload: T) => void)\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n // skip if connection is not open\n if (!this.connection?.isOpen) {\n return;\n }\n\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<T>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<T>[MessageType]>\n )\n public send<T = any>(messageType: string | number, payload?: T): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(Math.round(now() - this.#lastPingTime));\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay/1000).toFixed(1)} seconds...`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n console.log(\".reconnect() failed\", e);\n if (this.reconnection.retryCount < this.reconnection.maxRetries) {\n this.retryReconnection();\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌\n }\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":["createSignal","createNanoEvents","Packr","getSerializer","Connection","CloseCode","Protocol","__classPrivateFieldSet","now","encode","SchemaSerializer","decode","unpack","__classPrivateFieldGet"],"mappings":";;;;;;;;;;;;;;;;;;;;;MAuFa,IAAI,CAAA;IA+Cb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;QAnCxD,IAAA,CAAA,aAAa,GAAGA,mBAAY,EAA0B;QACtD,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA4C;QAClE,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA2C;QAEjE,IAAA,CAAA,WAAW,GAAGA,mBAAY,EAAc;QACxC,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAA2C;QAE7D,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAAE;;AAM1B,QAAA,IAAA,CAAA,YAAY,GAAwB;AACvC,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,QAAQ,EAAE,GAAG;AACb,YAA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,EAA4B,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,uEAAA,CAAyE,CAAC,CAAC;gBACpJ;YACJ;QACJ,CAAC,EAAE,KAAK,CAAC;IACb;AACH;;AAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAa,KAAI;AAC1D,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAmB,EAAA;AACnD,IAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
package/build/Room.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.16
|
|
7
7
|
import { CloseCode } from '@colyseus/shared-types';
|
|
8
8
|
import { encode, decode } from '@colyseus/schema';
|
|
9
9
|
import { Packr, unpack } from '@colyseus/msgpackr';
|
|
@@ -33,7 +33,7 @@ class Room {
|
|
|
33
33
|
// reconnection logic
|
|
34
34
|
reconnection = {
|
|
35
35
|
retryCount: 0,
|
|
36
|
-
maxRetries:
|
|
36
|
+
maxRetries: 15,
|
|
37
37
|
delay: 100,
|
|
38
38
|
minDelay: 100,
|
|
39
39
|
maxDelay: 5000,
|
|
@@ -57,7 +57,6 @@ class Room {
|
|
|
57
57
|
this.serializer = new (getSerializer("schema"));
|
|
58
58
|
this.serializer.state = new rootSchema();
|
|
59
59
|
}
|
|
60
|
-
this.onError((code, message) => console.warn?.(`colyseus.js - onError => (${code}) ${message}`));
|
|
61
60
|
this.onLeave(() => this.removeAllListeners());
|
|
62
61
|
}
|
|
63
62
|
connect(endpoint, options, headers) {
|
|
@@ -72,7 +71,7 @@ class Room {
|
|
|
72
71
|
if (e.code === CloseCode.NO_STATUS_RECEIVED ||
|
|
73
72
|
e.code === CloseCode.ABNORMAL_CLOSURE ||
|
|
74
73
|
e.code === CloseCode.GOING_AWAY ||
|
|
75
|
-
e.code === CloseCode.
|
|
74
|
+
e.code === CloseCode.MAY_TRY_RECONNECT) {
|
|
76
75
|
this.onDrop.invoke(e.code, e.reason);
|
|
77
76
|
this.handleReconnection();
|
|
78
77
|
}
|
|
@@ -82,7 +81,6 @@ class Room {
|
|
|
82
81
|
}
|
|
83
82
|
};
|
|
84
83
|
this.connection.events.onerror = (e) => {
|
|
85
|
-
console.warn?.(`Room, onError (${e.code}): ${e.reason}`);
|
|
86
84
|
this.onError.invoke(e.code, e.reason);
|
|
87
85
|
};
|
|
88
86
|
/**
|
|
@@ -120,6 +118,10 @@ class Room {
|
|
|
120
118
|
return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);
|
|
121
119
|
}
|
|
122
120
|
ping(callback) {
|
|
121
|
+
// skip if connection is not open
|
|
122
|
+
if (!this.connection?.isOpen) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
123
125
|
this.#lastPingTime = now();
|
|
124
126
|
this.#pingCallback = callback;
|
|
125
127
|
this.packr.buffer[0] = Protocol.PING;
|
|
@@ -276,7 +278,7 @@ class Room {
|
|
|
276
278
|
this.dispatchMessage(type, buffer.subarray(it.offset));
|
|
277
279
|
}
|
|
278
280
|
else if (code === Protocol.PING) {
|
|
279
|
-
this.#pingCallback?.(now() - this.#lastPingTime);
|
|
281
|
+
this.#pingCallback?.(Math.round(now() - this.#lastPingTime));
|
|
280
282
|
this.#pingCallback = undefined;
|
|
281
283
|
}
|
|
282
284
|
}
|
|
@@ -312,7 +314,6 @@ class Room {
|
|
|
312
314
|
return;
|
|
313
315
|
}
|
|
314
316
|
if (!this.reconnection.isReconnecting) {
|
|
315
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing connection with roomId '${this.roomId}'...`); // 🔄
|
|
316
317
|
this.reconnection.retryCount = 0;
|
|
317
318
|
this.reconnection.isReconnecting = true;
|
|
318
319
|
}
|
|
@@ -321,16 +322,18 @@ class Room {
|
|
|
321
322
|
retryReconnection() {
|
|
322
323
|
this.reconnection.retryCount++;
|
|
323
324
|
const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
|
|
324
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(
|
|
325
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
|
|
325
326
|
// Wait before attempting reconnection
|
|
326
327
|
setTimeout(() => {
|
|
327
328
|
try {
|
|
329
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄
|
|
328
330
|
this.connection.reconnect({
|
|
329
331
|
reconnectionToken: this.reconnectionToken.split(":")[1],
|
|
330
332
|
skipHandshake: true, // we already applied the handshake on first join
|
|
331
333
|
});
|
|
332
334
|
}
|
|
333
335
|
catch (e) {
|
|
336
|
+
console.log(".reconnect() failed", e);
|
|
334
337
|
if (this.reconnection.retryCount < this.reconnection.maxRetries) {
|
|
335
338
|
this.retryReconnection();
|
|
336
339
|
}
|