@danidoble/webserial 4.4.0-beta.3 → 4.4.0-beta.5
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/boardroid.cjs +1 -1
- package/dist/boardroid.js +1 -1
- package/dist/hopper.cjs +2 -2
- package/dist/hopper.js +8 -8
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +1 -1
- package/dist/{kernel-C1HLYiV1.cjs → kernel-9JeWIxgz.cjs} +1 -1
- package/dist/{kernel-DtXV8d8B.js → kernel-BnWXOCde.js} +1 -1
- package/dist/kernel.cjs +1 -1
- package/dist/kernel.js +1 -1
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +1 -1
- package/dist/pinpad.cjs +7 -7
- package/dist/pinpad.js +33 -32
- package/dist/pinpax.cjs +1 -1
- package/dist/pinpax.js +1 -1
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +1 -1
- package/dist/types/kernel.d.ts.map +1 -0
- package/dist/types/main.d.ts.map +1 -0
- package/dist/{serial → types/serial}/boardroid.d.ts +1 -1
- package/dist/types/serial/boardroid.d.ts.map +1 -0
- package/dist/types/serial/hopper.d.ts.map +1 -0
- package/dist/{serial → types/serial}/jofemar.d.ts +1 -1
- package/dist/types/serial/jofemar.d.ts.map +1 -0
- package/dist/types/serial/kernel.d.ts.map +1 -0
- package/dist/{serial → types/serial}/locker.d.ts +1 -1
- package/dist/types/serial/locker.d.ts.map +1 -0
- package/dist/types/serial/pinpad.d.ts.map +1 -0
- package/dist/types/serial/pinpax.d.ts.map +1 -0
- package/dist/types/serial/relay.d.ts.map +1 -0
- package/dist/types/utils/devices.d.ts.map +1 -0
- package/dist/types/utils/dispatcher.d.ts.map +1 -0
- package/dist/types/utils/emulator.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/{webserial-core-CH2Xov2y.js → webserial-core-52yJu-0N.js} +827 -827
- package/dist/webserial-core-BgEbN4Gb.cjs +4 -0
- package/dist/webserial.cjs +2 -2
- package/dist/webserial.js +5 -5
- package/package.json +88 -79
- package/dist/kernel-C8ISUhzV.cjs +0 -1
- package/dist/kernel-CQcZ_OiG.js +0 -831
- package/dist/kernel-DkC7Kj3m.js +0 -841
- package/dist/kernel-DyNuXvtW.cjs +0 -1
- package/dist/kernel-aqBCxtkj.js +0 -831
- package/dist/kernel-pO_elWba.cjs +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/serial/boardroid.d.ts.map +0 -1
- package/dist/serial/hopper.d.ts.map +0 -1
- package/dist/serial/jofemar.d.ts.map +0 -1
- package/dist/serial/kernel.d.ts.map +0 -1
- package/dist/serial/locker.d.ts.map +0 -1
- package/dist/serial/pinpad.d.ts.map +0 -1
- package/dist/serial/pinpax.d.ts.map +0 -1
- package/dist/serial/relay.d.ts.map +0 -1
- package/dist/utils/devices.d.ts.map +0 -1
- package/dist/utils/dispatcher.d.ts.map +0 -1
- package/dist/utils/emulator.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/webserial-core-Cj_EZjAU.cjs +0 -4
- package/dist/webserial-core-D3luFguv.js +0 -3325
- package/dist/webserial-core-YjdXyVOx.cjs +0 -4
- /package/dist/{kernel.d.ts → types/kernel.d.ts} +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
- /package/dist/{serial → types/serial}/hopper.d.ts +0 -0
- /package/dist/{serial → types/serial}/kernel.d.ts +0 -0
- /package/dist/{serial → types/serial}/pinpad.d.ts +0 -0
- /package/dist/{serial → types/serial}/pinpax.d.ts +0 -0
- /package/dist/{serial → types/serial}/relay.d.ts +0 -0
- /package/dist/{utils → types/utils}/devices.d.ts +0 -0
- /package/dist/{utils → types/utils}/dispatcher.d.ts +0 -0
- /package/dist/{utils → types/utils}/emulator.d.ts +0 -0
- /package/dist/{utils → types/utils}/utils.d.ts +0 -0
|
@@ -1,126 +1,3 @@
|
|
|
1
|
-
class Y extends CustomEvent {
|
|
2
|
-
constructor(e, t) {
|
|
3
|
-
super(e, t);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
class te extends EventTarget {
|
|
7
|
-
__listeners__ = {
|
|
8
|
-
debug: !1
|
|
9
|
-
};
|
|
10
|
-
__debug__ = !1;
|
|
11
|
-
__listenersCallbacks__ = [];
|
|
12
|
-
dispatch(e, t = null) {
|
|
13
|
-
const n = new Y(e, { detail: t });
|
|
14
|
-
this.dispatchEvent(n), this.__debug__ && this.dispatchEvent(new Y("debug", { detail: { type: e, data: t } }));
|
|
15
|
-
}
|
|
16
|
-
dispatchAsync(e, t = null, n = 100) {
|
|
17
|
-
const r = this;
|
|
18
|
-
setTimeout(() => {
|
|
19
|
-
r.dispatch(e, t);
|
|
20
|
-
}, n);
|
|
21
|
-
}
|
|
22
|
-
on(e, t) {
|
|
23
|
-
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
|
|
24
|
-
}
|
|
25
|
-
off(e, t) {
|
|
26
|
-
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((n) => !(n.key === e && n.callback === t)), this.removeEventListener(e, t);
|
|
27
|
-
}
|
|
28
|
-
serialRegisterAvailableListener(e) {
|
|
29
|
-
this.__listeners__[e] || (this.__listeners__[e] = !1);
|
|
30
|
-
}
|
|
31
|
-
get availableListeners() {
|
|
32
|
-
return Object.keys(this.__listeners__).sort().map((e) => ({
|
|
33
|
-
type: e,
|
|
34
|
-
listening: this.__listeners__[e]
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
removeAllListeners() {
|
|
38
|
-
for (const e of this.__listenersCallbacks__)
|
|
39
|
-
["internal:queue"].includes(e.key) || (this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((t) => !(t.key === e.key && t.callback === e.callback)), this.removeEventListener(e.key, e.callback));
|
|
40
|
-
for (const e of Object.keys(this.__listeners__))
|
|
41
|
-
this.__listeners__[e] = !1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
class a extends te {
|
|
45
|
-
static instance;
|
|
46
|
-
static devices = {};
|
|
47
|
-
constructor() {
|
|
48
|
-
super(), ["change"].forEach((e) => {
|
|
49
|
-
this.serialRegisterAvailableListener(e);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
static $dispatchChange(e = null) {
|
|
53
|
-
e && e.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: e });
|
|
54
|
-
}
|
|
55
|
-
static typeError(e) {
|
|
56
|
-
const t = new Error();
|
|
57
|
-
throw t.message = `Type ${e} is not supported`, t.name = "DeviceTypeError", t;
|
|
58
|
-
}
|
|
59
|
-
static registerType(e) {
|
|
60
|
-
typeof a.devices[e] > "u" && (a.devices = { ...a.devices, [e]: {} });
|
|
61
|
-
}
|
|
62
|
-
static add(e) {
|
|
63
|
-
const t = e.typeDevice;
|
|
64
|
-
typeof a.devices[t] > "u" && a.registerType(t);
|
|
65
|
-
const n = e.uuid;
|
|
66
|
-
if (typeof a.devices[t] > "u" && a.typeError(t), a.devices[t][n])
|
|
67
|
-
throw new Error(`Device with id ${n} already exists`);
|
|
68
|
-
return a.devices[t][n] = e, a.$dispatchChange(e), Object.keys(a.devices[t]).indexOf(n);
|
|
69
|
-
}
|
|
70
|
-
static get(e, t) {
|
|
71
|
-
return typeof a.devices[e] > "u" && a.registerType(e), typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t];
|
|
72
|
-
}
|
|
73
|
-
static getAll(e = null) {
|
|
74
|
-
return e === null ? a.devices : (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e]);
|
|
75
|
-
}
|
|
76
|
-
static getList() {
|
|
77
|
-
return Object.values(a.devices).map((e) => Object.values(e)).flat();
|
|
78
|
-
}
|
|
79
|
-
static getByNumber(e, t) {
|
|
80
|
-
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
81
|
-
}
|
|
82
|
-
static getCustom(e, t = 1) {
|
|
83
|
-
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
84
|
-
}
|
|
85
|
-
static async connectToAll() {
|
|
86
|
-
const e = a.getList();
|
|
87
|
-
for (const t of e)
|
|
88
|
-
t.isConnected || await t.connect().catch(console.warn);
|
|
89
|
-
return Promise.resolve(a.areAllConnected());
|
|
90
|
-
}
|
|
91
|
-
static async disconnectAll() {
|
|
92
|
-
const e = a.getList();
|
|
93
|
-
for (const t of e)
|
|
94
|
-
t.isDisconnected || await t.disconnect().catch(console.warn);
|
|
95
|
-
return Promise.resolve(a.areAllDisconnected());
|
|
96
|
-
}
|
|
97
|
-
static async areAllConnected() {
|
|
98
|
-
const e = a.getList();
|
|
99
|
-
for (const t of e)
|
|
100
|
-
if (!t.isConnected) return Promise.resolve(!1);
|
|
101
|
-
return Promise.resolve(!0);
|
|
102
|
-
}
|
|
103
|
-
static async areAllDisconnected() {
|
|
104
|
-
const e = a.getList();
|
|
105
|
-
for (const t of e)
|
|
106
|
-
if (!t.isDisconnected) return Promise.resolve(!1);
|
|
107
|
-
return Promise.resolve(!0);
|
|
108
|
-
}
|
|
109
|
-
static async getAllConnected() {
|
|
110
|
-
const e = a.getList();
|
|
111
|
-
return Promise.resolve(e.filter((t) => t.isConnected));
|
|
112
|
-
}
|
|
113
|
-
static async getAllDisconnected() {
|
|
114
|
-
const e = a.getList();
|
|
115
|
-
return Promise.resolve(e.filter((t) => t.isDisconnected));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
a.instance || (a.instance = new a());
|
|
119
|
-
function J(s = 100) {
|
|
120
|
-
return new Promise(
|
|
121
|
-
(e) => setTimeout(() => e(), s)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
1
|
const m = /* @__PURE__ */ Object.create(null);
|
|
125
2
|
m.open = "0";
|
|
126
3
|
m.close = "1";
|
|
@@ -129,253 +6,253 @@ m.pong = "3";
|
|
|
129
6
|
m.message = "4";
|
|
130
7
|
m.upgrade = "5";
|
|
131
8
|
m.noop = "6";
|
|
132
|
-
const
|
|
133
|
-
Object.keys(m).forEach((
|
|
134
|
-
|
|
9
|
+
const S = /* @__PURE__ */ Object.create(null);
|
|
10
|
+
Object.keys(m).forEach((n) => {
|
|
11
|
+
S[m[n]] = n;
|
|
135
12
|
});
|
|
136
|
-
const D = { type: "error", data: "parser error" },
|
|
13
|
+
const D = { type: "error", data: "parser error" }, te = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", se = typeof ArrayBuffer == "function", ne = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n && n.buffer instanceof ArrayBuffer, H = ({ type: n, data: e }, t, s) => te && e instanceof Blob ? t ? s(e) : J(e, s) : se && (e instanceof ArrayBuffer || ne(e)) ? t ? s(e) : J(new Blob([e]), s) : s(m[n] + (e || "")), J = (n, e) => {
|
|
137
14
|
const t = new FileReader();
|
|
138
15
|
return t.onload = function() {
|
|
139
|
-
const
|
|
140
|
-
e("b" + (
|
|
141
|
-
}, t.readAsDataURL(
|
|
16
|
+
const s = t.result.split(",")[1];
|
|
17
|
+
e("b" + (s || ""));
|
|
18
|
+
}, t.readAsDataURL(n);
|
|
142
19
|
};
|
|
143
|
-
function
|
|
144
|
-
return
|
|
20
|
+
function Q(n) {
|
|
21
|
+
return n instanceof Uint8Array ? n : n instanceof ArrayBuffer ? new Uint8Array(n) : new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
145
22
|
}
|
|
146
23
|
let P;
|
|
147
|
-
function
|
|
148
|
-
if (
|
|
149
|
-
return
|
|
150
|
-
if (
|
|
151
|
-
return e(
|
|
152
|
-
|
|
24
|
+
function de(n, e) {
|
|
25
|
+
if (te && n.data instanceof Blob)
|
|
26
|
+
return n.data.arrayBuffer().then(Q).then(e);
|
|
27
|
+
if (se && (n.data instanceof ArrayBuffer || ne(n.data)))
|
|
28
|
+
return e(Q(n.data));
|
|
29
|
+
H(n, !1, (t) => {
|
|
153
30
|
P || (P = new TextEncoder()), e(P.encode(t));
|
|
154
31
|
});
|
|
155
32
|
}
|
|
156
|
-
const
|
|
157
|
-
for (let
|
|
158
|
-
|
|
159
|
-
const ye = (
|
|
160
|
-
let e =
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
for (
|
|
164
|
-
|
|
165
|
-
return
|
|
166
|
-
}, ge = typeof ArrayBuffer == "function",
|
|
167
|
-
if (typeof
|
|
33
|
+
const X = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", k = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
|
|
34
|
+
for (let n = 0; n < X.length; n++)
|
|
35
|
+
k[X.charCodeAt(n)] = n;
|
|
36
|
+
const ye = (n) => {
|
|
37
|
+
let e = n.length * 0.75, t = n.length, s, i = 0, r, o, l, c;
|
|
38
|
+
n[n.length - 1] === "=" && (e--, n[n.length - 2] === "=" && e--);
|
|
39
|
+
const f = new ArrayBuffer(e), u = new Uint8Array(f);
|
|
40
|
+
for (s = 0; s < t; s += 4)
|
|
41
|
+
r = k[n.charCodeAt(s)], o = k[n.charCodeAt(s + 1)], l = k[n.charCodeAt(s + 2)], c = k[n.charCodeAt(s + 3)], u[i++] = r << 2 | o >> 4, u[i++] = (o & 15) << 4 | l >> 2, u[i++] = (l & 3) << 6 | c & 63;
|
|
42
|
+
return f;
|
|
43
|
+
}, ge = typeof ArrayBuffer == "function", W = (n, e) => {
|
|
44
|
+
if (typeof n != "string")
|
|
168
45
|
return {
|
|
169
46
|
type: "message",
|
|
170
|
-
data: ie(
|
|
47
|
+
data: ie(n, e)
|
|
171
48
|
};
|
|
172
|
-
const t =
|
|
49
|
+
const t = n.charAt(0);
|
|
173
50
|
return t === "b" ? {
|
|
174
51
|
type: "message",
|
|
175
|
-
data: me(
|
|
176
|
-
} :
|
|
177
|
-
type:
|
|
178
|
-
data:
|
|
52
|
+
data: me(n.substring(1), e)
|
|
53
|
+
} : S[t] ? n.length > 1 ? {
|
|
54
|
+
type: S[t],
|
|
55
|
+
data: n.substring(1)
|
|
179
56
|
} : {
|
|
180
|
-
type:
|
|
57
|
+
type: S[t]
|
|
181
58
|
} : D;
|
|
182
|
-
}, me = (
|
|
59
|
+
}, me = (n, e) => {
|
|
183
60
|
if (ge) {
|
|
184
|
-
const t = ye(
|
|
61
|
+
const t = ye(n);
|
|
185
62
|
return ie(t, e);
|
|
186
63
|
} else
|
|
187
|
-
return { base64: !0, data:
|
|
188
|
-
}, ie = (
|
|
64
|
+
return { base64: !0, data: n };
|
|
65
|
+
}, ie = (n, e) => {
|
|
189
66
|
switch (e) {
|
|
190
67
|
case "blob":
|
|
191
|
-
return
|
|
68
|
+
return n instanceof Blob ? n : new Blob([n]);
|
|
192
69
|
case "arraybuffer":
|
|
193
70
|
default:
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
const t =
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
71
|
+
return n instanceof ArrayBuffer ? n : n.buffer;
|
|
72
|
+
}
|
|
73
|
+
}, re = "", be = (n, e) => {
|
|
74
|
+
const t = n.length, s = new Array(t);
|
|
75
|
+
let i = 0;
|
|
76
|
+
n.forEach((r, o) => {
|
|
77
|
+
H(r, !1, (l) => {
|
|
78
|
+
s[o] = l, ++i === t && e(s.join(re));
|
|
202
79
|
});
|
|
203
80
|
});
|
|
204
|
-
}, we = (
|
|
205
|
-
const t =
|
|
206
|
-
for (let
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
81
|
+
}, we = (n, e) => {
|
|
82
|
+
const t = n.split(re), s = [];
|
|
83
|
+
for (let i = 0; i < t.length; i++) {
|
|
84
|
+
const r = W(t[i], e);
|
|
85
|
+
if (s.push(r), r.type === "error")
|
|
209
86
|
break;
|
|
210
87
|
}
|
|
211
|
-
return
|
|
88
|
+
return s;
|
|
212
89
|
};
|
|
213
90
|
function ve() {
|
|
214
91
|
return new TransformStream({
|
|
215
|
-
transform(
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
let
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
else if (
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
92
|
+
transform(n, e) {
|
|
93
|
+
de(n, (t) => {
|
|
94
|
+
const s = t.length;
|
|
95
|
+
let i;
|
|
96
|
+
if (s < 126)
|
|
97
|
+
i = new Uint8Array(1), new DataView(i.buffer).setUint8(0, s);
|
|
98
|
+
else if (s < 65536) {
|
|
99
|
+
i = new Uint8Array(3);
|
|
100
|
+
const r = new DataView(i.buffer);
|
|
101
|
+
r.setUint8(0, 126), r.setUint16(1, s);
|
|
225
102
|
} else {
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
103
|
+
i = new Uint8Array(9);
|
|
104
|
+
const r = new DataView(i.buffer);
|
|
105
|
+
r.setUint8(0, 127), r.setBigUint64(1, BigInt(s));
|
|
229
106
|
}
|
|
230
|
-
|
|
107
|
+
n.data && typeof n.data != "string" && (i[0] |= 128), e.enqueue(i), e.enqueue(t);
|
|
231
108
|
});
|
|
232
109
|
}
|
|
233
110
|
});
|
|
234
111
|
}
|
|
235
112
|
let N;
|
|
236
|
-
function C(
|
|
237
|
-
return
|
|
113
|
+
function C(n) {
|
|
114
|
+
return n.reduce((e, t) => e + t.length, 0);
|
|
238
115
|
}
|
|
239
|
-
function T(
|
|
240
|
-
if (
|
|
241
|
-
return
|
|
116
|
+
function T(n, e) {
|
|
117
|
+
if (n[0].length === e)
|
|
118
|
+
return n.shift();
|
|
242
119
|
const t = new Uint8Array(e);
|
|
243
|
-
let
|
|
244
|
-
for (let
|
|
245
|
-
t[
|
|
246
|
-
return
|
|
120
|
+
let s = 0;
|
|
121
|
+
for (let i = 0; i < e; i++)
|
|
122
|
+
t[i] = n[0][s++], s === n[0].length && (n.shift(), s = 0);
|
|
123
|
+
return n.length && s < n[0].length && (n[0] = n[0].slice(s)), t;
|
|
247
124
|
}
|
|
248
|
-
function
|
|
125
|
+
function Ee(n, e) {
|
|
249
126
|
N || (N = new TextDecoder());
|
|
250
127
|
const t = [];
|
|
251
|
-
let
|
|
128
|
+
let s = 0, i = -1, r = !1;
|
|
252
129
|
return new TransformStream({
|
|
253
|
-
transform(o,
|
|
130
|
+
transform(o, l) {
|
|
254
131
|
for (t.push(o); ; ) {
|
|
255
|
-
if (
|
|
132
|
+
if (s === 0) {
|
|
256
133
|
if (C(t) < 1)
|
|
257
134
|
break;
|
|
258
135
|
const c = T(t, 1);
|
|
259
|
-
|
|
260
|
-
} else if (
|
|
136
|
+
r = (c[0] & 128) === 128, i = c[0] & 127, i < 126 ? s = 3 : i === 126 ? s = 1 : s = 2;
|
|
137
|
+
} else if (s === 1) {
|
|
261
138
|
if (C(t) < 2)
|
|
262
139
|
break;
|
|
263
140
|
const c = T(t, 2);
|
|
264
|
-
|
|
265
|
-
} else if (
|
|
141
|
+
i = new DataView(c.buffer, c.byteOffset, c.length).getUint16(0), s = 3;
|
|
142
|
+
} else if (s === 2) {
|
|
266
143
|
if (C(t) < 8)
|
|
267
144
|
break;
|
|
268
|
-
const c = T(t, 8),
|
|
145
|
+
const c = T(t, 8), f = new DataView(c.buffer, c.byteOffset, c.length), u = f.getUint32(0);
|
|
269
146
|
if (u > Math.pow(2, 21) - 1) {
|
|
270
|
-
|
|
147
|
+
l.enqueue(D);
|
|
271
148
|
break;
|
|
272
149
|
}
|
|
273
|
-
|
|
150
|
+
i = u * Math.pow(2, 32) + f.getUint32(4), s = 3;
|
|
274
151
|
} else {
|
|
275
|
-
if (C(t) <
|
|
152
|
+
if (C(t) < i)
|
|
276
153
|
break;
|
|
277
|
-
const c = T(t,
|
|
278
|
-
|
|
154
|
+
const c = T(t, i);
|
|
155
|
+
l.enqueue(W(r ? c : N.decode(c), e)), s = 0;
|
|
279
156
|
}
|
|
280
|
-
if (
|
|
281
|
-
|
|
157
|
+
if (i === 0 || i > n) {
|
|
158
|
+
l.enqueue(D);
|
|
282
159
|
break;
|
|
283
160
|
}
|
|
284
161
|
}
|
|
285
162
|
}
|
|
286
163
|
});
|
|
287
164
|
}
|
|
288
|
-
const
|
|
289
|
-
function _(
|
|
290
|
-
if (
|
|
165
|
+
const oe = 4;
|
|
166
|
+
function _(n) {
|
|
167
|
+
if (n) return ke(n);
|
|
291
168
|
}
|
|
292
|
-
function
|
|
169
|
+
function ke(n) {
|
|
293
170
|
for (var e in _.prototype)
|
|
294
|
-
|
|
295
|
-
return
|
|
171
|
+
n[e] = _.prototype[e];
|
|
172
|
+
return n;
|
|
296
173
|
}
|
|
297
|
-
_.prototype.on = _.prototype.addEventListener = function(
|
|
298
|
-
return this._callbacks = this._callbacks || {}, (this._callbacks["$" +
|
|
174
|
+
_.prototype.on = _.prototype.addEventListener = function(n, e) {
|
|
175
|
+
return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
|
|
299
176
|
};
|
|
300
|
-
_.prototype.once = function(
|
|
177
|
+
_.prototype.once = function(n, e) {
|
|
301
178
|
function t() {
|
|
302
|
-
this.off(
|
|
179
|
+
this.off(n, t), e.apply(this, arguments);
|
|
303
180
|
}
|
|
304
|
-
return t.fn = e, this.on(
|
|
181
|
+
return t.fn = e, this.on(n, t), this;
|
|
305
182
|
};
|
|
306
|
-
_.prototype.off = _.prototype.removeListener = _.prototype.removeAllListeners = _.prototype.removeEventListener = function(
|
|
183
|
+
_.prototype.off = _.prototype.removeListener = _.prototype.removeAllListeners = _.prototype.removeEventListener = function(n, e) {
|
|
307
184
|
if (this._callbacks = this._callbacks || {}, arguments.length == 0)
|
|
308
185
|
return this._callbacks = {}, this;
|
|
309
|
-
var t = this._callbacks["$" +
|
|
186
|
+
var t = this._callbacks["$" + n];
|
|
310
187
|
if (!t) return this;
|
|
311
188
|
if (arguments.length == 1)
|
|
312
|
-
return delete this._callbacks["$" +
|
|
313
|
-
for (var
|
|
314
|
-
if (
|
|
315
|
-
t.splice(
|
|
189
|
+
return delete this._callbacks["$" + n], this;
|
|
190
|
+
for (var s, i = 0; i < t.length; i++)
|
|
191
|
+
if (s = t[i], s === e || s.fn === e) {
|
|
192
|
+
t.splice(i, 1);
|
|
316
193
|
break;
|
|
317
194
|
}
|
|
318
|
-
return t.length === 0 && delete this._callbacks["$" +
|
|
195
|
+
return t.length === 0 && delete this._callbacks["$" + n], this;
|
|
319
196
|
};
|
|
320
|
-
_.prototype.emit = function(
|
|
197
|
+
_.prototype.emit = function(n) {
|
|
321
198
|
this._callbacks = this._callbacks || {};
|
|
322
|
-
for (var e = new Array(arguments.length - 1), t = this._callbacks["$" +
|
|
323
|
-
e[
|
|
199
|
+
for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + n], s = 1; s < arguments.length; s++)
|
|
200
|
+
e[s - 1] = arguments[s];
|
|
324
201
|
if (t) {
|
|
325
202
|
t = t.slice(0);
|
|
326
|
-
for (var
|
|
327
|
-
t[
|
|
203
|
+
for (var s = 0, i = t.length; s < i; ++s)
|
|
204
|
+
t[s].apply(this, e);
|
|
328
205
|
}
|
|
329
206
|
return this;
|
|
330
207
|
};
|
|
331
208
|
_.prototype.emitReserved = _.prototype.emit;
|
|
332
|
-
_.prototype.listeners = function(
|
|
333
|
-
return this._callbacks = this._callbacks || {}, this._callbacks["$" +
|
|
209
|
+
_.prototype.listeners = function(n) {
|
|
210
|
+
return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
|
|
334
211
|
};
|
|
335
|
-
_.prototype.hasListeners = function(
|
|
336
|
-
return !!this.listeners(
|
|
212
|
+
_.prototype.hasListeners = function(n) {
|
|
213
|
+
return !!this.listeners(n).length;
|
|
337
214
|
};
|
|
338
|
-
const O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (
|
|
339
|
-
function
|
|
340
|
-
return e.reduce((t,
|
|
215
|
+
const O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), d = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ce = "arraybuffer";
|
|
216
|
+
function ae(n, ...e) {
|
|
217
|
+
return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
|
|
341
218
|
}
|
|
342
219
|
const Te = d.setTimeout, Ae = d.clearTimeout;
|
|
343
|
-
function L(
|
|
344
|
-
e.useNativeTimers ? (
|
|
220
|
+
function L(n, e) {
|
|
221
|
+
e.useNativeTimers ? (n.setTimeoutFn = Te.bind(d), n.clearTimeoutFn = Ae.bind(d)) : (n.setTimeoutFn = d.setTimeout.bind(d), n.clearTimeoutFn = d.clearTimeout.bind(d));
|
|
345
222
|
}
|
|
346
|
-
const
|
|
347
|
-
function
|
|
348
|
-
return typeof
|
|
223
|
+
const Se = 1.33;
|
|
224
|
+
function xe(n) {
|
|
225
|
+
return typeof n == "string" ? Re(n) : Math.ceil((n.byteLength || n.size) * Se);
|
|
349
226
|
}
|
|
350
|
-
function Re(
|
|
227
|
+
function Re(n) {
|
|
351
228
|
let e = 0, t = 0;
|
|
352
|
-
for (let
|
|
353
|
-
e =
|
|
229
|
+
for (let s = 0, i = n.length; s < i; s++)
|
|
230
|
+
e = n.charCodeAt(s), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (s++, t += 4);
|
|
354
231
|
return t;
|
|
355
232
|
}
|
|
356
|
-
function
|
|
233
|
+
function ce() {
|
|
357
234
|
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
358
235
|
}
|
|
359
|
-
function Be(
|
|
236
|
+
function Be(n) {
|
|
360
237
|
let e = "";
|
|
361
|
-
for (let t in
|
|
362
|
-
|
|
238
|
+
for (let t in n)
|
|
239
|
+
n.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(n[t]));
|
|
363
240
|
return e;
|
|
364
241
|
}
|
|
365
|
-
function Oe(
|
|
366
|
-
let e = {}, t =
|
|
367
|
-
for (let
|
|
368
|
-
let
|
|
369
|
-
e[decodeURIComponent(
|
|
242
|
+
function Oe(n) {
|
|
243
|
+
let e = {}, t = n.split("&");
|
|
244
|
+
for (let s = 0, i = t.length; s < i; s++) {
|
|
245
|
+
let r = t[s].split("=");
|
|
246
|
+
e[decodeURIComponent(r[0])] = decodeURIComponent(r[1]);
|
|
370
247
|
}
|
|
371
248
|
return e;
|
|
372
249
|
}
|
|
373
250
|
class Le extends Error {
|
|
374
|
-
constructor(e, t,
|
|
375
|
-
super(e), this.description = t, this.context =
|
|
251
|
+
constructor(e, t, s) {
|
|
252
|
+
super(e), this.description = t, this.context = s, this.type = "TransportError";
|
|
376
253
|
}
|
|
377
254
|
}
|
|
378
|
-
class
|
|
255
|
+
class K extends _ {
|
|
379
256
|
/**
|
|
380
257
|
* Transport abstract constructor.
|
|
381
258
|
*
|
|
@@ -394,8 +271,8 @@ class W extends _ {
|
|
|
394
271
|
* @return {Transport} for chaining
|
|
395
272
|
* @protected
|
|
396
273
|
*/
|
|
397
|
-
onError(e, t,
|
|
398
|
-
return super.emitReserved("error", new Le(e, t,
|
|
274
|
+
onError(e, t, s) {
|
|
275
|
+
return super.emitReserved("error", new Le(e, t, s)), this;
|
|
399
276
|
}
|
|
400
277
|
/**
|
|
401
278
|
* Opens the transport.
|
|
@@ -432,7 +309,7 @@ class W extends _ {
|
|
|
432
309
|
* @protected
|
|
433
310
|
*/
|
|
434
311
|
onData(e) {
|
|
435
|
-
const t =
|
|
312
|
+
const t = W(e, this.socket.binaryType);
|
|
436
313
|
this.onPacket(t);
|
|
437
314
|
}
|
|
438
315
|
/**
|
|
@@ -473,7 +350,7 @@ class W extends _ {
|
|
|
473
350
|
return t.length ? "?" + t : "";
|
|
474
351
|
}
|
|
475
352
|
}
|
|
476
|
-
class Pe extends
|
|
353
|
+
class Pe extends K {
|
|
477
354
|
constructor() {
|
|
478
355
|
super(...arguments), this._polling = !1;
|
|
479
356
|
}
|
|
@@ -501,11 +378,11 @@ class Pe extends W {
|
|
|
501
378
|
this.readyState = "paused", e();
|
|
502
379
|
};
|
|
503
380
|
if (this._polling || !this.writable) {
|
|
504
|
-
let
|
|
505
|
-
this._polling && (
|
|
506
|
-
--
|
|
507
|
-
})), this.writable || (
|
|
508
|
-
--
|
|
381
|
+
let s = 0;
|
|
382
|
+
this._polling && (s++, this.once("pollComplete", function() {
|
|
383
|
+
--s || t();
|
|
384
|
+
})), this.writable || (s++, this.once("drain", function() {
|
|
385
|
+
--s || t();
|
|
509
386
|
}));
|
|
510
387
|
} else
|
|
511
388
|
t();
|
|
@@ -524,10 +401,10 @@ class Pe extends W {
|
|
|
524
401
|
* @protected
|
|
525
402
|
*/
|
|
526
403
|
onData(e) {
|
|
527
|
-
const t = (
|
|
528
|
-
if (this.readyState === "opening" &&
|
|
404
|
+
const t = (s) => {
|
|
405
|
+
if (this.readyState === "opening" && s.type === "open" && this.onOpen(), s.type === "close")
|
|
529
406
|
return this.onClose({ description: "transport closed by the server" }), !1;
|
|
530
|
-
this.onPacket(
|
|
407
|
+
this.onPacket(s);
|
|
531
408
|
};
|
|
532
409
|
we(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
|
|
533
410
|
}
|
|
@@ -562,15 +439,15 @@ class Pe extends W {
|
|
|
562
439
|
*/
|
|
563
440
|
uri() {
|
|
564
441
|
const e = this.opts.secure ? "https" : "http", t = this.query || {};
|
|
565
|
-
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] =
|
|
442
|
+
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = ce()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
566
443
|
}
|
|
567
444
|
}
|
|
568
|
-
let
|
|
445
|
+
let le = !1;
|
|
569
446
|
try {
|
|
570
|
-
|
|
447
|
+
le = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
571
448
|
} catch {
|
|
572
449
|
}
|
|
573
|
-
const Ne =
|
|
450
|
+
const Ne = le;
|
|
574
451
|
function Ie() {
|
|
575
452
|
}
|
|
576
453
|
class qe extends Pe {
|
|
@@ -583,8 +460,8 @@ class qe extends Pe {
|
|
|
583
460
|
constructor(e) {
|
|
584
461
|
if (super(e), typeof location < "u") {
|
|
585
462
|
const t = location.protocol === "https:";
|
|
586
|
-
let
|
|
587
|
-
|
|
463
|
+
let s = location.port;
|
|
464
|
+
s || (s = t ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || s !== e.port;
|
|
588
465
|
}
|
|
589
466
|
}
|
|
590
467
|
/**
|
|
@@ -595,12 +472,12 @@ class qe extends Pe {
|
|
|
595
472
|
* @private
|
|
596
473
|
*/
|
|
597
474
|
doWrite(e, t) {
|
|
598
|
-
const
|
|
475
|
+
const s = this.request({
|
|
599
476
|
method: "POST",
|
|
600
477
|
data: e
|
|
601
478
|
});
|
|
602
|
-
|
|
603
|
-
this.onError("xhr post error",
|
|
479
|
+
s.on("success", t), s.on("error", (i, r) => {
|
|
480
|
+
this.onError("xhr post error", i, r);
|
|
604
481
|
});
|
|
605
482
|
}
|
|
606
483
|
/**
|
|
@@ -610,8 +487,8 @@ class qe extends Pe {
|
|
|
610
487
|
*/
|
|
611
488
|
doPoll() {
|
|
612
489
|
const e = this.request();
|
|
613
|
-
e.on("data", this.onData.bind(this)), e.on("error", (t,
|
|
614
|
-
this.onError("xhr poll error", t,
|
|
490
|
+
e.on("data", this.onData.bind(this)), e.on("error", (t, s) => {
|
|
491
|
+
this.onError("xhr poll error", t, s);
|
|
615
492
|
}), this.pollXhr = e;
|
|
616
493
|
}
|
|
617
494
|
}
|
|
@@ -622,8 +499,8 @@ class g extends _ {
|
|
|
622
499
|
* @param {Object} options
|
|
623
500
|
* @package
|
|
624
501
|
*/
|
|
625
|
-
constructor(e, t,
|
|
626
|
-
super(), this.createRequest = e, L(this,
|
|
502
|
+
constructor(e, t, s) {
|
|
503
|
+
super(), this.createRequest = e, L(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
|
|
627
504
|
}
|
|
628
505
|
/**
|
|
629
506
|
* Creates the XHR object and sends the request.
|
|
@@ -632,40 +509,40 @@ class g extends _ {
|
|
|
632
509
|
*/
|
|
633
510
|
_create() {
|
|
634
511
|
var e;
|
|
635
|
-
const t =
|
|
512
|
+
const t = ae(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
636
513
|
t.xdomain = !!this._opts.xd;
|
|
637
|
-
const
|
|
514
|
+
const s = this._xhr = this.createRequest(t);
|
|
638
515
|
try {
|
|
639
|
-
|
|
516
|
+
s.open(this._method, this._uri, !0);
|
|
640
517
|
try {
|
|
641
518
|
if (this._opts.extraHeaders) {
|
|
642
|
-
|
|
643
|
-
for (let
|
|
644
|
-
this._opts.extraHeaders.hasOwnProperty(
|
|
519
|
+
s.setDisableHeaderCheck && s.setDisableHeaderCheck(!0);
|
|
520
|
+
for (let i in this._opts.extraHeaders)
|
|
521
|
+
this._opts.extraHeaders.hasOwnProperty(i) && s.setRequestHeader(i, this._opts.extraHeaders[i]);
|
|
645
522
|
}
|
|
646
523
|
} catch {
|
|
647
524
|
}
|
|
648
525
|
if (this._method === "POST")
|
|
649
526
|
try {
|
|
650
|
-
|
|
527
|
+
s.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
651
528
|
} catch {
|
|
652
529
|
}
|
|
653
530
|
try {
|
|
654
|
-
|
|
531
|
+
s.setRequestHeader("Accept", "*/*");
|
|
655
532
|
} catch {
|
|
656
533
|
}
|
|
657
|
-
(e = this._opts.cookieJar) === null || e === void 0 || e.addCookies(
|
|
658
|
-
var
|
|
659
|
-
|
|
534
|
+
(e = this._opts.cookieJar) === null || e === void 0 || e.addCookies(s), "withCredentials" in s && (s.withCredentials = this._opts.withCredentials), this._opts.requestTimeout && (s.timeout = this._opts.requestTimeout), s.onreadystatechange = () => {
|
|
535
|
+
var i;
|
|
536
|
+
s.readyState === 3 && ((i = this._opts.cookieJar) === null || i === void 0 || i.parseCookies(
|
|
660
537
|
// @ts-ignore
|
|
661
|
-
|
|
662
|
-
)),
|
|
663
|
-
this._onError(typeof
|
|
538
|
+
s.getResponseHeader("set-cookie")
|
|
539
|
+
)), s.readyState === 4 && (s.status === 200 || s.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
|
|
540
|
+
this._onError(typeof s.status == "number" ? s.status : 0);
|
|
664
541
|
}, 0));
|
|
665
|
-
},
|
|
666
|
-
} catch (
|
|
542
|
+
}, s.send(this._data);
|
|
543
|
+
} catch (i) {
|
|
667
544
|
this.setTimeoutFn(() => {
|
|
668
|
-
this._onError(
|
|
545
|
+
this._onError(i);
|
|
669
546
|
}, 0);
|
|
670
547
|
return;
|
|
671
548
|
}
|
|
@@ -716,21 +593,21 @@ g.requestsCount = 0;
|
|
|
716
593
|
g.requests = {};
|
|
717
594
|
if (typeof document < "u") {
|
|
718
595
|
if (typeof attachEvent == "function")
|
|
719
|
-
attachEvent("onunload",
|
|
596
|
+
attachEvent("onunload", j);
|
|
720
597
|
else if (typeof addEventListener == "function") {
|
|
721
|
-
const
|
|
722
|
-
addEventListener(
|
|
598
|
+
const n = "onpagehide" in d ? "pagehide" : "unload";
|
|
599
|
+
addEventListener(n, j, !1);
|
|
723
600
|
}
|
|
724
601
|
}
|
|
725
|
-
function
|
|
726
|
-
for (let
|
|
727
|
-
g.requests.hasOwnProperty(
|
|
602
|
+
function j() {
|
|
603
|
+
for (let n in g.requests)
|
|
604
|
+
g.requests.hasOwnProperty(n) && g.requests[n].abort();
|
|
728
605
|
}
|
|
729
606
|
const De = function() {
|
|
730
|
-
const
|
|
607
|
+
const n = he({
|
|
731
608
|
xdomain: !1
|
|
732
609
|
});
|
|
733
|
-
return
|
|
610
|
+
return n && n.responseType !== null;
|
|
734
611
|
}();
|
|
735
612
|
class Ue extends qe {
|
|
736
613
|
constructor(e) {
|
|
@@ -739,11 +616,11 @@ class Ue extends qe {
|
|
|
739
616
|
this.supportsBinary = De && !t;
|
|
740
617
|
}
|
|
741
618
|
request(e = {}) {
|
|
742
|
-
return Object.assign(e, { xd: this.xd }, this.opts), new g(
|
|
619
|
+
return Object.assign(e, { xd: this.xd }, this.opts), new g(he, this.uri(), e);
|
|
743
620
|
}
|
|
744
621
|
}
|
|
745
|
-
function
|
|
746
|
-
const e =
|
|
622
|
+
function he(n) {
|
|
623
|
+
const e = n.xdomain;
|
|
747
624
|
try {
|
|
748
625
|
if (typeof XMLHttpRequest < "u" && (!e || Ne))
|
|
749
626
|
return new XMLHttpRequest();
|
|
@@ -755,18 +632,18 @@ function ue(s) {
|
|
|
755
632
|
} catch {
|
|
756
633
|
}
|
|
757
634
|
}
|
|
758
|
-
const
|
|
759
|
-
class
|
|
635
|
+
const ue = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
|
|
636
|
+
class Me extends K {
|
|
760
637
|
get name() {
|
|
761
638
|
return "websocket";
|
|
762
639
|
}
|
|
763
640
|
doOpen() {
|
|
764
|
-
const e = this.uri(), t = this.opts.protocols,
|
|
765
|
-
this.opts.extraHeaders && (
|
|
641
|
+
const e = this.uri(), t = this.opts.protocols, s = ue ? {} : ae(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
642
|
+
this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
|
|
766
643
|
try {
|
|
767
|
-
this.ws = this.createSocket(e, t,
|
|
768
|
-
} catch (
|
|
769
|
-
return this.emitReserved("error",
|
|
644
|
+
this.ws = this.createSocket(e, t, s);
|
|
645
|
+
} catch (i) {
|
|
646
|
+
return this.emitReserved("error", i);
|
|
770
647
|
}
|
|
771
648
|
this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
|
|
772
649
|
}
|
|
@@ -786,13 +663,13 @@ class je extends W {
|
|
|
786
663
|
write(e) {
|
|
787
664
|
this.writable = !1;
|
|
788
665
|
for (let t = 0; t < e.length; t++) {
|
|
789
|
-
const
|
|
790
|
-
|
|
666
|
+
const s = e[t], i = t === e.length - 1;
|
|
667
|
+
H(s, this.supportsBinary, (r) => {
|
|
791
668
|
try {
|
|
792
|
-
this.doWrite(
|
|
669
|
+
this.doWrite(s, r);
|
|
793
670
|
} catch {
|
|
794
671
|
}
|
|
795
|
-
|
|
672
|
+
i && O(() => {
|
|
796
673
|
this.writable = !0, this.emitReserved("drain");
|
|
797
674
|
}, this.setTimeoutFn);
|
|
798
675
|
});
|
|
@@ -809,19 +686,19 @@ class je extends W {
|
|
|
809
686
|
*/
|
|
810
687
|
uri() {
|
|
811
688
|
const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
|
|
812
|
-
return this.opts.timestampRequests && (t[this.opts.timestampParam] =
|
|
689
|
+
return this.opts.timestampRequests && (t[this.opts.timestampParam] = ce()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
813
690
|
}
|
|
814
691
|
}
|
|
815
692
|
const I = d.WebSocket || d.MozWebSocket;
|
|
816
|
-
class
|
|
817
|
-
createSocket(e, t,
|
|
818
|
-
return
|
|
693
|
+
class Fe extends Me {
|
|
694
|
+
createSocket(e, t, s) {
|
|
695
|
+
return ue ? new I(e, t, s) : t ? new I(e, t) : new I(e);
|
|
819
696
|
}
|
|
820
697
|
doWrite(e, t) {
|
|
821
698
|
this.ws.send(t);
|
|
822
699
|
}
|
|
823
700
|
}
|
|
824
|
-
class
|
|
701
|
+
class $e extends K {
|
|
825
702
|
get name() {
|
|
826
703
|
return "webtransport";
|
|
827
704
|
}
|
|
@@ -837,15 +714,15 @@ class Fe extends W {
|
|
|
837
714
|
this.onError("webtransport error", e);
|
|
838
715
|
}), this._transport.ready.then(() => {
|
|
839
716
|
this._transport.createBidirectionalStream().then((e) => {
|
|
840
|
-
const t =
|
|
841
|
-
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}).catch((
|
|
717
|
+
const t = Ee(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), i = ve();
|
|
718
|
+
i.readable.pipeTo(e.writable), this._writer = i.writable.getWriter();
|
|
719
|
+
const r = () => {
|
|
720
|
+
s.read().then(({ done: l, value: c }) => {
|
|
721
|
+
l || (this.onPacket(c), r());
|
|
722
|
+
}).catch((l) => {
|
|
846
723
|
});
|
|
847
724
|
};
|
|
848
|
-
|
|
725
|
+
r();
|
|
849
726
|
const o = { type: "open" };
|
|
850
727
|
this.query.sid && (o.data = `{"sid":"${this.query.sid}"}`), this._writer.write(o).then(() => this.onOpen());
|
|
851
728
|
});
|
|
@@ -854,9 +731,9 @@ class Fe extends W {
|
|
|
854
731
|
write(e) {
|
|
855
732
|
this.writable = !1;
|
|
856
733
|
for (let t = 0; t < e.length; t++) {
|
|
857
|
-
const
|
|
858
|
-
this._writer.write(
|
|
859
|
-
|
|
734
|
+
const s = e[t], i = t === e.length - 1;
|
|
735
|
+
this._writer.write(s).then(() => {
|
|
736
|
+
i && O(() => {
|
|
860
737
|
this.writable = !0, this.emitReserved("drain");
|
|
861
738
|
}, this.setTimeoutFn);
|
|
862
739
|
});
|
|
@@ -867,11 +744,11 @@ class Fe extends W {
|
|
|
867
744
|
(e = this._transport) === null || e === void 0 || e.close();
|
|
868
745
|
}
|
|
869
746
|
}
|
|
870
|
-
const
|
|
871
|
-
websocket:
|
|
872
|
-
webtransport:
|
|
747
|
+
const Ve = {
|
|
748
|
+
websocket: Fe,
|
|
749
|
+
webtransport: $e,
|
|
873
750
|
polling: Ue
|
|
874
|
-
},
|
|
751
|
+
}, He = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, We = [
|
|
875
752
|
"source",
|
|
876
753
|
"protocol",
|
|
877
754
|
"authority",
|
|
@@ -887,29 +764,29 @@ const $e = {
|
|
|
887
764
|
"query",
|
|
888
765
|
"anchor"
|
|
889
766
|
];
|
|
890
|
-
function U(
|
|
891
|
-
if (
|
|
767
|
+
function U(n) {
|
|
768
|
+
if (n.length > 8e3)
|
|
892
769
|
throw "URI too long";
|
|
893
|
-
const e =
|
|
894
|
-
t != -1 &&
|
|
895
|
-
let
|
|
770
|
+
const e = n, t = n.indexOf("["), s = n.indexOf("]");
|
|
771
|
+
t != -1 && s != -1 && (n = n.substring(0, t) + n.substring(t, s).replace(/:/g, ";") + n.substring(s, n.length));
|
|
772
|
+
let i = He.exec(n || ""), r = {}, o = 14;
|
|
896
773
|
for (; o--; )
|
|
897
|
-
|
|
898
|
-
return t != -1 &&
|
|
774
|
+
r[We[o]] = i[o] || "";
|
|
775
|
+
return t != -1 && s != -1 && (r.source = e, r.host = r.host.substring(1, r.host.length - 1).replace(/;/g, ":"), r.authority = r.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), r.ipv6uri = !0), r.pathNames = Ke(r, r.path), r.queryKey = ze(r, r.query), r;
|
|
899
776
|
}
|
|
900
|
-
function
|
|
901
|
-
const t = /\/{2,9}/g,
|
|
902
|
-
return (e.slice(0, 1) == "/" || e.length === 0) &&
|
|
777
|
+
function Ke(n, e) {
|
|
778
|
+
const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
|
|
779
|
+
return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
|
|
903
780
|
}
|
|
904
|
-
function ze(
|
|
781
|
+
function ze(n, e) {
|
|
905
782
|
const t = {};
|
|
906
|
-
return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(
|
|
907
|
-
|
|
783
|
+
return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, i, r) {
|
|
784
|
+
i && (t[i] = r);
|
|
908
785
|
}), t;
|
|
909
786
|
}
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
787
|
+
const M = typeof addEventListener == "function" && typeof removeEventListener == "function", x = [];
|
|
788
|
+
M && addEventListener("offline", () => {
|
|
789
|
+
x.forEach((n) => n());
|
|
913
790
|
}, !1);
|
|
914
791
|
class b extends _ {
|
|
915
792
|
/**
|
|
@@ -920,12 +797,12 @@ class b extends _ {
|
|
|
920
797
|
*/
|
|
921
798
|
constructor(e, t) {
|
|
922
799
|
if (super(), this.binaryType = Ce, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
|
|
923
|
-
const
|
|
924
|
-
t.hostname =
|
|
800
|
+
const s = U(e);
|
|
801
|
+
t.hostname = s.host, t.secure = s.protocol === "https" || s.protocol === "wss", t.port = s.port, s.query && (t.query = s.query);
|
|
925
802
|
} else t.host && (t.hostname = U(t.host).host);
|
|
926
|
-
L(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((
|
|
927
|
-
const
|
|
928
|
-
this.transports.push(
|
|
803
|
+
L(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
|
|
804
|
+
const i = s.prototype.name;
|
|
805
|
+
this.transports.push(i), this._transportsByName[i] = s;
|
|
929
806
|
}), this.opts = Object.assign({
|
|
930
807
|
path: "/engine.io",
|
|
931
808
|
agent: !1,
|
|
@@ -940,13 +817,13 @@ class b extends _ {
|
|
|
940
817
|
},
|
|
941
818
|
transportOptions: {},
|
|
942
819
|
closeOnBeforeunload: !1
|
|
943
|
-
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Oe(this.opts.query)),
|
|
820
|
+
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Oe(this.opts.query)), M && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
|
|
944
821
|
this.transport && (this.transport.removeAllListeners(), this.transport.close());
|
|
945
822
|
}, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
|
|
946
823
|
this._onClose("transport close", {
|
|
947
824
|
description: "network connection lost"
|
|
948
825
|
});
|
|
949
|
-
},
|
|
826
|
+
}, x.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
|
|
950
827
|
}
|
|
951
828
|
/**
|
|
952
829
|
* Creates transport of the given type.
|
|
@@ -957,15 +834,15 @@ class b extends _ {
|
|
|
957
834
|
*/
|
|
958
835
|
createTransport(e) {
|
|
959
836
|
const t = Object.assign({}, this.opts.query);
|
|
960
|
-
t.EIO =
|
|
961
|
-
const
|
|
837
|
+
t.EIO = oe, t.transport = e, this.id && (t.sid = this.id);
|
|
838
|
+
const s = Object.assign({}, this.opts, {
|
|
962
839
|
query: t,
|
|
963
840
|
socket: this,
|
|
964
841
|
hostname: this.hostname,
|
|
965
842
|
secure: this.secure,
|
|
966
843
|
port: this.port
|
|
967
844
|
}, this.opts.transportOptions[e]);
|
|
968
|
-
return new this._transportsByName[e](
|
|
845
|
+
return new this._transportsByName[e](s);
|
|
969
846
|
}
|
|
970
847
|
/**
|
|
971
848
|
* Initializes transport to use and starts probe.
|
|
@@ -1072,12 +949,12 @@ class b extends _ {
|
|
|
1072
949
|
_getWritablePackets() {
|
|
1073
950
|
if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1))
|
|
1074
951
|
return this.writeBuffer;
|
|
1075
|
-
let
|
|
1076
|
-
for (let
|
|
1077
|
-
const
|
|
1078
|
-
if (
|
|
1079
|
-
return this.writeBuffer.slice(0,
|
|
1080
|
-
|
|
952
|
+
let t = 1;
|
|
953
|
+
for (let s = 0; s < this.writeBuffer.length; s++) {
|
|
954
|
+
const i = this.writeBuffer[s].data;
|
|
955
|
+
if (i && (t += xe(i)), s > 0 && t > this._maxPayload)
|
|
956
|
+
return this.writeBuffer.slice(0, s);
|
|
957
|
+
t += 2;
|
|
1081
958
|
}
|
|
1082
959
|
return this.writeBuffer;
|
|
1083
960
|
}
|
|
@@ -1107,8 +984,8 @@ class b extends _ {
|
|
|
1107
984
|
* @param {Function} fn - callback function.
|
|
1108
985
|
* @return {Socket} for chaining.
|
|
1109
986
|
*/
|
|
1110
|
-
write(e, t,
|
|
1111
|
-
return this._sendPacket("message", e, t,
|
|
987
|
+
write(e, t, s) {
|
|
988
|
+
return this._sendPacket("message", e, t, s), this;
|
|
1112
989
|
}
|
|
1113
990
|
/**
|
|
1114
991
|
* Sends a message. Alias of {@link Socket#write}.
|
|
@@ -1118,8 +995,8 @@ class b extends _ {
|
|
|
1118
995
|
* @param {Function} fn - callback function.
|
|
1119
996
|
* @return {Socket} for chaining.
|
|
1120
997
|
*/
|
|
1121
|
-
send(e, t,
|
|
1122
|
-
return this._sendPacket("message", e, t,
|
|
998
|
+
send(e, t, s) {
|
|
999
|
+
return this._sendPacket("message", e, t, s), this;
|
|
1123
1000
|
}
|
|
1124
1001
|
/**
|
|
1125
1002
|
* Sends a packet.
|
|
@@ -1130,16 +1007,16 @@ class b extends _ {
|
|
|
1130
1007
|
* @param {Function} fn - callback function.
|
|
1131
1008
|
* @private
|
|
1132
1009
|
*/
|
|
1133
|
-
_sendPacket(e, t,
|
|
1134
|
-
if (typeof t == "function" && (
|
|
1010
|
+
_sendPacket(e, t, s, i) {
|
|
1011
|
+
if (typeof t == "function" && (i = t, t = void 0), typeof s == "function" && (i = s, s = null), this.readyState === "closing" || this.readyState === "closed")
|
|
1135
1012
|
return;
|
|
1136
|
-
|
|
1137
|
-
const
|
|
1013
|
+
s = s || {}, s.compress = s.compress !== !1;
|
|
1014
|
+
const r = {
|
|
1138
1015
|
type: e,
|
|
1139
1016
|
data: t,
|
|
1140
|
-
options:
|
|
1017
|
+
options: s
|
|
1141
1018
|
};
|
|
1142
|
-
this.emitReserved("packetCreate",
|
|
1019
|
+
this.emitReserved("packetCreate", r), this.writeBuffer.push(r), i && this.once("flush", i), this.flush();
|
|
1143
1020
|
}
|
|
1144
1021
|
/**
|
|
1145
1022
|
* Closes the connection.
|
|
@@ -1149,12 +1026,12 @@ class b extends _ {
|
|
|
1149
1026
|
this._onClose("forced close"), this.transport.close();
|
|
1150
1027
|
}, t = () => {
|
|
1151
1028
|
this.off("upgrade", t), this.off("upgradeError", t), e();
|
|
1152
|
-
},
|
|
1029
|
+
}, s = () => {
|
|
1153
1030
|
this.once("upgrade", t), this.once("upgradeError", t);
|
|
1154
1031
|
};
|
|
1155
1032
|
return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
|
|
1156
|
-
this.upgrading ?
|
|
1157
|
-
}) : this.upgrading ?
|
|
1033
|
+
this.upgrading ? s() : e();
|
|
1034
|
+
}) : this.upgrading ? s() : e()), this;
|
|
1158
1035
|
}
|
|
1159
1036
|
/**
|
|
1160
1037
|
* Called upon transport error
|
|
@@ -1173,16 +1050,16 @@ class b extends _ {
|
|
|
1173
1050
|
*/
|
|
1174
1051
|
_onClose(e, t) {
|
|
1175
1052
|
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
|
|
1176
|
-
if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(),
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1053
|
+
if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), M && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
|
|
1054
|
+
const s = x.indexOf(this._offlineEventListener);
|
|
1055
|
+
s !== -1 && x.splice(s, 1);
|
|
1179
1056
|
}
|
|
1180
1057
|
this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
|
|
1181
1058
|
}
|
|
1182
1059
|
}
|
|
1183
1060
|
}
|
|
1184
|
-
b.protocol =
|
|
1185
|
-
class
|
|
1061
|
+
b.protocol = oe;
|
|
1062
|
+
class Ye extends b {
|
|
1186
1063
|
constructor() {
|
|
1187
1064
|
super(...arguments), this._upgrades = [];
|
|
1188
1065
|
}
|
|
@@ -1198,16 +1075,16 @@ class Ke extends b {
|
|
|
1198
1075
|
* @private
|
|
1199
1076
|
*/
|
|
1200
1077
|
_probe(e) {
|
|
1201
|
-
let t = this.createTransport(e),
|
|
1078
|
+
let t = this.createTransport(e), s = !1;
|
|
1202
1079
|
b.priorWebsocketSuccess = !1;
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
if (!
|
|
1206
|
-
if (
|
|
1080
|
+
const i = () => {
|
|
1081
|
+
s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (p) => {
|
|
1082
|
+
if (!s)
|
|
1083
|
+
if (p.type === "pong" && p.data === "probe") {
|
|
1207
1084
|
if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
|
|
1208
1085
|
return;
|
|
1209
1086
|
b.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
|
|
1210
|
-
|
|
1087
|
+
s || this.readyState !== "closed" && (u(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
|
|
1211
1088
|
});
|
|
1212
1089
|
} else {
|
|
1213
1090
|
const v = new Error("probe error");
|
|
@@ -1215,27 +1092,27 @@ class Ke extends b {
|
|
|
1215
1092
|
}
|
|
1216
1093
|
}));
|
|
1217
1094
|
};
|
|
1218
|
-
function
|
|
1219
|
-
|
|
1095
|
+
function r() {
|
|
1096
|
+
s || (s = !0, u(), t.close(), t = null);
|
|
1220
1097
|
}
|
|
1221
|
-
const o = (
|
|
1222
|
-
const v = new Error("probe error: " +
|
|
1223
|
-
v.transport = t.name,
|
|
1098
|
+
const o = (p) => {
|
|
1099
|
+
const v = new Error("probe error: " + p);
|
|
1100
|
+
v.transport = t.name, r(), this.emitReserved("upgradeError", v);
|
|
1224
1101
|
};
|
|
1225
|
-
function
|
|
1102
|
+
function l() {
|
|
1226
1103
|
o("transport closed");
|
|
1227
1104
|
}
|
|
1228
1105
|
function c() {
|
|
1229
1106
|
o("socket closed");
|
|
1230
1107
|
}
|
|
1231
|
-
function p
|
|
1232
|
-
t &&
|
|
1108
|
+
function f(p) {
|
|
1109
|
+
t && p.name !== t.name && r();
|
|
1233
1110
|
}
|
|
1234
1111
|
const u = () => {
|
|
1235
|
-
t.removeListener("open",
|
|
1112
|
+
t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", l), this.off("close", c), this.off("upgrading", f);
|
|
1236
1113
|
};
|
|
1237
|
-
t.once("open",
|
|
1238
|
-
|
|
1114
|
+
t.once("open", i), t.once("error", o), t.once("close", l), this.once("close", c), this.once("upgrading", f), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
|
|
1115
|
+
s || t.open();
|
|
1239
1116
|
}, 200) : t.open();
|
|
1240
1117
|
}
|
|
1241
1118
|
onHandshake(e) {
|
|
@@ -1249,85 +1126,85 @@ class Ke extends b {
|
|
|
1249
1126
|
*/
|
|
1250
1127
|
_filterUpgrades(e) {
|
|
1251
1128
|
const t = [];
|
|
1252
|
-
for (let
|
|
1253
|
-
~this.transports.indexOf(e[
|
|
1129
|
+
for (let s = 0; s < e.length; s++)
|
|
1130
|
+
~this.transports.indexOf(e[s]) && t.push(e[s]);
|
|
1254
1131
|
return t;
|
|
1255
1132
|
}
|
|
1256
1133
|
}
|
|
1257
|
-
let
|
|
1258
|
-
constructor(
|
|
1259
|
-
const
|
|
1260
|
-
(!
|
|
1134
|
+
let Je = class extends Ye {
|
|
1135
|
+
constructor(e, t = {}) {
|
|
1136
|
+
const s = typeof e == "object" ? e : t;
|
|
1137
|
+
(!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((i) => Ve[i]).filter((i) => !!i)), super(e, s);
|
|
1261
1138
|
}
|
|
1262
1139
|
};
|
|
1263
|
-
function
|
|
1264
|
-
let
|
|
1265
|
-
t = t || typeof location < "u" && location,
|
|
1266
|
-
const r =
|
|
1267
|
-
return
|
|
1140
|
+
function Qe(n, e = "", t) {
|
|
1141
|
+
let s = n;
|
|
1142
|
+
t = t || typeof location < "u" && location, n == null && (n = t.protocol + "//" + t.host), typeof n == "string" && (n.charAt(0) === "/" && (n.charAt(1) === "/" ? n = t.protocol + n : n = t.host + n), /^(https?|wss?):\/\//.test(n) || (typeof t < "u" ? n = t.protocol + "//" + n : n = "https://" + n), s = U(n)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
|
|
1143
|
+
const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
|
|
1144
|
+
return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
|
|
1268
1145
|
}
|
|
1269
|
-
const
|
|
1270
|
-
function z(
|
|
1271
|
-
return
|
|
1146
|
+
const Xe = typeof ArrayBuffer == "function", je = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, _e = Object.prototype.toString, Ge = typeof Blob == "function" || typeof Blob < "u" && _e.call(Blob) === "[object BlobConstructor]", Ze = typeof File == "function" || typeof File < "u" && _e.call(File) === "[object FileConstructor]";
|
|
1147
|
+
function z(n) {
|
|
1148
|
+
return Xe && (n instanceof ArrayBuffer || je(n)) || Ge && n instanceof Blob || Ze && n instanceof File;
|
|
1272
1149
|
}
|
|
1273
|
-
function R(
|
|
1274
|
-
if (!
|
|
1150
|
+
function R(n, e) {
|
|
1151
|
+
if (!n || typeof n != "object")
|
|
1275
1152
|
return !1;
|
|
1276
|
-
if (Array.isArray(
|
|
1277
|
-
for (let t = 0,
|
|
1278
|
-
if (R(
|
|
1153
|
+
if (Array.isArray(n)) {
|
|
1154
|
+
for (let t = 0, s = n.length; t < s; t++)
|
|
1155
|
+
if (R(n[t]))
|
|
1279
1156
|
return !0;
|
|
1280
1157
|
return !1;
|
|
1281
1158
|
}
|
|
1282
|
-
if (z(
|
|
1159
|
+
if (z(n))
|
|
1283
1160
|
return !0;
|
|
1284
|
-
if (
|
|
1285
|
-
return R(
|
|
1286
|
-
for (const t in
|
|
1287
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
1161
|
+
if (n.toJSON && typeof n.toJSON == "function" && arguments.length === 1)
|
|
1162
|
+
return R(n.toJSON(), !0);
|
|
1163
|
+
for (const t in n)
|
|
1164
|
+
if (Object.prototype.hasOwnProperty.call(n, t) && R(n[t]))
|
|
1288
1165
|
return !0;
|
|
1289
1166
|
return !1;
|
|
1290
1167
|
}
|
|
1291
|
-
function et(
|
|
1292
|
-
const e = [], t =
|
|
1293
|
-
return
|
|
1168
|
+
function et(n) {
|
|
1169
|
+
const e = [], t = n.data, s = n;
|
|
1170
|
+
return s.data = F(t, e), s.attachments = e.length, { packet: s, buffers: e };
|
|
1294
1171
|
}
|
|
1295
|
-
function
|
|
1296
|
-
if (!
|
|
1297
|
-
return
|
|
1298
|
-
if (z(
|
|
1172
|
+
function F(n, e) {
|
|
1173
|
+
if (!n)
|
|
1174
|
+
return n;
|
|
1175
|
+
if (z(n)) {
|
|
1299
1176
|
const t = { _placeholder: !0, num: e.length };
|
|
1300
|
-
return e.push(
|
|
1301
|
-
} else if (Array.isArray(
|
|
1302
|
-
const t = new Array(
|
|
1303
|
-
for (let
|
|
1304
|
-
t[
|
|
1177
|
+
return e.push(n), t;
|
|
1178
|
+
} else if (Array.isArray(n)) {
|
|
1179
|
+
const t = new Array(n.length);
|
|
1180
|
+
for (let s = 0; s < n.length; s++)
|
|
1181
|
+
t[s] = F(n[s], e);
|
|
1305
1182
|
return t;
|
|
1306
|
-
} else if (typeof
|
|
1183
|
+
} else if (typeof n == "object" && !(n instanceof Date)) {
|
|
1307
1184
|
const t = {};
|
|
1308
|
-
for (const
|
|
1309
|
-
Object.prototype.hasOwnProperty.call(
|
|
1185
|
+
for (const s in n)
|
|
1186
|
+
Object.prototype.hasOwnProperty.call(n, s) && (t[s] = F(n[s], e));
|
|
1310
1187
|
return t;
|
|
1311
1188
|
}
|
|
1312
|
-
return
|
|
1189
|
+
return n;
|
|
1313
1190
|
}
|
|
1314
|
-
function tt(
|
|
1315
|
-
return
|
|
1191
|
+
function tt(n, e) {
|
|
1192
|
+
return n.data = $(n.data, e), delete n.attachments, n;
|
|
1316
1193
|
}
|
|
1317
|
-
function
|
|
1318
|
-
if (!
|
|
1319
|
-
return
|
|
1320
|
-
if (
|
|
1321
|
-
if (typeof
|
|
1322
|
-
return e[
|
|
1194
|
+
function $(n, e) {
|
|
1195
|
+
if (!n)
|
|
1196
|
+
return n;
|
|
1197
|
+
if (n && n._placeholder === !0) {
|
|
1198
|
+
if (typeof n.num == "number" && n.num >= 0 && n.num < e.length)
|
|
1199
|
+
return e[n.num];
|
|
1323
1200
|
throw new Error("illegal attachments");
|
|
1324
|
-
} else if (Array.isArray(
|
|
1325
|
-
for (let t = 0; t <
|
|
1326
|
-
|
|
1327
|
-
else if (typeof
|
|
1328
|
-
for (const t in
|
|
1329
|
-
Object.prototype.hasOwnProperty.call(
|
|
1330
|
-
return
|
|
1201
|
+
} else if (Array.isArray(n))
|
|
1202
|
+
for (let t = 0; t < n.length; t++)
|
|
1203
|
+
n[t] = $(n[t], e);
|
|
1204
|
+
else if (typeof n == "object")
|
|
1205
|
+
for (const t in n)
|
|
1206
|
+
Object.prototype.hasOwnProperty.call(n, t) && (n[t] = $(n[t], e));
|
|
1207
|
+
return n;
|
|
1331
1208
|
}
|
|
1332
1209
|
const st = [
|
|
1333
1210
|
"connect",
|
|
@@ -1338,11 +1215,11 @@ const st = [
|
|
|
1338
1215
|
"removeListener"
|
|
1339
1216
|
// used by the Node.js EventEmitter
|
|
1340
1217
|
], nt = 5;
|
|
1341
|
-
var
|
|
1342
|
-
(function(
|
|
1343
|
-
|
|
1344
|
-
})(
|
|
1345
|
-
class
|
|
1218
|
+
var h;
|
|
1219
|
+
(function(n) {
|
|
1220
|
+
n[n.CONNECT = 0] = "CONNECT", n[n.DISCONNECT = 1] = "DISCONNECT", n[n.EVENT = 2] = "EVENT", n[n.ACK = 3] = "ACK", n[n.CONNECT_ERROR = 4] = "CONNECT_ERROR", n[n.BINARY_EVENT = 5] = "BINARY_EVENT", n[n.BINARY_ACK = 6] = "BINARY_ACK";
|
|
1221
|
+
})(h || (h = {}));
|
|
1222
|
+
class it {
|
|
1346
1223
|
/**
|
|
1347
1224
|
* Encoder constructor
|
|
1348
1225
|
*
|
|
@@ -1358,8 +1235,8 @@ class rt {
|
|
|
1358
1235
|
* @param {Object} obj - packet object
|
|
1359
1236
|
*/
|
|
1360
1237
|
encode(e) {
|
|
1361
|
-
return (e.type ===
|
|
1362
|
-
type: e.type ===
|
|
1238
|
+
return (e.type === h.EVENT || e.type === h.ACK) && R(e) ? this.encodeAsBinary({
|
|
1239
|
+
type: e.type === h.EVENT ? h.BINARY_EVENT : h.BINARY_ACK,
|
|
1363
1240
|
nsp: e.nsp,
|
|
1364
1241
|
data: e.data,
|
|
1365
1242
|
id: e.id
|
|
@@ -1370,7 +1247,7 @@ class rt {
|
|
|
1370
1247
|
*/
|
|
1371
1248
|
encodeAsString(e) {
|
|
1372
1249
|
let t = "" + e.type;
|
|
1373
|
-
return (e.type ===
|
|
1250
|
+
return (e.type === h.BINARY_EVENT || e.type === h.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
|
|
1374
1251
|
}
|
|
1375
1252
|
/**
|
|
1376
1253
|
* Encode packet as 'buffer sequence' by removing blobs, and
|
|
@@ -1378,14 +1255,14 @@ class rt {
|
|
|
1378
1255
|
* a list of buffers.
|
|
1379
1256
|
*/
|
|
1380
1257
|
encodeAsBinary(e) {
|
|
1381
|
-
const t = et(e),
|
|
1382
|
-
return
|
|
1258
|
+
const t = et(e), s = this.encodeAsString(t.packet), i = t.buffers;
|
|
1259
|
+
return i.unshift(s), i;
|
|
1383
1260
|
}
|
|
1384
1261
|
}
|
|
1385
|
-
function
|
|
1386
|
-
return Object.prototype.toString.call(
|
|
1262
|
+
function G(n) {
|
|
1263
|
+
return Object.prototype.toString.call(n) === "[object Object]";
|
|
1387
1264
|
}
|
|
1388
|
-
class
|
|
1265
|
+
class Y extends _ {
|
|
1389
1266
|
/**
|
|
1390
1267
|
* Decoder constructor
|
|
1391
1268
|
*
|
|
@@ -1405,8 +1282,8 @@ class K extends _ {
|
|
|
1405
1282
|
if (this.reconstructor)
|
|
1406
1283
|
throw new Error("got plaintext data when reconstructing a packet");
|
|
1407
1284
|
t = this.decodeString(e);
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1285
|
+
const s = t.type === h.BINARY_EVENT;
|
|
1286
|
+
s || t.type === h.BINARY_ACK ? (t.type = s ? h.EVENT : h.ACK, this.reconstructor = new rt(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
|
|
1410
1287
|
} else if (z(e) || e.base64)
|
|
1411
1288
|
if (this.reconstructor)
|
|
1412
1289
|
t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
|
|
@@ -1423,30 +1300,30 @@ class K extends _ {
|
|
|
1423
1300
|
*/
|
|
1424
1301
|
decodeString(e) {
|
|
1425
1302
|
let t = 0;
|
|
1426
|
-
const
|
|
1303
|
+
const s = {
|
|
1427
1304
|
type: Number(e.charAt(0))
|
|
1428
1305
|
};
|
|
1429
|
-
if (
|
|
1430
|
-
throw new Error("unknown packet type " +
|
|
1431
|
-
if (
|
|
1432
|
-
const
|
|
1306
|
+
if (h[s.type] === void 0)
|
|
1307
|
+
throw new Error("unknown packet type " + s.type);
|
|
1308
|
+
if (s.type === h.BINARY_EVENT || s.type === h.BINARY_ACK) {
|
|
1309
|
+
const r = t + 1;
|
|
1433
1310
|
for (; e.charAt(++t) !== "-" && t != e.length; )
|
|
1434
1311
|
;
|
|
1435
|
-
const o = e.substring(
|
|
1312
|
+
const o = e.substring(r, t);
|
|
1436
1313
|
if (o != Number(o) || e.charAt(t) !== "-")
|
|
1437
1314
|
throw new Error("Illegal attachments");
|
|
1438
|
-
|
|
1315
|
+
s.attachments = Number(o);
|
|
1439
1316
|
}
|
|
1440
1317
|
if (e.charAt(t + 1) === "/") {
|
|
1441
|
-
const
|
|
1318
|
+
const r = t + 1;
|
|
1442
1319
|
for (; ++t && !(e.charAt(t) === "," || t === e.length); )
|
|
1443
1320
|
;
|
|
1444
|
-
|
|
1321
|
+
s.nsp = e.substring(r, t);
|
|
1445
1322
|
} else
|
|
1446
|
-
|
|
1447
|
-
const
|
|
1448
|
-
if (
|
|
1449
|
-
const
|
|
1323
|
+
s.nsp = "/";
|
|
1324
|
+
const i = e.charAt(t + 1);
|
|
1325
|
+
if (i !== "" && Number(i) == i) {
|
|
1326
|
+
const r = t + 1;
|
|
1450
1327
|
for (; ++t; ) {
|
|
1451
1328
|
const o = e.charAt(t);
|
|
1452
1329
|
if (o == null || Number(o) != o) {
|
|
@@ -1456,16 +1333,16 @@ class K extends _ {
|
|
|
1456
1333
|
if (t === e.length)
|
|
1457
1334
|
break;
|
|
1458
1335
|
}
|
|
1459
|
-
|
|
1336
|
+
s.id = Number(e.substring(r, t + 1));
|
|
1460
1337
|
}
|
|
1461
1338
|
if (e.charAt(++t)) {
|
|
1462
|
-
const
|
|
1463
|
-
if (
|
|
1464
|
-
|
|
1339
|
+
const r = this.tryParse(e.substr(t));
|
|
1340
|
+
if (Y.isPayloadValid(s.type, r))
|
|
1341
|
+
s.data = r;
|
|
1465
1342
|
else
|
|
1466
1343
|
throw new Error("invalid payload");
|
|
1467
1344
|
}
|
|
1468
|
-
return
|
|
1345
|
+
return s;
|
|
1469
1346
|
}
|
|
1470
1347
|
tryParse(e) {
|
|
1471
1348
|
try {
|
|
@@ -1476,17 +1353,17 @@ class K extends _ {
|
|
|
1476
1353
|
}
|
|
1477
1354
|
static isPayloadValid(e, t) {
|
|
1478
1355
|
switch (e) {
|
|
1479
|
-
case
|
|
1480
|
-
return
|
|
1481
|
-
case
|
|
1356
|
+
case h.CONNECT:
|
|
1357
|
+
return G(t);
|
|
1358
|
+
case h.DISCONNECT:
|
|
1482
1359
|
return t === void 0;
|
|
1483
|
-
case
|
|
1484
|
-
return typeof t == "string" ||
|
|
1485
|
-
case
|
|
1486
|
-
case
|
|
1360
|
+
case h.CONNECT_ERROR:
|
|
1361
|
+
return typeof t == "string" || G(t);
|
|
1362
|
+
case h.EVENT:
|
|
1363
|
+
case h.BINARY_EVENT:
|
|
1487
1364
|
return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && st.indexOf(t[0]) === -1);
|
|
1488
|
-
case
|
|
1489
|
-
case
|
|
1365
|
+
case h.ACK:
|
|
1366
|
+
case h.BINARY_ACK:
|
|
1490
1367
|
return Array.isArray(t);
|
|
1491
1368
|
}
|
|
1492
1369
|
}
|
|
@@ -1497,7 +1374,7 @@ class K extends _ {
|
|
|
1497
1374
|
this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
|
|
1498
1375
|
}
|
|
1499
1376
|
}
|
|
1500
|
-
class
|
|
1377
|
+
class rt {
|
|
1501
1378
|
constructor(e) {
|
|
1502
1379
|
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
1503
1380
|
}
|
|
@@ -1525,16 +1402,16 @@ class it {
|
|
|
1525
1402
|
}
|
|
1526
1403
|
const ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1527
1404
|
__proto__: null,
|
|
1528
|
-
Decoder:
|
|
1529
|
-
Encoder:
|
|
1405
|
+
Decoder: Y,
|
|
1406
|
+
Encoder: it,
|
|
1530
1407
|
get PacketType() {
|
|
1531
|
-
return
|
|
1408
|
+
return h;
|
|
1532
1409
|
},
|
|
1533
1410
|
protocol: nt
|
|
1534
1411
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1535
|
-
function
|
|
1536
|
-
return
|
|
1537
|
-
|
|
1412
|
+
function y(n, e, t) {
|
|
1413
|
+
return n.on(e, t), function() {
|
|
1414
|
+
n.off(e, t);
|
|
1538
1415
|
};
|
|
1539
1416
|
}
|
|
1540
1417
|
const at = Object.freeze({
|
|
@@ -1546,12 +1423,12 @@ const at = Object.freeze({
|
|
|
1546
1423
|
newListener: 1,
|
|
1547
1424
|
removeListener: 1
|
|
1548
1425
|
});
|
|
1549
|
-
|
|
1426
|
+
class fe extends _ {
|
|
1550
1427
|
/**
|
|
1551
1428
|
* `Socket` constructor.
|
|
1552
1429
|
*/
|
|
1553
|
-
constructor(
|
|
1554
|
-
super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io =
|
|
1430
|
+
constructor(e, t, s) {
|
|
1431
|
+
super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, s && s.auth && (this.auth = s.auth), this._opts = Object.assign({}, s), this.io._autoConnect && this.open();
|
|
1555
1432
|
}
|
|
1556
1433
|
/**
|
|
1557
1434
|
* Whether the socket is currently disconnected
|
|
@@ -1578,12 +1455,12 @@ let de = class extends _ {
|
|
|
1578
1455
|
subEvents() {
|
|
1579
1456
|
if (this.subs)
|
|
1580
1457
|
return;
|
|
1581
|
-
const
|
|
1458
|
+
const e = this.io;
|
|
1582
1459
|
this.subs = [
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1460
|
+
y(e, "open", this.onopen.bind(this)),
|
|
1461
|
+
y(e, "packet", this.onpacket.bind(this)),
|
|
1462
|
+
y(e, "error", this.onerror.bind(this)),
|
|
1463
|
+
y(e, "close", this.onclose.bind(this))
|
|
1587
1464
|
];
|
|
1588
1465
|
}
|
|
1589
1466
|
/**
|
|
@@ -1640,8 +1517,8 @@ let de = class extends _ {
|
|
|
1640
1517
|
*
|
|
1641
1518
|
* @return self
|
|
1642
1519
|
*/
|
|
1643
|
-
send(...
|
|
1644
|
-
return
|
|
1520
|
+
send(...e) {
|
|
1521
|
+
return e.unshift("message"), this.emit.apply(this, e), this;
|
|
1645
1522
|
}
|
|
1646
1523
|
/**
|
|
1647
1524
|
* Override `emit`.
|
|
@@ -1660,42 +1537,42 @@ let de = class extends _ {
|
|
|
1660
1537
|
*
|
|
1661
1538
|
* @return self
|
|
1662
1539
|
*/
|
|
1663
|
-
emit(
|
|
1664
|
-
var
|
|
1665
|
-
if (at.hasOwnProperty(
|
|
1666
|
-
throw new Error('"' +
|
|
1667
|
-
if (
|
|
1668
|
-
return this._addToQueue(
|
|
1669
|
-
const
|
|
1670
|
-
type:
|
|
1671
|
-
data:
|
|
1540
|
+
emit(e, ...t) {
|
|
1541
|
+
var s, i, r;
|
|
1542
|
+
if (at.hasOwnProperty(e))
|
|
1543
|
+
throw new Error('"' + e.toString() + '" is a reserved event name');
|
|
1544
|
+
if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
|
|
1545
|
+
return this._addToQueue(t), this;
|
|
1546
|
+
const o = {
|
|
1547
|
+
type: h.EVENT,
|
|
1548
|
+
data: t
|
|
1672
1549
|
};
|
|
1673
|
-
if (
|
|
1674
|
-
const
|
|
1675
|
-
this._registerAckCallback(
|
|
1550
|
+
if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
|
|
1551
|
+
const u = this.ids++, p = t.pop();
|
|
1552
|
+
this._registerAckCallback(u, p), o.id = u;
|
|
1676
1553
|
}
|
|
1677
|
-
const
|
|
1678
|
-
return this.flags.volatile && !
|
|
1554
|
+
const l = (i = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || i === void 0 ? void 0 : i.writable, c = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
|
|
1555
|
+
return this.flags.volatile && !l || (c ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
|
|
1679
1556
|
}
|
|
1680
1557
|
/**
|
|
1681
1558
|
* @private
|
|
1682
1559
|
*/
|
|
1683
|
-
_registerAckCallback(
|
|
1684
|
-
var
|
|
1685
|
-
const
|
|
1686
|
-
if (
|
|
1687
|
-
this.acks[
|
|
1560
|
+
_registerAckCallback(e, t) {
|
|
1561
|
+
var s;
|
|
1562
|
+
const i = (s = this.flags.timeout) !== null && s !== void 0 ? s : this._opts.ackTimeout;
|
|
1563
|
+
if (i === void 0) {
|
|
1564
|
+
this.acks[e] = t;
|
|
1688
1565
|
return;
|
|
1689
1566
|
}
|
|
1690
1567
|
const r = this.io.setTimeoutFn(() => {
|
|
1691
|
-
delete this.acks[
|
|
1692
|
-
for (let
|
|
1693
|
-
this.sendBuffer[
|
|
1694
|
-
|
|
1695
|
-
},
|
|
1696
|
-
this.io.clearTimeoutFn(r),
|
|
1568
|
+
delete this.acks[e];
|
|
1569
|
+
for (let l = 0; l < this.sendBuffer.length; l++)
|
|
1570
|
+
this.sendBuffer[l].id === e && this.sendBuffer.splice(l, 1);
|
|
1571
|
+
t.call(this, new Error("operation has timed out"));
|
|
1572
|
+
}, i), o = (...l) => {
|
|
1573
|
+
this.io.clearTimeoutFn(r), t.apply(this, l);
|
|
1697
1574
|
};
|
|
1698
|
-
|
|
1575
|
+
o.withError = !0, this.acks[e] = o;
|
|
1699
1576
|
}
|
|
1700
1577
|
/**
|
|
1701
1578
|
* Emits an event and waits for an acknowledgement
|
|
@@ -1713,10 +1590,10 @@ let de = class extends _ {
|
|
|
1713
1590
|
*
|
|
1714
1591
|
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
1715
1592
|
*/
|
|
1716
|
-
emitWithAck(
|
|
1717
|
-
return new Promise((
|
|
1718
|
-
const r = (
|
|
1719
|
-
r.withError = !0,
|
|
1593
|
+
emitWithAck(e, ...t) {
|
|
1594
|
+
return new Promise((s, i) => {
|
|
1595
|
+
const r = (o, l) => o ? i(o) : s(l);
|
|
1596
|
+
r.withError = !0, t.push(r), this.emit(e, ...t);
|
|
1720
1597
|
});
|
|
1721
1598
|
}
|
|
1722
1599
|
/**
|
|
@@ -1724,17 +1601,17 @@ let de = class extends _ {
|
|
|
1724
1601
|
* @param args
|
|
1725
1602
|
* @private
|
|
1726
1603
|
*/
|
|
1727
|
-
_addToQueue(
|
|
1728
|
-
let
|
|
1729
|
-
typeof
|
|
1730
|
-
const
|
|
1604
|
+
_addToQueue(e) {
|
|
1605
|
+
let t;
|
|
1606
|
+
typeof e[e.length - 1] == "function" && (t = e.pop());
|
|
1607
|
+
const s = {
|
|
1731
1608
|
id: this._queueSeq++,
|
|
1732
1609
|
tryCount: 0,
|
|
1733
1610
|
pending: !1,
|
|
1734
|
-
args:
|
|
1611
|
+
args: e,
|
|
1735
1612
|
flags: Object.assign({ fromQueue: !0 }, this.flags)
|
|
1736
1613
|
};
|
|
1737
|
-
|
|
1614
|
+
e.push((i, ...r) => s !== this._queue[0] ? void 0 : (i !== null ? s.tryCount > this._opts.retries && (this._queue.shift(), t && t(i)) : (this._queue.shift(), t && t(null, ...r)), s.pending = !1, this._drainQueue())), this._queue.push(s), this._drainQueue();
|
|
1738
1615
|
}
|
|
1739
1616
|
/**
|
|
1740
1617
|
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
@@ -1742,11 +1619,11 @@ let de = class extends _ {
|
|
|
1742
1619
|
*
|
|
1743
1620
|
* @private
|
|
1744
1621
|
*/
|
|
1745
|
-
_drainQueue(
|
|
1622
|
+
_drainQueue(e = !1) {
|
|
1746
1623
|
if (!this.connected || this._queue.length === 0)
|
|
1747
1624
|
return;
|
|
1748
|
-
const
|
|
1749
|
-
|
|
1625
|
+
const t = this._queue[0];
|
|
1626
|
+
t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
|
|
1750
1627
|
}
|
|
1751
1628
|
/**
|
|
1752
1629
|
* Sends a packet.
|
|
@@ -1754,8 +1631,8 @@ let de = class extends _ {
|
|
|
1754
1631
|
* @param packet
|
|
1755
1632
|
* @private
|
|
1756
1633
|
*/
|
|
1757
|
-
packet(
|
|
1758
|
-
|
|
1634
|
+
packet(e) {
|
|
1635
|
+
e.nsp = this.nsp, this.io._packet(e);
|
|
1759
1636
|
}
|
|
1760
1637
|
/**
|
|
1761
1638
|
* Called upon engine `open`.
|
|
@@ -1763,8 +1640,8 @@ let de = class extends _ {
|
|
|
1763
1640
|
* @private
|
|
1764
1641
|
*/
|
|
1765
1642
|
onopen() {
|
|
1766
|
-
typeof this.auth == "function" ? this.auth((
|
|
1767
|
-
this._sendConnectPacket(
|
|
1643
|
+
typeof this.auth == "function" ? this.auth((e) => {
|
|
1644
|
+
this._sendConnectPacket(e);
|
|
1768
1645
|
}) : this._sendConnectPacket(this.auth);
|
|
1769
1646
|
}
|
|
1770
1647
|
/**
|
|
@@ -1773,10 +1650,10 @@ let de = class extends _ {
|
|
|
1773
1650
|
* @param data
|
|
1774
1651
|
* @private
|
|
1775
1652
|
*/
|
|
1776
|
-
_sendConnectPacket(
|
|
1653
|
+
_sendConnectPacket(e) {
|
|
1777
1654
|
this.packet({
|
|
1778
|
-
type:
|
|
1779
|
-
data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset },
|
|
1655
|
+
type: h.CONNECT,
|
|
1656
|
+
data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
|
|
1780
1657
|
});
|
|
1781
1658
|
}
|
|
1782
1659
|
/**
|
|
@@ -1785,8 +1662,8 @@ let de = class extends _ {
|
|
|
1785
1662
|
* @param err
|
|
1786
1663
|
* @private
|
|
1787
1664
|
*/
|
|
1788
|
-
onerror(
|
|
1789
|
-
this.connected || this.emitReserved("connect_error",
|
|
1665
|
+
onerror(e) {
|
|
1666
|
+
this.connected || this.emitReserved("connect_error", e);
|
|
1790
1667
|
}
|
|
1791
1668
|
/**
|
|
1792
1669
|
* Called upon engine `close`.
|
|
@@ -1795,8 +1672,8 @@ let de = class extends _ {
|
|
|
1795
1672
|
* @param description
|
|
1796
1673
|
* @private
|
|
1797
1674
|
*/
|
|
1798
|
-
onclose(
|
|
1799
|
-
this.connected = !1, delete this.id, this.emitReserved("disconnect",
|
|
1675
|
+
onclose(e, t) {
|
|
1676
|
+
this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
|
|
1800
1677
|
}
|
|
1801
1678
|
/**
|
|
1802
1679
|
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
@@ -1805,10 +1682,10 @@ let de = class extends _ {
|
|
|
1805
1682
|
* @private
|
|
1806
1683
|
*/
|
|
1807
1684
|
_clearAcks() {
|
|
1808
|
-
Object.keys(this.acks).forEach((
|
|
1809
|
-
if (!this.sendBuffer.some((
|
|
1810
|
-
const
|
|
1811
|
-
delete this.acks[
|
|
1685
|
+
Object.keys(this.acks).forEach((e) => {
|
|
1686
|
+
if (!this.sendBuffer.some((s) => String(s.id) === e)) {
|
|
1687
|
+
const s = this.acks[e];
|
|
1688
|
+
delete this.acks[e], s.withError && s.call(this, new Error("socket has been disconnected"));
|
|
1812
1689
|
}
|
|
1813
1690
|
});
|
|
1814
1691
|
}
|
|
@@ -1818,27 +1695,27 @@ let de = class extends _ {
|
|
|
1818
1695
|
* @param packet
|
|
1819
1696
|
* @private
|
|
1820
1697
|
*/
|
|
1821
|
-
onpacket(
|
|
1822
|
-
if (
|
|
1823
|
-
switch (
|
|
1824
|
-
case
|
|
1825
|
-
|
|
1698
|
+
onpacket(e) {
|
|
1699
|
+
if (e.nsp === this.nsp)
|
|
1700
|
+
switch (e.type) {
|
|
1701
|
+
case h.CONNECT:
|
|
1702
|
+
e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
|
1826
1703
|
break;
|
|
1827
|
-
case
|
|
1828
|
-
case
|
|
1829
|
-
this.onevent(
|
|
1704
|
+
case h.EVENT:
|
|
1705
|
+
case h.BINARY_EVENT:
|
|
1706
|
+
this.onevent(e);
|
|
1830
1707
|
break;
|
|
1831
|
-
case
|
|
1832
|
-
case
|
|
1833
|
-
this.onack(
|
|
1708
|
+
case h.ACK:
|
|
1709
|
+
case h.BINARY_ACK:
|
|
1710
|
+
this.onack(e);
|
|
1834
1711
|
break;
|
|
1835
|
-
case
|
|
1712
|
+
case h.DISCONNECT:
|
|
1836
1713
|
this.ondisconnect();
|
|
1837
1714
|
break;
|
|
1838
|
-
case
|
|
1715
|
+
case h.CONNECT_ERROR:
|
|
1839
1716
|
this.destroy();
|
|
1840
|
-
const
|
|
1841
|
-
|
|
1717
|
+
const s = new Error(e.data.message);
|
|
1718
|
+
s.data = e.data.data, this.emitReserved("connect_error", s);
|
|
1842
1719
|
break;
|
|
1843
1720
|
}
|
|
1844
1721
|
}
|
|
@@ -1848,31 +1725,31 @@ let de = class extends _ {
|
|
|
1848
1725
|
* @param packet
|
|
1849
1726
|
* @private
|
|
1850
1727
|
*/
|
|
1851
|
-
onevent(
|
|
1852
|
-
const
|
|
1853
|
-
|
|
1728
|
+
onevent(e) {
|
|
1729
|
+
const t = e.data || [];
|
|
1730
|
+
e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
|
|
1854
1731
|
}
|
|
1855
|
-
emitEvent(
|
|
1732
|
+
emitEvent(e) {
|
|
1856
1733
|
if (this._anyListeners && this._anyListeners.length) {
|
|
1857
|
-
const
|
|
1858
|
-
for (const
|
|
1859
|
-
|
|
1734
|
+
const t = this._anyListeners.slice();
|
|
1735
|
+
for (const s of t)
|
|
1736
|
+
s.apply(this, e);
|
|
1860
1737
|
}
|
|
1861
|
-
super.emit.apply(this,
|
|
1738
|
+
super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
|
|
1862
1739
|
}
|
|
1863
1740
|
/**
|
|
1864
1741
|
* Produces an ack callback to emit with an event.
|
|
1865
1742
|
*
|
|
1866
1743
|
* @private
|
|
1867
1744
|
*/
|
|
1868
|
-
ack(
|
|
1869
|
-
const
|
|
1870
|
-
let
|
|
1871
|
-
return function(...
|
|
1872
|
-
|
|
1873
|
-
type:
|
|
1874
|
-
id:
|
|
1875
|
-
data:
|
|
1745
|
+
ack(e) {
|
|
1746
|
+
const t = this;
|
|
1747
|
+
let s = !1;
|
|
1748
|
+
return function(...i) {
|
|
1749
|
+
s || (s = !0, t.packet({
|
|
1750
|
+
type: h.ACK,
|
|
1751
|
+
id: e,
|
|
1752
|
+
data: i
|
|
1876
1753
|
}));
|
|
1877
1754
|
};
|
|
1878
1755
|
}
|
|
@@ -1882,17 +1759,17 @@ let de = class extends _ {
|
|
|
1882
1759
|
* @param packet
|
|
1883
1760
|
* @private
|
|
1884
1761
|
*/
|
|
1885
|
-
onack(
|
|
1886
|
-
const
|
|
1887
|
-
typeof
|
|
1762
|
+
onack(e) {
|
|
1763
|
+
const t = this.acks[e.id];
|
|
1764
|
+
typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
|
|
1888
1765
|
}
|
|
1889
1766
|
/**
|
|
1890
1767
|
* Called upon server connect.
|
|
1891
1768
|
*
|
|
1892
1769
|
* @private
|
|
1893
1770
|
*/
|
|
1894
|
-
onconnect(
|
|
1895
|
-
this.id =
|
|
1771
|
+
onconnect(e, t) {
|
|
1772
|
+
this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this.emitReserved("connect"), this._drainQueue(!0);
|
|
1896
1773
|
}
|
|
1897
1774
|
/**
|
|
1898
1775
|
* Emit buffered events (received and emitted).
|
|
@@ -1900,8 +1777,8 @@ let de = class extends _ {
|
|
|
1900
1777
|
* @private
|
|
1901
1778
|
*/
|
|
1902
1779
|
emitBuffered() {
|
|
1903
|
-
this.receiveBuffer.forEach((
|
|
1904
|
-
this.notifyOutgoingListeners(
|
|
1780
|
+
this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
|
|
1781
|
+
this.notifyOutgoingListeners(e), this.packet(e);
|
|
1905
1782
|
}), this.sendBuffer = [];
|
|
1906
1783
|
}
|
|
1907
1784
|
/**
|
|
@@ -1920,7 +1797,7 @@ let de = class extends _ {
|
|
|
1920
1797
|
* @private
|
|
1921
1798
|
*/
|
|
1922
1799
|
destroy() {
|
|
1923
|
-
this.subs && (this.subs.forEach((
|
|
1800
|
+
this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
|
|
1924
1801
|
}
|
|
1925
1802
|
/**
|
|
1926
1803
|
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
@@ -1939,7 +1816,7 @@ let de = class extends _ {
|
|
|
1939
1816
|
* @return self
|
|
1940
1817
|
*/
|
|
1941
1818
|
disconnect() {
|
|
1942
|
-
return this.connected && this.packet({ type:
|
|
1819
|
+
return this.connected && this.packet({ type: h.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
|
|
1943
1820
|
}
|
|
1944
1821
|
/**
|
|
1945
1822
|
* Alias for {@link disconnect()}.
|
|
@@ -1958,8 +1835,8 @@ let de = class extends _ {
|
|
|
1958
1835
|
* @param compress - if `true`, compresses the sending data
|
|
1959
1836
|
* @return self
|
|
1960
1837
|
*/
|
|
1961
|
-
compress(
|
|
1962
|
-
return this.flags.compress =
|
|
1838
|
+
compress(e) {
|
|
1839
|
+
return this.flags.compress = e, this;
|
|
1963
1840
|
}
|
|
1964
1841
|
/**
|
|
1965
1842
|
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
@@ -1986,8 +1863,8 @@ let de = class extends _ {
|
|
|
1986
1863
|
*
|
|
1987
1864
|
* @returns self
|
|
1988
1865
|
*/
|
|
1989
|
-
timeout(
|
|
1990
|
-
return this.flags.timeout =
|
|
1866
|
+
timeout(e) {
|
|
1867
|
+
return this.flags.timeout = e, this;
|
|
1991
1868
|
}
|
|
1992
1869
|
/**
|
|
1993
1870
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
@@ -2000,8 +1877,8 @@ let de = class extends _ {
|
|
|
2000
1877
|
*
|
|
2001
1878
|
* @param listener
|
|
2002
1879
|
*/
|
|
2003
|
-
onAny(
|
|
2004
|
-
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(
|
|
1880
|
+
onAny(e) {
|
|
1881
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
|
|
2005
1882
|
}
|
|
2006
1883
|
/**
|
|
2007
1884
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
@@ -2014,8 +1891,8 @@ let de = class extends _ {
|
|
|
2014
1891
|
*
|
|
2015
1892
|
* @param listener
|
|
2016
1893
|
*/
|
|
2017
|
-
prependAny(
|
|
2018
|
-
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(
|
|
1894
|
+
prependAny(e) {
|
|
1895
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
|
|
2019
1896
|
}
|
|
2020
1897
|
/**
|
|
2021
1898
|
* Removes the listener that will be fired when any event is emitted.
|
|
@@ -2035,14 +1912,14 @@ let de = class extends _ {
|
|
|
2035
1912
|
*
|
|
2036
1913
|
* @param listener
|
|
2037
1914
|
*/
|
|
2038
|
-
offAny(
|
|
1915
|
+
offAny(e) {
|
|
2039
1916
|
if (!this._anyListeners)
|
|
2040
1917
|
return this;
|
|
2041
|
-
if (
|
|
2042
|
-
const
|
|
2043
|
-
for (let
|
|
2044
|
-
if (
|
|
2045
|
-
return
|
|
1918
|
+
if (e) {
|
|
1919
|
+
const t = this._anyListeners;
|
|
1920
|
+
for (let s = 0; s < t.length; s++)
|
|
1921
|
+
if (e === t[s])
|
|
1922
|
+
return t.splice(s, 1), this;
|
|
2046
1923
|
} else
|
|
2047
1924
|
this._anyListeners = [];
|
|
2048
1925
|
return this;
|
|
@@ -2067,8 +1944,8 @@ let de = class extends _ {
|
|
|
2067
1944
|
*
|
|
2068
1945
|
* @param listener
|
|
2069
1946
|
*/
|
|
2070
|
-
onAnyOutgoing(
|
|
2071
|
-
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(
|
|
1947
|
+
onAnyOutgoing(e) {
|
|
1948
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
|
|
2072
1949
|
}
|
|
2073
1950
|
/**
|
|
2074
1951
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
@@ -2083,8 +1960,8 @@ let de = class extends _ {
|
|
|
2083
1960
|
*
|
|
2084
1961
|
* @param listener
|
|
2085
1962
|
*/
|
|
2086
|
-
prependAnyOutgoing(
|
|
2087
|
-
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(
|
|
1963
|
+
prependAnyOutgoing(e) {
|
|
1964
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
|
|
2088
1965
|
}
|
|
2089
1966
|
/**
|
|
2090
1967
|
* Removes the listener that will be fired when any event is emitted.
|
|
@@ -2104,14 +1981,14 @@ let de = class extends _ {
|
|
|
2104
1981
|
*
|
|
2105
1982
|
* @param [listener] - the catch-all listener (optional)
|
|
2106
1983
|
*/
|
|
2107
|
-
offAnyOutgoing(
|
|
1984
|
+
offAnyOutgoing(e) {
|
|
2108
1985
|
if (!this._anyOutgoingListeners)
|
|
2109
1986
|
return this;
|
|
2110
|
-
if (
|
|
2111
|
-
const
|
|
2112
|
-
for (let
|
|
2113
|
-
if (
|
|
2114
|
-
return
|
|
1987
|
+
if (e) {
|
|
1988
|
+
const t = this._anyOutgoingListeners;
|
|
1989
|
+
for (let s = 0; s < t.length; s++)
|
|
1990
|
+
if (e === t[s])
|
|
1991
|
+
return t.splice(s, 1), this;
|
|
2115
1992
|
} else
|
|
2116
1993
|
this._anyOutgoingListeners = [];
|
|
2117
1994
|
return this;
|
|
@@ -2130,47 +2007,47 @@ let de = class extends _ {
|
|
|
2130
2007
|
*
|
|
2131
2008
|
* @private
|
|
2132
2009
|
*/
|
|
2133
|
-
notifyOutgoingListeners(
|
|
2010
|
+
notifyOutgoingListeners(e) {
|
|
2134
2011
|
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
2135
|
-
const
|
|
2136
|
-
for (const
|
|
2137
|
-
|
|
2012
|
+
const t = this._anyOutgoingListeners.slice();
|
|
2013
|
+
for (const s of t)
|
|
2014
|
+
s.apply(this, e.data);
|
|
2138
2015
|
}
|
|
2139
2016
|
}
|
|
2140
|
-
}
|
|
2141
|
-
function w(
|
|
2142
|
-
|
|
2017
|
+
}
|
|
2018
|
+
function w(n) {
|
|
2019
|
+
n = n || {}, this.ms = n.min || 100, this.max = n.max || 1e4, this.factor = n.factor || 2, this.jitter = n.jitter > 0 && n.jitter <= 1 ? n.jitter : 0, this.attempts = 0;
|
|
2143
2020
|
}
|
|
2144
2021
|
w.prototype.duration = function() {
|
|
2145
|
-
var
|
|
2022
|
+
var n = this.ms * Math.pow(this.factor, this.attempts++);
|
|
2146
2023
|
if (this.jitter) {
|
|
2147
|
-
var e = Math.random(), t = Math.floor(e * this.jitter *
|
|
2148
|
-
|
|
2024
|
+
var e = Math.random(), t = Math.floor(e * this.jitter * n);
|
|
2025
|
+
n = (Math.floor(e * 10) & 1) == 0 ? n - t : n + t;
|
|
2149
2026
|
}
|
|
2150
|
-
return Math.min(
|
|
2027
|
+
return Math.min(n, this.max) | 0;
|
|
2151
2028
|
};
|
|
2152
2029
|
w.prototype.reset = function() {
|
|
2153
2030
|
this.attempts = 0;
|
|
2154
2031
|
};
|
|
2155
|
-
w.prototype.setMin = function(
|
|
2156
|
-
this.ms =
|
|
2032
|
+
w.prototype.setMin = function(n) {
|
|
2033
|
+
this.ms = n;
|
|
2157
2034
|
};
|
|
2158
|
-
w.prototype.setMax = function(
|
|
2159
|
-
this.max =
|
|
2035
|
+
w.prototype.setMax = function(n) {
|
|
2036
|
+
this.max = n;
|
|
2160
2037
|
};
|
|
2161
|
-
w.prototype.setJitter = function(
|
|
2162
|
-
this.jitter =
|
|
2038
|
+
w.prototype.setJitter = function(n) {
|
|
2039
|
+
this.jitter = n;
|
|
2163
2040
|
};
|
|
2164
|
-
class
|
|
2041
|
+
class V extends _ {
|
|
2165
2042
|
constructor(e, t) {
|
|
2166
|
-
var
|
|
2167
|
-
super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, L(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((
|
|
2043
|
+
var s;
|
|
2044
|
+
super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, L(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new w({
|
|
2168
2045
|
min: this.reconnectionDelay(),
|
|
2169
2046
|
max: this.reconnectionDelayMax(),
|
|
2170
2047
|
jitter: this.randomizationFactor()
|
|
2171
2048
|
}), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
|
|
2172
|
-
const
|
|
2173
|
-
this.encoder = new
|
|
2049
|
+
const i = t.parser || ot;
|
|
2050
|
+
this.encoder = new i.Encoder(), this.decoder = new i.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
|
|
2174
2051
|
}
|
|
2175
2052
|
reconnection(e) {
|
|
2176
2053
|
return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
|
|
@@ -2212,23 +2089,23 @@ class $ extends _ {
|
|
|
2212
2089
|
open(e) {
|
|
2213
2090
|
if (~this._readyState.indexOf("open"))
|
|
2214
2091
|
return this;
|
|
2215
|
-
this.engine = new
|
|
2216
|
-
const t = this.engine,
|
|
2092
|
+
this.engine = new Je(this.uri, this.opts);
|
|
2093
|
+
const t = this.engine, s = this;
|
|
2217
2094
|
this._readyState = "opening", this.skipReconnect = !1;
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
}),
|
|
2221
|
-
this.cleanup(), this._readyState = "closed", this.emitReserved("error",
|
|
2222
|
-
}, o =
|
|
2095
|
+
const i = y(t, "open", function() {
|
|
2096
|
+
s.onopen(), e && e();
|
|
2097
|
+
}), r = (l) => {
|
|
2098
|
+
this.cleanup(), this._readyState = "closed", this.emitReserved("error", l), e ? e(l) : this.maybeReconnectOnOpen();
|
|
2099
|
+
}, o = y(t, "error", r);
|
|
2223
2100
|
if (this._timeout !== !1) {
|
|
2224
|
-
const
|
|
2225
|
-
|
|
2226
|
-
},
|
|
2101
|
+
const l = this._timeout, c = this.setTimeoutFn(() => {
|
|
2102
|
+
i(), r(new Error("timeout")), t.close();
|
|
2103
|
+
}, l);
|
|
2227
2104
|
this.opts.autoUnref && c.unref(), this.subs.push(() => {
|
|
2228
2105
|
this.clearTimeoutFn(c);
|
|
2229
2106
|
});
|
|
2230
2107
|
}
|
|
2231
|
-
return this.subs.push(
|
|
2108
|
+
return this.subs.push(i), this.subs.push(o), this;
|
|
2232
2109
|
}
|
|
2233
2110
|
/**
|
|
2234
2111
|
* Alias for open()
|
|
@@ -2248,12 +2125,12 @@ class $ extends _ {
|
|
|
2248
2125
|
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
2249
2126
|
const e = this.engine;
|
|
2250
2127
|
this.subs.push(
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2128
|
+
y(e, "ping", this.onping.bind(this)),
|
|
2129
|
+
y(e, "data", this.ondata.bind(this)),
|
|
2130
|
+
y(e, "error", this.onerror.bind(this)),
|
|
2131
|
+
y(e, "close", this.onclose.bind(this)),
|
|
2255
2132
|
// @ts-ignore
|
|
2256
|
-
|
|
2133
|
+
y(this.decoder, "decoded", this.ondecoded.bind(this))
|
|
2257
2134
|
);
|
|
2258
2135
|
}
|
|
2259
2136
|
/**
|
|
@@ -2301,8 +2178,8 @@ class $ extends _ {
|
|
|
2301
2178
|
* @public
|
|
2302
2179
|
*/
|
|
2303
2180
|
socket(e, t) {
|
|
2304
|
-
let
|
|
2305
|
-
return
|
|
2181
|
+
let s = this.nsps[e];
|
|
2182
|
+
return s ? this._autoConnect && !s.active && s.connect() : (s = new fe(this, e, t), this.nsps[e] = s), s;
|
|
2306
2183
|
}
|
|
2307
2184
|
/**
|
|
2308
2185
|
* Called upon a socket close.
|
|
@@ -2312,8 +2189,8 @@ class $ extends _ {
|
|
|
2312
2189
|
*/
|
|
2313
2190
|
_destroy(e) {
|
|
2314
2191
|
const t = Object.keys(this.nsps);
|
|
2315
|
-
for (const
|
|
2316
|
-
if (this.nsps[
|
|
2192
|
+
for (const s of t)
|
|
2193
|
+
if (this.nsps[s].active)
|
|
2317
2194
|
return;
|
|
2318
2195
|
this._close();
|
|
2319
2196
|
}
|
|
@@ -2325,8 +2202,8 @@ class $ extends _ {
|
|
|
2325
2202
|
*/
|
|
2326
2203
|
_packet(e) {
|
|
2327
2204
|
const t = this.encoder.encode(e);
|
|
2328
|
-
for (let
|
|
2329
|
-
this.engine.write(t[
|
|
2205
|
+
for (let s = 0; s < t.length; s++)
|
|
2206
|
+
this.engine.write(t[s], e.options);
|
|
2330
2207
|
}
|
|
2331
2208
|
/**
|
|
2332
2209
|
* Clean up transport subscriptions and packet buffer.
|
|
@@ -2362,8 +2239,8 @@ class $ extends _ {
|
|
|
2362
2239
|
* @private
|
|
2363
2240
|
*/
|
|
2364
2241
|
onclose(e, t) {
|
|
2365
|
-
var
|
|
2366
|
-
this.cleanup(), (
|
|
2242
|
+
var s;
|
|
2243
|
+
this.cleanup(), (s = this.engine) === null || s === void 0 || s.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
|
|
2367
2244
|
}
|
|
2368
2245
|
/**
|
|
2369
2246
|
* Attempt a reconnection.
|
|
@@ -2379,13 +2256,13 @@ class $ extends _ {
|
|
|
2379
2256
|
else {
|
|
2380
2257
|
const t = this.backoff.duration();
|
|
2381
2258
|
this._reconnecting = !0;
|
|
2382
|
-
const
|
|
2383
|
-
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((
|
|
2384
|
-
|
|
2259
|
+
const s = this.setTimeoutFn(() => {
|
|
2260
|
+
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((i) => {
|
|
2261
|
+
i ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", i)) : e.onreconnect();
|
|
2385
2262
|
}));
|
|
2386
2263
|
}, t);
|
|
2387
|
-
this.opts.autoUnref &&
|
|
2388
|
-
this.clearTimeoutFn(
|
|
2264
|
+
this.opts.autoUnref && s.unref(), this.subs.push(() => {
|
|
2265
|
+
this.clearTimeoutFn(s);
|
|
2389
2266
|
});
|
|
2390
2267
|
}
|
|
2391
2268
|
}
|
|
@@ -2399,26 +2276,149 @@ class $ extends _ {
|
|
|
2399
2276
|
this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
|
|
2400
2277
|
}
|
|
2401
2278
|
}
|
|
2402
|
-
const
|
|
2403
|
-
function B(
|
|
2404
|
-
typeof
|
|
2405
|
-
const t =
|
|
2279
|
+
const E = {};
|
|
2280
|
+
function B(n, e) {
|
|
2281
|
+
typeof n == "object" && (e = n, n = void 0), e = e || {};
|
|
2282
|
+
const t = Qe(n, e.path || "/socket.io"), s = t.source, i = t.id, r = t.path, o = E[i] && r in E[i].nsps, l = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
|
|
2406
2283
|
let c;
|
|
2407
|
-
return
|
|
2284
|
+
return l ? c = new V(s, e) : (E[i] || (E[i] = new V(s, e)), c = E[i]), t.query && !e.query && (e.query = t.queryKey), c.socket(t.path, e);
|
|
2408
2285
|
}
|
|
2409
2286
|
Object.assign(B, {
|
|
2410
|
-
Manager:
|
|
2411
|
-
Socket:
|
|
2287
|
+
Manager: V,
|
|
2288
|
+
Socket: fe,
|
|
2412
2289
|
io: B,
|
|
2413
2290
|
connect: B
|
|
2414
2291
|
});
|
|
2292
|
+
class Z extends CustomEvent {
|
|
2293
|
+
constructor(e, t) {
|
|
2294
|
+
super(e, t);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
class pe extends EventTarget {
|
|
2298
|
+
__listeners__ = {
|
|
2299
|
+
debug: !1
|
|
2300
|
+
};
|
|
2301
|
+
__debug__ = !1;
|
|
2302
|
+
__listenersCallbacks__ = [];
|
|
2303
|
+
dispatch(e, t = null) {
|
|
2304
|
+
const s = new Z(e, { detail: t });
|
|
2305
|
+
this.dispatchEvent(s), this.__debug__ && this.dispatchEvent(new Z("debug", { detail: { type: e, data: t } }));
|
|
2306
|
+
}
|
|
2307
|
+
dispatchAsync(e, t = null, s = 100) {
|
|
2308
|
+
const i = this;
|
|
2309
|
+
setTimeout(() => {
|
|
2310
|
+
i.dispatch(e, t);
|
|
2311
|
+
}, s);
|
|
2312
|
+
}
|
|
2313
|
+
on(e, t) {
|
|
2314
|
+
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
|
|
2315
|
+
}
|
|
2316
|
+
off(e, t) {
|
|
2317
|
+
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((s) => !(s.key === e && s.callback === t)), this.removeEventListener(e, t);
|
|
2318
|
+
}
|
|
2319
|
+
serialRegisterAvailableListener(e) {
|
|
2320
|
+
this.__listeners__[e] || (this.__listeners__[e] = !1);
|
|
2321
|
+
}
|
|
2322
|
+
get availableListeners() {
|
|
2323
|
+
return Object.keys(this.__listeners__).sort().map((e) => ({
|
|
2324
|
+
type: e,
|
|
2325
|
+
listening: this.__listeners__[e]
|
|
2326
|
+
}));
|
|
2327
|
+
}
|
|
2328
|
+
removeAllListeners() {
|
|
2329
|
+
for (const e of this.__listenersCallbacks__)
|
|
2330
|
+
["internal:queue"].includes(e.key) || (this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((t) => !(t.key === e.key && t.callback === e.callback)), this.removeEventListener(e.key, e.callback));
|
|
2331
|
+
for (const e of Object.keys(this.__listeners__))
|
|
2332
|
+
this.__listeners__[e] = !1;
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
class a extends pe {
|
|
2336
|
+
static instance;
|
|
2337
|
+
static devices = {};
|
|
2338
|
+
constructor() {
|
|
2339
|
+
super(), ["change"].forEach((e) => {
|
|
2340
|
+
this.serialRegisterAvailableListener(e);
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
static $dispatchChange(e = null) {
|
|
2344
|
+
e && e.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: e });
|
|
2345
|
+
}
|
|
2346
|
+
static typeError(e) {
|
|
2347
|
+
const t = new Error();
|
|
2348
|
+
throw t.message = `Type ${e} is not supported`, t.name = "DeviceTypeError", t;
|
|
2349
|
+
}
|
|
2350
|
+
static registerType(e) {
|
|
2351
|
+
typeof a.devices[e] > "u" && (a.devices = { ...a.devices, [e]: {} });
|
|
2352
|
+
}
|
|
2353
|
+
static add(e) {
|
|
2354
|
+
const t = e.typeDevice;
|
|
2355
|
+
typeof a.devices[t] > "u" && a.registerType(t);
|
|
2356
|
+
const s = e.uuid;
|
|
2357
|
+
if (typeof a.devices[t] > "u" && a.typeError(t), a.devices[t][s])
|
|
2358
|
+
throw new Error(`Device with id ${s} already exists`);
|
|
2359
|
+
return a.devices[t][s] = e, a.$dispatchChange(e), Object.keys(a.devices[t]).indexOf(s);
|
|
2360
|
+
}
|
|
2361
|
+
static get(e, t) {
|
|
2362
|
+
return typeof a.devices[e] > "u" && a.registerType(e), typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t];
|
|
2363
|
+
}
|
|
2364
|
+
static getAll(e = null) {
|
|
2365
|
+
return e === null ? a.devices : (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e]);
|
|
2366
|
+
}
|
|
2367
|
+
static getList() {
|
|
2368
|
+
return Object.values(a.devices).map((e) => Object.values(e)).flat();
|
|
2369
|
+
}
|
|
2370
|
+
static getByNumber(e, t) {
|
|
2371
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((s) => s.deviceNumber === t) ?? null;
|
|
2372
|
+
}
|
|
2373
|
+
static getCustom(e, t = 1) {
|
|
2374
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((s) => s.deviceNumber === t) ?? null;
|
|
2375
|
+
}
|
|
2376
|
+
static async connectToAll() {
|
|
2377
|
+
const e = a.getList();
|
|
2378
|
+
for (const t of e)
|
|
2379
|
+
t.isConnected || await t.connect().catch(console.warn);
|
|
2380
|
+
return Promise.resolve(a.areAllConnected());
|
|
2381
|
+
}
|
|
2382
|
+
static async disconnectAll() {
|
|
2383
|
+
const e = a.getList();
|
|
2384
|
+
for (const t of e)
|
|
2385
|
+
t.isDisconnected || await t.disconnect().catch(console.warn);
|
|
2386
|
+
return Promise.resolve(a.areAllDisconnected());
|
|
2387
|
+
}
|
|
2388
|
+
static async areAllConnected() {
|
|
2389
|
+
const e = a.getList();
|
|
2390
|
+
for (const t of e)
|
|
2391
|
+
if (!t.isConnected) return Promise.resolve(!1);
|
|
2392
|
+
return Promise.resolve(!0);
|
|
2393
|
+
}
|
|
2394
|
+
static async areAllDisconnected() {
|
|
2395
|
+
const e = a.getList();
|
|
2396
|
+
for (const t of e)
|
|
2397
|
+
if (!t.isDisconnected) return Promise.resolve(!1);
|
|
2398
|
+
return Promise.resolve(!0);
|
|
2399
|
+
}
|
|
2400
|
+
static async getAllConnected() {
|
|
2401
|
+
const e = a.getList();
|
|
2402
|
+
return Promise.resolve(e.filter((t) => t.isConnected));
|
|
2403
|
+
}
|
|
2404
|
+
static async getAllDisconnected() {
|
|
2405
|
+
const e = a.getList();
|
|
2406
|
+
return Promise.resolve(e.filter((t) => t.isDisconnected));
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
a.instance || (a.instance = new a());
|
|
2410
|
+
function ee(n = 100) {
|
|
2411
|
+
return new Promise(
|
|
2412
|
+
(e) => setTimeout(() => e(), n)
|
|
2413
|
+
);
|
|
2414
|
+
}
|
|
2415
2415
|
class ct {
|
|
2416
2416
|
#t = "http://localhost:3000";
|
|
2417
2417
|
#s = {
|
|
2418
2418
|
transports: ["websocket"]
|
|
2419
2419
|
};
|
|
2420
2420
|
#e;
|
|
2421
|
-
#
|
|
2421
|
+
#r = !1;
|
|
2422
2422
|
#o = {};
|
|
2423
2423
|
set uri(e) {
|
|
2424
2424
|
const t = new URL(e);
|
|
@@ -2441,10 +2441,10 @@ class ct {
|
|
|
2441
2441
|
this.#o.onResponse = this.onResponse.bind(this);
|
|
2442
2442
|
}
|
|
2443
2443
|
disconnect() {
|
|
2444
|
-
this.#e && (this.#e.off("response", this.#o.onResponse), this.#e.disconnect(), this.#e = null), this.#
|
|
2444
|
+
this.#e && (this.#e.off("response", this.#o.onResponse), this.#e.disconnect(), this.#e = null), this.#r = !1;
|
|
2445
2445
|
}
|
|
2446
2446
|
prepare() {
|
|
2447
|
-
this.#
|
|
2447
|
+
this.#r || (this.#e = B(this.#t, this.#s), this.#r = !0, this.#e.on("response", this.#o.onResponse));
|
|
2448
2448
|
}
|
|
2449
2449
|
connectDevice(e) {
|
|
2450
2450
|
this.#e.emit("connectDevice", { config: e });
|
|
@@ -2471,7 +2471,7 @@ const A = new ct(), q = {
|
|
|
2471
2471
|
bufferSize: 32768,
|
|
2472
2472
|
flowControl: "none"
|
|
2473
2473
|
};
|
|
2474
|
-
class
|
|
2474
|
+
class ht extends pe {
|
|
2475
2475
|
__internal__ = {
|
|
2476
2476
|
bypassSerialBytesConnection: !1,
|
|
2477
2477
|
auto_response: !1,
|
|
@@ -2549,9 +2549,9 @@ class lt extends te {
|
|
|
2549
2549
|
constructor({
|
|
2550
2550
|
filters: e = null,
|
|
2551
2551
|
config_port: t = q,
|
|
2552
|
-
no_device:
|
|
2553
|
-
device_listen_on_channel:
|
|
2554
|
-
bypassSerialBytesConnection:
|
|
2552
|
+
no_device: s = 1,
|
|
2553
|
+
device_listen_on_channel: i = 1,
|
|
2554
|
+
bypassSerialBytesConnection: r = !1,
|
|
2555
2555
|
socket: o = !1
|
|
2556
2556
|
} = {
|
|
2557
2557
|
filters: null,
|
|
@@ -2563,7 +2563,7 @@ class lt extends te {
|
|
|
2563
2563
|
}) {
|
|
2564
2564
|
if (super(), !("serial" in navigator))
|
|
2565
2565
|
throw new Error("Web Serial not supported");
|
|
2566
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t),
|
|
2566
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), r && (this.__internal__.bypassSerialBytesConnection = r), s && this.#w(s), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), this.__internal__.serial.socket = o, this.#y(), this.#g();
|
|
2567
2567
|
}
|
|
2568
2568
|
set listenOnChannel(e) {
|
|
2569
2569
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -2605,7 +2605,7 @@ class lt extends te {
|
|
|
2605
2605
|
}
|
|
2606
2606
|
get isDisconnected() {
|
|
2607
2607
|
const e = this.__internal__.serial.connected, t = this.#s(this.__internal__.serial.port);
|
|
2608
|
-
return !e && t && (this.dispatch("serial:connected"), this.#
|
|
2608
|
+
return !e && t && (this.dispatch("serial:connected"), this.#i(!1), a.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
2609
2609
|
}
|
|
2610
2610
|
get deviceNumber() {
|
|
2611
2611
|
return this.__internal__.device_number;
|
|
@@ -2794,24 +2794,24 @@ class lt extends te {
|
|
|
2794
2794
|
#e(e = null) {
|
|
2795
2795
|
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), a.$dispatchChange(this);
|
|
2796
2796
|
}
|
|
2797
|
-
#
|
|
2797
|
+
#r(e) {
|
|
2798
2798
|
this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
|
|
2799
2799
|
}
|
|
2800
2800
|
socketResponse(e) {
|
|
2801
2801
|
const t = this.__internal__.serial.connected;
|
|
2802
|
-
if (e.type === "disconnect" || e.type === "error" && e.data === "DISCONNECTED" ? this.__internal__.serial.connected = !1 : e.type === "success" && (this.__internal__.serial.connected = !0), a.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#
|
|
2802
|
+
if (e.type === "disconnect" || e.type === "error" && e.data === "DISCONNECTED" ? this.__internal__.serial.connected = !1 : e.type === "success" && (this.__internal__.serial.connected = !0), a.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#i(!1)), e.type === "success")
|
|
2803
2803
|
this.#n(new Uint8Array(e.data));
|
|
2804
2804
|
else if (e.type === "error") {
|
|
2805
|
-
const
|
|
2806
|
-
this.serialErrors(
|
|
2805
|
+
const s = new Error("The port is closed or is not readable/writable");
|
|
2806
|
+
this.serialErrors(s);
|
|
2807
2807
|
} else e.type === "timeout" && this.timeout(e.data.bytes ?? [], this.lastAction || "unknown");
|
|
2808
2808
|
this.__internal__.serial.last_action = null;
|
|
2809
2809
|
}
|
|
2810
2810
|
async connect() {
|
|
2811
2811
|
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
2812
|
-
this.#t || (this.#t = this.#
|
|
2813
|
-
const
|
|
2814
|
-
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(
|
|
2812
|
+
this.#t || (this.#t = this.#r.bind(this)), this.on("internal:connecting", this.#t);
|
|
2813
|
+
const s = setInterval(() => {
|
|
2814
|
+
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(s), this.__internal__.serial.aux_connecting = "idle", this.#t !== null && this.off("internal:connecting", this.#t), this.isConnected ? e(!0) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`)) : this.__internal__.serial.aux_connecting === "connecting" && (this.__internal__.serial.aux_connecting = "idle", this.dispatch("internal:connecting", { active: !0 }), this.dispatch("serial:connecting", { active: !0 }));
|
|
2815
2815
|
}, 100);
|
|
2816
2816
|
this.serialConnect();
|
|
2817
2817
|
}));
|
|
@@ -2822,7 +2822,7 @@ class lt extends te {
|
|
|
2822
2822
|
A.disconnectDevice(this.configDeviceSocket);
|
|
2823
2823
|
else {
|
|
2824
2824
|
const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
|
|
2825
|
-
e && (await e.cancel().catch((
|
|
2825
|
+
e && (await e.cancel().catch((s) => this.serialErrors(s)), await this.__internal__.serial.input_done), t && (await t.getWriter().close(), await this.__internal__.serial.output_done), this.__internal__.serial.connected && this.__internal__.serial && this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
2826
2826
|
}
|
|
2827
2827
|
} catch (e) {
|
|
2828
2828
|
this.serialErrors(e);
|
|
@@ -2844,39 +2844,39 @@ class lt extends te {
|
|
|
2844
2844
|
const t = this.__internal__.serial.port;
|
|
2845
2845
|
if (!t || t && (!t.readable || !t.writable))
|
|
2846
2846
|
throw this.#e({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
2847
|
-
const
|
|
2847
|
+
const s = this.validateBytes(e);
|
|
2848
2848
|
if (this.useRTSCTS && await this.#c(t, 5e3), t.writable === null) return;
|
|
2849
|
-
const
|
|
2850
|
-
await
|
|
2849
|
+
const i = t.writable.getWriter();
|
|
2850
|
+
await i.write(s), i.releaseLock();
|
|
2851
2851
|
}
|
|
2852
2852
|
async #c(e, t = 5e3) {
|
|
2853
|
-
const
|
|
2853
|
+
const s = Date.now();
|
|
2854
2854
|
for (; ; ) {
|
|
2855
|
-
if (Date.now() -
|
|
2855
|
+
if (Date.now() - s > t)
|
|
2856
2856
|
throw new Error("Timeout waiting for clearToSend signal");
|
|
2857
|
-
const { clearToSend:
|
|
2858
|
-
if (
|
|
2859
|
-
await
|
|
2857
|
+
const { clearToSend: i } = await e.getSignals();
|
|
2858
|
+
if (i) return;
|
|
2859
|
+
await ee(100);
|
|
2860
2860
|
}
|
|
2861
2861
|
}
|
|
2862
2862
|
#n(e = new Uint8Array([]), t = !1) {
|
|
2863
2863
|
if (e && e.length > 0) {
|
|
2864
|
-
const
|
|
2865
|
-
if (this.__internal__.serial.connected = this.#s(this.__internal__.serial.port), a.$dispatchChange(this), !
|
|
2864
|
+
const s = this.__internal__.serial.connected;
|
|
2865
|
+
if (this.__internal__.serial.connected = this.#s(this.__internal__.serial.port), a.$dispatchChange(this), !s && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#i(!1)), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
2866
2866
|
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
2867
2867
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
2868
2868
|
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
2869
2869
|
else if (this.__internal__.serial.response.as === "string") {
|
|
2870
|
-
const
|
|
2870
|
+
const i = this.parseUint8ArrayToString(e);
|
|
2871
2871
|
if (this.__internal__.serial.response.limiter !== null) {
|
|
2872
|
-
const
|
|
2873
|
-
for (const o in
|
|
2874
|
-
|
|
2872
|
+
const r = i.split(this.__internal__.serial.response.limiter);
|
|
2873
|
+
for (const o in r)
|
|
2874
|
+
r[o] && (t ? this.serialCorruptMessage(r[o]) : this.serialMessage(r[o]));
|
|
2875
2875
|
} else
|
|
2876
|
-
t ? this.serialCorruptMessage(
|
|
2876
|
+
t ? this.serialCorruptMessage(i) : this.serialMessage(i);
|
|
2877
2877
|
} else {
|
|
2878
|
-
const
|
|
2879
|
-
t ? this.serialCorruptMessage(
|
|
2878
|
+
const i = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
|
|
2879
|
+
t ? this.serialCorruptMessage(i) : this.serialMessage(i);
|
|
2880
2880
|
}
|
|
2881
2881
|
}
|
|
2882
2882
|
if (this.__internal__.serial.queue.length === 0) {
|
|
@@ -2899,16 +2899,16 @@ class lt extends te {
|
|
|
2899
2899
|
}
|
|
2900
2900
|
async #l() {
|
|
2901
2901
|
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
2902
|
-
return e.length === 0 ? t : t.filter((
|
|
2903
|
-
const
|
|
2904
|
-
return e.some((
|
|
2905
|
-
}).filter((
|
|
2902
|
+
return e.length === 0 ? t : t.filter((s) => {
|
|
2903
|
+
const i = s.getInfo();
|
|
2904
|
+
return e.some((r) => i.usbProductId === r.usbProductId && i.usbVendorId === r.usbVendorId);
|
|
2905
|
+
}).filter((s) => !this.#s(s));
|
|
2906
2906
|
}
|
|
2907
2907
|
async serialPortsSaved(e) {
|
|
2908
2908
|
const t = this.serialFilters;
|
|
2909
2909
|
if (this.__internal__.aux_port_connector < e.length) {
|
|
2910
|
-
const
|
|
2911
|
-
this.__internal__.serial.port = e[
|
|
2910
|
+
const s = this.__internal__.aux_port_connector;
|
|
2911
|
+
this.__internal__.serial.port = e[s];
|
|
2912
2912
|
} else
|
|
2913
2913
|
this.__internal__.aux_port_connector = 0, this.__internal__.serial.port = await navigator.serial.requestPort({
|
|
2914
2914
|
filters: t
|
|
@@ -2965,8 +2965,8 @@ class lt extends te {
|
|
|
2965
2965
|
}
|
|
2966
2966
|
#h(e) {
|
|
2967
2967
|
if (e) {
|
|
2968
|
-
const t = this.__internal__.serial.response.buffer,
|
|
2969
|
-
|
|
2968
|
+
const t = this.__internal__.serial.response.buffer, s = new Uint8Array(t.length + e.byteLength);
|
|
2969
|
+
s.set(t, 0), s.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = s;
|
|
2970
2970
|
}
|
|
2971
2971
|
}
|
|
2972
2972
|
async #u() {
|
|
@@ -2979,91 +2979,91 @@ class lt extends te {
|
|
|
2979
2979
|
let t = this.__internal__.serial.response.buffer;
|
|
2980
2980
|
if (this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), !(e === null || !t || t.length === 0)) {
|
|
2981
2981
|
for (; t.length >= e; ) {
|
|
2982
|
-
const
|
|
2983
|
-
this.#n(
|
|
2982
|
+
const s = t.slice(0, e);
|
|
2983
|
+
this.#n(s), t = t.slice(e);
|
|
2984
2984
|
}
|
|
2985
2985
|
this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
2986
2986
|
this.#n(this.__internal__.serial.response.buffer, !0);
|
|
2987
2987
|
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
2988
2988
|
}
|
|
2989
2989
|
}
|
|
2990
|
-
async #
|
|
2990
|
+
async #f() {
|
|
2991
2991
|
const {
|
|
2992
2992
|
limiter: e,
|
|
2993
2993
|
prefixLimiter: t = !1,
|
|
2994
|
-
sufixLimiter:
|
|
2994
|
+
sufixLimiter: s = !0
|
|
2995
2995
|
} = this.__internal__.serial.response;
|
|
2996
2996
|
if (!e)
|
|
2997
2997
|
throw new Error("No limiter defined for delimited serial response");
|
|
2998
|
-
const
|
|
2999
|
-
if (!e || !
|
|
2998
|
+
const i = this.__internal__.serial.response.buffer;
|
|
2999
|
+
if (!e || !i || i.length === 0) return;
|
|
3000
3000
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
3001
|
-
let
|
|
3001
|
+
let r = new TextDecoder().decode(i);
|
|
3002
3002
|
const o = [];
|
|
3003
3003
|
if (typeof e == "string") {
|
|
3004
3004
|
let c;
|
|
3005
|
-
if (t &&
|
|
3005
|
+
if (t && s)
|
|
3006
3006
|
c = new RegExp(`${e}([^${e}]+)${e}`, "g");
|
|
3007
3007
|
else if (t)
|
|
3008
3008
|
c = new RegExp(`${e}([^${e}]*)`, "g");
|
|
3009
|
-
else if (
|
|
3009
|
+
else if (s)
|
|
3010
3010
|
c = new RegExp(`([^${e}]+)${e}`, "g");
|
|
3011
3011
|
else
|
|
3012
3012
|
return;
|
|
3013
|
-
let
|
|
3014
|
-
for (; (
|
|
3015
|
-
o.push(new TextEncoder().encode(
|
|
3016
|
-
|
|
3013
|
+
let f, u = 0;
|
|
3014
|
+
for (; (f = c.exec(r)) !== null; )
|
|
3015
|
+
o.push(new TextEncoder().encode(f[1])), u = c.lastIndex;
|
|
3016
|
+
r = r.slice(u);
|
|
3017
3017
|
} else if (e instanceof RegExp) {
|
|
3018
|
-
let c,
|
|
3019
|
-
if (t &&
|
|
3018
|
+
let c, f = 0;
|
|
3019
|
+
if (t && s) {
|
|
3020
3020
|
const u = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
3021
|
-
for (; (c = u.exec(
|
|
3022
|
-
o.push(new TextEncoder().encode(c[1])),
|
|
3023
|
-
} else if (
|
|
3024
|
-
for (; (c = e.exec(
|
|
3025
|
-
const u = c.index,
|
|
3026
|
-
o.push(new TextEncoder().encode(
|
|
3021
|
+
for (; (c = u.exec(r)) !== null; )
|
|
3022
|
+
o.push(new TextEncoder().encode(c[1])), f = u.lastIndex;
|
|
3023
|
+
} else if (s)
|
|
3024
|
+
for (; (c = e.exec(r)) !== null; ) {
|
|
3025
|
+
const u = c.index, p = r.slice(f, u);
|
|
3026
|
+
o.push(new TextEncoder().encode(p)), f = e.lastIndex;
|
|
3027
3027
|
}
|
|
3028
3028
|
else if (t) {
|
|
3029
|
-
const u =
|
|
3029
|
+
const u = r.split(e);
|
|
3030
3030
|
u.shift();
|
|
3031
|
-
for (const
|
|
3032
|
-
o.push(new TextEncoder().encode(
|
|
3033
|
-
|
|
3031
|
+
for (const p of u)
|
|
3032
|
+
o.push(new TextEncoder().encode(p));
|
|
3033
|
+
r = "";
|
|
3034
3034
|
}
|
|
3035
|
-
|
|
3035
|
+
r = r.slice(f);
|
|
3036
3036
|
}
|
|
3037
3037
|
for (const c of o)
|
|
3038
3038
|
this.#n(c);
|
|
3039
|
-
const
|
|
3040
|
-
this.__internal__.serial.response.buffer =
|
|
3039
|
+
const l = new TextEncoder().encode(r);
|
|
3040
|
+
this.__internal__.serial.response.buffer = l, l.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
3041
3041
|
this.#n(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
3042
3042
|
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
3043
3043
|
}
|
|
3044
|
-
async #
|
|
3044
|
+
async #p() {
|
|
3045
3045
|
const e = this.__internal__.serial.port;
|
|
3046
3046
|
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
3047
3047
|
const t = e.readable.getReader();
|
|
3048
3048
|
this.__internal__.serial.reader = t;
|
|
3049
3049
|
try {
|
|
3050
3050
|
for (; this.__internal__.serial.keep_reading; ) {
|
|
3051
|
-
const { value:
|
|
3052
|
-
if (
|
|
3053
|
-
this.#h(
|
|
3051
|
+
const { value: s, done: i } = await t.read();
|
|
3052
|
+
if (i) break;
|
|
3053
|
+
this.#h(s), this.__internal__.serial.response.delimited ? await this.#f() : this.__internal__.serial.response.length === null ? await this.#u() : await this.#_();
|
|
3054
3054
|
}
|
|
3055
|
-
} catch (
|
|
3056
|
-
this.serialErrors(
|
|
3055
|
+
} catch (s) {
|
|
3056
|
+
this.serialErrors(s);
|
|
3057
3057
|
} finally {
|
|
3058
3058
|
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
3059
3059
|
}
|
|
3060
3060
|
}
|
|
3061
|
-
#
|
|
3061
|
+
#i(e) {
|
|
3062
3062
|
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
|
|
3063
3063
|
}
|
|
3064
3064
|
async serialConnect() {
|
|
3065
3065
|
try {
|
|
3066
|
-
if (this.#
|
|
3066
|
+
if (this.#i(!0), this.useSocket)
|
|
3067
3067
|
A.prepare(), this.__internal__.serial.last_action = "connect", this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
3068
3068
|
await this.timeout(this.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
3069
3069
|
}, this.__internal__.time.response_connection), A.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
|
|
@@ -3075,36 +3075,36 @@ class lt extends te {
|
|
|
3075
3075
|
if (e.length > 0)
|
|
3076
3076
|
await this.serialPortsSaved(e);
|
|
3077
3077
|
else {
|
|
3078
|
-
const
|
|
3078
|
+
const i = this.serialFilters;
|
|
3079
3079
|
this.__internal__.serial.port = await navigator.serial.requestPort({
|
|
3080
|
-
filters:
|
|
3080
|
+
filters: i
|
|
3081
3081
|
});
|
|
3082
3082
|
}
|
|
3083
3083
|
const t = this.__internal__.serial.port;
|
|
3084
3084
|
if (!t)
|
|
3085
3085
|
throw new Error("No port selected by the user");
|
|
3086
3086
|
await t.open(this.serialConfigPort);
|
|
3087
|
-
const
|
|
3088
|
-
t.onconnect = (
|
|
3089
|
-
|
|
3087
|
+
const s = this;
|
|
3088
|
+
t.onconnect = (i) => {
|
|
3089
|
+
s.dispatch("serial:connected", i), s.#i(!1), a.$dispatchChange(this), s.__internal__.serial.queue.length > 0 ? s.dispatch("internal:queue", {}) : s.__internal__.serial.running_queue = !1;
|
|
3090
3090
|
}, t.ondisconnect = async () => {
|
|
3091
|
-
await
|
|
3092
|
-
}, await
|
|
3093
|
-
await
|
|
3091
|
+
await s.disconnect();
|
|
3092
|
+
}, await ee(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
3093
|
+
await s.timeout(s.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
3094
3094
|
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#a(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
3095
3095
|
action: "connect",
|
|
3096
3096
|
bytes: this.__internal__.serial.bytes_connection
|
|
3097
|
-
}), this.__internal__.auto_response && this.#n(this.__internal__.serial.auto_response), await this.#
|
|
3097
|
+
}), this.__internal__.auto_response && this.#n(this.__internal__.serial.auto_response), await this.#p();
|
|
3098
3098
|
}
|
|
3099
3099
|
} catch (e) {
|
|
3100
|
-
this.#
|
|
3100
|
+
this.#i(!1), this.serialErrors(e);
|
|
3101
3101
|
}
|
|
3102
3102
|
}
|
|
3103
|
-
async #
|
|
3103
|
+
async #d() {
|
|
3104
3104
|
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
3105
3105
|
}
|
|
3106
3106
|
async serialForget() {
|
|
3107
|
-
return await this.#
|
|
3107
|
+
return await this.#d();
|
|
3108
3108
|
}
|
|
3109
3109
|
decToHex(e) {
|
|
3110
3110
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -3117,8 +3117,8 @@ class lt extends te {
|
|
|
3117
3117
|
}
|
|
3118
3118
|
add0x(e) {
|
|
3119
3119
|
const t = [];
|
|
3120
|
-
return e.forEach((
|
|
3121
|
-
t[
|
|
3120
|
+
return e.forEach((s, i) => {
|
|
3121
|
+
t[i] = "0x" + s;
|
|
3122
3122
|
}), t;
|
|
3123
3123
|
}
|
|
3124
3124
|
bytesToHex(e) {
|
|
@@ -3177,16 +3177,16 @@ class lt extends te {
|
|
|
3177
3177
|
action: e.action,
|
|
3178
3178
|
bytes: e.bytes
|
|
3179
3179
|
}), this.__internal__.auto_response) {
|
|
3180
|
-
let
|
|
3180
|
+
let i = new Uint8Array(0);
|
|
3181
3181
|
try {
|
|
3182
|
-
|
|
3183
|
-
} catch (
|
|
3184
|
-
this.serialErrors(
|
|
3182
|
+
i = this.validateBytes(this.__internal__.serial.auto_response);
|
|
3183
|
+
} catch (r) {
|
|
3184
|
+
this.serialErrors(r);
|
|
3185
3185
|
}
|
|
3186
|
-
this.#n(
|
|
3186
|
+
this.#n(i);
|
|
3187
3187
|
}
|
|
3188
|
-
const
|
|
3189
|
-
this.__internal__.serial.queue =
|
|
3188
|
+
const s = [...this.__internal__.serial.queue];
|
|
3189
|
+
this.__internal__.serial.queue = s.splice(1), this.__internal__.serial.queue.length > 0 && (this.__internal__.serial.running_queue = !0);
|
|
3190
3190
|
}
|
|
3191
3191
|
validateBytes(e) {
|
|
3192
3192
|
let t = new Uint8Array(0);
|
|
@@ -3203,13 +3203,13 @@ class lt extends te {
|
|
|
3203
3203
|
return t;
|
|
3204
3204
|
}
|
|
3205
3205
|
async appendToQueue(e, t) {
|
|
3206
|
-
const
|
|
3206
|
+
const s = this.validateBytes(e);
|
|
3207
3207
|
if (["connect", "connection:start"].includes(t)) {
|
|
3208
3208
|
if (this.__internal__.serial.connected) return;
|
|
3209
3209
|
await this.serialConnect();
|
|
3210
3210
|
return;
|
|
3211
3211
|
}
|
|
3212
|
-
this.__internal__.serial.queue.push({ bytes:
|
|
3212
|
+
this.__internal__.serial.queue.push({ bytes: s, action: t }), this.dispatch("internal:queue", {});
|
|
3213
3213
|
}
|
|
3214
3214
|
#w(e = 1) {
|
|
3215
3215
|
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
@@ -3237,8 +3237,8 @@ class lt extends te {
|
|
|
3237
3237
|
}
|
|
3238
3238
|
sumHex(e) {
|
|
3239
3239
|
let t = 0;
|
|
3240
|
-
return e.forEach((
|
|
3241
|
-
t += parseInt(
|
|
3240
|
+
return e.forEach((s) => {
|
|
3241
|
+
t += parseInt(s, 16);
|
|
3242
3242
|
}), t.toString(16);
|
|
3243
3243
|
}
|
|
3244
3244
|
toString() {
|
|
@@ -3272,13 +3272,13 @@ class lt extends te {
|
|
|
3272
3272
|
}
|
|
3273
3273
|
parseStringToTextEncoder(e = "", t = `
|
|
3274
3274
|
`) {
|
|
3275
|
-
const
|
|
3276
|
-
return e += t,
|
|
3275
|
+
const s = new TextEncoder();
|
|
3276
|
+
return e += t, s.encode(e);
|
|
3277
3277
|
}
|
|
3278
3278
|
parseStringToBytes(e = "", t = `
|
|
3279
3279
|
`) {
|
|
3280
|
-
const
|
|
3281
|
-
return Array.from(
|
|
3280
|
+
const s = this.parseStringToTextEncoder(e, t);
|
|
3281
|
+
return Array.from(s).map((i) => i.toString(16));
|
|
3282
3282
|
}
|
|
3283
3283
|
parseUint8ToHex(e) {
|
|
3284
3284
|
return Array.from(e).map((t) => t.toString(16).padStart(2, "0").toLowerCase());
|
|
@@ -3288,29 +3288,29 @@ class lt extends te {
|
|
|
3288
3288
|
}
|
|
3289
3289
|
stringArrayToUint8Array(e) {
|
|
3290
3290
|
const t = [];
|
|
3291
|
-
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((
|
|
3292
|
-
const
|
|
3293
|
-
t.push(parseInt(
|
|
3291
|
+
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((s) => {
|
|
3292
|
+
const i = s.replace("0x", "");
|
|
3293
|
+
t.push(parseInt(i, 16));
|
|
3294
3294
|
}), new Uint8Array(t));
|
|
3295
3295
|
}
|
|
3296
3296
|
parseUint8ArrayToString(e) {
|
|
3297
3297
|
let t = new Uint8Array(0);
|
|
3298
3298
|
e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
|
|
3299
|
-
const
|
|
3300
|
-
return this.__internal__.serial.response.replacer ? String.fromCharCode(...
|
|
3299
|
+
const s = e.map((i) => parseInt(i, 16));
|
|
3300
|
+
return this.__internal__.serial.response.replacer ? String.fromCharCode(...s).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...s);
|
|
3301
3301
|
}
|
|
3302
3302
|
hexToAscii(e) {
|
|
3303
3303
|
const t = e.toString();
|
|
3304
|
-
let
|
|
3305
|
-
for (let
|
|
3306
|
-
|
|
3307
|
-
return
|
|
3304
|
+
let s = "";
|
|
3305
|
+
for (let i = 0; i < t.length; i += 2)
|
|
3306
|
+
s += String.fromCharCode(parseInt(t.substring(i, 2), 16));
|
|
3307
|
+
return s;
|
|
3308
3308
|
}
|
|
3309
3309
|
asciiToHex(e) {
|
|
3310
3310
|
const t = [];
|
|
3311
|
-
for (let
|
|
3312
|
-
const
|
|
3313
|
-
t.push(
|
|
3311
|
+
for (let s = 0, i = e.length; s < i; s++) {
|
|
3312
|
+
const r = Number(e.charCodeAt(s)).toString(16);
|
|
3313
|
+
t.push(r);
|
|
3314
3314
|
}
|
|
3315
3315
|
return t.join("");
|
|
3316
3316
|
}
|
|
@@ -3319,7 +3319,7 @@ class lt extends te {
|
|
|
3319
3319
|
}
|
|
3320
3320
|
}
|
|
3321
3321
|
export {
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3322
|
+
a as s,
|
|
3323
|
+
A as u,
|
|
3324
|
+
ht as v
|
|
3325
3325
|
};
|