@colyseus/sdk 0.17.0
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/LICENSE +22 -0
- package/README.md +27 -0
- package/build/cjs/3rd_party/discord.js +56 -0
- package/build/cjs/3rd_party/discord.js.map +1 -0
- package/build/cjs/Auth.js +156 -0
- package/build/cjs/Auth.js.map +1 -0
- package/build/cjs/Client.js +282 -0
- package/build/cjs/Client.js.map +1 -0
- package/build/cjs/Connection.js +48 -0
- package/build/cjs/Connection.js.map +1 -0
- package/build/cjs/HTTP.js +156 -0
- package/build/cjs/HTTP.js.map +1 -0
- package/build/cjs/Protocol.js +34 -0
- package/build/cjs/Protocol.js.map +1 -0
- package/build/cjs/Room.js +357 -0
- package/build/cjs/Room.js.map +1 -0
- package/build/cjs/Storage.js +98 -0
- package/build/cjs/Storage.js.map +1 -0
- package/build/cjs/core/nanoevents.js +50 -0
- package/build/cjs/core/nanoevents.js.map +1 -0
- package/build/cjs/core/signal.js +53 -0
- package/build/cjs/core/signal.js.map +1 -0
- package/build/cjs/core/utils.js +14 -0
- package/build/cjs/core/utils.js.map +1 -0
- package/build/cjs/errors/Errors.js +29 -0
- package/build/cjs/errors/Errors.js.map +1 -0
- package/build/cjs/index.js +43 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/legacy.js +34 -0
- package/build/cjs/legacy.js.map +1 -0
- package/build/cjs/serializer/NoneSerializer.js +18 -0
- package/build/cjs/serializer/NoneSerializer.js.map +1 -0
- package/build/cjs/serializer/SchemaSerializer.js +61 -0
- package/build/cjs/serializer/SchemaSerializer.js.map +1 -0
- package/build/cjs/serializer/Serializer.js +23 -0
- package/build/cjs/serializer/Serializer.js.map +1 -0
- package/build/cjs/transport/H3Transport.js +171 -0
- package/build/cjs/transport/H3Transport.js.map +1 -0
- package/build/cjs/transport/WebSocketTransport.js +50 -0
- package/build/cjs/transport/WebSocketTransport.js.map +1 -0
- package/build/esm/3rd_party/discord.mjs +53 -0
- package/build/esm/3rd_party/discord.mjs.map +1 -0
- package/build/esm/Auth.mjs +137 -0
- package/build/esm/Auth.mjs.map +1 -0
- package/build/esm/Client.mjs +272 -0
- package/build/esm/Client.mjs.map +1 -0
- package/build/esm/Connection.mjs +49 -0
- package/build/esm/Connection.mjs.map +1 -0
- package/build/esm/HTTP.mjs +159 -0
- package/build/esm/HTTP.mjs.map +1 -0
- package/build/esm/Protocol.mjs +34 -0
- package/build/esm/Protocol.mjs.map +1 -0
- package/build/esm/Room.mjs +355 -0
- package/build/esm/Room.mjs.map +1 -0
- package/build/esm/Storage.mjs +86 -0
- package/build/esm/Storage.mjs.map +1 -0
- package/build/esm/core/nanoevents.mjs +46 -0
- package/build/esm/core/nanoevents.mjs.map +1 -0
- package/build/esm/core/signal.mjs +48 -0
- package/build/esm/core/signal.mjs.map +1 -0
- package/build/esm/core/utils.mjs +12 -0
- package/build/esm/core/utils.mjs.map +1 -0
- package/build/esm/errors/Errors.mjs +28 -0
- package/build/esm/errors/Errors.mjs.map +1 -0
- package/build/esm/index.mjs +22 -0
- package/build/esm/index.mjs.map +1 -0
- package/build/esm/legacy.mjs +32 -0
- package/build/esm/legacy.mjs.map +1 -0
- package/build/esm/serializer/NoneSerializer.mjs +16 -0
- package/build/esm/serializer/NoneSerializer.mjs.map +1 -0
- package/build/esm/serializer/SchemaSerializer.mjs +60 -0
- package/build/esm/serializer/SchemaSerializer.mjs.map +1 -0
- package/build/esm/serializer/Serializer.mjs +20 -0
- package/build/esm/serializer/Serializer.mjs.map +1 -0
- package/build/esm/transport/H3Transport.mjs +170 -0
- package/build/esm/transport/H3Transport.mjs.map +1 -0
- package/build/esm/transport/WebSocketTransport.mjs +51 -0
- package/build/esm/transport/WebSocketTransport.mjs.map +1 -0
- package/dist/colyseus-cocos-creator.js +9538 -0
- package/dist/colyseus-cocos-creator.js.map +1 -0
- package/dist/colyseus.js +9537 -0
- package/dist/colyseus.js.map +1 -0
- package/dist/debug.js +2460 -0
- package/dist/debug.js.map +1 -0
- package/lib/3rd_party/discord.d.ts +33 -0
- package/lib/Auth.d.ts +31 -0
- package/lib/Client.d.ts +92 -0
- package/lib/Connection.d.ts +17 -0
- package/lib/HTTP.d.ts +113 -0
- package/lib/HTTP_bkp.d.ts +18 -0
- package/lib/Protocol.d.ts +21 -0
- package/lib/Room.d.ts +140 -0
- package/lib/Storage.d.ts +3 -0
- package/lib/core/http_bkp.d.ts +319 -0
- package/lib/core/nanoevents.d.ts +27 -0
- package/lib/core/signal.d.ts +17 -0
- package/lib/core/utils.d.ts +1 -0
- package/lib/debug.d.ts +1 -0
- package/lib/errors/Errors.d.ts +17 -0
- package/lib/index.d.ts +9 -0
- package/lib/legacy.d.ts +0 -0
- package/lib/serializer/FossilDeltaSerializer.d.ts +0 -0
- package/lib/serializer/NoneSerializer.d.ts +8 -0
- package/lib/serializer/SchemaSerializer.d.ts +14 -0
- package/lib/serializer/Serializer.d.ts +10 -0
- package/lib/src/3rd_party/discord.d.ts +33 -0
- package/lib/src/Auth.d.ts +31 -0
- package/lib/src/Client.d.ts +62 -0
- package/lib/src/Connection.d.ts +17 -0
- package/lib/src/HTTP.d.ts +113 -0
- package/lib/src/HTTP_bkp.d.ts +18 -0
- package/lib/src/Protocol.d.ts +28 -0
- package/lib/src/Room.d.ts +132 -0
- package/lib/src/Storage.d.ts +3 -0
- package/lib/src/core/http_bkp.d.ts +319 -0
- package/lib/src/core/nanoevents.d.ts +27 -0
- package/lib/src/core/signal.d.ts +17 -0
- package/lib/src/debug.d.ts +1 -0
- package/lib/src/errors/Errors.d.ts +15 -0
- package/lib/src/index.d.ts +9 -0
- package/lib/src/legacy.d.ts +0 -0
- package/lib/src/serializer/FossilDeltaSerializer.d.ts +0 -0
- package/lib/src/serializer/NoneSerializer.d.ts +8 -0
- package/lib/src/serializer/SchemaSerializer.d.ts +14 -0
- package/lib/src/serializer/Serializer.d.ts +11 -0
- package/lib/src/transport/H3Transport.d.ts +20 -0
- package/lib/src/transport/ITransport.d.ts +16 -0
- package/lib/src/transport/WebSocketTransport.d.ts +17 -0
- package/lib/transport/H3Transport.d.ts +20 -0
- package/lib/transport/ITransport.d.ts +16 -0
- package/lib/transport/WebSocketTransport.d.ts +17 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015-2024 Endel Dreyer
|
|
2
|
+
|
|
3
|
+
MIT License:
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/colyseus/colyseus">
|
|
3
|
+
<img src="https://github.com/colyseus/colyseus/blob/master/media/logo.svg?raw=true" width="40%" height="100" />
|
|
4
|
+
</a>
|
|
5
|
+
<br>
|
|
6
|
+
<br>
|
|
7
|
+
<a href="https://npmjs.com/package/colyseus">
|
|
8
|
+
<img src="https://img.shields.io/npm/dm/colyseus.svg?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAHdElNRQfjAgETESWYxR33AAAAtElEQVQoz4WQMQrCQBRE38Z0QoTcwF4Qg1h4BO0sxGOk80iCtViksrIQRRBTewWxMI1mbELYjYu+4rPMDPtn12ChMT3gavb4US5Jym0tcBIta3oDHv4Gwmr7nC4QAxBrCdzM2q6XqUnm9m9r59h7Rc0n2pFv24k4ttGMUXW+sGELTJjSr7QDKuqLS6UKFChVWWuFkZw9Z2AAvAirKT+JTlppIRnd6XgaP4goefI2Shj++OnjB3tBmHYK8z9zAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE5LTAyLTAxVDE4OjE3OjM3KzAxOjAwGQQixQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOS0wMi0wMVQxODoxNzozNyswMTowMGhZmnkAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://discuss.colyseus.io" title="Discuss on Forum">
|
|
11
|
+
<img src="https://img.shields.io/badge/discuss-on%20forum-brightgreen.svg?style=for-the-badge&colorB=0069b8&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAHdElNRQfjAgETDROxCNUzAAABB0lEQVQoz4WRvyvEARjGP193CnWRH+dHQmGwKZtFGcSmxHAL400GN95ktIpV2dzlLzDJgsGgGNRdDAzoQueS/PgY3HXHyT3T+/Y87/s89UANBKXBdoZo5J6L4K1K5ZxHfnjnlQUf3bKvkgy57a0r9hS3cXfMO1kWJMza++tj3Ac7/LY343x1NA9cNmYMwnSS/SP8JVFuSJmr44iFqvtmpjhmhBCrOOazCesq6H4P3bPBjFoIBydOk2bUA17I080Es+wSZ51B4DIA2zgjSpYcEe44Js01G0XjRcCU+y4ZMrDeLmfc9EnVd5M/o0VMeu6nJZxWJivLmhyw1WHTvrr2b4+2OFqra+ALwouTMDcqmjMAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDItMDFUMTg6MTM6MTkrMDE6MDAC9f6fAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTAyLTAxVDE4OjEzOjE5KzAxOjAwc6hGIwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAASUVORK5CYII=" alt="Discussion forum" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://discord.gg/RY8rRS7">
|
|
14
|
+
<img src="https://img.shields.io/discord/525739117951320081.svg?style=for-the-badge&colorB=7581dc&logo=discord&logoColor=white">
|
|
15
|
+
</a>
|
|
16
|
+
<h3>
|
|
17
|
+
Multiplayer SDK for JavaScript/TypeScript. <br /><a href="https://docs.colyseus.io/client">View documentation</a>
|
|
18
|
+
<h3>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
**Browser support tested with:**
|
|
22
|
+
|
|
23
|
+
<a href="https://www.browserstack.com/"><img src="media/browserstack-logo.png?raw=true" width="300" /></a>
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright (c) 2026 Endel Dreyer.
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT License.
|
|
4
|
+
// https://opensource.org/license/MIT
|
|
5
|
+
//
|
|
6
|
+
// colyseus.js@0.17.0
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Discord Embedded App SDK
|
|
11
|
+
* https://github.com/colyseus/colyseus/issues/707
|
|
12
|
+
*
|
|
13
|
+
* All URLs must go through the local proxy from
|
|
14
|
+
* https://<app_id>.discordsays.com/.proxy/<mapped_url>/...
|
|
15
|
+
*
|
|
16
|
+
* URL Mapping Examples:
|
|
17
|
+
*
|
|
18
|
+
* 1. Using Colyseus Cloud:
|
|
19
|
+
* - /colyseus/{subdomain} -> {subdomain}.colyseus.cloud
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* const client = new Client("https://xxxx.colyseus.cloud");
|
|
23
|
+
*
|
|
24
|
+
* -------------------------------------------------------------
|
|
25
|
+
*
|
|
26
|
+
* 2. Using `cloudflared` tunnel:
|
|
27
|
+
* - /colyseus/ -> <your-cloudflared-url>.trycloudflare.com
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
* const client = new Client("https://<your-cloudflared-url>.trycloudflare.com");
|
|
31
|
+
*
|
|
32
|
+
* -------------------------------------------------------------
|
|
33
|
+
*
|
|
34
|
+
* 3. Providing a manual /.proxy/your-mapping:
|
|
35
|
+
* - /your-mapping/ -> your-endpoint.com
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
* const client = new Client("/.proxy/your-mapping");
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
function discordURLBuilder(url) {
|
|
42
|
+
var _a;
|
|
43
|
+
const localHostname = ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) || "localhost";
|
|
44
|
+
const remoteHostnameSplitted = url.hostname.split('.');
|
|
45
|
+
const subdomain = (!url.hostname.includes("trycloudflare.com") && // ignore cloudflared subdomains
|
|
46
|
+
!url.hostname.includes("discordsays.com") && // ignore discordsays.com subdomains
|
|
47
|
+
remoteHostnameSplitted.length > 2)
|
|
48
|
+
? `/${remoteHostnameSplitted[0]}`
|
|
49
|
+
: '';
|
|
50
|
+
return (url.pathname.startsWith("/.proxy"))
|
|
51
|
+
? `${url.protocol}//${localHostname}${subdomain}${url.pathname}${url.search}`
|
|
52
|
+
: `${url.protocol}//${localHostname}/.proxy/colyseus${subdomain}${url.pathname}${url.search}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.discordURLBuilder = discordURLBuilder;
|
|
56
|
+
//# sourceMappingURL=discord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord.js","sources":["../../../src/3rd_party/discord.ts"],"sourcesContent":["/**\n * Discord Embedded App SDK\n * https://github.com/colyseus/colyseus/issues/707\n *\n * All URLs must go through the local proxy from\n * https://<app_id>.discordsays.com/.proxy/<mapped_url>/...\n *\n * URL Mapping Examples:\n *\n * 1. Using Colyseus Cloud:\n * - /colyseus/{subdomain} -> {subdomain}.colyseus.cloud\n *\n * Example:\n * const client = new Client(\"https://xxxx.colyseus.cloud\");\n *\n * -------------------------------------------------------------\n *\n * 2. Using `cloudflared` tunnel:\n * - /colyseus/ -> <your-cloudflared-url>.trycloudflare.com\n *\n * Example:\n * const client = new Client(\"https://<your-cloudflared-url>.trycloudflare.com\");\n *\n * -------------------------------------------------------------\n *\n * 3. Providing a manual /.proxy/your-mapping:\n * - /your-mapping/ -> your-endpoint.com\n *\n * Example:\n * const client = new Client(\"/.proxy/your-mapping\");\n *\n */\nexport function discordURLBuilder (url: URL): string {\n const localHostname = window?.location?.hostname || \"localhost\";\n\n const remoteHostnameSplitted = url.hostname.split('.');\n const subdomain = (\n !url.hostname.includes(\"trycloudflare.com\") && // ignore cloudflared subdomains\n !url.hostname.includes(\"discordsays.com\") && // ignore discordsays.com subdomains\n remoteHostnameSplitted.length > 2\n )\n ? `/${remoteHostnameSplitted[0]}`\n : '';\n\n return (url.pathname.startsWith(\"/.proxy\"))\n ? `${url.protocol}//${localHostname}${subdomain}${url.pathname}${url.search}`\n : `${url.protocol}//${localHostname}/.proxy/colyseus${subdomain}${url.pathname}${url.search}`;\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACG,SAAU,iBAAiB,CAAE,GAAQ,EAAA;;AACvC,IAAA,MAAM,aAAa,GAAG,CAAA,CAAA,EAAA,GAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,MAAA,GAAA,MAAA,GAAN,MAAM,CAAE,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,QAAQ,KAAI,WAAW;IAE/D,MAAM,sBAAsB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;AACtD,IAAA,MAAM,SAAS,GAAG,CACd,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC3C,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC;AACzC,QAAA,sBAAsB,CAAC,MAAM,GAAG,CAAC;AAEjC,UAAE,CAAA,CAAA,EAAI,sBAAsB,CAAC,CAAC,CAAC,CAAA;UAC7B,EAAE;IAER,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;AACtC,UAAE,CAAA,EAAG,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAA,EAAG,SAAS,CAAA,EAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAA;AAC3E,UAAE,CAAA,EAAG,GAAG,CAAC,QAAQ,CAAA,EAAA,EAAK,aAAa,CAAA,gBAAA,EAAmB,SAAS,CAAA,EAAG,GAAG,CAAC,QAAQ,CAAA,EAAG,GAAG,CAAC,MAAM,EAAE;AACrG;;;;"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright (c) 2026 Endel Dreyer.
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT License.
|
|
4
|
+
// https://opensource.org/license/MIT
|
|
5
|
+
//
|
|
6
|
+
// colyseus.js@0.17.0
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var tslib = require('tslib');
|
|
10
|
+
var Storage = require('./Storage.js');
|
|
11
|
+
var nanoevents = require('./core/nanoevents.js');
|
|
12
|
+
|
|
13
|
+
var _Auth__initialized, _Auth__signInWindow, _Auth__events;
|
|
14
|
+
class Auth {
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.settings = {
|
|
17
|
+
path: "/auth",
|
|
18
|
+
key: "colyseus-auth-token",
|
|
19
|
+
};
|
|
20
|
+
_Auth__initialized.set(this, false);
|
|
21
|
+
_Auth__signInWindow.set(this, null);
|
|
22
|
+
_Auth__events.set(this, nanoevents.createNanoEvents());
|
|
23
|
+
this.http = http;
|
|
24
|
+
Storage.getItem(this.settings.key, (token) => this.token = token);
|
|
25
|
+
}
|
|
26
|
+
set token(token) {
|
|
27
|
+
this.http.authToken = token;
|
|
28
|
+
}
|
|
29
|
+
get token() {
|
|
30
|
+
return this.http.authToken;
|
|
31
|
+
}
|
|
32
|
+
onChange(callback) {
|
|
33
|
+
const unbindChange = tslib.__classPrivateFieldGet(this, _Auth__events, "f").on("change", callback);
|
|
34
|
+
if (!tslib.__classPrivateFieldGet(this, _Auth__initialized, "f")) {
|
|
35
|
+
this.getUserData().then((userData) => {
|
|
36
|
+
this.emitChange(Object.assign(Object.assign({}, userData), { token: this.token }));
|
|
37
|
+
}).catch((e) => {
|
|
38
|
+
// user is not logged in, or service is down
|
|
39
|
+
this.emitChange({ user: null, token: undefined });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
tslib.__classPrivateFieldSet(this, _Auth__initialized, true, "f");
|
|
43
|
+
return unbindChange;
|
|
44
|
+
}
|
|
45
|
+
getUserData() {
|
|
46
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (this.token) {
|
|
48
|
+
return (yield this.http.get(`${this.settings.path}/userdata`)).data;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error("missing auth.token");
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
registerWithEmailAndPassword(email, password, options) {
|
|
56
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const data = (yield this.http.post(`${this.settings.path}/register`, {
|
|
58
|
+
body: { email, password, options, },
|
|
59
|
+
})).data;
|
|
60
|
+
this.emitChange(data);
|
|
61
|
+
return data;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
signInWithEmailAndPassword(email, password) {
|
|
65
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const data = (yield this.http.post(`${this.settings.path}/login`, {
|
|
67
|
+
body: { email, password, },
|
|
68
|
+
})).data;
|
|
69
|
+
this.emitChange(data);
|
|
70
|
+
return data;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
signInAnonymously(options) {
|
|
74
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const data = (yield this.http.post(`${this.settings.path}/anonymous`, {
|
|
76
|
+
body: { options, }
|
|
77
|
+
})).data;
|
|
78
|
+
this.emitChange(data);
|
|
79
|
+
return data;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
sendPasswordResetEmail(email) {
|
|
83
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return (yield this.http.post(`${this.settings.path}/forgot-password`, {
|
|
85
|
+
body: { email, }
|
|
86
|
+
})).data;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
signInWithProvider(providerName_1) {
|
|
90
|
+
return tslib.__awaiter(this, arguments, void 0, function* (providerName, settings = {}) {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const w = settings.width || 480;
|
|
93
|
+
const h = settings.height || 768;
|
|
94
|
+
// forward existing token for upgrading
|
|
95
|
+
const upgradingToken = this.token ? `?token=${this.token}` : "";
|
|
96
|
+
// Capitalize first letter of providerName
|
|
97
|
+
const title = `Login with ${(providerName[0].toUpperCase() + providerName.substring(1))}`;
|
|
98
|
+
const url = this.http['sdk']['getHttpEndpoint'](`${(settings.prefix || `${this.settings.path}/provider`)}/${providerName}${upgradingToken}`);
|
|
99
|
+
const left = (screen.width / 2) - (w / 2);
|
|
100
|
+
const top = (screen.height / 2) - (h / 2);
|
|
101
|
+
tslib.__classPrivateFieldSet(this, _Auth__signInWindow, window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left), "f");
|
|
102
|
+
const onMessage = (event) => {
|
|
103
|
+
// TODO: it is a good idea to check if event.origin can be trusted!
|
|
104
|
+
// if (event.origin.indexOf(window.location.hostname) === -1) { return; }
|
|
105
|
+
var _a;
|
|
106
|
+
// require 'user' and 'token' inside received data.
|
|
107
|
+
if (event.data.user === undefined && event.data.token === undefined) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
clearInterval(rejectionChecker);
|
|
111
|
+
(_a = tslib.__classPrivateFieldGet(this, _Auth__signInWindow, "f")) === null || _a === void 0 ? void 0 : _a.close();
|
|
112
|
+
tslib.__classPrivateFieldSet(this, _Auth__signInWindow, null, "f");
|
|
113
|
+
window.removeEventListener("message", onMessage);
|
|
114
|
+
if (event.data.error !== undefined) {
|
|
115
|
+
reject(event.data.error);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
resolve(event.data);
|
|
119
|
+
this.emitChange(event.data);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const rejectionChecker = setInterval(() => {
|
|
123
|
+
if (!tslib.__classPrivateFieldGet(this, _Auth__signInWindow, "f") || tslib.__classPrivateFieldGet(this, _Auth__signInWindow, "f").closed) {
|
|
124
|
+
tslib.__classPrivateFieldSet(this, _Auth__signInWindow, null, "f");
|
|
125
|
+
reject("cancelled");
|
|
126
|
+
window.removeEventListener("message", onMessage);
|
|
127
|
+
}
|
|
128
|
+
}, 200);
|
|
129
|
+
window.addEventListener("message", onMessage);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
signOut() {
|
|
134
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
this.emitChange({ user: null, token: null });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
emitChange(authData) {
|
|
140
|
+
if (authData.token !== undefined) {
|
|
141
|
+
this.token = authData.token;
|
|
142
|
+
if (authData.token === null) {
|
|
143
|
+
Storage.removeItem(this.settings.key);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// store key in localStorage
|
|
147
|
+
Storage.setItem(this.settings.key, authData.token);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
tslib.__classPrivateFieldGet(this, _Auth__events, "f").emit("change", authData);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
_Auth__initialized = new WeakMap(), _Auth__signInWindow = new WeakMap(), _Auth__events = new WeakMap();
|
|
154
|
+
|
|
155
|
+
exports.Auth = Auth;
|
|
156
|
+
//# sourceMappingURL=Auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auth.js","sources":["../../src/Auth.ts"],"sourcesContent":["import { HTTP } from \"./HTTP.ts\";\nimport { getItem, removeItem, setItem } from \"./Storage.ts\";\nimport { createNanoEvents } from './core/nanoevents.ts';\n\nexport interface AuthSettings {\n path: string;\n key: string;\n}\n\nexport interface PopupSettings {\n prefix: string;\n width: number;\n height: number;\n}\n\nexport interface AuthData {\n user: any;\n token: string;\n}\n\nexport class Auth {\n settings: AuthSettings = {\n path: \"/auth\",\n key: \"colyseus-auth-token\",\n };\n\n #_initialized = false;\n #_signInWindow: WindowProxy | null = null;\n #_events = createNanoEvents();\n\n protected http: HTTP<any>;\n\n constructor(http: HTTP<any>) {\n this.http = http;\n getItem(this.settings.key, (token: string) => this.token = token);\n }\n\n public set token(token: string) {\n this.http.authToken = token;\n }\n\n public get token(): string | undefined {\n return this.http.authToken;\n }\n\n public onChange(callback: (response: AuthData) => void) {\n const unbindChange = this.#_events.on(\"change\", callback);\n if (!this.#_initialized) {\n this.getUserData().then((userData: any) => {\n this.emitChange({ ...userData, token: this.token });\n\n }).catch((e) => {\n // user is not logged in, or service is down\n this.emitChange({ user: null, token: undefined });\n });\n }\n this.#_initialized = true;\n return unbindChange;\n }\n\n public async getUserData() {\n if (this.token) {\n return (await this.http.get(`${this.settings.path}/userdata`)).data;\n } else {\n throw new Error(\"missing auth.token\");\n }\n }\n\n public async registerWithEmailAndPassword(email: string, password: string, options?: any) {\n const data = (await this.http.post(`${this.settings.path}/register`, {\n body: { email, password, options, },\n })).data;\n\n this.emitChange(data as any);\n\n return data;\n }\n\n public async signInWithEmailAndPassword(email: string, password: string) {\n const data = (await this.http.post(`${this.settings.path}/login`, {\n body: { email, password, },\n })).data;\n\n this.emitChange(data as any);\n\n return data;\n }\n\n public async signInAnonymously(options?: any) {\n const data = (await this.http.post(`${this.settings.path}/anonymous`, {\n body: { options, }\n })).data;\n\n this.emitChange(data as any);\n\n return data;\n }\n\n public async sendPasswordResetEmail(email: string) {\n return (await this.http.post(`${this.settings.path}/forgot-password`, {\n body: { email, }\n })).data;\n }\n\n public async signInWithProvider(providerName: string, settings: Partial<PopupSettings> = {}) {\n return new Promise((resolve, reject) => {\n const w = settings.width || 480;\n const h = settings.height || 768;\n\n // forward existing token for upgrading\n const upgradingToken = this.token ? `?token=${this.token}` : \"\";\n\n // Capitalize first letter of providerName\n const title = `Login with ${(providerName[0].toUpperCase() + providerName.substring(1))}`;\n const url = this.http['sdk']['getHttpEndpoint'](`${(settings.prefix || `${this.settings.path}/provider`)}/${providerName}${upgradingToken}`);\n\n const left = (screen.width / 2) - (w / 2);\n const top = (screen.height / 2) - (h / 2);\n\n this.#_signInWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);\n\n const onMessage = (event: MessageEvent) => {\n // TODO: it is a good idea to check if event.origin can be trusted!\n // if (event.origin.indexOf(window.location.hostname) === -1) { return; }\n\n // require 'user' and 'token' inside received data.\n if (event.data.user === undefined && event.data.token === undefined) { return; }\n\n clearInterval(rejectionChecker);\n this.#_signInWindow?.close();\n this.#_signInWindow = null;\n\n window.removeEventListener(\"message\", onMessage);\n\n if (event.data.error !== undefined) {\n reject(event.data.error);\n\n } else {\n resolve(event.data);\n this.emitChange(event.data);\n }\n }\n\n const rejectionChecker = setInterval(() => {\n if (!this.#_signInWindow || this.#_signInWindow.closed) {\n this.#_signInWindow = null;\n reject(\"cancelled\");\n window.removeEventListener(\"message\", onMessage);\n }\n }, 200);\n\n window.addEventListener(\"message\", onMessage);\n });\n }\n\n public async signOut() {\n // @ts-ignore\n this.emitChange({ user: null, token: null });\n }\n\n private emitChange(authData: Partial<AuthData>) {\n if (authData.token !== undefined) {\n this.token = authData.token;\n\n if (authData.token === null) {\n removeItem(this.settings.key);\n\n } else {\n // store key in localStorage\n setItem(this.settings.key, authData.token);\n }\n }\n\n this.#_events.emit(\"change\", authData);\n }\n\n}\n"],"names":["createNanoEvents","getItem","__classPrivateFieldGet","__classPrivateFieldSet","removeItem","setItem"],"mappings":";;;;;;;;;;;;;MAoBa,IAAI,CAAA;AAYb,IAAA,WAAA,CAAY,IAAe,EAAA;AAX3B,QAAA,IAAA,CAAA,QAAQ,GAAiB;AACrB,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,GAAG,EAAE,qBAAqB;SAC7B;AAED,QAAA,kBAAA,CAAA,GAAA,CAAA,IAAA,EAAgB,KAAK,CAAA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//
|
|
6
|
+
// colyseus.js@0.17.0
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var tslib = require('tslib');
|
|
10
|
+
var Errors = require('./errors/Errors.js');
|
|
11
|
+
var Room = require('./Room.js');
|
|
12
|
+
var HTTP = require('./HTTP.js');
|
|
13
|
+
var Auth = require('./Auth.js');
|
|
14
|
+
var Protocol = require('./Protocol.js');
|
|
15
|
+
var Connection = require('./Connection.js');
|
|
16
|
+
var discord = require('./3rd_party/discord.js');
|
|
17
|
+
|
|
18
|
+
var _a;
|
|
19
|
+
class MatchMakeError extends Error {
|
|
20
|
+
constructor(message, code) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "MatchMakeError";
|
|
24
|
+
Object.setPrototypeOf(this, MatchMakeError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// - React Native does not provide `window.location`
|
|
28
|
+
// - Cocos Creator (Native) does not provide `window.location.hostname`
|
|
29
|
+
const DEFAULT_ENDPOINT = (typeof (window) !== "undefined" && typeof ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) !== "undefined")
|
|
30
|
+
? `${window.location.protocol.replace("http", "ws")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`
|
|
31
|
+
: "ws://127.0.0.1:2567";
|
|
32
|
+
class ColyseusSDK {
|
|
33
|
+
constructor(settings = DEFAULT_ENDPOINT, options) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
if (typeof (settings) === "string") {
|
|
36
|
+
//
|
|
37
|
+
// endpoint by url
|
|
38
|
+
//
|
|
39
|
+
const url = (settings.startsWith("/"))
|
|
40
|
+
? new URL(settings, DEFAULT_ENDPOINT)
|
|
41
|
+
: new URL(settings);
|
|
42
|
+
const secure = (url.protocol === "https:" || url.protocol === "wss:");
|
|
43
|
+
const port = Number(url.port || (secure ? 443 : 80));
|
|
44
|
+
this.settings = {
|
|
45
|
+
hostname: url.hostname,
|
|
46
|
+
pathname: url.pathname,
|
|
47
|
+
port,
|
|
48
|
+
secure,
|
|
49
|
+
searchParams: url.searchParams.toString() || undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
//
|
|
54
|
+
// endpoint by settings
|
|
55
|
+
//
|
|
56
|
+
if (settings.port === undefined) {
|
|
57
|
+
settings.port = (settings.secure) ? 443 : 80;
|
|
58
|
+
}
|
|
59
|
+
if (settings.pathname === undefined) {
|
|
60
|
+
settings.pathname = "";
|
|
61
|
+
}
|
|
62
|
+
this.settings = settings;
|
|
63
|
+
}
|
|
64
|
+
// make sure pathname does not end with "/"
|
|
65
|
+
if (this.settings.pathname.endsWith("/")) {
|
|
66
|
+
this.settings.pathname = this.settings.pathname.slice(0, -1);
|
|
67
|
+
}
|
|
68
|
+
// specify room connection protocol if provided
|
|
69
|
+
if (options === null || options === void 0 ? void 0 : options.protocol) {
|
|
70
|
+
this.settings.protocol = options.protocol;
|
|
71
|
+
}
|
|
72
|
+
this.http = new HTTP.HTTP(this, {
|
|
73
|
+
headers: (options === null || options === void 0 ? void 0 : options.headers) || {},
|
|
74
|
+
});
|
|
75
|
+
this.auth = new Auth.Auth(this.http);
|
|
76
|
+
this.urlBuilder = options === null || options === void 0 ? void 0 : options.urlBuilder;
|
|
77
|
+
//
|
|
78
|
+
// Discord Embedded SDK requires a custom URL builder
|
|
79
|
+
//
|
|
80
|
+
if (!this.urlBuilder &&
|
|
81
|
+
typeof (window) !== "undefined" &&
|
|
82
|
+
((_b = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) === null || _b === void 0 ? void 0 : _b.includes("discordsays.com"))) {
|
|
83
|
+
this.urlBuilder = discord.discordURLBuilder;
|
|
84
|
+
console.log("Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Select the endpoint with the lowest latency.
|
|
89
|
+
* @param endpoints Array of endpoints to select from.
|
|
90
|
+
* @param options Client options.
|
|
91
|
+
* @param latencyOptions Latency measurement options (protocol, pingCount).
|
|
92
|
+
* @returns The client with the lowest latency.
|
|
93
|
+
*/
|
|
94
|
+
static selectByLatency(endpoints_1, options_1) {
|
|
95
|
+
return tslib.__awaiter(this, arguments, void 0, function* (endpoints, options, latencyOptions = {}) {
|
|
96
|
+
const clients = endpoints.map(endpoint => new ColyseusSDK(endpoint, options));
|
|
97
|
+
const latencies = (yield Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {
|
|
98
|
+
const settings = clients[index].settings;
|
|
99
|
+
console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);
|
|
100
|
+
return [index, latency];
|
|
101
|
+
}))))
|
|
102
|
+
.filter((result) => result.status === 'fulfilled')
|
|
103
|
+
.map(result => result.value);
|
|
104
|
+
if (latencies.length === 0) {
|
|
105
|
+
throw new Error('All endpoints failed to respond');
|
|
106
|
+
}
|
|
107
|
+
return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Implementation
|
|
111
|
+
joinOrCreate(roomName_1) {
|
|
112
|
+
return tslib.__awaiter(this, arguments, void 0, function* (roomName, options = {}, rootSchema) {
|
|
113
|
+
return yield this.createMatchMakeRequest('joinOrCreate', roomName, options, rootSchema);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// Implementation
|
|
117
|
+
create(roomName_1) {
|
|
118
|
+
return tslib.__awaiter(this, arguments, void 0, function* (roomName, options = {}, rootSchema) {
|
|
119
|
+
return yield this.createMatchMakeRequest('create', roomName, options, rootSchema);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Implementation
|
|
123
|
+
join(roomName_1) {
|
|
124
|
+
return tslib.__awaiter(this, arguments, void 0, function* (roomName, options = {}, rootSchema) {
|
|
125
|
+
return yield this.createMatchMakeRequest('join', roomName, options, rootSchema);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Implementation
|
|
129
|
+
joinById(roomId_1) {
|
|
130
|
+
return tslib.__awaiter(this, arguments, void 0, function* (roomId, options = {}, rootSchema) {
|
|
131
|
+
return yield this.createMatchMakeRequest('joinById', roomId, options, rootSchema);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// Implementation
|
|
135
|
+
reconnect(reconnectionToken, rootSchema) {
|
|
136
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
if (typeof (reconnectionToken) === "string" && typeof (rootSchema) === "string") {
|
|
138
|
+
throw new Error("DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\nYou can get this token from previously connected `room.reconnectionToken`");
|
|
139
|
+
}
|
|
140
|
+
const [roomId, token] = reconnectionToken.split(":");
|
|
141
|
+
if (!roomId || !token) {
|
|
142
|
+
throw new Error("Invalid reconnection token format.\nThe format should be roomId:reconnectionToken");
|
|
143
|
+
}
|
|
144
|
+
return yield this.createMatchMakeRequest('reconnect', roomId, { reconnectionToken: token }, rootSchema);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
consumeSeatReservation(response, rootSchema) {
|
|
148
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const room = this.createRoom(response.name, rootSchema);
|
|
150
|
+
room.roomId = response.roomId;
|
|
151
|
+
room.sessionId = response.sessionId;
|
|
152
|
+
const options = { sessionId: room.sessionId };
|
|
153
|
+
// forward "reconnection token" in case of reconnection.
|
|
154
|
+
if (response.reconnectionToken) {
|
|
155
|
+
options.reconnectionToken = response.reconnectionToken;
|
|
156
|
+
}
|
|
157
|
+
room.connect(this.buildEndpoint(response, options), response, this.http.options.headers);
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
const onError = (code, message) => reject(new Errors.ServerError(code, message));
|
|
160
|
+
room.onError.once(onError);
|
|
161
|
+
room['onJoin'].once(() => {
|
|
162
|
+
room.onError.remove(onError);
|
|
163
|
+
resolve(room);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a new connection with the server, and measure the latency.
|
|
170
|
+
* @param options Latency measurement options (protocol, pingCount).
|
|
171
|
+
*/
|
|
172
|
+
getLatency(options = {}) {
|
|
173
|
+
var _a, _b;
|
|
174
|
+
const protocol = (_a = options.protocol) !== null && _a !== void 0 ? _a : "ws";
|
|
175
|
+
const pingCount = (_b = options.pingCount) !== null && _b !== void 0 ? _b : 1;
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
const conn = new Connection.Connection(protocol);
|
|
178
|
+
const latencies = [];
|
|
179
|
+
let pingStart = 0;
|
|
180
|
+
conn.events.onopen = () => {
|
|
181
|
+
pingStart = Date.now();
|
|
182
|
+
conn.send(new Uint8Array([Protocol.Protocol.PING]));
|
|
183
|
+
};
|
|
184
|
+
conn.events.onmessage = (_) => {
|
|
185
|
+
latencies.push(Date.now() - pingStart);
|
|
186
|
+
if (latencies.length < pingCount) {
|
|
187
|
+
// Send another ping
|
|
188
|
+
pingStart = Date.now();
|
|
189
|
+
conn.send(new Uint8Array([Protocol.Protocol.PING]));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Done, calculate average and close
|
|
193
|
+
conn.close();
|
|
194
|
+
const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;
|
|
195
|
+
resolve(average);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
conn.events.onerror = (event) => {
|
|
199
|
+
reject(new Errors.ServerError(Errors.CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
|
|
200
|
+
};
|
|
201
|
+
conn.connect(this.getHttpEndpoint());
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
createMatchMakeRequest(method_1, roomName_1) {
|
|
205
|
+
return tslib.__awaiter(this, arguments, void 0, function* (method, roomName, options = {}, rootSchema) {
|
|
206
|
+
const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
|
|
207
|
+
headers: {
|
|
208
|
+
'Accept': 'application/json',
|
|
209
|
+
'Content-Type': 'application/json'
|
|
210
|
+
},
|
|
211
|
+
body: options
|
|
212
|
+
});
|
|
213
|
+
// Handle HTTP error responses
|
|
214
|
+
if (!httpResponse.ok) {
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);
|
|
217
|
+
}
|
|
218
|
+
const response = httpResponse.data;
|
|
219
|
+
// forward reconnection token during "reconnect" methods.
|
|
220
|
+
if (method === "reconnect") {
|
|
221
|
+
response.reconnectionToken = options.reconnectionToken;
|
|
222
|
+
}
|
|
223
|
+
return yield this.consumeSeatReservation(response, rootSchema);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
createRoom(roomName, rootSchema) {
|
|
227
|
+
return new Room.Room(roomName, rootSchema);
|
|
228
|
+
}
|
|
229
|
+
buildEndpoint(seatReservation, options = {}) {
|
|
230
|
+
let protocol = this.settings.protocol || "ws";
|
|
231
|
+
let searchParams = this.settings.searchParams || "";
|
|
232
|
+
// forward authentication token
|
|
233
|
+
if (this.http.authToken) {
|
|
234
|
+
options['_authToken'] = this.http.authToken;
|
|
235
|
+
}
|
|
236
|
+
// append provided options
|
|
237
|
+
for (const name in options) {
|
|
238
|
+
if (!options.hasOwnProperty(name)) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;
|
|
242
|
+
}
|
|
243
|
+
if (protocol === "h3") {
|
|
244
|
+
protocol = "http";
|
|
245
|
+
}
|
|
246
|
+
let endpoint = (this.settings.secure)
|
|
247
|
+
? `${protocol}s://`
|
|
248
|
+
: `${protocol}://`;
|
|
249
|
+
if (seatReservation.publicAddress) {
|
|
250
|
+
endpoint += `${seatReservation.publicAddress}`;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;
|
|
254
|
+
}
|
|
255
|
+
const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;
|
|
256
|
+
return (this.urlBuilder)
|
|
257
|
+
? this.urlBuilder(new URL(endpointURL))
|
|
258
|
+
: endpointURL;
|
|
259
|
+
}
|
|
260
|
+
getHttpEndpoint(segments = '') {
|
|
261
|
+
const path = segments.startsWith("/") ? segments : `/${segments}`;
|
|
262
|
+
let endpointURL = `${(this.settings.secure) ? "https" : "http"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;
|
|
263
|
+
if (this.settings.searchParams) {
|
|
264
|
+
endpointURL += `?${this.settings.searchParams}`;
|
|
265
|
+
}
|
|
266
|
+
return (this.urlBuilder)
|
|
267
|
+
? this.urlBuilder(new URL(endpointURL))
|
|
268
|
+
: endpointURL;
|
|
269
|
+
}
|
|
270
|
+
getEndpointPort() {
|
|
271
|
+
return (this.settings.port !== 80 && this.settings.port !== 443)
|
|
272
|
+
? `:${this.settings.port}`
|
|
273
|
+
: "";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
ColyseusSDK.VERSION = "0.17";
|
|
277
|
+
const Client = ColyseusSDK;
|
|
278
|
+
|
|
279
|
+
exports.Client = Client;
|
|
280
|
+
exports.ColyseusSDK = ColyseusSDK;
|
|
281
|
+
exports.MatchMakeError = MatchMakeError;
|
|
282
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","sources":["../../src/Client.ts"],"sourcesContent":["import type { matchMaker, SDKTypes, Room as ServerRoom } from '@colyseus/core';\n\nimport { CloseCode, ServerError } from './errors/Errors.ts';\nimport { Room } from './Room.ts';\nimport { SchemaConstructor } from './serializer/SchemaSerializer.ts';\nimport { HTTP } from './HTTP.ts';\nimport { Auth } from './Auth.ts';\nimport { Protocol } from './Protocol.ts';\nimport { Connection } from './Connection.ts';\nimport { discordURLBuilder } from './3rd_party/discord.ts';\n\nexport type JoinOptions = any;\nexport type ISeatReservation = matchMaker.ISeatReservation;\n\nexport class MatchMakeError extends Error {\n code: number;\n constructor(message: string, code: number) {\n super(message);\n this.code = code;\n this.name = \"MatchMakeError\";\n Object.setPrototypeOf(this, MatchMakeError.prototype);\n }\n}\n\n// - React Native does not provide `window.location`\n// - Cocos Creator (Native) does not provide `window.location.hostname`\nconst DEFAULT_ENDPOINT = (typeof (window) !== \"undefined\" && typeof (window?.location?.hostname) !== \"undefined\")\n ? `${window.location.protocol.replace(\"http\", \"ws\")}//${window.location.hostname}${(window.location.port && `:${window.location.port}`)}`\n : \"ws://127.0.0.1:2567\";\n\nexport interface EndpointSettings {\n hostname: string,\n secure: boolean,\n port?: number,\n pathname?: string,\n searchParams?: string,\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface ClientOptions {\n headers?: { [id: string]: string };\n urlBuilder?: (url: URL) => string;\n protocol?: \"ws\" | \"h3\";\n}\n\nexport interface LatencyOptions {\n /** \"ws\" for WebSocket, \"h3\" for WebTransport (default: \"ws\") */\n protocol?: \"ws\" | \"h3\";\n /** Number of pings to send (default: 1). Returns the average latency when > 1. */\n pingCount?: number;\n}\n\nexport class ColyseusSDK<ServerType extends SDKTypes = any> {\n static VERSION = \"0.17\";\n\n /**\n * The HTTP client to make requests to the server.\n */\n public http: HTTP<ServerType['~routes']>;\n\n /**\n * The authentication module to authenticate into requests and rooms.\n */\n public auth: Auth;\n\n /**\n * The settings used to connect to the server.\n */\n public settings: EndpointSettings;\n\n protected urlBuilder: (url: URL) => string;\n\n constructor(\n settings: string | EndpointSettings = DEFAULT_ENDPOINT,\n options?: ClientOptions,\n ) {\n if (typeof (settings) === \"string\") {\n\n //\n // endpoint by url\n //\n const url = (settings.startsWith(\"/\"))\n ? new URL(settings, DEFAULT_ENDPOINT)\n : new URL(settings);\n\n const secure = (url.protocol === \"https:\" || url.protocol === \"wss:\");\n const port = Number(url.port || (secure ? 443 : 80));\n\n this.settings = {\n hostname: url.hostname,\n pathname: url.pathname,\n port,\n secure,\n searchParams: url.searchParams.toString() || undefined,\n };\n\n } else {\n //\n // endpoint by settings\n //\n if (settings.port === undefined) {\n settings.port = (settings.secure) ? 443 : 80;\n }\n if (settings.pathname === undefined) {\n settings.pathname = \"\";\n }\n this.settings = settings;\n }\n\n // make sure pathname does not end with \"/\"\n if (this.settings.pathname.endsWith(\"/\")) {\n this.settings.pathname = this.settings.pathname.slice(0, -1);\n }\n\n // specify room connection protocol if provided\n if (options?.protocol) {\n this.settings.protocol = options.protocol;\n }\n\n this.http = new HTTP(this, {\n headers: options?.headers || {},\n });\n this.auth = new Auth(this.http);\n\n this.urlBuilder = options?.urlBuilder;\n\n //\n // Discord Embedded SDK requires a custom URL builder\n //\n if (\n !this.urlBuilder &&\n typeof (window) !== \"undefined\" &&\n window?.location?.hostname?.includes(\"discordsays.com\")\n ) {\n this.urlBuilder = discordURLBuilder;\n console.log(\"Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder.\");\n }\n }\n\n /**\n * Select the endpoint with the lowest latency.\n * @param endpoints Array of endpoints to select from.\n * @param options Client options.\n * @param latencyOptions Latency measurement options (protocol, pingCount).\n * @returns The client with the lowest latency.\n */\n static async selectByLatency<ServerType extends SDKTypes = any>(\n endpoints: Array<string | EndpointSettings>,\n options?: ClientOptions,\n latencyOptions: LatencyOptions = {}\n ) {\n const clients = endpoints.map(endpoint => new ColyseusSDK<ServerType>(endpoint, options));\n\n const latencies = (await Promise.allSettled(clients.map((client, index) => client.getLatency(latencyOptions).then(latency => {\n const settings = clients[index].settings;\n console.log(`🛜 Endpoint Latency: ${latency}ms - ${settings.hostname}:${settings.port}${settings.pathname}`);\n return [index, latency]\n }))))\n .filter((result) => result.status === 'fulfilled')\n .map(result => result.value);\n\n if (latencies.length === 0) {\n throw new Error('All endpoints failed to respond');\n }\n\n return clients[latencies.sort((a, b) => a[1] - b[1])[0][0]];\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinOrCreate<R extends keyof ServerType['~rooms']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinOrCreate<RoomType extends typeof ServerRoom>(\n roomName: string,\n options?: Parameters<RoomType['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<RoomType['prototype']['state']>\n ): Promise<Room<RoomType>>\n // Overload: Pass State type directly\n public async joinOrCreate<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinOrCreate<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinOrCreate', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async create<R extends keyof ServerType['~rooms']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async create<RoomType extends typeof ServerRoom>(\n roomName: string,\n options?: Parameters<RoomType['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<RoomType['prototype']['state']>\n ): Promise<Room<RoomType>>\n // Overload: Pass State type directly\n public async create<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async create<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('create', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async join<R extends keyof ServerType['~rooms']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async join<RoomType extends typeof ServerRoom>(\n roomName: string,\n options?: Parameters<RoomType['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<RoomType['prototype']['state']>\n ): Promise<Room<RoomType>>\n // Overload: Pass State type directly\n public async join<State = any>(\n roomName: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async join<T = any>(roomName: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('join', roomName, options, rootSchema);\n }\n\n // Overload: Use room name from ServerType to infer room type\n public async joinById<R extends keyof ServerType['~rooms']>(\n roomName: R,\n options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<ServerType>\n ): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async joinById<RoomType extends typeof ServerRoom>(\n roomId: string,\n options?: Parameters<RoomType['prototype']['onJoin']>[1],\n rootSchema?: SchemaConstructor<RoomType['prototype']['state']>\n ): Promise<Room<RoomType>>\n // Overload: Pass State type directly\n public async joinById<State = any>(\n roomId: string,\n options?: JoinOptions,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async joinById<T = any>(roomId: string, options: JoinOptions = {}, rootSchema?: SchemaConstructor<T>) {\n return await this.createMatchMakeRequest<T>('joinById', roomId, options, rootSchema);\n }\n\n /**\n * Re-establish connection with a room this client was previously connected to.\n *\n * @param reconnectionToken The `room.reconnectionToken` from previously connected room.\n * @param rootSchema (optional) Concrete root schema definition\n * @returns Promise<Room>\n */\n // Overload: Use room name from ServerType to infer room type\n public async reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>\n // Overload: Pass RoomType directly to extract state\n public async reconnect<RoomType extends typeof ServerRoom>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<RoomType['prototype']['state']>\n ): Promise<Room<RoomType>>\n // Overload: Pass State type directly\n public async reconnect<State = any>(\n reconnectionToken: string,\n rootSchema?: SchemaConstructor<State>\n ): Promise<Room<any, State>>\n // Implementation\n public async reconnect<T = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<T>) {\n if (typeof (reconnectionToken) === \"string\" && typeof (rootSchema) === \"string\") {\n throw new Error(\"DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\\nYou can get this token from previously connected `room.reconnectionToken`\");\n }\n const [roomId, token] = reconnectionToken.split(\":\");\n\t\tif (!roomId || !token) {\n\t\t\tthrow new Error(\"Invalid reconnection token format.\\nThe format should be roomId:reconnectionToken\");\n\t\t}\n return await this.createMatchMakeRequest<T>('reconnect', roomId, { reconnectionToken: token }, rootSchema);\n }\n\n public async consumeSeatReservation<T>(\n response: ISeatReservation,\n rootSchema?: SchemaConstructor<T>\n ): Promise<Room<any, T>> {\n const room = this.createRoom<T>(response.name, rootSchema);\n room.roomId = response.roomId;\n room.sessionId = response.sessionId;\n\n const options: any = { sessionId: room.sessionId };\n\n // forward \"reconnection token\" in case of reconnection.\n if (response.reconnectionToken) {\n options.reconnectionToken = response.reconnectionToken;\n }\n\n room.connect(\n this.buildEndpoint(response, options),\n response,\n this.http.options.headers\n );\n\n return new Promise((resolve, reject) => {\n const onError = (code, message) => reject(new ServerError(code, message));\n room.onError.once(onError);\n\n room['onJoin'].once(() => {\n room.onError.remove(onError);\n resolve(room);\n });\n });\n }\n\n /**\n * Create a new connection with the server, and measure the latency.\n * @param options Latency measurement options (protocol, pingCount).\n */\n public getLatency(options: LatencyOptions = {}): Promise<number> {\n const protocol = options.protocol ?? \"ws\";\n const pingCount = options.pingCount ?? 1;\n\n return new Promise<number>((resolve, reject) => {\n const conn = new Connection(protocol);\n const latencies: number[] = [];\n let pingStart = 0;\n\n conn.events.onopen = () => {\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n };\n\n conn.events.onmessage = (_: MessageEvent) => {\n latencies.push(Date.now() - pingStart);\n\n if (latencies.length < pingCount) {\n // Send another ping\n pingStart = Date.now();\n conn.send(new Uint8Array([Protocol.PING]));\n } else {\n // Done, calculate average and close\n conn.close();\n const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;\n resolve(average);\n }\n };\n\n conn.events.onerror = (event: ErrorEvent) => {\n reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));\n };\n\n conn.connect(this.getHttpEndpoint());\n });\n }\n\n protected async createMatchMakeRequest<T>(\n method: string,\n roomName: string,\n options: JoinOptions = {},\n rootSchema?: SchemaConstructor<T>,\n ) {\n const httpResponse = await (this.http as HTTP<any>).post(`/matchmake/${method}/${roomName}`, {\n headers: {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: options\n });\n\n // Handle HTTP error responses\n if (!httpResponse.ok) {\n // @ts-ignore\n throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);\n }\n\n const response = httpResponse.data as unknown as ISeatReservation;\n\n // forward reconnection token during \"reconnect\" methods.\n if (method === \"reconnect\") {\n response.reconnectionToken = options.reconnectionToken;\n }\n\n return await this.consumeSeatReservation<T>(response, rootSchema);\n }\n\n protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {\n return new Room<any, T>(roomName, rootSchema);\n }\n\n protected buildEndpoint(seatReservation: ISeatReservation, options: any = {}) {\n let protocol: string = this.settings.protocol || \"ws\";\n let searchParams = this.settings.searchParams || \"\";\n\n // forward authentication token\n if (this.http.authToken) {\n options['_authToken'] = this.http.authToken;\n }\n\n // append provided options\n for (const name in options) {\n if (!options.hasOwnProperty(name)) {\n continue;\n }\n searchParams += (searchParams ? '&' : '') + `${name}=${options[name]}`;\n }\n\n if (protocol === \"h3\") {\n protocol = \"http\";\n }\n\n let endpoint = (this.settings.secure)\n ? `${protocol}s://`\n : `${protocol}://`;\n\n if (seatReservation.publicAddress) {\n endpoint += `${seatReservation.publicAddress}`;\n\n } else {\n endpoint += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;\n }\n\n const endpointURL = `${endpoint}/${seatReservation.processId}/${seatReservation.roomId}?${searchParams}`;\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getHttpEndpoint(segments: string = '') {\n const path = segments.startsWith(\"/\") ? segments : `/${segments}`;\n\n let endpointURL = `${(this.settings.secure) ? \"https\" : \"http\"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${path}`;\n\n if (this.settings.searchParams) {\n endpointURL += `?${this.settings.searchParams}`;\n }\n\n return (this.urlBuilder)\n ? this.urlBuilder(new URL(endpointURL))\n : endpointURL;\n }\n\n protected getEndpointPort() {\n return (this.settings.port !== 80 && this.settings.port !== 443)\n ? `:${this.settings.port}`\n : \"\";\n }\n}\n\nexport const Client = ColyseusSDK;\nexport type Client = InstanceType<typeof ColyseusSDK>;"],"names":["HTTP","Auth","discordURLBuilder","__awaiter","ServerError","Connection","Protocol","CloseCode","Room"],"mappings":";;;;;;;;;;;;;;;;;;AAcM,MAAO,cAAe,SAAQ,KAAK,CAAA;IAErC,WAAA,CAAY,OAAe,EAAE,IAAY,EAAA;QACrC,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,IAAI,GAAG,gBAAgB;QAC5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC;IACzD;AACH;AAED;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,QAAQ,MAAM,CAAC,KAAK,WAAW,IAAK,QAAQ,MAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,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