@rpgjs/client 5.0.0-alpha.43 → 5.0.0-alpha.44
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/dist/Game/AnimationManager.js +25 -24
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/Event.js +11 -10
- package/dist/Game/Event.js.map +1 -1
- package/dist/Game/Map.js +78 -94
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.js +182 -216
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Player.js +11 -10
- package/dist/Game/Player.js.map +1 -1
- package/dist/Gui/Gui.js +440 -473
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/Gui/NotificationManager.js +48 -50
- package/dist/Gui/NotificationManager.js.map +1 -1
- package/dist/Resource.js +132 -113
- package/dist/Resource.js.map +1 -1
- package/dist/RpgClientEngine.js +1333 -1486
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js +162 -92
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +22 -19
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/hit.ce.js +67 -68
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.js +9 -8
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +390 -314
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/dynamics/parse-value.js +42 -52
- package/dist/components/dynamics/parse-value.js.map +1 -1
- package/dist/components/dynamics/text.ce.js +71 -139
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js +26 -25
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +202 -149
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +190 -138
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +90 -33
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +478 -346
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +52 -33
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +341 -226
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +414 -205
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +46 -26
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +104 -50
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.js +18 -21
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/mobile.ce.js +76 -15
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +62 -36
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +386 -239
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +649 -319
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +187 -145
- package/dist/components/gui/title-screen.ce.js.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/prebuilt/hp-bar.ce.js +114 -104
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +92 -74
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +58 -42
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +87 -64
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js +26 -16
- package/dist/components/scenes/event-layer.ce.js.map +1 -1
- package/dist/core/inject.js +11 -10
- package/dist/core/inject.js.map +1 -1
- package/dist/core/setup.js +13 -13
- package/dist/core/setup.js.map +1 -1
- package/dist/index.js +44 -41
- package/dist/module.js +169 -168
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js +209 -298
- package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +430 -507
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js +2062 -2571
- package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +8 -3
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js +78 -101
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js +264 -401
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +9 -7
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +106 -165
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +361 -461
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3633 -4280
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
- package/dist/presets/animation.js +37 -25
- package/dist/presets/animation.js.map +1 -1
- package/dist/presets/faceset.js +49 -22
- package/dist/presets/faceset.js.map +1 -1
- package/dist/presets/icon.js +13 -13
- package/dist/presets/icon.js.map +1 -1
- package/dist/presets/index.js +15 -14
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/lpc.js +96 -93
- package/dist/presets/lpc.js.map +1 -1
- package/dist/presets/rmspritesheet.js +40 -39
- package/dist/presets/rmspritesheet.js.map +1 -1
- package/dist/services/AbstractSocket.js +10 -8
- package/dist/services/AbstractSocket.js.map +1 -1
- package/dist/services/keyboardControls.js +20 -18
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/loadMap.js +120 -36
- package/dist/services/loadMap.js.map +1 -1
- package/dist/services/mmorpg.js +128 -136
- package/dist/services/mmorpg.js.map +1 -1
- package/dist/services/save.js +74 -66
- package/dist/services/save.js.map +1 -1
- package/dist/services/standalone.js +165 -167
- package/dist/services/standalone.js.map +1 -1
- package/dist/utils/getEntityProp.js +49 -51
- package/dist/utils/getEntityProp.js.map +1 -1
- package/package.json +8 -8
- package/src/components/character.ce +1 -1
- package/src/components/scenes/draw-map.ce +3 -1
- package/dist/index.js.map +0 -1
package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
if (!globalThis.EventTarget || !globalThis.Event)
|
|
3
|
-
console.error(`
|
|
1
|
+
//#region ../../node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.mjs
|
|
2
|
+
if (!globalThis.EventTarget || !globalThis.Event) console.error(`
|
|
4
3
|
PartySocket requires a global 'EventTarget' class to be available!
|
|
5
4
|
You can polyfill this global by adding this to your code before any partysocket imports:
|
|
6
5
|
|
|
@@ -9,365 +8,284 @@ if (!globalThis.EventTarget || !globalThis.Event) {
|
|
|
9
8
|
\`\`\`
|
|
10
9
|
Please file an issue at https://github.com/partykit/partykit if you're still having trouble.
|
|
11
10
|
`);
|
|
12
|
-
}
|
|
13
11
|
var ErrorEvent = class extends Event {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
12
|
+
message;
|
|
13
|
+
error;
|
|
14
|
+
constructor(error, target) {
|
|
15
|
+
super("error", target);
|
|
16
|
+
this.message = error.message;
|
|
17
|
+
this.error = error;
|
|
18
|
+
}
|
|
22
19
|
};
|
|
23
20
|
var CloseEvent = class extends Event {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.reason = reason;
|
|
33
|
-
}
|
|
21
|
+
code;
|
|
22
|
+
reason;
|
|
23
|
+
wasClean = true;
|
|
24
|
+
constructor(code = 1e3, reason = "", target) {
|
|
25
|
+
super("close", target);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.reason = reason;
|
|
28
|
+
}
|
|
34
29
|
};
|
|
35
30
|
var Events = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
Event,
|
|
32
|
+
ErrorEvent,
|
|
33
|
+
CloseEvent
|
|
39
34
|
};
|
|
40
35
|
function assert(condition, msg) {
|
|
41
|
-
|
|
42
|
-
throw new Error(msg);
|
|
43
|
-
}
|
|
36
|
+
if (!condition) throw new Error(msg);
|
|
44
37
|
}
|
|
45
38
|
function cloneEventBrowser(e) {
|
|
46
|
-
|
|
39
|
+
return new e.constructor(e.type, e);
|
|
47
40
|
}
|
|
48
41
|
function cloneEventNode(e) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if ("code" in e || "reason" in e) {
|
|
54
|
-
const evt2 = new CloseEvent(
|
|
55
|
-
// @ts-expect-error we need to fix event/listener types
|
|
56
|
-
e.code || 1999,
|
|
57
|
-
// @ts-expect-error we need to fix event/listener types
|
|
58
|
-
e.reason || "unknown reason",
|
|
59
|
-
e
|
|
60
|
-
);
|
|
61
|
-
return evt2;
|
|
62
|
-
}
|
|
63
|
-
if ("error" in e) {
|
|
64
|
-
const evt2 = new ErrorEvent(e.error, e);
|
|
65
|
-
return evt2;
|
|
66
|
-
}
|
|
67
|
-
const evt = new Event(e.type, e);
|
|
68
|
-
return evt;
|
|
42
|
+
if ("data" in e) return new MessageEvent(e.type, e);
|
|
43
|
+
if ("code" in e || "reason" in e) return new CloseEvent(e.code || 1999, e.reason || "unknown reason", e);
|
|
44
|
+
if ("error" in e) return new ErrorEvent(e.error, e);
|
|
45
|
+
return new Event(e.type, e);
|
|
69
46
|
}
|
|
70
47
|
var _a;
|
|
71
|
-
var
|
|
72
|
-
typeof process !== "undefined" &&
|
|
73
|
-
typeof ((_a = process.versions) == null ? void 0 : _a.node) !== "undefined" &&
|
|
74
|
-
typeof document === "undefined";
|
|
75
|
-
var cloneEvent = isNode ? cloneEventNode : cloneEventBrowser;
|
|
48
|
+
var cloneEvent = typeof process !== "undefined" && typeof ((_a = process.versions) == null ? void 0 : _a.node) !== "undefined" && typeof document === "undefined" ? cloneEventNode : cloneEventBrowser;
|
|
76
49
|
var DEFAULT = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
50
|
+
maxReconnectionDelay: 1e4,
|
|
51
|
+
minReconnectionDelay: 1e3 + Math.random() * 4e3,
|
|
52
|
+
minUptime: 5e3,
|
|
53
|
+
reconnectionDelayGrowFactor: 1.3,
|
|
54
|
+
connectionTimeout: 4e3,
|
|
55
|
+
maxRetries: Number.POSITIVE_INFINITY,
|
|
56
|
+
maxEnqueuedMessages: Number.POSITIVE_INFINITY,
|
|
57
|
+
startClosed: false,
|
|
58
|
+
debug: false
|
|
59
|
+
};
|
|
84
60
|
var didWarnAboutMissingWebSocket = false;
|
|
85
61
|
var ReconnectingWebSocket = class _ReconnectingWebSocket extends EventTarget {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (typeof protocols === "string" || Array.isArray(protocols)) {
|
|
314
|
-
return Promise.resolve(protocols);
|
|
315
|
-
}
|
|
316
|
-
if (protocols.then) {
|
|
317
|
-
return protocols;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
throw Error("Invalid protocols");
|
|
321
|
-
}
|
|
322
|
-
_getNextUrl(urlProvider) {
|
|
323
|
-
if (typeof urlProvider === "string") {
|
|
324
|
-
return Promise.resolve(urlProvider);
|
|
325
|
-
}
|
|
326
|
-
if (typeof urlProvider === "function") {
|
|
327
|
-
const url = urlProvider();
|
|
328
|
-
if (typeof url === "string") {
|
|
329
|
-
return Promise.resolve(url);
|
|
330
|
-
}
|
|
331
|
-
if (url.then) {
|
|
332
|
-
return url;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
throw Error("Invalid URL");
|
|
336
|
-
}
|
|
337
|
-
_connect() {
|
|
338
|
-
if (this._connectLock || !this._shouldReconnect) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
this._connectLock = true;
|
|
342
|
-
const {
|
|
343
|
-
maxRetries = DEFAULT.maxRetries,
|
|
344
|
-
connectionTimeout = DEFAULT.connectionTimeout
|
|
345
|
-
} = this._options;
|
|
346
|
-
if (this._retryCount >= maxRetries) {
|
|
347
|
-
this._debug("max retries reached", this._retryCount, ">=", maxRetries);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
this._retryCount++;
|
|
351
|
-
this._debug("connect", this._retryCount);
|
|
352
|
-
this._removeListeners();
|
|
353
|
-
this._wait()
|
|
354
|
-
.then(() =>
|
|
355
|
-
Promise.all([
|
|
356
|
-
this._getNextUrl(this._url),
|
|
357
|
-
this._getNextProtocols(this._protocols || null)
|
|
358
|
-
])
|
|
359
|
-
)
|
|
360
|
-
.then(([url, protocols]) => {
|
|
361
|
-
if (this._closeCalled) {
|
|
362
|
-
this._connectLock = false;
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
if (
|
|
366
|
-
!this._options.WebSocket &&
|
|
367
|
-
typeof WebSocket === "undefined" &&
|
|
368
|
-
!didWarnAboutMissingWebSocket
|
|
369
|
-
) {
|
|
370
|
-
console.error(`\u203C\uFE0F No WebSocket implementation available. You should define options.WebSocket.
|
|
62
|
+
_ws;
|
|
63
|
+
_retryCount = -1;
|
|
64
|
+
_uptimeTimeout;
|
|
65
|
+
_connectTimeout;
|
|
66
|
+
_shouldReconnect = true;
|
|
67
|
+
_connectLock = false;
|
|
68
|
+
_binaryType = "blob";
|
|
69
|
+
_closeCalled = false;
|
|
70
|
+
_messageQueue = [];
|
|
71
|
+
_debugLogger = console.log.bind(console);
|
|
72
|
+
_url;
|
|
73
|
+
_protocols;
|
|
74
|
+
_options;
|
|
75
|
+
constructor(url, protocols, options = {}) {
|
|
76
|
+
super();
|
|
77
|
+
this._url = url;
|
|
78
|
+
this._protocols = protocols;
|
|
79
|
+
this._options = options;
|
|
80
|
+
if (this._options.startClosed) this._shouldReconnect = false;
|
|
81
|
+
if (this._options.debugLogger) this._debugLogger = this._options.debugLogger;
|
|
82
|
+
this._connect();
|
|
83
|
+
}
|
|
84
|
+
static get CONNECTING() {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
static get OPEN() {
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
static get CLOSING() {
|
|
91
|
+
return 2;
|
|
92
|
+
}
|
|
93
|
+
static get CLOSED() {
|
|
94
|
+
return 3;
|
|
95
|
+
}
|
|
96
|
+
get CONNECTING() {
|
|
97
|
+
return _ReconnectingWebSocket.CONNECTING;
|
|
98
|
+
}
|
|
99
|
+
get OPEN() {
|
|
100
|
+
return _ReconnectingWebSocket.OPEN;
|
|
101
|
+
}
|
|
102
|
+
get CLOSING() {
|
|
103
|
+
return _ReconnectingWebSocket.CLOSING;
|
|
104
|
+
}
|
|
105
|
+
get CLOSED() {
|
|
106
|
+
return _ReconnectingWebSocket.CLOSED;
|
|
107
|
+
}
|
|
108
|
+
get binaryType() {
|
|
109
|
+
return this._ws ? this._ws.binaryType : this._binaryType;
|
|
110
|
+
}
|
|
111
|
+
set binaryType(value) {
|
|
112
|
+
this._binaryType = value;
|
|
113
|
+
if (this._ws) this._ws.binaryType = value;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns the number or connection retries
|
|
117
|
+
*/
|
|
118
|
+
get retryCount() {
|
|
119
|
+
return Math.max(this._retryCount, 0);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The number of bytes of data that have been queued using calls to send() but not yet
|
|
123
|
+
* transmitted to the network. This value resets to zero once all queued data has been sent.
|
|
124
|
+
* This value does not reset to zero when the connection is closed; if you keep calling send(),
|
|
125
|
+
* this will continue to climb. Read only
|
|
126
|
+
*/
|
|
127
|
+
get bufferedAmount() {
|
|
128
|
+
return this._messageQueue.reduce((acc, message) => {
|
|
129
|
+
if (typeof message === "string") acc += message.length;
|
|
130
|
+
else if (message instanceof Blob) acc += message.size;
|
|
131
|
+
else acc += message.byteLength;
|
|
132
|
+
return acc;
|
|
133
|
+
}, 0) + (this._ws ? this._ws.bufferedAmount : 0);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The extensions selected by the server. This is currently only the empty string or a list of
|
|
137
|
+
* extensions as negotiated by the connection
|
|
138
|
+
*/
|
|
139
|
+
get extensions() {
|
|
140
|
+
return this._ws ? this._ws.extensions : "";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A string indicating the name of the sub-protocol the server selected;
|
|
144
|
+
* this will be one of the strings specified in the protocols parameter when creating the
|
|
145
|
+
* WebSocket object
|
|
146
|
+
*/
|
|
147
|
+
get protocol() {
|
|
148
|
+
return this._ws ? this._ws.protocol : "";
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The current state of the connection; this is one of the Ready state constants
|
|
152
|
+
*/
|
|
153
|
+
get readyState() {
|
|
154
|
+
if (this._ws) return this._ws.readyState;
|
|
155
|
+
return this._options.startClosed ? _ReconnectingWebSocket.CLOSED : _ReconnectingWebSocket.CONNECTING;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The URL as resolved by the constructor
|
|
159
|
+
*/
|
|
160
|
+
get url() {
|
|
161
|
+
return this._ws ? this._ws.url : "";
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Whether the websocket object is now in reconnectable state
|
|
165
|
+
*/
|
|
166
|
+
get shouldReconnect() {
|
|
167
|
+
return this._shouldReconnect;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* An event listener to be called when the WebSocket connection's readyState changes to CLOSED
|
|
171
|
+
*/
|
|
172
|
+
onclose = null;
|
|
173
|
+
/**
|
|
174
|
+
* An event listener to be called when an error occurs
|
|
175
|
+
*/
|
|
176
|
+
onerror = null;
|
|
177
|
+
/**
|
|
178
|
+
* An event listener to be called when a message is received from the server
|
|
179
|
+
*/
|
|
180
|
+
onmessage = null;
|
|
181
|
+
/**
|
|
182
|
+
* An event listener to be called when the WebSocket connection's readyState changes to OPEN;
|
|
183
|
+
* this indicates that the connection is ready to send and receive data
|
|
184
|
+
*/
|
|
185
|
+
onopen = null;
|
|
186
|
+
/**
|
|
187
|
+
* Closes the WebSocket connection or connection attempt, if any. If the connection is already
|
|
188
|
+
* CLOSED, this method does nothing
|
|
189
|
+
*/
|
|
190
|
+
close(code = 1e3, reason) {
|
|
191
|
+
this._closeCalled = true;
|
|
192
|
+
this._shouldReconnect = false;
|
|
193
|
+
this._clearTimeouts();
|
|
194
|
+
if (!this._ws) {
|
|
195
|
+
this._debug("close enqueued: no ws instance");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (this._ws.readyState === this.CLOSED) {
|
|
199
|
+
this._debug("close: already closed");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this._ws.close(code, reason);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Closes the WebSocket connection or connection attempt and connects again.
|
|
206
|
+
* Resets retry counter;
|
|
207
|
+
*/
|
|
208
|
+
reconnect(code, reason) {
|
|
209
|
+
this._shouldReconnect = true;
|
|
210
|
+
this._closeCalled = false;
|
|
211
|
+
this._retryCount = -1;
|
|
212
|
+
if (!this._ws || this._ws.readyState === this.CLOSED) this._connect();
|
|
213
|
+
else {
|
|
214
|
+
this._disconnect(code, reason);
|
|
215
|
+
this._connect();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Enqueue specified data to be transmitted to the server over the WebSocket connection
|
|
220
|
+
*/
|
|
221
|
+
send(data) {
|
|
222
|
+
if (this._ws && this._ws.readyState === this.OPEN) {
|
|
223
|
+
this._debug("send", data);
|
|
224
|
+
this._ws.send(data);
|
|
225
|
+
} else {
|
|
226
|
+
const { maxEnqueuedMessages = DEFAULT.maxEnqueuedMessages } = this._options;
|
|
227
|
+
if (this._messageQueue.length < maxEnqueuedMessages) {
|
|
228
|
+
this._debug("enqueue", data);
|
|
229
|
+
this._messageQueue.push(data);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_debug(...args) {
|
|
234
|
+
if (this._options.debug) this._debugLogger("RWS>", ...args);
|
|
235
|
+
}
|
|
236
|
+
_getNextDelay() {
|
|
237
|
+
const { reconnectionDelayGrowFactor = DEFAULT.reconnectionDelayGrowFactor, minReconnectionDelay = DEFAULT.minReconnectionDelay, maxReconnectionDelay = DEFAULT.maxReconnectionDelay } = this._options;
|
|
238
|
+
let delay = 0;
|
|
239
|
+
if (this._retryCount > 0) {
|
|
240
|
+
delay = minReconnectionDelay * reconnectionDelayGrowFactor ** (this._retryCount - 1);
|
|
241
|
+
if (delay > maxReconnectionDelay) delay = maxReconnectionDelay;
|
|
242
|
+
}
|
|
243
|
+
this._debug("next delay", delay);
|
|
244
|
+
return delay;
|
|
245
|
+
}
|
|
246
|
+
_wait() {
|
|
247
|
+
return new Promise((resolve) => {
|
|
248
|
+
setTimeout(resolve, this._getNextDelay());
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
_getNextProtocols(protocolsProvider) {
|
|
252
|
+
if (!protocolsProvider) return Promise.resolve(null);
|
|
253
|
+
if (typeof protocolsProvider === "string" || Array.isArray(protocolsProvider)) return Promise.resolve(protocolsProvider);
|
|
254
|
+
if (typeof protocolsProvider === "function") {
|
|
255
|
+
const protocols = protocolsProvider();
|
|
256
|
+
if (!protocols) return Promise.resolve(null);
|
|
257
|
+
if (typeof protocols === "string" || Array.isArray(protocols)) return Promise.resolve(protocols);
|
|
258
|
+
if (protocols.then) return protocols;
|
|
259
|
+
}
|
|
260
|
+
throw Error("Invalid protocols");
|
|
261
|
+
}
|
|
262
|
+
_getNextUrl(urlProvider) {
|
|
263
|
+
if (typeof urlProvider === "string") return Promise.resolve(urlProvider);
|
|
264
|
+
if (typeof urlProvider === "function") {
|
|
265
|
+
const url = urlProvider();
|
|
266
|
+
if (typeof url === "string") return Promise.resolve(url);
|
|
267
|
+
if (url.then) return url;
|
|
268
|
+
}
|
|
269
|
+
throw Error("Invalid URL");
|
|
270
|
+
}
|
|
271
|
+
_connect() {
|
|
272
|
+
if (this._connectLock || !this._shouldReconnect) return;
|
|
273
|
+
this._connectLock = true;
|
|
274
|
+
const { maxRetries = DEFAULT.maxRetries, connectionTimeout = DEFAULT.connectionTimeout } = this._options;
|
|
275
|
+
if (this._retryCount >= maxRetries) {
|
|
276
|
+
this._debug("max retries reached", this._retryCount, ">=", maxRetries);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
this._retryCount++;
|
|
280
|
+
this._debug("connect", this._retryCount);
|
|
281
|
+
this._removeListeners();
|
|
282
|
+
this._wait().then(() => Promise.all([this._getNextUrl(this._url), this._getNextProtocols(this._protocols || null)])).then(([url, protocols]) => {
|
|
283
|
+
if (this._closeCalled) {
|
|
284
|
+
this._connectLock = false;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (!this._options.WebSocket && typeof WebSocket === "undefined" && !didWarnAboutMissingWebSocket) {
|
|
288
|
+
console.error(`\u203C\uFE0F No WebSocket implementation available. You should define options.WebSocket.
|
|
371
289
|
|
|
372
290
|
For example, if you're using node.js, run \`npm install ws\`, and then in your code:
|
|
373
291
|
|
|
@@ -381,121 +299,103 @@ const partysocket = new PartySocket({
|
|
|
381
299
|
});
|
|
382
300
|
|
|
383
301
|
`);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
this._ws.removeEventListener("open", this._handleOpen);
|
|
474
|
-
this._ws.removeEventListener("close", this._handleClose);
|
|
475
|
-
this._ws.removeEventListener("message", this._handleMessage);
|
|
476
|
-
this._ws.removeEventListener("error", this._handleError);
|
|
477
|
-
}
|
|
478
|
-
_addListeners() {
|
|
479
|
-
if (!this._ws) {
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
this._debug("addListeners");
|
|
483
|
-
this._ws.addEventListener("open", this._handleOpen);
|
|
484
|
-
this._ws.addEventListener("close", this._handleClose);
|
|
485
|
-
this._ws.addEventListener("message", this._handleMessage);
|
|
486
|
-
this._ws.addEventListener("error", this._handleError);
|
|
487
|
-
}
|
|
488
|
-
_clearTimeouts() {
|
|
489
|
-
clearTimeout(this._connectTimeout);
|
|
490
|
-
clearTimeout(this._uptimeTimeout);
|
|
491
|
-
}
|
|
302
|
+
didWarnAboutMissingWebSocket = true;
|
|
303
|
+
}
|
|
304
|
+
const WS = this._options.WebSocket || WebSocket;
|
|
305
|
+
this._debug("connect", {
|
|
306
|
+
url,
|
|
307
|
+
protocols
|
|
308
|
+
});
|
|
309
|
+
this._ws = protocols ? new WS(url, protocols) : new WS(url);
|
|
310
|
+
this._ws.binaryType = this._binaryType;
|
|
311
|
+
this._connectLock = false;
|
|
312
|
+
this._addListeners();
|
|
313
|
+
this._connectTimeout = setTimeout(() => this._handleTimeout(), connectionTimeout);
|
|
314
|
+
}).catch((err) => {
|
|
315
|
+
this._connectLock = false;
|
|
316
|
+
this._handleError(new Events.ErrorEvent(Error(err.message), this));
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
_handleTimeout() {
|
|
320
|
+
this._debug("timeout event");
|
|
321
|
+
this._handleError(new Events.ErrorEvent(Error("TIMEOUT"), this));
|
|
322
|
+
}
|
|
323
|
+
_disconnect(code = 1e3, reason) {
|
|
324
|
+
this._clearTimeouts();
|
|
325
|
+
if (!this._ws) return;
|
|
326
|
+
this._removeListeners();
|
|
327
|
+
try {
|
|
328
|
+
if (this._ws.readyState === this.OPEN) this._ws.close(code, reason);
|
|
329
|
+
this._handleClose(new Events.CloseEvent(code, reason, this));
|
|
330
|
+
} catch (error) {}
|
|
331
|
+
}
|
|
332
|
+
_acceptOpen() {
|
|
333
|
+
this._debug("accept open");
|
|
334
|
+
this._retryCount = 0;
|
|
335
|
+
}
|
|
336
|
+
_handleOpen = (event) => {
|
|
337
|
+
this._debug("open event");
|
|
338
|
+
const { minUptime = DEFAULT.minUptime } = this._options;
|
|
339
|
+
clearTimeout(this._connectTimeout);
|
|
340
|
+
this._uptimeTimeout = setTimeout(() => this._acceptOpen(), minUptime);
|
|
341
|
+
assert(this._ws, "WebSocket is not defined");
|
|
342
|
+
this._ws.binaryType = this._binaryType;
|
|
343
|
+
this._messageQueue.forEach((message) => {
|
|
344
|
+
var _a2;
|
|
345
|
+
return (_a2 = this._ws) == null ? void 0 : _a2.send(message);
|
|
346
|
+
});
|
|
347
|
+
this._messageQueue = [];
|
|
348
|
+
if (this.onopen) this.onopen(event);
|
|
349
|
+
this.dispatchEvent(cloneEvent(event));
|
|
350
|
+
};
|
|
351
|
+
_handleMessage = (event) => {
|
|
352
|
+
this._debug("message event");
|
|
353
|
+
if (this.onmessage) this.onmessage(event);
|
|
354
|
+
this.dispatchEvent(cloneEvent(event));
|
|
355
|
+
};
|
|
356
|
+
_handleError = (event) => {
|
|
357
|
+
this._debug("error event", event.message);
|
|
358
|
+
this._disconnect(void 0, event.message === "TIMEOUT" ? "timeout" : void 0);
|
|
359
|
+
if (this.onerror) this.onerror(event);
|
|
360
|
+
this._debug("exec error listeners");
|
|
361
|
+
this.dispatchEvent(cloneEvent(event));
|
|
362
|
+
this._connect();
|
|
363
|
+
};
|
|
364
|
+
_handleClose = (event) => {
|
|
365
|
+
this._debug("close event");
|
|
366
|
+
this._clearTimeouts();
|
|
367
|
+
if (this._shouldReconnect) this._connect();
|
|
368
|
+
if (this.onclose) this.onclose(event);
|
|
369
|
+
this.dispatchEvent(cloneEvent(event));
|
|
370
|
+
};
|
|
371
|
+
_removeListeners() {
|
|
372
|
+
if (!this._ws) return;
|
|
373
|
+
this._debug("removeListeners");
|
|
374
|
+
this._ws.removeEventListener("open", this._handleOpen);
|
|
375
|
+
this._ws.removeEventListener("close", this._handleClose);
|
|
376
|
+
this._ws.removeEventListener("message", this._handleMessage);
|
|
377
|
+
this._ws.removeEventListener("error", this._handleError);
|
|
378
|
+
}
|
|
379
|
+
_addListeners() {
|
|
380
|
+
if (!this._ws) return;
|
|
381
|
+
this._debug("addListeners");
|
|
382
|
+
this._ws.addEventListener("open", this._handleOpen);
|
|
383
|
+
this._ws.addEventListener("close", this._handleClose);
|
|
384
|
+
this._ws.addEventListener("message", this._handleMessage);
|
|
385
|
+
this._ws.addEventListener("error", this._handleError);
|
|
386
|
+
}
|
|
387
|
+
_clearTimeouts() {
|
|
388
|
+
clearTimeout(this._connectTimeout);
|
|
389
|
+
clearTimeout(this._uptimeTimeout);
|
|
390
|
+
}
|
|
492
391
|
};
|
|
493
392
|
/*!
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
393
|
+
* Reconnecting WebSocket
|
|
394
|
+
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|
|
395
|
+
* https://github.com/pladaria/reconnecting-websocket
|
|
396
|
+
* License MIT
|
|
397
|
+
*/
|
|
398
|
+
//#endregion
|
|
399
|
+
export { ReconnectingWebSocket };
|
|
499
400
|
|
|
500
|
-
|
|
501
|
-
//# sourceMappingURL=chunk-S74YV6PU.js.map
|
|
401
|
+
//# sourceMappingURL=chunk-S74YV6PU.js.map
|