@rpgjs/client 5.0.0-alpha.22 → 5.0.0-alpha.24

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.
Files changed (134) hide show
  1. package/dist/Game/Object.d.ts +2 -0
  2. package/dist/RpgClientEngine.d.ts +115 -9
  3. package/dist/components/gui/mobile/index.d.ts +8 -0
  4. package/dist/components/prebuilt/index.d.ts +1 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.js +13 -8
  7. package/dist/index.js.map +1 -1
  8. package/dist/index10.js +1 -1
  9. package/dist/index11.js +6 -5
  10. package/dist/index11.js.map +1 -1
  11. package/dist/index12.js +2 -2
  12. package/dist/index13.js +102 -10
  13. package/dist/index13.js.map +1 -1
  14. package/dist/index14.js +67 -9
  15. package/dist/index14.js.map +1 -1
  16. package/dist/index15.js +10 -263
  17. package/dist/index15.js.map +1 -1
  18. package/dist/index16.js +9 -97
  19. package/dist/index16.js.map +1 -1
  20. package/dist/index17.js +300 -89
  21. package/dist/index17.js.map +1 -1
  22. package/dist/index18.js +63 -80
  23. package/dist/index18.js.map +1 -1
  24. package/dist/index19.js +96 -348
  25. package/dist/index19.js.map +1 -1
  26. package/dist/index2.js +176 -24
  27. package/dist/index2.js.map +1 -1
  28. package/dist/index20.js +360 -17
  29. package/dist/index20.js.map +1 -1
  30. package/dist/index21.js +19 -50
  31. package/dist/index21.js.map +1 -1
  32. package/dist/index22.js +212 -5
  33. package/dist/index22.js.map +1 -1
  34. package/dist/index23.js +6 -395
  35. package/dist/index23.js.map +1 -1
  36. package/dist/index24.js +4 -39
  37. package/dist/index24.js.map +1 -1
  38. package/dist/index25.js +19 -20
  39. package/dist/index25.js.map +1 -1
  40. package/dist/index26.js +43 -2624
  41. package/dist/index26.js.map +1 -1
  42. package/dist/index27.js +5 -110
  43. package/dist/index27.js.map +1 -1
  44. package/dist/index28.js +394 -65
  45. package/dist/index28.js.map +1 -1
  46. package/dist/index29.js +40 -15
  47. package/dist/index29.js.map +1 -1
  48. package/dist/index3.js +3 -3
  49. package/dist/index30.js +21 -23
  50. package/dist/index30.js.map +1 -1
  51. package/dist/index31.js +2624 -86
  52. package/dist/index31.js.map +1 -1
  53. package/dist/index32.js +107 -34
  54. package/dist/index32.js.map +1 -1
  55. package/dist/index33.js +69 -22
  56. package/dist/index33.js.map +1 -1
  57. package/dist/index34.js +19 -3
  58. package/dist/index34.js.map +1 -1
  59. package/dist/index35.js +21 -329
  60. package/dist/index35.js.map +1 -1
  61. package/dist/index36.js +91 -30
  62. package/dist/index36.js.map +1 -1
  63. package/dist/index37.js +37 -7
  64. package/dist/index37.js.map +1 -1
  65. package/dist/index38.js +22 -9
  66. package/dist/index38.js.map +1 -1
  67. package/dist/index39.js +139 -10
  68. package/dist/index39.js.map +1 -1
  69. package/dist/index4.js +3 -3
  70. package/dist/index40.js +16 -6
  71. package/dist/index40.js.map +1 -1
  72. package/dist/index41.js +1 -325
  73. package/dist/index41.js.map +1 -1
  74. package/dist/index42.js +530 -3680
  75. package/dist/index42.js.map +1 -1
  76. package/dist/index43.js +24 -67
  77. package/dist/index43.js.map +1 -1
  78. package/dist/index44.js +9 -184
  79. package/dist/index44.js.map +1 -1
  80. package/dist/index45.js +6 -503
  81. package/dist/index45.js.map +1 -1
  82. package/dist/index46.js +325 -2
  83. package/dist/index46.js.map +1 -1
  84. package/dist/index47.js +3687 -17
  85. package/dist/index47.js.map +1 -1
  86. package/dist/index48.js +69 -202
  87. package/dist/index48.js.map +1 -1
  88. package/dist/index49.js +182 -7
  89. package/dist/index49.js.map +1 -1
  90. package/dist/index5.js +1 -1
  91. package/dist/index50.js +497 -106
  92. package/dist/index50.js.map +1 -1
  93. package/dist/index51.js +48 -130
  94. package/dist/index51.js.map +1 -1
  95. package/dist/index52.js +17 -134
  96. package/dist/index52.js.map +1 -1
  97. package/dist/index53.js +3 -109
  98. package/dist/index53.js.map +1 -1
  99. package/dist/index54.js +9 -138
  100. package/dist/index54.js.map +1 -1
  101. package/dist/index55.js +111 -7
  102. package/dist/index55.js.map +1 -1
  103. package/dist/index56.js +130 -48
  104. package/dist/index56.js.map +1 -1
  105. package/dist/index57.js +137 -0
  106. package/dist/index57.js.map +1 -0
  107. package/dist/index58.js +112 -0
  108. package/dist/index58.js.map +1 -0
  109. package/dist/index59.js +9 -0
  110. package/dist/index59.js.map +1 -0
  111. package/dist/index6.js +1 -1
  112. package/dist/index7.js +1 -1
  113. package/dist/index8.js +17 -2
  114. package/dist/index8.js.map +1 -1
  115. package/dist/index9.js +10 -27
  116. package/dist/index9.js.map +1 -1
  117. package/dist/services/keyboardControls.d.ts +1 -2
  118. package/dist/services/mmorpg.d.ts +1 -1
  119. package/dist/services/standalone.d.ts +1 -1
  120. package/package.json +9 -9
  121. package/src/Game/Object.ts +8 -0
  122. package/src/Gui/Gui.ts +4 -31
  123. package/src/RpgClientEngine.ts +193 -20
  124. package/src/components/character.ce +146 -9
  125. package/src/components/gui/mobile/index.ts +24 -0
  126. package/src/components/gui/mobile/mobile.ce +80 -0
  127. package/src/components/prebuilt/index.ts +1 -0
  128. package/src/components/prebuilt/light-halo.ce +148 -0
  129. package/src/components/scenes/canvas.ce +2 -2
  130. package/src/components/scenes/event-layer.ce +1 -0
  131. package/src/components/scenes/transition.ce +60 -0
  132. package/src/index.ts +6 -1
  133. package/src/module.ts +15 -0
  134. package/src/services/keyboardControls.ts +1 -1
package/dist/index50.js CHANGED
@@ -1,113 +1,504 @@
1
- import { getErrorMap } from './index49.js';
2
- import errorMap from './index53.js';
3
-
4
- const makeIssue = (params) => {
5
- const { data, path, errorMaps, issueData } = params;
6
- const fullPath = [...path, ...(issueData.path || [])];
7
- const fullIssue = {
8
- ...issueData,
9
- path: fullPath,
10
- };
11
- if (issueData.message !== undefined) {
12
- return {
13
- ...issueData,
14
- path: fullPath,
15
- message: issueData.message,
16
- };
17
- }
18
- let errorMessage = "";
19
- const maps = errorMaps
20
- .filter((m) => !!m)
21
- .slice()
22
- .reverse();
23
- for (const map of maps) {
24
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
25
- }
26
- return {
27
- ...issueData,
28
- path: fullPath,
29
- message: errorMessage,
30
- };
1
+ // src/ws.ts
2
+ if (!globalThis.EventTarget || !globalThis.Event) {
3
+ console.error(`
4
+ PartySocket requires a global 'EventTarget' class to be available!
5
+ You can polyfill this global by adding this to your code before any partysocket imports:
6
+
7
+ \`\`\`
8
+ import 'partysocket/event-target-polyfill';
9
+ \`\`\`
10
+ Please file an issue at https://github.com/partykit/partykit if you're still having trouble.
11
+ `);
12
+ }
13
+ var ErrorEvent = class extends Event {
14
+ message;
15
+ error;
16
+ // biome-ignore lint/suspicious/noExplicitAny: vibes
17
+ constructor(error, target) {
18
+ super("error", target);
19
+ this.message = error.message;
20
+ this.error = error;
21
+ }
31
22
  };
32
- const EMPTY_PATH = [];
33
- function addIssueToContext(ctx, issueData) {
34
- const overrideMap = getErrorMap();
35
- const issue = makeIssue({
36
- issueData: issueData,
37
- data: ctx.data,
38
- path: ctx.path,
39
- errorMaps: [
40
- ctx.common.contextualErrorMap, // contextual error map is first priority
41
- ctx.schemaErrorMap, // then schema-bound map if available
42
- overrideMap, // then global override map
43
- overrideMap === errorMap ? undefined : errorMap, // then global default map
44
- ].filter((x) => !!x),
45
- });
46
- ctx.common.issues.push(issue);
23
+ var CloseEvent = class extends Event {
24
+ code;
25
+ reason;
26
+ wasClean = true;
27
+ // biome-ignore lint/style/useDefaultParameterLast: legacy
28
+ // biome-ignore lint/suspicious/noExplicitAny: legacy
29
+ constructor(code = 1e3, reason = "", target) {
30
+ super("close", target);
31
+ this.code = code;
32
+ this.reason = reason;
33
+ }
34
+ };
35
+ var Events = {
36
+ Event,
37
+ ErrorEvent,
38
+ CloseEvent
39
+ };
40
+ function assert(condition, msg) {
41
+ if (!condition) {
42
+ throw new Error(msg);
43
+ }
47
44
  }
48
- class ParseStatus {
49
- constructor() {
50
- this.value = "valid";
51
- }
52
- dirty() {
53
- if (this.value === "valid")
54
- this.value = "dirty";
55
- }
56
- abort() {
57
- if (this.value !== "aborted")
58
- this.value = "aborted";
59
- }
60
- static mergeArray(status, results) {
61
- const arrayValue = [];
62
- for (const s of results) {
63
- if (s.status === "aborted")
64
- return INVALID;
65
- if (s.status === "dirty")
66
- status.dirty();
67
- arrayValue.push(s.value);
68
- }
69
- return { status: status.value, value: arrayValue };
70
- }
71
- static async mergeObjectAsync(status, pairs) {
72
- const syncPairs = [];
73
- for (const pair of pairs) {
74
- const key = await pair.key;
75
- const value = await pair.value;
76
- syncPairs.push({
77
- key,
78
- value,
79
- });
45
+ function cloneEventBrowser(e) {
46
+ return new e.constructor(e.type, e);
47
+ }
48
+ function cloneEventNode(e) {
49
+ if ("data" in e) {
50
+ const evt2 = new MessageEvent(e.type, e);
51
+ return evt2;
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;
69
+ }
70
+ var _a;
71
+ var isNode =
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;
76
+ var DEFAULT = {
77
+ maxReconnectionDelay: 1e4,
78
+ minReconnectionDelay: 1e3 + Math.random() * 4e3,
79
+ minUptime: 5e3,
80
+ reconnectionDelayGrowFactor: 1.3,
81
+ connectionTimeout: 4e3,
82
+ maxRetries: Number.POSITIVE_INFINITY,
83
+ maxEnqueuedMessages: Number.POSITIVE_INFINITY};
84
+ var didWarnAboutMissingWebSocket = false;
85
+ var ReconnectingWebSocket = class _ReconnectingWebSocket extends EventTarget {
86
+ _ws;
87
+ _retryCount = -1;
88
+ _uptimeTimeout;
89
+ _connectTimeout;
90
+ _shouldReconnect = true;
91
+ _connectLock = false;
92
+ _binaryType = "blob";
93
+ _closeCalled = false;
94
+ _messageQueue = [];
95
+ _debugLogger = console.log.bind(console);
96
+ _url;
97
+ _protocols;
98
+ _options;
99
+ constructor(url, protocols, options = {}) {
100
+ super();
101
+ this._url = url;
102
+ this._protocols = protocols;
103
+ this._options = options;
104
+ if (this._options.startClosed) {
105
+ this._shouldReconnect = false;
106
+ }
107
+ if (this._options.debugLogger) {
108
+ this._debugLogger = this._options.debugLogger;
109
+ }
110
+ this._connect();
111
+ }
112
+ static get CONNECTING() {
113
+ return 0;
114
+ }
115
+ static get OPEN() {
116
+ return 1;
117
+ }
118
+ static get CLOSING() {
119
+ return 2;
120
+ }
121
+ static get CLOSED() {
122
+ return 3;
123
+ }
124
+ get CONNECTING() {
125
+ return _ReconnectingWebSocket.CONNECTING;
126
+ }
127
+ get OPEN() {
128
+ return _ReconnectingWebSocket.OPEN;
129
+ }
130
+ get CLOSING() {
131
+ return _ReconnectingWebSocket.CLOSING;
132
+ }
133
+ get CLOSED() {
134
+ return _ReconnectingWebSocket.CLOSED;
135
+ }
136
+ get binaryType() {
137
+ return this._ws ? this._ws.binaryType : this._binaryType;
138
+ }
139
+ set binaryType(value) {
140
+ this._binaryType = value;
141
+ if (this._ws) {
142
+ this._ws.binaryType = value;
143
+ }
144
+ }
145
+ /**
146
+ * Returns the number or connection retries
147
+ */
148
+ get retryCount() {
149
+ return Math.max(this._retryCount, 0);
150
+ }
151
+ /**
152
+ * The number of bytes of data that have been queued using calls to send() but not yet
153
+ * transmitted to the network. This value resets to zero once all queued data has been sent.
154
+ * This value does not reset to zero when the connection is closed; if you keep calling send(),
155
+ * this will continue to climb. Read only
156
+ */
157
+ get bufferedAmount() {
158
+ const bytes = this._messageQueue.reduce((acc, message) => {
159
+ if (typeof message === "string") {
160
+ acc += message.length;
161
+ } else if (message instanceof Blob) {
162
+ acc += message.size;
163
+ } else {
164
+ acc += message.byteLength;
165
+ }
166
+ return acc;
167
+ }, 0);
168
+ return bytes + (this._ws ? this._ws.bufferedAmount : 0);
169
+ }
170
+ /**
171
+ * The extensions selected by the server. This is currently only the empty string or a list of
172
+ * extensions as negotiated by the connection
173
+ */
174
+ get extensions() {
175
+ return this._ws ? this._ws.extensions : "";
176
+ }
177
+ /**
178
+ * A string indicating the name of the sub-protocol the server selected;
179
+ * this will be one of the strings specified in the protocols parameter when creating the
180
+ * WebSocket object
181
+ */
182
+ get protocol() {
183
+ return this._ws ? this._ws.protocol : "";
184
+ }
185
+ /**
186
+ * The current state of the connection; this is one of the Ready state constants
187
+ */
188
+ get readyState() {
189
+ if (this._ws) {
190
+ return this._ws.readyState;
191
+ }
192
+ return this._options.startClosed
193
+ ? _ReconnectingWebSocket.CLOSED
194
+ : _ReconnectingWebSocket.CONNECTING;
195
+ }
196
+ /**
197
+ * The URL as resolved by the constructor
198
+ */
199
+ get url() {
200
+ return this._ws ? this._ws.url : "";
201
+ }
202
+ /**
203
+ * Whether the websocket object is now in reconnectable state
204
+ */
205
+ get shouldReconnect() {
206
+ return this._shouldReconnect;
207
+ }
208
+ /**
209
+ * An event listener to be called when the WebSocket connection's readyState changes to CLOSED
210
+ */
211
+ onclose = null;
212
+ /**
213
+ * An event listener to be called when an error occurs
214
+ */
215
+ onerror = null;
216
+ /**
217
+ * An event listener to be called when a message is received from the server
218
+ */
219
+ onmessage = null;
220
+ /**
221
+ * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
222
+ * this indicates that the connection is ready to send and receive data
223
+ */
224
+ onopen = null;
225
+ /**
226
+ * Closes the WebSocket connection or connection attempt, if any. If the connection is already
227
+ * CLOSED, this method does nothing
228
+ */
229
+ close(code = 1e3, reason) {
230
+ this._closeCalled = true;
231
+ this._shouldReconnect = false;
232
+ this._clearTimeouts();
233
+ if (!this._ws) {
234
+ this._debug("close enqueued: no ws instance");
235
+ return;
236
+ }
237
+ if (this._ws.readyState === this.CLOSED) {
238
+ this._debug("close: already closed");
239
+ return;
240
+ }
241
+ this._ws.close(code, reason);
242
+ }
243
+ /**
244
+ * Closes the WebSocket connection or connection attempt and connects again.
245
+ * Resets retry counter;
246
+ */
247
+ reconnect(code, reason) {
248
+ this._shouldReconnect = true;
249
+ this._closeCalled = false;
250
+ this._retryCount = -1;
251
+ if (!this._ws || this._ws.readyState === this.CLOSED) {
252
+ this._connect();
253
+ } else {
254
+ this._disconnect(code, reason);
255
+ this._connect();
256
+ }
257
+ }
258
+ /**
259
+ * Enqueue specified data to be transmitted to the server over the WebSocket connection
260
+ */
261
+ send(data) {
262
+ if (this._ws && this._ws.readyState === this.OPEN) {
263
+ this._debug("send", data);
264
+ this._ws.send(data);
265
+ } else {
266
+ const { maxEnqueuedMessages = DEFAULT.maxEnqueuedMessages } =
267
+ this._options;
268
+ if (this._messageQueue.length < maxEnqueuedMessages) {
269
+ this._debug("enqueue", data);
270
+ this._messageQueue.push(data);
271
+ }
272
+ }
273
+ }
274
+ _debug(...args) {
275
+ if (this._options.debug) {
276
+ this._debugLogger("RWS>", ...args);
277
+ }
278
+ }
279
+ _getNextDelay() {
280
+ const {
281
+ reconnectionDelayGrowFactor = DEFAULT.reconnectionDelayGrowFactor,
282
+ minReconnectionDelay = DEFAULT.minReconnectionDelay,
283
+ maxReconnectionDelay = DEFAULT.maxReconnectionDelay
284
+ } = this._options;
285
+ let delay = 0;
286
+ if (this._retryCount > 0) {
287
+ delay =
288
+ minReconnectionDelay *
289
+ reconnectionDelayGrowFactor ** (this._retryCount - 1);
290
+ if (delay > maxReconnectionDelay) {
291
+ delay = maxReconnectionDelay;
292
+ }
293
+ }
294
+ this._debug("next delay", delay);
295
+ return delay;
296
+ }
297
+ _wait() {
298
+ return new Promise((resolve) => {
299
+ setTimeout(resolve, this._getNextDelay());
300
+ });
301
+ }
302
+ _getNextProtocols(protocolsProvider) {
303
+ if (!protocolsProvider) return Promise.resolve(null);
304
+ if (
305
+ typeof protocolsProvider === "string" ||
306
+ Array.isArray(protocolsProvider)
307
+ ) {
308
+ return Promise.resolve(protocolsProvider);
309
+ }
310
+ if (typeof protocolsProvider === "function") {
311
+ const protocols = protocolsProvider();
312
+ if (!protocols) return Promise.resolve(null);
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;
80
364
  }
81
- return ParseStatus.mergeObjectSync(status, syncPairs);
82
- }
83
- static mergeObjectSync(status, pairs) {
84
- const finalObject = {};
85
- for (const pair of pairs) {
86
- const { key, value } = pair;
87
- if (key.status === "aborted")
88
- return INVALID;
89
- if (value.status === "aborted")
90
- return INVALID;
91
- if (key.status === "dirty")
92
- status.dirty();
93
- if (value.status === "dirty")
94
- status.dirty();
95
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
96
- finalObject[key.value] = value.value;
97
- }
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.
371
+
372
+ For example, if you're using node.js, run \`npm install ws\`, and then in your code:
373
+
374
+ import PartySocket from 'partysocket';
375
+ import WS from 'ws';
376
+
377
+ const partysocket = new PartySocket({
378
+ host: "127.0.0.1:1999",
379
+ room: "test-room",
380
+ WebSocket: WS
381
+ });
382
+
383
+ `);
384
+ didWarnAboutMissingWebSocket = true;
98
385
  }
99
- return { status: status.value, value: finalObject };
386
+ const WS = this._options.WebSocket || WebSocket;
387
+ this._debug("connect", { url, protocols });
388
+ this._ws = protocols ? new WS(url, protocols) : new WS(url);
389
+ this._ws.binaryType = this._binaryType;
390
+ this._connectLock = false;
391
+ this._addListeners();
392
+ this._connectTimeout = setTimeout(
393
+ () => this._handleTimeout(),
394
+ connectionTimeout
395
+ );
396
+ })
397
+ .catch((err) => {
398
+ this._connectLock = false;
399
+ this._handleError(new Events.ErrorEvent(Error(err.message), this));
400
+ });
401
+ }
402
+ _handleTimeout() {
403
+ this._debug("timeout event");
404
+ this._handleError(new Events.ErrorEvent(Error("TIMEOUT"), this));
405
+ }
406
+ _disconnect(code = 1e3, reason) {
407
+ this._clearTimeouts();
408
+ if (!this._ws) {
409
+ return;
100
410
  }
101
- }
102
- const INVALID = Object.freeze({
103
- status: "aborted",
104
- });
105
- const DIRTY = (value) => ({ status: "dirty", value });
106
- const OK = (value) => ({ status: "valid", value });
107
- const isAborted = (x) => x.status === "aborted";
108
- const isDirty = (x) => x.status === "dirty";
109
- const isValid = (x) => x.status === "valid";
110
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
411
+ this._removeListeners();
412
+ try {
413
+ if (
414
+ this._ws.readyState === this.OPEN ||
415
+ this._ws.readyState === this.CONNECTING
416
+ ) {
417
+ this._ws.close(code, reason);
418
+ }
419
+ this._handleClose(new Events.CloseEvent(code, reason, this));
420
+ } catch (error) {}
421
+ }
422
+ _acceptOpen() {
423
+ this._debug("accept open");
424
+ this._retryCount = 0;
425
+ }
426
+ _handleOpen = (event) => {
427
+ this._debug("open event");
428
+ const { minUptime = DEFAULT.minUptime } = this._options;
429
+ clearTimeout(this._connectTimeout);
430
+ this._uptimeTimeout = setTimeout(() => this._acceptOpen(), minUptime);
431
+ assert(this._ws, "WebSocket is not defined");
432
+ this._ws.binaryType = this._binaryType;
433
+ this._messageQueue.forEach((message) => {
434
+ var _a2;
435
+ return (_a2 = this._ws) == null ? void 0 : _a2.send(message);
436
+ });
437
+ this._messageQueue = [];
438
+ if (this.onopen) {
439
+ this.onopen(event);
440
+ }
441
+ this.dispatchEvent(cloneEvent(event));
442
+ };
443
+ _handleMessage = (event) => {
444
+ this._debug("message event");
445
+ if (this.onmessage) {
446
+ this.onmessage(event);
447
+ }
448
+ this.dispatchEvent(cloneEvent(event));
449
+ };
450
+ _handleError = (event) => {
451
+ this._debug("error event", event.message);
452
+ this._disconnect(void 0, event.message === "TIMEOUT" ? "timeout" : void 0);
453
+ if (this.onerror) {
454
+ this.onerror(event);
455
+ }
456
+ this._debug("exec error listeners");
457
+ this.dispatchEvent(cloneEvent(event));
458
+ this._connect();
459
+ };
460
+ _handleClose = (event) => {
461
+ this._debug("close event");
462
+ this._clearTimeouts();
463
+ if (this._shouldReconnect) {
464
+ this._connect();
465
+ }
466
+ if (this.onclose) {
467
+ this.onclose(event);
468
+ }
469
+ this.dispatchEvent(cloneEvent(event));
470
+ };
471
+ _removeListeners() {
472
+ if (!this._ws) {
473
+ return;
474
+ }
475
+ this._debug("removeListeners");
476
+ this._ws.removeEventListener("open", this._handleOpen);
477
+ this._ws.removeEventListener("close", this._handleClose);
478
+ this._ws.removeEventListener("message", this._handleMessage);
479
+ this._ws.removeEventListener("error", this._handleError);
480
+ }
481
+ _addListeners() {
482
+ if (!this._ws) {
483
+ return;
484
+ }
485
+ this._debug("addListeners");
486
+ this._ws.addEventListener("open", this._handleOpen);
487
+ this._ws.addEventListener("close", this._handleClose);
488
+ this._ws.addEventListener("message", this._handleMessage);
489
+ this._ws.addEventListener("error", this._handleError);
490
+ }
491
+ _clearTimeouts() {
492
+ clearTimeout(this._connectTimeout);
493
+ clearTimeout(this._uptimeTimeout);
494
+ }
495
+ };
496
+ /*!
497
+ * Reconnecting WebSocket
498
+ * by Pedro Ladaria <pedro.ladaria@gmail.com>
499
+ * https://github.com/pladaria/reconnecting-websocket
500
+ * License MIT
501
+ */
111
502
 
112
- export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, addIssueToContext, isAborted, isAsync, isDirty, isValid, makeIssue };
503
+ export { CloseEvent, ErrorEvent, ReconnectingWebSocket };
113
504
  //# sourceMappingURL=index50.js.map