zigap-utils 0.0.461 → 0.0.462
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/package.json +2 -2
- package/dist/App.d.ts +0 -2
- package/dist/components/AddressProvideQR/AddressProvideQR.d.ts +0 -4
- package/dist/components/AddressProvideQR/AddressProvideQR.types.d.ts +0 -15
- package/dist/components/AddressProvideQR/index.d.ts +0 -2
- package/dist/components/LoginQR/LoginQR.d.ts +0 -4
- package/dist/components/LoginQR/LoginQR.types.d.ts +0 -33
- package/dist/components/LoginQR/index.d.ts +0 -2
- package/dist/components/index.d.ts +0 -2
- package/dist/cryptoUtils.cjs.js +0 -1
- package/dist/cryptoUtils.es.js +0 -5492
- package/dist/index.cjs.js +0 -42
- package/dist/index.cjs2.js +0 -14
- package/dist/index.cjs3.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +0 -1382
- package/dist/index.es2.js +0 -5025
- package/dist/index.es3.js +0 -2303
- package/dist/main.d.ts +0 -1
- package/dist/utils/addressProvide.d.ts +0 -9
- package/dist/utils/cryptoUtils.d.ts +0 -19
- package/dist/utils/login.d.ts +0 -11
- package/dist/utils/socketInstance.d.ts +0 -9
- package/dist/utils/types.d.ts +0 -23
- package/dist/xphere/enc.d.ts +0 -12
- package/dist/xphere/index.d.ts +0 -4
- package/dist/xphere/sign.d.ts +0 -18
- package/dist/xphere/util.d.ts +0 -10
- package/dist/xphere/validation.d.ts +0 -10
- package/dist/xphere.cjs.js +0 -1
- package/dist/xphere.es.js +0 -32
- package/dist/zigap/index.d.ts +0 -2
- package/dist/zigap/qr.d.ts +0 -7
- package/dist/zigap/types.d.ts +0 -4
- package/dist/zigap.cjs.js +0 -1
- package/dist/zigap.es.js +0 -5
package/dist/index.es3.js
DELETED
|
@@ -1,2303 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var be = Object.defineProperty;
|
|
3
|
-
var ve = (n, e, t) => e in n ? be(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
4
|
-
var A = (n, e, t) => (ve(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
5
|
-
import { C as J } from "./index.es2.js";
|
|
6
|
-
const d = /* @__PURE__ */ Object.create(null);
|
|
7
|
-
d.open = "0";
|
|
8
|
-
d.close = "1";
|
|
9
|
-
d.ping = "2";
|
|
10
|
-
d.pong = "3";
|
|
11
|
-
d.message = "4";
|
|
12
|
-
d.upgrade = "5";
|
|
13
|
-
d.noop = "6";
|
|
14
|
-
const S = /* @__PURE__ */ Object.create(null);
|
|
15
|
-
Object.keys(d).forEach((n) => {
|
|
16
|
-
S[d[n]] = n;
|
|
17
|
-
});
|
|
18
|
-
const P = { type: "error", data: "parser error" }, re = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", oe = typeof ArrayBuffer == "function", ce = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n && n.buffer instanceof ArrayBuffer, $ = ({ type: n, data: e }, t, s) => re && e instanceof Blob ? t ? s(e) : Q(e, s) : oe && (e instanceof ArrayBuffer || ce(e)) ? t ? s(e) : Q(new Blob([e]), s) : s(d[n] + (e || "")), Q = (n, e) => {
|
|
19
|
-
const t = new FileReader();
|
|
20
|
-
return t.onload = function() {
|
|
21
|
-
const s = t.result.split(",")[1];
|
|
22
|
-
e("b" + (s || ""));
|
|
23
|
-
}, t.readAsDataURL(n);
|
|
24
|
-
};
|
|
25
|
-
function X(n) {
|
|
26
|
-
return n instanceof Uint8Array ? n : n instanceof ArrayBuffer ? new Uint8Array(n) : new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
27
|
-
}
|
|
28
|
-
let L;
|
|
29
|
-
function ke(n, e) {
|
|
30
|
-
if (re && n.data instanceof Blob)
|
|
31
|
-
return n.data.arrayBuffer().then(X).then(e);
|
|
32
|
-
if (oe && (n.data instanceof ArrayBuffer || ce(n.data)))
|
|
33
|
-
return e(X(n.data));
|
|
34
|
-
$(n, !1, (t) => {
|
|
35
|
-
L || (L = new TextEncoder()), e(L.encode(t));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const j = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", _ = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
|
|
39
|
-
for (let n = 0; n < j.length; n++)
|
|
40
|
-
_[j.charCodeAt(n)] = n;
|
|
41
|
-
const Ee = (n) => {
|
|
42
|
-
let e = n.length * 0.75, t = n.length, s, i = 0, r, o, a, h;
|
|
43
|
-
n[n.length - 1] === "=" && (e--, n[n.length - 2] === "=" && e--);
|
|
44
|
-
const g = new ArrayBuffer(e), y = new Uint8Array(g);
|
|
45
|
-
for (s = 0; s < t; s += 4)
|
|
46
|
-
r = _[n.charCodeAt(s)], o = _[n.charCodeAt(s + 1)], a = _[n.charCodeAt(s + 2)], h = _[n.charCodeAt(s + 3)], y[i++] = r << 2 | o >> 4, y[i++] = (o & 15) << 4 | a >> 2, y[i++] = (a & 3) << 6 | h & 63;
|
|
47
|
-
return g;
|
|
48
|
-
}, _e = typeof ArrayBuffer == "function", H = (n, e) => {
|
|
49
|
-
if (typeof n != "string")
|
|
50
|
-
return {
|
|
51
|
-
type: "message",
|
|
52
|
-
data: ae(n, e)
|
|
53
|
-
};
|
|
54
|
-
const t = n.charAt(0);
|
|
55
|
-
return t === "b" ? {
|
|
56
|
-
type: "message",
|
|
57
|
-
data: Ae(n.substring(1), e)
|
|
58
|
-
} : S[t] ? n.length > 1 ? {
|
|
59
|
-
type: S[t],
|
|
60
|
-
data: n.substring(1)
|
|
61
|
-
} : {
|
|
62
|
-
type: S[t]
|
|
63
|
-
} : P;
|
|
64
|
-
}, Ae = (n, e) => {
|
|
65
|
-
if (_e) {
|
|
66
|
-
const t = Ee(n);
|
|
67
|
-
return ae(t, e);
|
|
68
|
-
} else
|
|
69
|
-
return { base64: !0, data: n };
|
|
70
|
-
}, ae = (n, e) => {
|
|
71
|
-
switch (e) {
|
|
72
|
-
case "blob":
|
|
73
|
-
return n instanceof Blob ? n : new Blob([n]);
|
|
74
|
-
case "arraybuffer":
|
|
75
|
-
default:
|
|
76
|
-
return n instanceof ArrayBuffer ? n : n.buffer;
|
|
77
|
-
}
|
|
78
|
-
}, he = "", Re = (n, e) => {
|
|
79
|
-
const t = n.length, s = new Array(t);
|
|
80
|
-
let i = 0;
|
|
81
|
-
n.forEach((r, o) => {
|
|
82
|
-
$(r, !1, (a) => {
|
|
83
|
-
s[o] = a, ++i === t && e(s.join(he));
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}, Te = (n, e) => {
|
|
87
|
-
const t = n.split(he), s = [];
|
|
88
|
-
for (let i = 0; i < t.length; i++) {
|
|
89
|
-
const r = H(t[i], e);
|
|
90
|
-
if (s.push(r), r.type === "error")
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
return s;
|
|
94
|
-
};
|
|
95
|
-
function Oe() {
|
|
96
|
-
return new TransformStream({
|
|
97
|
-
transform(n, e) {
|
|
98
|
-
ke(n, (t) => {
|
|
99
|
-
const s = t.length;
|
|
100
|
-
let i;
|
|
101
|
-
if (s < 126)
|
|
102
|
-
i = new Uint8Array(1), new DataView(i.buffer).setUint8(0, s);
|
|
103
|
-
else if (s < 65536) {
|
|
104
|
-
i = new Uint8Array(3);
|
|
105
|
-
const r = new DataView(i.buffer);
|
|
106
|
-
r.setUint8(0, 126), r.setUint16(1, s);
|
|
107
|
-
} else {
|
|
108
|
-
i = new Uint8Array(9);
|
|
109
|
-
const r = new DataView(i.buffer);
|
|
110
|
-
r.setUint8(0, 127), r.setBigUint64(1, BigInt(s));
|
|
111
|
-
}
|
|
112
|
-
n.data && typeof n.data != "string" && (i[0] |= 128), e.enqueue(i), e.enqueue(t);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
let q;
|
|
118
|
-
function R(n) {
|
|
119
|
-
return n.reduce((e, t) => e + t.length, 0);
|
|
120
|
-
}
|
|
121
|
-
function T(n, e) {
|
|
122
|
-
if (n[0].length === e)
|
|
123
|
-
return n.shift();
|
|
124
|
-
const t = new Uint8Array(e);
|
|
125
|
-
let s = 0;
|
|
126
|
-
for (let i = 0; i < e; i++)
|
|
127
|
-
t[i] = n[0][s++], s === n[0].length && (n.shift(), s = 0);
|
|
128
|
-
return n.length && s < n[0].length && (n[0] = n[0].slice(s)), t;
|
|
129
|
-
}
|
|
130
|
-
function Ce(n, e) {
|
|
131
|
-
q || (q = new TextDecoder());
|
|
132
|
-
const t = [];
|
|
133
|
-
let s = 0, i = -1, r = !1;
|
|
134
|
-
return new TransformStream({
|
|
135
|
-
transform(o, a) {
|
|
136
|
-
for (t.push(o); ; ) {
|
|
137
|
-
if (s === 0) {
|
|
138
|
-
if (R(t) < 1)
|
|
139
|
-
break;
|
|
140
|
-
const h = T(t, 1);
|
|
141
|
-
r = (h[0] & 128) === 128, i = h[0] & 127, i < 126 ? s = 3 : i === 126 ? s = 1 : s = 2;
|
|
142
|
-
} else if (s === 1) {
|
|
143
|
-
if (R(t) < 2)
|
|
144
|
-
break;
|
|
145
|
-
const h = T(t, 2);
|
|
146
|
-
i = new DataView(h.buffer, h.byteOffset, h.length).getUint16(0), s = 3;
|
|
147
|
-
} else if (s === 2) {
|
|
148
|
-
if (R(t) < 8)
|
|
149
|
-
break;
|
|
150
|
-
const h = T(t, 8), g = new DataView(h.buffer, h.byteOffset, h.length), y = g.getUint32(0);
|
|
151
|
-
if (y > Math.pow(2, 21) - 1) {
|
|
152
|
-
a.enqueue(P);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
i = y * Math.pow(2, 32) + g.getUint32(4), s = 3;
|
|
156
|
-
} else {
|
|
157
|
-
if (R(t) < i)
|
|
158
|
-
break;
|
|
159
|
-
const h = T(t, i);
|
|
160
|
-
a.enqueue(H(r ? h : q.decode(h), e)), s = 0;
|
|
161
|
-
}
|
|
162
|
-
if (i === 0 || i > n) {
|
|
163
|
-
a.enqueue(P);
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
const fe = 4;
|
|
171
|
-
function f(n) {
|
|
172
|
-
if (n)
|
|
173
|
-
return Se(n);
|
|
174
|
-
}
|
|
175
|
-
function Se(n) {
|
|
176
|
-
for (var e in f.prototype)
|
|
177
|
-
n[e] = f.prototype[e];
|
|
178
|
-
return n;
|
|
179
|
-
}
|
|
180
|
-
f.prototype.on = f.prototype.addEventListener = function(n, e) {
|
|
181
|
-
return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
|
|
182
|
-
};
|
|
183
|
-
f.prototype.once = function(n, e) {
|
|
184
|
-
function t() {
|
|
185
|
-
this.off(n, t), e.apply(this, arguments);
|
|
186
|
-
}
|
|
187
|
-
return t.fn = e, this.on(n, t), this;
|
|
188
|
-
};
|
|
189
|
-
f.prototype.off = f.prototype.removeListener = f.prototype.removeAllListeners = f.prototype.removeEventListener = function(n, e) {
|
|
190
|
-
if (this._callbacks = this._callbacks || {}, arguments.length == 0)
|
|
191
|
-
return this._callbacks = {}, this;
|
|
192
|
-
var t = this._callbacks["$" + n];
|
|
193
|
-
if (!t)
|
|
194
|
-
return this;
|
|
195
|
-
if (arguments.length == 1)
|
|
196
|
-
return delete this._callbacks["$" + n], this;
|
|
197
|
-
for (var s, i = 0; i < t.length; i++)
|
|
198
|
-
if (s = t[i], s === e || s.fn === e) {
|
|
199
|
-
t.splice(i, 1);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
return t.length === 0 && delete this._callbacks["$" + n], this;
|
|
203
|
-
};
|
|
204
|
-
f.prototype.emit = function(n) {
|
|
205
|
-
this._callbacks = this._callbacks || {};
|
|
206
|
-
for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + n], s = 1; s < arguments.length; s++)
|
|
207
|
-
e[s - 1] = arguments[s];
|
|
208
|
-
if (t) {
|
|
209
|
-
t = t.slice(0);
|
|
210
|
-
for (var s = 0, i = t.length; s < i; ++s)
|
|
211
|
-
t[s].apply(this, e);
|
|
212
|
-
}
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
f.prototype.emitReserved = f.prototype.emit;
|
|
216
|
-
f.prototype.listeners = function(n) {
|
|
217
|
-
return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
|
|
218
|
-
};
|
|
219
|
-
f.prototype.hasListeners = function(n) {
|
|
220
|
-
return !!this.listeners(n).length;
|
|
221
|
-
};
|
|
222
|
-
const u = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
|
|
223
|
-
function ue(n, ...e) {
|
|
224
|
-
return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
|
|
225
|
-
}
|
|
226
|
-
const Be = u.setTimeout, xe = u.clearTimeout;
|
|
227
|
-
function N(n, e) {
|
|
228
|
-
e.useNativeTimers ? (n.setTimeoutFn = Be.bind(u), n.clearTimeoutFn = xe.bind(u)) : (n.setTimeoutFn = u.setTimeout.bind(u), n.clearTimeoutFn = u.clearTimeout.bind(u));
|
|
229
|
-
}
|
|
230
|
-
const Ne = 1.33;
|
|
231
|
-
function Le(n) {
|
|
232
|
-
return typeof n == "string" ? qe(n) : Math.ceil((n.byteLength || n.size) * Ne);
|
|
233
|
-
}
|
|
234
|
-
function qe(n) {
|
|
235
|
-
let e = 0, t = 0;
|
|
236
|
-
for (let s = 0, i = n.length; s < i; s++)
|
|
237
|
-
e = n.charCodeAt(s), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (s++, t += 4);
|
|
238
|
-
return t;
|
|
239
|
-
}
|
|
240
|
-
function Pe(n) {
|
|
241
|
-
let e = "";
|
|
242
|
-
for (let t in n)
|
|
243
|
-
n.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(n[t]));
|
|
244
|
-
return e;
|
|
245
|
-
}
|
|
246
|
-
function Ie(n) {
|
|
247
|
-
let e = {}, t = n.split("&");
|
|
248
|
-
for (let s = 0, i = t.length; s < i; s++) {
|
|
249
|
-
let r = t[s].split("=");
|
|
250
|
-
e[decodeURIComponent(r[0])] = decodeURIComponent(r[1]);
|
|
251
|
-
}
|
|
252
|
-
return e;
|
|
253
|
-
}
|
|
254
|
-
class De extends Error {
|
|
255
|
-
constructor(e, t, s) {
|
|
256
|
-
super(e), this.description = t, this.context = s, this.type = "TransportError";
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
class K extends f {
|
|
260
|
-
/**
|
|
261
|
-
* Transport abstract constructor.
|
|
262
|
-
*
|
|
263
|
-
* @param {Object} opts - options
|
|
264
|
-
* @protected
|
|
265
|
-
*/
|
|
266
|
-
constructor(e) {
|
|
267
|
-
super(), this.writable = !1, N(this, e), this.opts = e, this.query = e.query, this.socket = e.socket;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Emits an error.
|
|
271
|
-
*
|
|
272
|
-
* @param {String} reason
|
|
273
|
-
* @param description
|
|
274
|
-
* @param context - the error context
|
|
275
|
-
* @return {Transport} for chaining
|
|
276
|
-
* @protected
|
|
277
|
-
*/
|
|
278
|
-
onError(e, t, s) {
|
|
279
|
-
return super.emitReserved("error", new De(e, t, s)), this;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Opens the transport.
|
|
283
|
-
*/
|
|
284
|
-
open() {
|
|
285
|
-
return this.readyState = "opening", this.doOpen(), this;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Closes the transport.
|
|
289
|
-
*/
|
|
290
|
-
close() {
|
|
291
|
-
return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Sends multiple packets.
|
|
295
|
-
*
|
|
296
|
-
* @param {Array} packets
|
|
297
|
-
*/
|
|
298
|
-
send(e) {
|
|
299
|
-
this.readyState === "open" && this.write(e);
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Called upon open
|
|
303
|
-
*
|
|
304
|
-
* @protected
|
|
305
|
-
*/
|
|
306
|
-
onOpen() {
|
|
307
|
-
this.readyState = "open", this.writable = !0, super.emitReserved("open");
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Called with data.
|
|
311
|
-
*
|
|
312
|
-
* @param {String} data
|
|
313
|
-
* @protected
|
|
314
|
-
*/
|
|
315
|
-
onData(e) {
|
|
316
|
-
const t = H(e, this.socket.binaryType);
|
|
317
|
-
this.onPacket(t);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Called with a decoded packet.
|
|
321
|
-
*
|
|
322
|
-
* @protected
|
|
323
|
-
*/
|
|
324
|
-
onPacket(e) {
|
|
325
|
-
super.emitReserved("packet", e);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Called upon close.
|
|
329
|
-
*
|
|
330
|
-
* @protected
|
|
331
|
-
*/
|
|
332
|
-
onClose(e) {
|
|
333
|
-
this.readyState = "closed", super.emitReserved("close", e);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
337
|
-
*
|
|
338
|
-
* @param onPause
|
|
339
|
-
*/
|
|
340
|
-
pause(e) {
|
|
341
|
-
}
|
|
342
|
-
createUri(e, t = {}) {
|
|
343
|
-
return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
|
|
344
|
-
}
|
|
345
|
-
_hostname() {
|
|
346
|
-
const e = this.opts.hostname;
|
|
347
|
-
return e.indexOf(":") === -1 ? e : "[" + e + "]";
|
|
348
|
-
}
|
|
349
|
-
_port() {
|
|
350
|
-
return this.opts.port && (this.opts.secure && +(this.opts.port !== 443) || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
|
|
351
|
-
}
|
|
352
|
-
_query(e) {
|
|
353
|
-
const t = Pe(e);
|
|
354
|
-
return t.length ? "?" + t : "";
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
const le = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""), I = 64, Ue = {};
|
|
358
|
-
let G = 0, O = 0, Z;
|
|
359
|
-
function ee(n) {
|
|
360
|
-
let e = "";
|
|
361
|
-
do
|
|
362
|
-
e = le[n % I] + e, n = Math.floor(n / I);
|
|
363
|
-
while (n > 0);
|
|
364
|
-
return e;
|
|
365
|
-
}
|
|
366
|
-
function pe() {
|
|
367
|
-
const n = ee(+/* @__PURE__ */ new Date());
|
|
368
|
-
return n !== Z ? (G = 0, Z = n) : n + "." + ee(G++);
|
|
369
|
-
}
|
|
370
|
-
for (; O < I; O++)
|
|
371
|
-
Ue[le[O]] = O;
|
|
372
|
-
let de = !1;
|
|
373
|
-
try {
|
|
374
|
-
de = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
375
|
-
} catch {
|
|
376
|
-
}
|
|
377
|
-
const Me = de;
|
|
378
|
-
function ye(n) {
|
|
379
|
-
const e = n.xdomain;
|
|
380
|
-
try {
|
|
381
|
-
if (typeof XMLHttpRequest < "u" && (!e || Me))
|
|
382
|
-
return new XMLHttpRequest();
|
|
383
|
-
} catch {
|
|
384
|
-
}
|
|
385
|
-
if (!e)
|
|
386
|
-
try {
|
|
387
|
-
return new u[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
388
|
-
} catch {
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function Ve() {
|
|
392
|
-
}
|
|
393
|
-
const Fe = function() {
|
|
394
|
-
return new ye({
|
|
395
|
-
xdomain: !1
|
|
396
|
-
}).responseType != null;
|
|
397
|
-
}();
|
|
398
|
-
class $e extends K {
|
|
399
|
-
/**
|
|
400
|
-
* XHR Polling constructor.
|
|
401
|
-
*
|
|
402
|
-
* @param {Object} opts
|
|
403
|
-
* @package
|
|
404
|
-
*/
|
|
405
|
-
constructor(e) {
|
|
406
|
-
if (super(e), this.polling = !1, typeof location < "u") {
|
|
407
|
-
const s = location.protocol === "https:";
|
|
408
|
-
let i = location.port;
|
|
409
|
-
i || (i = s ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || i !== e.port;
|
|
410
|
-
}
|
|
411
|
-
const t = e && e.forceBase64;
|
|
412
|
-
this.supportsBinary = Fe && !t, this.opts.withCredentials && (this.cookieJar = void 0);
|
|
413
|
-
}
|
|
414
|
-
get name() {
|
|
415
|
-
return "polling";
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Opens the socket (triggers polling). We write a PING message to determine
|
|
419
|
-
* when the transport is open.
|
|
420
|
-
*
|
|
421
|
-
* @protected
|
|
422
|
-
*/
|
|
423
|
-
doOpen() {
|
|
424
|
-
this.poll();
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Pauses polling.
|
|
428
|
-
*
|
|
429
|
-
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
430
|
-
* @package
|
|
431
|
-
*/
|
|
432
|
-
pause(e) {
|
|
433
|
-
this.readyState = "pausing";
|
|
434
|
-
const t = () => {
|
|
435
|
-
this.readyState = "paused", e();
|
|
436
|
-
};
|
|
437
|
-
if (this.polling || !this.writable) {
|
|
438
|
-
let s = 0;
|
|
439
|
-
this.polling && (s++, this.once("pollComplete", function() {
|
|
440
|
-
--s || t();
|
|
441
|
-
})), this.writable || (s++, this.once("drain", function() {
|
|
442
|
-
--s || t();
|
|
443
|
-
}));
|
|
444
|
-
} else
|
|
445
|
-
t();
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Starts polling cycle.
|
|
449
|
-
*
|
|
450
|
-
* @private
|
|
451
|
-
*/
|
|
452
|
-
poll() {
|
|
453
|
-
this.polling = !0, this.doPoll(), this.emitReserved("poll");
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Overloads onData to detect payloads.
|
|
457
|
-
*
|
|
458
|
-
* @protected
|
|
459
|
-
*/
|
|
460
|
-
onData(e) {
|
|
461
|
-
const t = (s) => {
|
|
462
|
-
if (this.readyState === "opening" && s.type === "open" && this.onOpen(), s.type === "close")
|
|
463
|
-
return this.onClose({ description: "transport closed by the server" }), !1;
|
|
464
|
-
this.onPacket(s);
|
|
465
|
-
};
|
|
466
|
-
Te(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this.polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this.poll());
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* For polling, send a close packet.
|
|
470
|
-
*
|
|
471
|
-
* @protected
|
|
472
|
-
*/
|
|
473
|
-
doClose() {
|
|
474
|
-
const e = () => {
|
|
475
|
-
this.write([{ type: "close" }]);
|
|
476
|
-
};
|
|
477
|
-
this.readyState === "open" ? e() : this.once("open", e);
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Writes a packets payload.
|
|
481
|
-
*
|
|
482
|
-
* @param {Array} packets - data packets
|
|
483
|
-
* @protected
|
|
484
|
-
*/
|
|
485
|
-
write(e) {
|
|
486
|
-
this.writable = !1, Re(e, (t) => {
|
|
487
|
-
this.doWrite(t, () => {
|
|
488
|
-
this.writable = !0, this.emitReserved("drain");
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Generates uri for connection.
|
|
494
|
-
*
|
|
495
|
-
* @private
|
|
496
|
-
*/
|
|
497
|
-
uri() {
|
|
498
|
-
const e = this.opts.secure ? "https" : "http", t = this.query || {};
|
|
499
|
-
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = pe()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Creates a request.
|
|
503
|
-
*
|
|
504
|
-
* @param {String} method
|
|
505
|
-
* @private
|
|
506
|
-
*/
|
|
507
|
-
request(e = {}) {
|
|
508
|
-
return Object.assign(e, { xd: this.xd, cookieJar: this.cookieJar }, this.opts), new p(this.uri(), e);
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Sends data.
|
|
512
|
-
*
|
|
513
|
-
* @param {String} data to send.
|
|
514
|
-
* @param {Function} called upon flush.
|
|
515
|
-
* @private
|
|
516
|
-
*/
|
|
517
|
-
doWrite(e, t) {
|
|
518
|
-
const s = this.request({
|
|
519
|
-
method: "POST",
|
|
520
|
-
data: e
|
|
521
|
-
});
|
|
522
|
-
s.on("success", t), s.on("error", (i, r) => {
|
|
523
|
-
this.onError("xhr post error", i, r);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Starts a poll cycle.
|
|
528
|
-
*
|
|
529
|
-
* @private
|
|
530
|
-
*/
|
|
531
|
-
doPoll() {
|
|
532
|
-
const e = this.request();
|
|
533
|
-
e.on("data", this.onData.bind(this)), e.on("error", (t, s) => {
|
|
534
|
-
this.onError("xhr poll error", t, s);
|
|
535
|
-
}), this.pollXhr = e;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
class p extends f {
|
|
539
|
-
/**
|
|
540
|
-
* Request constructor
|
|
541
|
-
*
|
|
542
|
-
* @param {Object} options
|
|
543
|
-
* @package
|
|
544
|
-
*/
|
|
545
|
-
constructor(e, t) {
|
|
546
|
-
super(), N(this, t), this.opts = t, this.method = t.method || "GET", this.uri = e, this.data = t.data !== void 0 ? t.data : null, this.create();
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Creates the XHR object and sends the request.
|
|
550
|
-
*
|
|
551
|
-
* @private
|
|
552
|
-
*/
|
|
553
|
-
create() {
|
|
554
|
-
var e;
|
|
555
|
-
const t = ue(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
556
|
-
t.xdomain = !!this.opts.xd;
|
|
557
|
-
const s = this.xhr = new ye(t);
|
|
558
|
-
try {
|
|
559
|
-
s.open(this.method, this.uri, !0);
|
|
560
|
-
try {
|
|
561
|
-
if (this.opts.extraHeaders) {
|
|
562
|
-
s.setDisableHeaderCheck && s.setDisableHeaderCheck(!0);
|
|
563
|
-
for (let i in this.opts.extraHeaders)
|
|
564
|
-
this.opts.extraHeaders.hasOwnProperty(i) && s.setRequestHeader(i, this.opts.extraHeaders[i]);
|
|
565
|
-
}
|
|
566
|
-
} catch {
|
|
567
|
-
}
|
|
568
|
-
if (this.method === "POST")
|
|
569
|
-
try {
|
|
570
|
-
s.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
571
|
-
} catch {
|
|
572
|
-
}
|
|
573
|
-
try {
|
|
574
|
-
s.setRequestHeader("Accept", "*/*");
|
|
575
|
-
} catch {
|
|
576
|
-
}
|
|
577
|
-
(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 = () => {
|
|
578
|
-
var i;
|
|
579
|
-
s.readyState === 3 && ((i = this.opts.cookieJar) === null || i === void 0 || i.parseCookies(s)), s.readyState === 4 && (s.status === 200 || s.status === 1223 ? this.onLoad() : this.setTimeoutFn(() => {
|
|
580
|
-
this.onError(typeof s.status == "number" ? s.status : 0);
|
|
581
|
-
}, 0));
|
|
582
|
-
}, s.send(this.data);
|
|
583
|
-
} catch (i) {
|
|
584
|
-
this.setTimeoutFn(() => {
|
|
585
|
-
this.onError(i);
|
|
586
|
-
}, 0);
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
typeof document < "u" && (this.index = p.requestsCount++, p.requests[this.index] = this);
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Called upon error.
|
|
593
|
-
*
|
|
594
|
-
* @private
|
|
595
|
-
*/
|
|
596
|
-
onError(e) {
|
|
597
|
-
this.emitReserved("error", e, this.xhr), this.cleanup(!0);
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Cleans up house.
|
|
601
|
-
*
|
|
602
|
-
* @private
|
|
603
|
-
*/
|
|
604
|
-
cleanup(e) {
|
|
605
|
-
if (!(typeof this.xhr > "u" || this.xhr === null)) {
|
|
606
|
-
if (this.xhr.onreadystatechange = Ve, e)
|
|
607
|
-
try {
|
|
608
|
-
this.xhr.abort();
|
|
609
|
-
} catch {
|
|
610
|
-
}
|
|
611
|
-
typeof document < "u" && delete p.requests[this.index], this.xhr = null;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Called upon load.
|
|
616
|
-
*
|
|
617
|
-
* @private
|
|
618
|
-
*/
|
|
619
|
-
onLoad() {
|
|
620
|
-
const e = this.xhr.responseText;
|
|
621
|
-
e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this.cleanup());
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* Aborts the request.
|
|
625
|
-
*
|
|
626
|
-
* @package
|
|
627
|
-
*/
|
|
628
|
-
abort() {
|
|
629
|
-
this.cleanup();
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
p.requestsCount = 0;
|
|
633
|
-
p.requests = {};
|
|
634
|
-
if (typeof document < "u") {
|
|
635
|
-
if (typeof attachEvent == "function")
|
|
636
|
-
attachEvent("onunload", te);
|
|
637
|
-
else if (typeof addEventListener == "function") {
|
|
638
|
-
const n = "onpagehide" in u ? "pagehide" : "unload";
|
|
639
|
-
addEventListener(n, te, !1);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
function te() {
|
|
643
|
-
for (let n in p.requests)
|
|
644
|
-
p.requests.hasOwnProperty(n) && p.requests[n].abort();
|
|
645
|
-
}
|
|
646
|
-
const W = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), C = u.WebSocket || u.MozWebSocket, se = !0, He = "arraybuffer", ne = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
|
|
647
|
-
class Ke extends K {
|
|
648
|
-
/**
|
|
649
|
-
* WebSocket transport constructor.
|
|
650
|
-
*
|
|
651
|
-
* @param {Object} opts - connection options
|
|
652
|
-
* @protected
|
|
653
|
-
*/
|
|
654
|
-
constructor(e) {
|
|
655
|
-
super(e), this.supportsBinary = !e.forceBase64;
|
|
656
|
-
}
|
|
657
|
-
get name() {
|
|
658
|
-
return "websocket";
|
|
659
|
-
}
|
|
660
|
-
doOpen() {
|
|
661
|
-
if (!this.check())
|
|
662
|
-
return;
|
|
663
|
-
const e = this.uri(), t = this.opts.protocols, s = ne ? {} : ue(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
664
|
-
this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
|
|
665
|
-
try {
|
|
666
|
-
this.ws = se && !ne ? t ? new C(e, t) : new C(e) : new C(e, t, s);
|
|
667
|
-
} catch (i) {
|
|
668
|
-
return this.emitReserved("error", i);
|
|
669
|
-
}
|
|
670
|
-
this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Adds event listeners to the socket
|
|
674
|
-
*
|
|
675
|
-
* @private
|
|
676
|
-
*/
|
|
677
|
-
addEventListeners() {
|
|
678
|
-
this.ws.onopen = () => {
|
|
679
|
-
this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
|
|
680
|
-
}, this.ws.onclose = (e) => this.onClose({
|
|
681
|
-
description: "websocket connection closed",
|
|
682
|
-
context: e
|
|
683
|
-
}), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
684
|
-
}
|
|
685
|
-
write(e) {
|
|
686
|
-
this.writable = !1;
|
|
687
|
-
for (let t = 0; t < e.length; t++) {
|
|
688
|
-
const s = e[t], i = t === e.length - 1;
|
|
689
|
-
$(s, this.supportsBinary, (r) => {
|
|
690
|
-
const o = {};
|
|
691
|
-
try {
|
|
692
|
-
se && this.ws.send(r);
|
|
693
|
-
} catch {
|
|
694
|
-
}
|
|
695
|
-
i && W(() => {
|
|
696
|
-
this.writable = !0, this.emitReserved("drain");
|
|
697
|
-
}, this.setTimeoutFn);
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
doClose() {
|
|
702
|
-
typeof this.ws < "u" && (this.ws.close(), this.ws = null);
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Generates uri for connection.
|
|
706
|
-
*
|
|
707
|
-
* @private
|
|
708
|
-
*/
|
|
709
|
-
uri() {
|
|
710
|
-
const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
|
|
711
|
-
return this.opts.timestampRequests && (t[this.opts.timestampParam] = pe()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Feature detection for WebSocket.
|
|
715
|
-
*
|
|
716
|
-
* @return {Boolean} whether this transport is available.
|
|
717
|
-
* @private
|
|
718
|
-
*/
|
|
719
|
-
check() {
|
|
720
|
-
return !!C;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
class We extends K {
|
|
724
|
-
get name() {
|
|
725
|
-
return "webtransport";
|
|
726
|
-
}
|
|
727
|
-
doOpen() {
|
|
728
|
-
typeof WebTransport == "function" && (this.transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]), this.transport.closed.then(() => {
|
|
729
|
-
this.onClose();
|
|
730
|
-
}).catch((e) => {
|
|
731
|
-
this.onError("webtransport error", e);
|
|
732
|
-
}), this.transport.ready.then(() => {
|
|
733
|
-
this.transport.createBidirectionalStream().then((e) => {
|
|
734
|
-
const t = Ce(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), i = Oe();
|
|
735
|
-
i.readable.pipeTo(e.writable), this.writer = i.writable.getWriter();
|
|
736
|
-
const r = () => {
|
|
737
|
-
s.read().then(({ done: a, value: h }) => {
|
|
738
|
-
a || (this.onPacket(h), r());
|
|
739
|
-
}).catch((a) => {
|
|
740
|
-
});
|
|
741
|
-
};
|
|
742
|
-
r();
|
|
743
|
-
const o = { type: "open" };
|
|
744
|
-
this.query.sid && (o.data = `{"sid":"${this.query.sid}"}`), this.writer.write(o).then(() => this.onOpen());
|
|
745
|
-
});
|
|
746
|
-
}));
|
|
747
|
-
}
|
|
748
|
-
write(e) {
|
|
749
|
-
this.writable = !1;
|
|
750
|
-
for (let t = 0; t < e.length; t++) {
|
|
751
|
-
const s = e[t], i = t === e.length - 1;
|
|
752
|
-
this.writer.write(s).then(() => {
|
|
753
|
-
i && W(() => {
|
|
754
|
-
this.writable = !0, this.emitReserved("drain");
|
|
755
|
-
}, this.setTimeoutFn);
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
doClose() {
|
|
760
|
-
var e;
|
|
761
|
-
(e = this.transport) === null || e === void 0 || e.close();
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
const ze = {
|
|
765
|
-
websocket: Ke,
|
|
766
|
-
webtransport: We,
|
|
767
|
-
polling: $e
|
|
768
|
-
}, Ye = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, Je = [
|
|
769
|
-
"source",
|
|
770
|
-
"protocol",
|
|
771
|
-
"authority",
|
|
772
|
-
"userInfo",
|
|
773
|
-
"user",
|
|
774
|
-
"password",
|
|
775
|
-
"host",
|
|
776
|
-
"port",
|
|
777
|
-
"relative",
|
|
778
|
-
"path",
|
|
779
|
-
"directory",
|
|
780
|
-
"file",
|
|
781
|
-
"query",
|
|
782
|
-
"anchor"
|
|
783
|
-
];
|
|
784
|
-
function D(n) {
|
|
785
|
-
if (n.length > 2e3)
|
|
786
|
-
throw "URI too long";
|
|
787
|
-
const e = n, t = n.indexOf("["), s = n.indexOf("]");
|
|
788
|
-
t != -1 && s != -1 && (n = n.substring(0, t) + n.substring(t, s).replace(/:/g, ";") + n.substring(s, n.length));
|
|
789
|
-
let i = Ye.exec(n || ""), r = {}, o = 14;
|
|
790
|
-
for (; o--; )
|
|
791
|
-
r[Je[o]] = i[o] || "";
|
|
792
|
-
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 = Qe(r, r.path), r.queryKey = Xe(r, r.query), r;
|
|
793
|
-
}
|
|
794
|
-
function Qe(n, e) {
|
|
795
|
-
const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
|
|
796
|
-
return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
|
|
797
|
-
}
|
|
798
|
-
function Xe(n, e) {
|
|
799
|
-
const t = {};
|
|
800
|
-
return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, i, r) {
|
|
801
|
-
i && (t[i] = r);
|
|
802
|
-
}), t;
|
|
803
|
-
}
|
|
804
|
-
let ge = class b extends f {
|
|
805
|
-
/**
|
|
806
|
-
* Socket constructor.
|
|
807
|
-
*
|
|
808
|
-
* @param {String|Object} uri - uri or options
|
|
809
|
-
* @param {Object} opts - options
|
|
810
|
-
*/
|
|
811
|
-
constructor(e, t = {}) {
|
|
812
|
-
super(), this.binaryType = He, this.writeBuffer = [], e && typeof e == "object" && (t = e, e = null), e ? (e = D(e), t.hostname = e.host, t.secure = e.protocol === "https" || e.protocol === "wss", t.port = e.port, e.query && (t.query = e.query)) : t.host && (t.hostname = D(t.host).host), N(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 = t.transports || [
|
|
813
|
-
"polling",
|
|
814
|
-
"websocket",
|
|
815
|
-
"webtransport"
|
|
816
|
-
], this.writeBuffer = [], this.prevBufferLen = 0, this.opts = Object.assign({
|
|
817
|
-
path: "/engine.io",
|
|
818
|
-
agent: !1,
|
|
819
|
-
withCredentials: !1,
|
|
820
|
-
upgrade: !0,
|
|
821
|
-
timestampParam: "t",
|
|
822
|
-
rememberUpgrade: !1,
|
|
823
|
-
addTrailingSlash: !0,
|
|
824
|
-
rejectUnauthorized: !0,
|
|
825
|
-
perMessageDeflate: {
|
|
826
|
-
threshold: 1024
|
|
827
|
-
},
|
|
828
|
-
transportOptions: {},
|
|
829
|
-
closeOnBeforeunload: !1
|
|
830
|
-
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Ie(this.opts.query)), this.id = null, this.upgrades = null, this.pingInterval = null, this.pingTimeout = null, this.pingTimeoutTimer = null, typeof addEventListener == "function" && (this.opts.closeOnBeforeunload && (this.beforeunloadEventListener = () => {
|
|
831
|
-
this.transport && (this.transport.removeAllListeners(), this.transport.close());
|
|
832
|
-
}, addEventListener("beforeunload", this.beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this.offlineEventListener = () => {
|
|
833
|
-
this.onClose("transport close", {
|
|
834
|
-
description: "network connection lost"
|
|
835
|
-
});
|
|
836
|
-
}, addEventListener("offline", this.offlineEventListener, !1))), this.open();
|
|
837
|
-
}
|
|
838
|
-
/**
|
|
839
|
-
* Creates transport of the given type.
|
|
840
|
-
*
|
|
841
|
-
* @param {String} name - transport name
|
|
842
|
-
* @return {Transport}
|
|
843
|
-
* @private
|
|
844
|
-
*/
|
|
845
|
-
createTransport(e) {
|
|
846
|
-
const t = Object.assign({}, this.opts.query);
|
|
847
|
-
t.EIO = fe, t.transport = e, this.id && (t.sid = this.id);
|
|
848
|
-
const s = Object.assign({}, this.opts, {
|
|
849
|
-
query: t,
|
|
850
|
-
socket: this,
|
|
851
|
-
hostname: this.hostname,
|
|
852
|
-
secure: this.secure,
|
|
853
|
-
port: this.port
|
|
854
|
-
}, this.opts.transportOptions[e]);
|
|
855
|
-
return new ze[e](s);
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Initializes transport to use and starts probe.
|
|
859
|
-
*
|
|
860
|
-
* @private
|
|
861
|
-
*/
|
|
862
|
-
open() {
|
|
863
|
-
let e;
|
|
864
|
-
if (this.opts.rememberUpgrade && b.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1)
|
|
865
|
-
e = "websocket";
|
|
866
|
-
else if (this.transports.length === 0) {
|
|
867
|
-
this.setTimeoutFn(() => {
|
|
868
|
-
this.emitReserved("error", "No transports available");
|
|
869
|
-
}, 0);
|
|
870
|
-
return;
|
|
871
|
-
} else
|
|
872
|
-
e = this.transports[0];
|
|
873
|
-
this.readyState = "opening";
|
|
874
|
-
try {
|
|
875
|
-
e = this.createTransport(e);
|
|
876
|
-
} catch {
|
|
877
|
-
this.transports.shift(), this.open();
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
e.open(), this.setTransport(e);
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Sets the current transport. Disables the existing one (if any).
|
|
884
|
-
*
|
|
885
|
-
* @private
|
|
886
|
-
*/
|
|
887
|
-
setTransport(e) {
|
|
888
|
-
this.transport && this.transport.removeAllListeners(), this.transport = e, e.on("drain", this.onDrain.bind(this)).on("packet", this.onPacket.bind(this)).on("error", this.onError.bind(this)).on("close", (t) => this.onClose("transport close", t));
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Probes a transport.
|
|
892
|
-
*
|
|
893
|
-
* @param {String} name - transport name
|
|
894
|
-
* @private
|
|
895
|
-
*/
|
|
896
|
-
probe(e) {
|
|
897
|
-
let t = this.createTransport(e), s = !1;
|
|
898
|
-
b.priorWebsocketSuccess = !1;
|
|
899
|
-
const i = () => {
|
|
900
|
-
s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (w) => {
|
|
901
|
-
if (!s)
|
|
902
|
-
if (w.type === "pong" && w.data === "probe") {
|
|
903
|
-
if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
|
|
904
|
-
return;
|
|
905
|
-
b.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
|
|
906
|
-
s || this.readyState !== "closed" && (y(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
|
|
907
|
-
});
|
|
908
|
-
} else {
|
|
909
|
-
const k = new Error("probe error");
|
|
910
|
-
k.transport = t.name, this.emitReserved("upgradeError", k);
|
|
911
|
-
}
|
|
912
|
-
}));
|
|
913
|
-
};
|
|
914
|
-
function r() {
|
|
915
|
-
s || (s = !0, y(), t.close(), t = null);
|
|
916
|
-
}
|
|
917
|
-
const o = (w) => {
|
|
918
|
-
const k = new Error("probe error: " + w);
|
|
919
|
-
k.transport = t.name, r(), this.emitReserved("upgradeError", k);
|
|
920
|
-
};
|
|
921
|
-
function a() {
|
|
922
|
-
o("transport closed");
|
|
923
|
-
}
|
|
924
|
-
function h() {
|
|
925
|
-
o("socket closed");
|
|
926
|
-
}
|
|
927
|
-
function g(w) {
|
|
928
|
-
t && w.name !== t.name && r();
|
|
929
|
-
}
|
|
930
|
-
const y = () => {
|
|
931
|
-
t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", a), this.off("close", h), this.off("upgrading", g);
|
|
932
|
-
};
|
|
933
|
-
t.once("open", i), t.once("error", o), t.once("close", a), this.once("close", h), this.once("upgrading", g), this.upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
|
|
934
|
-
s || t.open();
|
|
935
|
-
}, 200) : t.open();
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Called when connection is deemed open.
|
|
939
|
-
*
|
|
940
|
-
* @private
|
|
941
|
-
*/
|
|
942
|
-
onOpen() {
|
|
943
|
-
if (this.readyState = "open", b.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush(), this.readyState === "open" && this.opts.upgrade) {
|
|
944
|
-
let e = 0;
|
|
945
|
-
const t = this.upgrades.length;
|
|
946
|
-
for (; e < t; e++)
|
|
947
|
-
this.probe(this.upgrades[e]);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Handles a packet.
|
|
952
|
-
*
|
|
953
|
-
* @private
|
|
954
|
-
*/
|
|
955
|
-
onPacket(e) {
|
|
956
|
-
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing")
|
|
957
|
-
switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), this.resetPingTimeout(), e.type) {
|
|
958
|
-
case "open":
|
|
959
|
-
this.onHandshake(JSON.parse(e.data));
|
|
960
|
-
break;
|
|
961
|
-
case "ping":
|
|
962
|
-
this.sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong");
|
|
963
|
-
break;
|
|
964
|
-
case "error":
|
|
965
|
-
const t = new Error("server error");
|
|
966
|
-
t.code = e.data, this.onError(t);
|
|
967
|
-
break;
|
|
968
|
-
case "message":
|
|
969
|
-
this.emitReserved("data", e.data), this.emitReserved("message", e.data);
|
|
970
|
-
break;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Called upon handshake completion.
|
|
975
|
-
*
|
|
976
|
-
* @param {Object} data - handshake obj
|
|
977
|
-
* @private
|
|
978
|
-
*/
|
|
979
|
-
onHandshake(e) {
|
|
980
|
-
this.emitReserved("handshake", e), this.id = e.sid, this.transport.query.sid = e.sid, this.upgrades = this.filterUpgrades(e.upgrades), this.pingInterval = e.pingInterval, this.pingTimeout = e.pingTimeout, this.maxPayload = e.maxPayload, this.onOpen(), this.readyState !== "closed" && this.resetPingTimeout();
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Sets and resets ping timeout timer based on server pings.
|
|
984
|
-
*
|
|
985
|
-
* @private
|
|
986
|
-
*/
|
|
987
|
-
resetPingTimeout() {
|
|
988
|
-
this.clearTimeoutFn(this.pingTimeoutTimer), this.pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
989
|
-
this.onClose("ping timeout");
|
|
990
|
-
}, this.pingInterval + this.pingTimeout), this.opts.autoUnref && this.pingTimeoutTimer.unref();
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Called on `drain` event
|
|
994
|
-
*
|
|
995
|
-
* @private
|
|
996
|
-
*/
|
|
997
|
-
onDrain() {
|
|
998
|
-
this.writeBuffer.splice(0, this.prevBufferLen), this.prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Flush write buffers.
|
|
1002
|
-
*
|
|
1003
|
-
* @private
|
|
1004
|
-
*/
|
|
1005
|
-
flush() {
|
|
1006
|
-
if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
1007
|
-
const e = this.getWritablePackets();
|
|
1008
|
-
this.transport.send(e), this.prevBufferLen = e.length, this.emitReserved("flush");
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
1013
|
-
* long-polling)
|
|
1014
|
-
*
|
|
1015
|
-
* @private
|
|
1016
|
-
*/
|
|
1017
|
-
getWritablePackets() {
|
|
1018
|
-
if (!(this.maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1))
|
|
1019
|
-
return this.writeBuffer;
|
|
1020
|
-
let t = 1;
|
|
1021
|
-
for (let s = 0; s < this.writeBuffer.length; s++) {
|
|
1022
|
-
const i = this.writeBuffer[s].data;
|
|
1023
|
-
if (i && (t += Le(i)), s > 0 && t > this.maxPayload)
|
|
1024
|
-
return this.writeBuffer.slice(0, s);
|
|
1025
|
-
t += 2;
|
|
1026
|
-
}
|
|
1027
|
-
return this.writeBuffer;
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Sends a message.
|
|
1031
|
-
*
|
|
1032
|
-
* @param {String} msg - message.
|
|
1033
|
-
* @param {Object} options.
|
|
1034
|
-
* @param {Function} callback function.
|
|
1035
|
-
* @return {Socket} for chaining.
|
|
1036
|
-
*/
|
|
1037
|
-
write(e, t, s) {
|
|
1038
|
-
return this.sendPacket("message", e, t, s), this;
|
|
1039
|
-
}
|
|
1040
|
-
send(e, t, s) {
|
|
1041
|
-
return this.sendPacket("message", e, t, s), this;
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Sends a packet.
|
|
1045
|
-
*
|
|
1046
|
-
* @param {String} type: packet type.
|
|
1047
|
-
* @param {String} data.
|
|
1048
|
-
* @param {Object} options.
|
|
1049
|
-
* @param {Function} fn - callback function.
|
|
1050
|
-
* @private
|
|
1051
|
-
*/
|
|
1052
|
-
sendPacket(e, t, s, i) {
|
|
1053
|
-
if (typeof t == "function" && (i = t, t = void 0), typeof s == "function" && (i = s, s = null), this.readyState === "closing" || this.readyState === "closed")
|
|
1054
|
-
return;
|
|
1055
|
-
s = s || {}, s.compress = s.compress !== !1;
|
|
1056
|
-
const r = {
|
|
1057
|
-
type: e,
|
|
1058
|
-
data: t,
|
|
1059
|
-
options: s
|
|
1060
|
-
};
|
|
1061
|
-
this.emitReserved("packetCreate", r), this.writeBuffer.push(r), i && this.once("flush", i), this.flush();
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Closes the connection.
|
|
1065
|
-
*/
|
|
1066
|
-
close() {
|
|
1067
|
-
const e = () => {
|
|
1068
|
-
this.onClose("forced close"), this.transport.close();
|
|
1069
|
-
}, t = () => {
|
|
1070
|
-
this.off("upgrade", t), this.off("upgradeError", t), e();
|
|
1071
|
-
}, s = () => {
|
|
1072
|
-
this.once("upgrade", t), this.once("upgradeError", t);
|
|
1073
|
-
};
|
|
1074
|
-
return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
|
|
1075
|
-
this.upgrading ? s() : e();
|
|
1076
|
-
}) : this.upgrading ? s() : e()), this;
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* Called upon transport error
|
|
1080
|
-
*
|
|
1081
|
-
* @private
|
|
1082
|
-
*/
|
|
1083
|
-
onError(e) {
|
|
1084
|
-
b.priorWebsocketSuccess = !1, this.emitReserved("error", e), this.onClose("transport error", e);
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Called upon transport close.
|
|
1088
|
-
*
|
|
1089
|
-
* @private
|
|
1090
|
-
*/
|
|
1091
|
-
onClose(e, t) {
|
|
1092
|
-
(this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") && (this.clearTimeoutFn(this.pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), typeof removeEventListener == "function" && (removeEventListener("beforeunload", this.beforeunloadEventListener, !1), removeEventListener("offline", this.offlineEventListener, !1)), this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this.prevBufferLen = 0);
|
|
1093
|
-
}
|
|
1094
|
-
/**
|
|
1095
|
-
* Filters upgrades, returning only those matching client transports.
|
|
1096
|
-
*
|
|
1097
|
-
* @param {Array} upgrades - server upgrades
|
|
1098
|
-
* @private
|
|
1099
|
-
*/
|
|
1100
|
-
filterUpgrades(e) {
|
|
1101
|
-
const t = [];
|
|
1102
|
-
let s = 0;
|
|
1103
|
-
const i = e.length;
|
|
1104
|
-
for (; s < i; s++)
|
|
1105
|
-
~this.transports.indexOf(e[s]) && t.push(e[s]);
|
|
1106
|
-
return t;
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
ge.protocol = fe;
|
|
1110
|
-
function je(n, e = "", t) {
|
|
1111
|
-
let s = n;
|
|
1112
|
-
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 = D(n)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
|
|
1113
|
-
const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
|
|
1114
|
-
return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
|
|
1115
|
-
}
|
|
1116
|
-
const Ge = typeof ArrayBuffer == "function", Ze = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, me = Object.prototype.toString, et = typeof Blob == "function" || typeof Blob < "u" && me.call(Blob) === "[object BlobConstructor]", tt = typeof File == "function" || typeof File < "u" && me.call(File) === "[object FileConstructor]";
|
|
1117
|
-
function z(n) {
|
|
1118
|
-
return Ge && (n instanceof ArrayBuffer || Ze(n)) || et && n instanceof Blob || tt && n instanceof File;
|
|
1119
|
-
}
|
|
1120
|
-
function B(n, e) {
|
|
1121
|
-
if (!n || typeof n != "object")
|
|
1122
|
-
return !1;
|
|
1123
|
-
if (Array.isArray(n)) {
|
|
1124
|
-
for (let t = 0, s = n.length; t < s; t++)
|
|
1125
|
-
if (B(n[t]))
|
|
1126
|
-
return !0;
|
|
1127
|
-
return !1;
|
|
1128
|
-
}
|
|
1129
|
-
if (z(n))
|
|
1130
|
-
return !0;
|
|
1131
|
-
if (n.toJSON && typeof n.toJSON == "function" && arguments.length === 1)
|
|
1132
|
-
return B(n.toJSON(), !0);
|
|
1133
|
-
for (const t in n)
|
|
1134
|
-
if (Object.prototype.hasOwnProperty.call(n, t) && B(n[t]))
|
|
1135
|
-
return !0;
|
|
1136
|
-
return !1;
|
|
1137
|
-
}
|
|
1138
|
-
function st(n) {
|
|
1139
|
-
const e = [], t = n.data, s = n;
|
|
1140
|
-
return s.data = U(t, e), s.attachments = e.length, { packet: s, buffers: e };
|
|
1141
|
-
}
|
|
1142
|
-
function U(n, e) {
|
|
1143
|
-
if (!n)
|
|
1144
|
-
return n;
|
|
1145
|
-
if (z(n)) {
|
|
1146
|
-
const t = { _placeholder: !0, num: e.length };
|
|
1147
|
-
return e.push(n), t;
|
|
1148
|
-
} else if (Array.isArray(n)) {
|
|
1149
|
-
const t = new Array(n.length);
|
|
1150
|
-
for (let s = 0; s < n.length; s++)
|
|
1151
|
-
t[s] = U(n[s], e);
|
|
1152
|
-
return t;
|
|
1153
|
-
} else if (typeof n == "object" && !(n instanceof Date)) {
|
|
1154
|
-
const t = {};
|
|
1155
|
-
for (const s in n)
|
|
1156
|
-
Object.prototype.hasOwnProperty.call(n, s) && (t[s] = U(n[s], e));
|
|
1157
|
-
return t;
|
|
1158
|
-
}
|
|
1159
|
-
return n;
|
|
1160
|
-
}
|
|
1161
|
-
function nt(n, e) {
|
|
1162
|
-
return n.data = M(n.data, e), delete n.attachments, n;
|
|
1163
|
-
}
|
|
1164
|
-
function M(n, e) {
|
|
1165
|
-
if (!n)
|
|
1166
|
-
return n;
|
|
1167
|
-
if (n && n._placeholder === !0) {
|
|
1168
|
-
if (typeof n.num == "number" && n.num >= 0 && n.num < e.length)
|
|
1169
|
-
return e[n.num];
|
|
1170
|
-
throw new Error("illegal attachments");
|
|
1171
|
-
} else if (Array.isArray(n))
|
|
1172
|
-
for (let t = 0; t < n.length; t++)
|
|
1173
|
-
n[t] = M(n[t], e);
|
|
1174
|
-
else if (typeof n == "object")
|
|
1175
|
-
for (const t in n)
|
|
1176
|
-
Object.prototype.hasOwnProperty.call(n, t) && (n[t] = M(n[t], e));
|
|
1177
|
-
return n;
|
|
1178
|
-
}
|
|
1179
|
-
const it = [
|
|
1180
|
-
"connect",
|
|
1181
|
-
"connect_error",
|
|
1182
|
-
"disconnect",
|
|
1183
|
-
"disconnecting",
|
|
1184
|
-
"newListener",
|
|
1185
|
-
"removeListener"
|
|
1186
|
-
// used by the Node.js EventEmitter
|
|
1187
|
-
], rt = 5;
|
|
1188
|
-
var c;
|
|
1189
|
-
(function(n) {
|
|
1190
|
-
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";
|
|
1191
|
-
})(c || (c = {}));
|
|
1192
|
-
class ot {
|
|
1193
|
-
/**
|
|
1194
|
-
* Encoder constructor
|
|
1195
|
-
*
|
|
1196
|
-
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
1197
|
-
*/
|
|
1198
|
-
constructor(e) {
|
|
1199
|
-
this.replacer = e;
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Encode a packet as a single string if non-binary, or as a
|
|
1203
|
-
* buffer sequence, depending on packet type.
|
|
1204
|
-
*
|
|
1205
|
-
* @param {Object} obj - packet object
|
|
1206
|
-
*/
|
|
1207
|
-
encode(e) {
|
|
1208
|
-
return (e.type === c.EVENT || e.type === c.ACK) && B(e) ? this.encodeAsBinary({
|
|
1209
|
-
type: e.type === c.EVENT ? c.BINARY_EVENT : c.BINARY_ACK,
|
|
1210
|
-
nsp: e.nsp,
|
|
1211
|
-
data: e.data,
|
|
1212
|
-
id: e.id
|
|
1213
|
-
}) : [this.encodeAsString(e)];
|
|
1214
|
-
}
|
|
1215
|
-
/**
|
|
1216
|
-
* Encode packet as string.
|
|
1217
|
-
*/
|
|
1218
|
-
encodeAsString(e) {
|
|
1219
|
-
let t = "" + e.type;
|
|
1220
|
-
return (e.type === c.BINARY_EVENT || e.type === c.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;
|
|
1221
|
-
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Encode packet as 'buffer sequence' by removing blobs, and
|
|
1224
|
-
* deconstructing packet into object with placeholders and
|
|
1225
|
-
* a list of buffers.
|
|
1226
|
-
*/
|
|
1227
|
-
encodeAsBinary(e) {
|
|
1228
|
-
const t = st(e), s = this.encodeAsString(t.packet), i = t.buffers;
|
|
1229
|
-
return i.unshift(s), i;
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
function ie(n) {
|
|
1233
|
-
return Object.prototype.toString.call(n) === "[object Object]";
|
|
1234
|
-
}
|
|
1235
|
-
class Y extends f {
|
|
1236
|
-
/**
|
|
1237
|
-
* Decoder constructor
|
|
1238
|
-
*
|
|
1239
|
-
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
1240
|
-
*/
|
|
1241
|
-
constructor(e) {
|
|
1242
|
-
super(), this.reviver = e;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Decodes an encoded packet string into packet JSON.
|
|
1246
|
-
*
|
|
1247
|
-
* @param {String} obj - encoded packet
|
|
1248
|
-
*/
|
|
1249
|
-
add(e) {
|
|
1250
|
-
let t;
|
|
1251
|
-
if (typeof e == "string") {
|
|
1252
|
-
if (this.reconstructor)
|
|
1253
|
-
throw new Error("got plaintext data when reconstructing a packet");
|
|
1254
|
-
t = this.decodeString(e);
|
|
1255
|
-
const s = t.type === c.BINARY_EVENT;
|
|
1256
|
-
s || t.type === c.BINARY_ACK ? (t.type = s ? c.EVENT : c.ACK, this.reconstructor = new ct(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
|
|
1257
|
-
} else if (z(e) || e.base64)
|
|
1258
|
-
if (this.reconstructor)
|
|
1259
|
-
t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
|
|
1260
|
-
else
|
|
1261
|
-
throw new Error("got binary data when not reconstructing a packet");
|
|
1262
|
-
else
|
|
1263
|
-
throw new Error("Unknown type: " + e);
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Decode a packet String (JSON data)
|
|
1267
|
-
*
|
|
1268
|
-
* @param {String} str
|
|
1269
|
-
* @return {Object} packet
|
|
1270
|
-
*/
|
|
1271
|
-
decodeString(e) {
|
|
1272
|
-
let t = 0;
|
|
1273
|
-
const s = {
|
|
1274
|
-
type: Number(e.charAt(0))
|
|
1275
|
-
};
|
|
1276
|
-
if (c[s.type] === void 0)
|
|
1277
|
-
throw new Error("unknown packet type " + s.type);
|
|
1278
|
-
if (s.type === c.BINARY_EVENT || s.type === c.BINARY_ACK) {
|
|
1279
|
-
const r = t + 1;
|
|
1280
|
-
for (; e.charAt(++t) !== "-" && t != e.length; )
|
|
1281
|
-
;
|
|
1282
|
-
const o = e.substring(r, t);
|
|
1283
|
-
if (o != Number(o) || e.charAt(t) !== "-")
|
|
1284
|
-
throw new Error("Illegal attachments");
|
|
1285
|
-
s.attachments = Number(o);
|
|
1286
|
-
}
|
|
1287
|
-
if (e.charAt(t + 1) === "/") {
|
|
1288
|
-
const r = t + 1;
|
|
1289
|
-
for (; ++t && !(e.charAt(t) === "," || t === e.length); )
|
|
1290
|
-
;
|
|
1291
|
-
s.nsp = e.substring(r, t);
|
|
1292
|
-
} else
|
|
1293
|
-
s.nsp = "/";
|
|
1294
|
-
const i = e.charAt(t + 1);
|
|
1295
|
-
if (i !== "" && Number(i) == i) {
|
|
1296
|
-
const r = t + 1;
|
|
1297
|
-
for (; ++t; ) {
|
|
1298
|
-
const o = e.charAt(t);
|
|
1299
|
-
if (o == null || Number(o) != o) {
|
|
1300
|
-
--t;
|
|
1301
|
-
break;
|
|
1302
|
-
}
|
|
1303
|
-
if (t === e.length)
|
|
1304
|
-
break;
|
|
1305
|
-
}
|
|
1306
|
-
s.id = Number(e.substring(r, t + 1));
|
|
1307
|
-
}
|
|
1308
|
-
if (e.charAt(++t)) {
|
|
1309
|
-
const r = this.tryParse(e.substr(t));
|
|
1310
|
-
if (Y.isPayloadValid(s.type, r))
|
|
1311
|
-
s.data = r;
|
|
1312
|
-
else
|
|
1313
|
-
throw new Error("invalid payload");
|
|
1314
|
-
}
|
|
1315
|
-
return s;
|
|
1316
|
-
}
|
|
1317
|
-
tryParse(e) {
|
|
1318
|
-
try {
|
|
1319
|
-
return JSON.parse(e, this.reviver);
|
|
1320
|
-
} catch {
|
|
1321
|
-
return !1;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
static isPayloadValid(e, t) {
|
|
1325
|
-
switch (e) {
|
|
1326
|
-
case c.CONNECT:
|
|
1327
|
-
return ie(t);
|
|
1328
|
-
case c.DISCONNECT:
|
|
1329
|
-
return t === void 0;
|
|
1330
|
-
case c.CONNECT_ERROR:
|
|
1331
|
-
return typeof t == "string" || ie(t);
|
|
1332
|
-
case c.EVENT:
|
|
1333
|
-
case c.BINARY_EVENT:
|
|
1334
|
-
return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && it.indexOf(t[0]) === -1);
|
|
1335
|
-
case c.ACK:
|
|
1336
|
-
case c.BINARY_ACK:
|
|
1337
|
-
return Array.isArray(t);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Deallocates a parser's resources
|
|
1342
|
-
*/
|
|
1343
|
-
destroy() {
|
|
1344
|
-
this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
class ct {
|
|
1348
|
-
constructor(e) {
|
|
1349
|
-
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Method to be called when binary data received from connection
|
|
1353
|
-
* after a BINARY_EVENT packet.
|
|
1354
|
-
*
|
|
1355
|
-
* @param {Buffer | ArrayBuffer} binData - the raw binary data received
|
|
1356
|
-
* @return {null | Object} returns null if more binary data is expected or
|
|
1357
|
-
* a reconstructed packet object if all buffers have been received.
|
|
1358
|
-
*/
|
|
1359
|
-
takeBinaryData(e) {
|
|
1360
|
-
if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
|
|
1361
|
-
const t = nt(this.reconPack, this.buffers);
|
|
1362
|
-
return this.finishedReconstruction(), t;
|
|
1363
|
-
}
|
|
1364
|
-
return null;
|
|
1365
|
-
}
|
|
1366
|
-
/**
|
|
1367
|
-
* Cleans up binary packet reconstruction variables.
|
|
1368
|
-
*/
|
|
1369
|
-
finishedReconstruction() {
|
|
1370
|
-
this.reconPack = null, this.buffers = [];
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
const at = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1374
|
-
__proto__: null,
|
|
1375
|
-
Decoder: Y,
|
|
1376
|
-
Encoder: ot,
|
|
1377
|
-
get PacketType() {
|
|
1378
|
-
return c;
|
|
1379
|
-
},
|
|
1380
|
-
protocol: rt
|
|
1381
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1382
|
-
function l(n, e, t) {
|
|
1383
|
-
return n.on(e, t), function() {
|
|
1384
|
-
n.off(e, t);
|
|
1385
|
-
};
|
|
1386
|
-
}
|
|
1387
|
-
const ht = Object.freeze({
|
|
1388
|
-
connect: 1,
|
|
1389
|
-
connect_error: 1,
|
|
1390
|
-
disconnect: 1,
|
|
1391
|
-
disconnecting: 1,
|
|
1392
|
-
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
|
1393
|
-
newListener: 1,
|
|
1394
|
-
removeListener: 1
|
|
1395
|
-
});
|
|
1396
|
-
class we extends f {
|
|
1397
|
-
/**
|
|
1398
|
-
* `Socket` constructor.
|
|
1399
|
-
*/
|
|
1400
|
-
constructor(e, t, s) {
|
|
1401
|
-
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();
|
|
1402
|
-
}
|
|
1403
|
-
/**
|
|
1404
|
-
* Whether the socket is currently disconnected
|
|
1405
|
-
*
|
|
1406
|
-
* @example
|
|
1407
|
-
* const socket = io();
|
|
1408
|
-
*
|
|
1409
|
-
* socket.on("connect", () => {
|
|
1410
|
-
* console.log(socket.disconnected); // false
|
|
1411
|
-
* });
|
|
1412
|
-
*
|
|
1413
|
-
* socket.on("disconnect", () => {
|
|
1414
|
-
* console.log(socket.disconnected); // true
|
|
1415
|
-
* });
|
|
1416
|
-
*/
|
|
1417
|
-
get disconnected() {
|
|
1418
|
-
return !this.connected;
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Subscribe to open, close and packet events
|
|
1422
|
-
*
|
|
1423
|
-
* @private
|
|
1424
|
-
*/
|
|
1425
|
-
subEvents() {
|
|
1426
|
-
if (this.subs)
|
|
1427
|
-
return;
|
|
1428
|
-
const e = this.io;
|
|
1429
|
-
this.subs = [
|
|
1430
|
-
l(e, "open", this.onopen.bind(this)),
|
|
1431
|
-
l(e, "packet", this.onpacket.bind(this)),
|
|
1432
|
-
l(e, "error", this.onerror.bind(this)),
|
|
1433
|
-
l(e, "close", this.onclose.bind(this))
|
|
1434
|
-
];
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
1438
|
-
*
|
|
1439
|
-
* @example
|
|
1440
|
-
* const socket = io();
|
|
1441
|
-
*
|
|
1442
|
-
* console.log(socket.active); // true
|
|
1443
|
-
*
|
|
1444
|
-
* socket.on("disconnect", (reason) => {
|
|
1445
|
-
* if (reason === "io server disconnect") {
|
|
1446
|
-
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
1447
|
-
* console.log(socket.active); // false
|
|
1448
|
-
* }
|
|
1449
|
-
* // else the socket will automatically try to reconnect
|
|
1450
|
-
* console.log(socket.active); // true
|
|
1451
|
-
* });
|
|
1452
|
-
*/
|
|
1453
|
-
get active() {
|
|
1454
|
-
return !!this.subs;
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* "Opens" the socket.
|
|
1458
|
-
*
|
|
1459
|
-
* @example
|
|
1460
|
-
* const socket = io({
|
|
1461
|
-
* autoConnect: false
|
|
1462
|
-
* });
|
|
1463
|
-
*
|
|
1464
|
-
* socket.connect();
|
|
1465
|
-
*/
|
|
1466
|
-
connect() {
|
|
1467
|
-
return this.connected ? this : (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen(), this);
|
|
1468
|
-
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Alias for {@link connect()}.
|
|
1471
|
-
*/
|
|
1472
|
-
open() {
|
|
1473
|
-
return this.connect();
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Sends a `message` event.
|
|
1477
|
-
*
|
|
1478
|
-
* This method mimics the WebSocket.send() method.
|
|
1479
|
-
*
|
|
1480
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
1481
|
-
*
|
|
1482
|
-
* @example
|
|
1483
|
-
* socket.send("hello");
|
|
1484
|
-
*
|
|
1485
|
-
* // this is equivalent to
|
|
1486
|
-
* socket.emit("message", "hello");
|
|
1487
|
-
*
|
|
1488
|
-
* @return self
|
|
1489
|
-
*/
|
|
1490
|
-
send(...e) {
|
|
1491
|
-
return e.unshift("message"), this.emit.apply(this, e), this;
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Override `emit`.
|
|
1495
|
-
* If the event is in `events`, it's emitted normally.
|
|
1496
|
-
*
|
|
1497
|
-
* @example
|
|
1498
|
-
* socket.emit("hello", "world");
|
|
1499
|
-
*
|
|
1500
|
-
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
1501
|
-
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
1502
|
-
*
|
|
1503
|
-
* // with an acknowledgement from the server
|
|
1504
|
-
* socket.emit("hello", "world", (val) => {
|
|
1505
|
-
* // ...
|
|
1506
|
-
* });
|
|
1507
|
-
*
|
|
1508
|
-
* @return self
|
|
1509
|
-
*/
|
|
1510
|
-
emit(e, ...t) {
|
|
1511
|
-
if (ht.hasOwnProperty(e))
|
|
1512
|
-
throw new Error('"' + e.toString() + '" is a reserved event name');
|
|
1513
|
-
if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
|
|
1514
|
-
return this._addToQueue(t), this;
|
|
1515
|
-
const s = {
|
|
1516
|
-
type: c.EVENT,
|
|
1517
|
-
data: t
|
|
1518
|
-
};
|
|
1519
|
-
if (s.options = {}, s.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
|
|
1520
|
-
const o = this.ids++, a = t.pop();
|
|
1521
|
-
this._registerAckCallback(o, a), s.id = o;
|
|
1522
|
-
}
|
|
1523
|
-
const i = this.io.engine && this.io.engine.transport && this.io.engine.transport.writable;
|
|
1524
|
-
return this.flags.volatile && (!i || !this.connected) || (this.connected ? (this.notifyOutgoingListeners(s), this.packet(s)) : this.sendBuffer.push(s)), this.flags = {}, this;
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* @private
|
|
1528
|
-
*/
|
|
1529
|
-
_registerAckCallback(e, t) {
|
|
1530
|
-
var s;
|
|
1531
|
-
const i = (s = this.flags.timeout) !== null && s !== void 0 ? s : this._opts.ackTimeout;
|
|
1532
|
-
if (i === void 0) {
|
|
1533
|
-
this.acks[e] = t;
|
|
1534
|
-
return;
|
|
1535
|
-
}
|
|
1536
|
-
const r = this.io.setTimeoutFn(() => {
|
|
1537
|
-
delete this.acks[e];
|
|
1538
|
-
for (let a = 0; a < this.sendBuffer.length; a++)
|
|
1539
|
-
this.sendBuffer[a].id === e && this.sendBuffer.splice(a, 1);
|
|
1540
|
-
t.call(this, new Error("operation has timed out"));
|
|
1541
|
-
}, i), o = (...a) => {
|
|
1542
|
-
this.io.clearTimeoutFn(r), t.apply(this, a);
|
|
1543
|
-
};
|
|
1544
|
-
o.withError = !0, this.acks[e] = o;
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Emits an event and waits for an acknowledgement
|
|
1548
|
-
*
|
|
1549
|
-
* @example
|
|
1550
|
-
* // without timeout
|
|
1551
|
-
* const response = await socket.emitWithAck("hello", "world");
|
|
1552
|
-
*
|
|
1553
|
-
* // with a specific timeout
|
|
1554
|
-
* try {
|
|
1555
|
-
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
1556
|
-
* } catch (err) {
|
|
1557
|
-
* // the server did not acknowledge the event in the given delay
|
|
1558
|
-
* }
|
|
1559
|
-
*
|
|
1560
|
-
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
1561
|
-
*/
|
|
1562
|
-
emitWithAck(e, ...t) {
|
|
1563
|
-
return new Promise((s, i) => {
|
|
1564
|
-
const r = (o, a) => o ? i(o) : s(a);
|
|
1565
|
-
r.withError = !0, t.push(r), this.emit(e, ...t);
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
/**
|
|
1569
|
-
* Add the packet to the queue.
|
|
1570
|
-
* @param args
|
|
1571
|
-
* @private
|
|
1572
|
-
*/
|
|
1573
|
-
_addToQueue(e) {
|
|
1574
|
-
let t;
|
|
1575
|
-
typeof e[e.length - 1] == "function" && (t = e.pop());
|
|
1576
|
-
const s = {
|
|
1577
|
-
id: this._queueSeq++,
|
|
1578
|
-
tryCount: 0,
|
|
1579
|
-
pending: !1,
|
|
1580
|
-
args: e,
|
|
1581
|
-
flags: Object.assign({ fromQueue: !0 }, this.flags)
|
|
1582
|
-
};
|
|
1583
|
-
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();
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
1587
|
-
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
1588
|
-
*
|
|
1589
|
-
* @private
|
|
1590
|
-
*/
|
|
1591
|
-
_drainQueue(e = !1) {
|
|
1592
|
-
if (!this.connected || this._queue.length === 0)
|
|
1593
|
-
return;
|
|
1594
|
-
const t = this._queue[0];
|
|
1595
|
-
t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Sends a packet.
|
|
1599
|
-
*
|
|
1600
|
-
* @param packet
|
|
1601
|
-
* @private
|
|
1602
|
-
*/
|
|
1603
|
-
packet(e) {
|
|
1604
|
-
e.nsp = this.nsp, this.io._packet(e);
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Called upon engine `open`.
|
|
1608
|
-
*
|
|
1609
|
-
* @private
|
|
1610
|
-
*/
|
|
1611
|
-
onopen() {
|
|
1612
|
-
typeof this.auth == "function" ? this.auth((e) => {
|
|
1613
|
-
this._sendConnectPacket(e);
|
|
1614
|
-
}) : this._sendConnectPacket(this.auth);
|
|
1615
|
-
}
|
|
1616
|
-
/**
|
|
1617
|
-
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
1618
|
-
*
|
|
1619
|
-
* @param data
|
|
1620
|
-
* @private
|
|
1621
|
-
*/
|
|
1622
|
-
_sendConnectPacket(e) {
|
|
1623
|
-
this.packet({
|
|
1624
|
-
type: c.CONNECT,
|
|
1625
|
-
data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
/**
|
|
1629
|
-
* Called upon engine or manager `error`.
|
|
1630
|
-
*
|
|
1631
|
-
* @param err
|
|
1632
|
-
* @private
|
|
1633
|
-
*/
|
|
1634
|
-
onerror(e) {
|
|
1635
|
-
this.connected || this.emitReserved("connect_error", e);
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* Called upon engine `close`.
|
|
1639
|
-
*
|
|
1640
|
-
* @param reason
|
|
1641
|
-
* @param description
|
|
1642
|
-
* @private
|
|
1643
|
-
*/
|
|
1644
|
-
onclose(e, t) {
|
|
1645
|
-
this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
|
|
1646
|
-
}
|
|
1647
|
-
/**
|
|
1648
|
-
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
1649
|
-
* the server.
|
|
1650
|
-
*
|
|
1651
|
-
* @private
|
|
1652
|
-
*/
|
|
1653
|
-
_clearAcks() {
|
|
1654
|
-
Object.keys(this.acks).forEach((e) => {
|
|
1655
|
-
if (!this.sendBuffer.some((s) => String(s.id) === e)) {
|
|
1656
|
-
const s = this.acks[e];
|
|
1657
|
-
delete this.acks[e], s.withError && s.call(this, new Error("socket has been disconnected"));
|
|
1658
|
-
}
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Called with socket packet.
|
|
1663
|
-
*
|
|
1664
|
-
* @param packet
|
|
1665
|
-
* @private
|
|
1666
|
-
*/
|
|
1667
|
-
onpacket(e) {
|
|
1668
|
-
if (e.nsp === this.nsp)
|
|
1669
|
-
switch (e.type) {
|
|
1670
|
-
case c.CONNECT:
|
|
1671
|
-
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/)"));
|
|
1672
|
-
break;
|
|
1673
|
-
case c.EVENT:
|
|
1674
|
-
case c.BINARY_EVENT:
|
|
1675
|
-
this.onevent(e);
|
|
1676
|
-
break;
|
|
1677
|
-
case c.ACK:
|
|
1678
|
-
case c.BINARY_ACK:
|
|
1679
|
-
this.onack(e);
|
|
1680
|
-
break;
|
|
1681
|
-
case c.DISCONNECT:
|
|
1682
|
-
this.ondisconnect();
|
|
1683
|
-
break;
|
|
1684
|
-
case c.CONNECT_ERROR:
|
|
1685
|
-
this.destroy();
|
|
1686
|
-
const s = new Error(e.data.message);
|
|
1687
|
-
s.data = e.data.data, this.emitReserved("connect_error", s);
|
|
1688
|
-
break;
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
/**
|
|
1692
|
-
* Called upon a server event.
|
|
1693
|
-
*
|
|
1694
|
-
* @param packet
|
|
1695
|
-
* @private
|
|
1696
|
-
*/
|
|
1697
|
-
onevent(e) {
|
|
1698
|
-
const t = e.data || [];
|
|
1699
|
-
e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
|
|
1700
|
-
}
|
|
1701
|
-
emitEvent(e) {
|
|
1702
|
-
if (this._anyListeners && this._anyListeners.length) {
|
|
1703
|
-
const t = this._anyListeners.slice();
|
|
1704
|
-
for (const s of t)
|
|
1705
|
-
s.apply(this, e);
|
|
1706
|
-
}
|
|
1707
|
-
super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Produces an ack callback to emit with an event.
|
|
1711
|
-
*
|
|
1712
|
-
* @private
|
|
1713
|
-
*/
|
|
1714
|
-
ack(e) {
|
|
1715
|
-
const t = this;
|
|
1716
|
-
let s = !1;
|
|
1717
|
-
return function(...i) {
|
|
1718
|
-
s || (s = !0, t.packet({
|
|
1719
|
-
type: c.ACK,
|
|
1720
|
-
id: e,
|
|
1721
|
-
data: i
|
|
1722
|
-
}));
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
/**
|
|
1726
|
-
* Called upon a server acknowledgement.
|
|
1727
|
-
*
|
|
1728
|
-
* @param packet
|
|
1729
|
-
* @private
|
|
1730
|
-
*/
|
|
1731
|
-
onack(e) {
|
|
1732
|
-
const t = this.acks[e.id];
|
|
1733
|
-
typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
|
|
1734
|
-
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Called upon server connect.
|
|
1737
|
-
*
|
|
1738
|
-
* @private
|
|
1739
|
-
*/
|
|
1740
|
-
onconnect(e, t) {
|
|
1741
|
-
this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this.emitReserved("connect"), this._drainQueue(!0);
|
|
1742
|
-
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Emit buffered events (received and emitted).
|
|
1745
|
-
*
|
|
1746
|
-
* @private
|
|
1747
|
-
*/
|
|
1748
|
-
emitBuffered() {
|
|
1749
|
-
this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
|
|
1750
|
-
this.notifyOutgoingListeners(e), this.packet(e);
|
|
1751
|
-
}), this.sendBuffer = [];
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Called upon server disconnect.
|
|
1755
|
-
*
|
|
1756
|
-
* @private
|
|
1757
|
-
*/
|
|
1758
|
-
ondisconnect() {
|
|
1759
|
-
this.destroy(), this.onclose("io server disconnect");
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* Called upon forced client/server side disconnections,
|
|
1763
|
-
* this method ensures the manager stops tracking us and
|
|
1764
|
-
* that reconnections don't get triggered for this.
|
|
1765
|
-
*
|
|
1766
|
-
* @private
|
|
1767
|
-
*/
|
|
1768
|
-
destroy() {
|
|
1769
|
-
this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
1773
|
-
*
|
|
1774
|
-
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
1775
|
-
*
|
|
1776
|
-
* @example
|
|
1777
|
-
* const socket = io();
|
|
1778
|
-
*
|
|
1779
|
-
* socket.on("disconnect", (reason) => {
|
|
1780
|
-
* // console.log(reason); prints "io client disconnect"
|
|
1781
|
-
* });
|
|
1782
|
-
*
|
|
1783
|
-
* socket.disconnect();
|
|
1784
|
-
*
|
|
1785
|
-
* @return self
|
|
1786
|
-
*/
|
|
1787
|
-
disconnect() {
|
|
1788
|
-
return this.connected && this.packet({ type: c.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
|
|
1789
|
-
}
|
|
1790
|
-
/**
|
|
1791
|
-
* Alias for {@link disconnect()}.
|
|
1792
|
-
*
|
|
1793
|
-
* @return self
|
|
1794
|
-
*/
|
|
1795
|
-
close() {
|
|
1796
|
-
return this.disconnect();
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Sets the compress flag.
|
|
1800
|
-
*
|
|
1801
|
-
* @example
|
|
1802
|
-
* socket.compress(false).emit("hello");
|
|
1803
|
-
*
|
|
1804
|
-
* @param compress - if `true`, compresses the sending data
|
|
1805
|
-
* @return self
|
|
1806
|
-
*/
|
|
1807
|
-
compress(e) {
|
|
1808
|
-
return this.flags.compress = e, this;
|
|
1809
|
-
}
|
|
1810
|
-
/**
|
|
1811
|
-
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
1812
|
-
* ready to send messages.
|
|
1813
|
-
*
|
|
1814
|
-
* @example
|
|
1815
|
-
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
1816
|
-
*
|
|
1817
|
-
* @returns self
|
|
1818
|
-
*/
|
|
1819
|
-
get volatile() {
|
|
1820
|
-
return this.flags.volatile = !0, this;
|
|
1821
|
-
}
|
|
1822
|
-
/**
|
|
1823
|
-
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
1824
|
-
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
1825
|
-
*
|
|
1826
|
-
* @example
|
|
1827
|
-
* socket.timeout(5000).emit("my-event", (err) => {
|
|
1828
|
-
* if (err) {
|
|
1829
|
-
* // the server did not acknowledge the event in the given delay
|
|
1830
|
-
* }
|
|
1831
|
-
* });
|
|
1832
|
-
*
|
|
1833
|
-
* @returns self
|
|
1834
|
-
*/
|
|
1835
|
-
timeout(e) {
|
|
1836
|
-
return this.flags.timeout = e, this;
|
|
1837
|
-
}
|
|
1838
|
-
/**
|
|
1839
|
-
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1840
|
-
* callback.
|
|
1841
|
-
*
|
|
1842
|
-
* @example
|
|
1843
|
-
* socket.onAny((event, ...args) => {
|
|
1844
|
-
* console.log(`got ${event}`);
|
|
1845
|
-
* });
|
|
1846
|
-
*
|
|
1847
|
-
* @param listener
|
|
1848
|
-
*/
|
|
1849
|
-
onAny(e) {
|
|
1850
|
-
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1854
|
-
* callback. The listener is added to the beginning of the listeners array.
|
|
1855
|
-
*
|
|
1856
|
-
* @example
|
|
1857
|
-
* socket.prependAny((event, ...args) => {
|
|
1858
|
-
* console.log(`got event ${event}`);
|
|
1859
|
-
* });
|
|
1860
|
-
*
|
|
1861
|
-
* @param listener
|
|
1862
|
-
*/
|
|
1863
|
-
prependAny(e) {
|
|
1864
|
-
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
|
|
1865
|
-
}
|
|
1866
|
-
/**
|
|
1867
|
-
* Removes the listener that will be fired when any event is emitted.
|
|
1868
|
-
*
|
|
1869
|
-
* @example
|
|
1870
|
-
* const catchAllListener = (event, ...args) => {
|
|
1871
|
-
* console.log(`got event ${event}`);
|
|
1872
|
-
* }
|
|
1873
|
-
*
|
|
1874
|
-
* socket.onAny(catchAllListener);
|
|
1875
|
-
*
|
|
1876
|
-
* // remove a specific listener
|
|
1877
|
-
* socket.offAny(catchAllListener);
|
|
1878
|
-
*
|
|
1879
|
-
* // or remove all listeners
|
|
1880
|
-
* socket.offAny();
|
|
1881
|
-
*
|
|
1882
|
-
* @param listener
|
|
1883
|
-
*/
|
|
1884
|
-
offAny(e) {
|
|
1885
|
-
if (!this._anyListeners)
|
|
1886
|
-
return this;
|
|
1887
|
-
if (e) {
|
|
1888
|
-
const t = this._anyListeners;
|
|
1889
|
-
for (let s = 0; s < t.length; s++)
|
|
1890
|
-
if (e === t[s])
|
|
1891
|
-
return t.splice(s, 1), this;
|
|
1892
|
-
} else
|
|
1893
|
-
this._anyListeners = [];
|
|
1894
|
-
return this;
|
|
1895
|
-
}
|
|
1896
|
-
/**
|
|
1897
|
-
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
1898
|
-
* e.g. to remove listeners.
|
|
1899
|
-
*/
|
|
1900
|
-
listenersAny() {
|
|
1901
|
-
return this._anyListeners || [];
|
|
1902
|
-
}
|
|
1903
|
-
/**
|
|
1904
|
-
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1905
|
-
* callback.
|
|
1906
|
-
*
|
|
1907
|
-
* Note: acknowledgements sent to the server are not included.
|
|
1908
|
-
*
|
|
1909
|
-
* @example
|
|
1910
|
-
* socket.onAnyOutgoing((event, ...args) => {
|
|
1911
|
-
* console.log(`sent event ${event}`);
|
|
1912
|
-
* });
|
|
1913
|
-
*
|
|
1914
|
-
* @param listener
|
|
1915
|
-
*/
|
|
1916
|
-
onAnyOutgoing(e) {
|
|
1917
|
-
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
|
|
1918
|
-
}
|
|
1919
|
-
/**
|
|
1920
|
-
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1921
|
-
* callback. The listener is added to the beginning of the listeners array.
|
|
1922
|
-
*
|
|
1923
|
-
* Note: acknowledgements sent to the server are not included.
|
|
1924
|
-
*
|
|
1925
|
-
* @example
|
|
1926
|
-
* socket.prependAnyOutgoing((event, ...args) => {
|
|
1927
|
-
* console.log(`sent event ${event}`);
|
|
1928
|
-
* });
|
|
1929
|
-
*
|
|
1930
|
-
* @param listener
|
|
1931
|
-
*/
|
|
1932
|
-
prependAnyOutgoing(e) {
|
|
1933
|
-
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* Removes the listener that will be fired when any event is emitted.
|
|
1937
|
-
*
|
|
1938
|
-
* @example
|
|
1939
|
-
* const catchAllListener = (event, ...args) => {
|
|
1940
|
-
* console.log(`sent event ${event}`);
|
|
1941
|
-
* }
|
|
1942
|
-
*
|
|
1943
|
-
* socket.onAnyOutgoing(catchAllListener);
|
|
1944
|
-
*
|
|
1945
|
-
* // remove a specific listener
|
|
1946
|
-
* socket.offAnyOutgoing(catchAllListener);
|
|
1947
|
-
*
|
|
1948
|
-
* // or remove all listeners
|
|
1949
|
-
* socket.offAnyOutgoing();
|
|
1950
|
-
*
|
|
1951
|
-
* @param [listener] - the catch-all listener (optional)
|
|
1952
|
-
*/
|
|
1953
|
-
offAnyOutgoing(e) {
|
|
1954
|
-
if (!this._anyOutgoingListeners)
|
|
1955
|
-
return this;
|
|
1956
|
-
if (e) {
|
|
1957
|
-
const t = this._anyOutgoingListeners;
|
|
1958
|
-
for (let s = 0; s < t.length; s++)
|
|
1959
|
-
if (e === t[s])
|
|
1960
|
-
return t.splice(s, 1), this;
|
|
1961
|
-
} else
|
|
1962
|
-
this._anyOutgoingListeners = [];
|
|
1963
|
-
return this;
|
|
1964
|
-
}
|
|
1965
|
-
/**
|
|
1966
|
-
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
1967
|
-
* e.g. to remove listeners.
|
|
1968
|
-
*/
|
|
1969
|
-
listenersAnyOutgoing() {
|
|
1970
|
-
return this._anyOutgoingListeners || [];
|
|
1971
|
-
}
|
|
1972
|
-
/**
|
|
1973
|
-
* Notify the listeners for each packet sent
|
|
1974
|
-
*
|
|
1975
|
-
* @param packet
|
|
1976
|
-
*
|
|
1977
|
-
* @private
|
|
1978
|
-
*/
|
|
1979
|
-
notifyOutgoingListeners(e) {
|
|
1980
|
-
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
1981
|
-
const t = this._anyOutgoingListeners.slice();
|
|
1982
|
-
for (const s of t)
|
|
1983
|
-
s.apply(this, e.data);
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
function v(n) {
|
|
1988
|
-
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;
|
|
1989
|
-
}
|
|
1990
|
-
v.prototype.duration = function() {
|
|
1991
|
-
var n = this.ms * Math.pow(this.factor, this.attempts++);
|
|
1992
|
-
if (this.jitter) {
|
|
1993
|
-
var e = Math.random(), t = Math.floor(e * this.jitter * n);
|
|
1994
|
-
n = Math.floor(e * 10) & 1 ? n + t : n - t;
|
|
1995
|
-
}
|
|
1996
|
-
return Math.min(n, this.max) | 0;
|
|
1997
|
-
};
|
|
1998
|
-
v.prototype.reset = function() {
|
|
1999
|
-
this.attempts = 0;
|
|
2000
|
-
};
|
|
2001
|
-
v.prototype.setMin = function(n) {
|
|
2002
|
-
this.ms = n;
|
|
2003
|
-
};
|
|
2004
|
-
v.prototype.setMax = function(n) {
|
|
2005
|
-
this.max = n;
|
|
2006
|
-
};
|
|
2007
|
-
v.prototype.setJitter = function(n) {
|
|
2008
|
-
this.jitter = n;
|
|
2009
|
-
};
|
|
2010
|
-
class V extends f {
|
|
2011
|
-
constructor(e, t) {
|
|
2012
|
-
var s;
|
|
2013
|
-
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, N(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 v({
|
|
2014
|
-
min: this.reconnectionDelay(),
|
|
2015
|
-
max: this.reconnectionDelayMax(),
|
|
2016
|
-
jitter: this.randomizationFactor()
|
|
2017
|
-
}), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
|
|
2018
|
-
const i = t.parser || at;
|
|
2019
|
-
this.encoder = new i.Encoder(), this.decoder = new i.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
|
|
2020
|
-
}
|
|
2021
|
-
reconnection(e) {
|
|
2022
|
-
return arguments.length ? (this._reconnection = !!e, this) : this._reconnection;
|
|
2023
|
-
}
|
|
2024
|
-
reconnectionAttempts(e) {
|
|
2025
|
-
return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
|
|
2026
|
-
}
|
|
2027
|
-
reconnectionDelay(e) {
|
|
2028
|
-
var t;
|
|
2029
|
-
return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
|
|
2030
|
-
}
|
|
2031
|
-
randomizationFactor(e) {
|
|
2032
|
-
var t;
|
|
2033
|
-
return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
|
|
2034
|
-
}
|
|
2035
|
-
reconnectionDelayMax(e) {
|
|
2036
|
-
var t;
|
|
2037
|
-
return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
|
|
2038
|
-
}
|
|
2039
|
-
timeout(e) {
|
|
2040
|
-
return arguments.length ? (this._timeout = e, this) : this._timeout;
|
|
2041
|
-
}
|
|
2042
|
-
/**
|
|
2043
|
-
* Starts trying to reconnect if reconnection is enabled and we have not
|
|
2044
|
-
* started reconnecting yet
|
|
2045
|
-
*
|
|
2046
|
-
* @private
|
|
2047
|
-
*/
|
|
2048
|
-
maybeReconnectOnOpen() {
|
|
2049
|
-
!this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
|
|
2050
|
-
}
|
|
2051
|
-
/**
|
|
2052
|
-
* Sets the current transport `socket`.
|
|
2053
|
-
*
|
|
2054
|
-
* @param {Function} fn - optional, callback
|
|
2055
|
-
* @return self
|
|
2056
|
-
* @public
|
|
2057
|
-
*/
|
|
2058
|
-
open(e) {
|
|
2059
|
-
if (~this._readyState.indexOf("open"))
|
|
2060
|
-
return this;
|
|
2061
|
-
this.engine = new ge(this.uri, this.opts);
|
|
2062
|
-
const t = this.engine, s = this;
|
|
2063
|
-
this._readyState = "opening", this.skipReconnect = !1;
|
|
2064
|
-
const i = l(t, "open", function() {
|
|
2065
|
-
s.onopen(), e && e();
|
|
2066
|
-
}), r = (a) => {
|
|
2067
|
-
this.cleanup(), this._readyState = "closed", this.emitReserved("error", a), e ? e(a) : this.maybeReconnectOnOpen();
|
|
2068
|
-
}, o = l(t, "error", r);
|
|
2069
|
-
if (this._timeout !== !1) {
|
|
2070
|
-
const a = this._timeout, h = this.setTimeoutFn(() => {
|
|
2071
|
-
i(), r(new Error("timeout")), t.close();
|
|
2072
|
-
}, a);
|
|
2073
|
-
this.opts.autoUnref && h.unref(), this.subs.push(() => {
|
|
2074
|
-
this.clearTimeoutFn(h);
|
|
2075
|
-
});
|
|
2076
|
-
}
|
|
2077
|
-
return this.subs.push(i), this.subs.push(o), this;
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* Alias for open()
|
|
2081
|
-
*
|
|
2082
|
-
* @return self
|
|
2083
|
-
* @public
|
|
2084
|
-
*/
|
|
2085
|
-
connect(e) {
|
|
2086
|
-
return this.open(e);
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* Called upon transport open.
|
|
2090
|
-
*
|
|
2091
|
-
* @private
|
|
2092
|
-
*/
|
|
2093
|
-
onopen() {
|
|
2094
|
-
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
2095
|
-
const e = this.engine;
|
|
2096
|
-
this.subs.push(l(e, "ping", this.onping.bind(this)), l(e, "data", this.ondata.bind(this)), l(e, "error", this.onerror.bind(this)), l(e, "close", this.onclose.bind(this)), l(this.decoder, "decoded", this.ondecoded.bind(this)));
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Called upon a ping.
|
|
2100
|
-
*
|
|
2101
|
-
* @private
|
|
2102
|
-
*/
|
|
2103
|
-
onping() {
|
|
2104
|
-
this.emitReserved("ping");
|
|
2105
|
-
}
|
|
2106
|
-
/**
|
|
2107
|
-
* Called with data.
|
|
2108
|
-
*
|
|
2109
|
-
* @private
|
|
2110
|
-
*/
|
|
2111
|
-
ondata(e) {
|
|
2112
|
-
try {
|
|
2113
|
-
this.decoder.add(e);
|
|
2114
|
-
} catch (t) {
|
|
2115
|
-
this.onclose("parse error", t);
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
/**
|
|
2119
|
-
* Called when parser fully decodes a packet.
|
|
2120
|
-
*
|
|
2121
|
-
* @private
|
|
2122
|
-
*/
|
|
2123
|
-
ondecoded(e) {
|
|
2124
|
-
W(() => {
|
|
2125
|
-
this.emitReserved("packet", e);
|
|
2126
|
-
}, this.setTimeoutFn);
|
|
2127
|
-
}
|
|
2128
|
-
/**
|
|
2129
|
-
* Called upon socket error.
|
|
2130
|
-
*
|
|
2131
|
-
* @private
|
|
2132
|
-
*/
|
|
2133
|
-
onerror(e) {
|
|
2134
|
-
this.emitReserved("error", e);
|
|
2135
|
-
}
|
|
2136
|
-
/**
|
|
2137
|
-
* Creates a new socket for the given `nsp`.
|
|
2138
|
-
*
|
|
2139
|
-
* @return {Socket}
|
|
2140
|
-
* @public
|
|
2141
|
-
*/
|
|
2142
|
-
socket(e, t) {
|
|
2143
|
-
let s = this.nsps[e];
|
|
2144
|
-
return s ? this._autoConnect && !s.active && s.connect() : (s = new we(this, e, t), this.nsps[e] = s), s;
|
|
2145
|
-
}
|
|
2146
|
-
/**
|
|
2147
|
-
* Called upon a socket close.
|
|
2148
|
-
*
|
|
2149
|
-
* @param socket
|
|
2150
|
-
* @private
|
|
2151
|
-
*/
|
|
2152
|
-
_destroy(e) {
|
|
2153
|
-
const t = Object.keys(this.nsps);
|
|
2154
|
-
for (const s of t)
|
|
2155
|
-
if (this.nsps[s].active)
|
|
2156
|
-
return;
|
|
2157
|
-
this._close();
|
|
2158
|
-
}
|
|
2159
|
-
/**
|
|
2160
|
-
* Writes a packet.
|
|
2161
|
-
*
|
|
2162
|
-
* @param packet
|
|
2163
|
-
* @private
|
|
2164
|
-
*/
|
|
2165
|
-
_packet(e) {
|
|
2166
|
-
const t = this.encoder.encode(e);
|
|
2167
|
-
for (let s = 0; s < t.length; s++)
|
|
2168
|
-
this.engine.write(t[s], e.options);
|
|
2169
|
-
}
|
|
2170
|
-
/**
|
|
2171
|
-
* Clean up transport subscriptions and packet buffer.
|
|
2172
|
-
*
|
|
2173
|
-
* @private
|
|
2174
|
-
*/
|
|
2175
|
-
cleanup() {
|
|
2176
|
-
this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Close the current socket.
|
|
2180
|
-
*
|
|
2181
|
-
* @private
|
|
2182
|
-
*/
|
|
2183
|
-
_close() {
|
|
2184
|
-
this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close"), this.engine && this.engine.close();
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* Alias for close()
|
|
2188
|
-
*
|
|
2189
|
-
* @private
|
|
2190
|
-
*/
|
|
2191
|
-
disconnect() {
|
|
2192
|
-
return this._close();
|
|
2193
|
-
}
|
|
2194
|
-
/**
|
|
2195
|
-
* Called upon engine close.
|
|
2196
|
-
*
|
|
2197
|
-
* @private
|
|
2198
|
-
*/
|
|
2199
|
-
onclose(e, t) {
|
|
2200
|
-
this.cleanup(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
|
|
2201
|
-
}
|
|
2202
|
-
/**
|
|
2203
|
-
* Attempt a reconnection.
|
|
2204
|
-
*
|
|
2205
|
-
* @private
|
|
2206
|
-
*/
|
|
2207
|
-
reconnect() {
|
|
2208
|
-
if (this._reconnecting || this.skipReconnect)
|
|
2209
|
-
return this;
|
|
2210
|
-
const e = this;
|
|
2211
|
-
if (this.backoff.attempts >= this._reconnectionAttempts)
|
|
2212
|
-
this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
|
|
2213
|
-
else {
|
|
2214
|
-
const t = this.backoff.duration();
|
|
2215
|
-
this._reconnecting = !0;
|
|
2216
|
-
const s = this.setTimeoutFn(() => {
|
|
2217
|
-
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((i) => {
|
|
2218
|
-
i ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", i)) : e.onreconnect();
|
|
2219
|
-
}));
|
|
2220
|
-
}, t);
|
|
2221
|
-
this.opts.autoUnref && s.unref(), this.subs.push(() => {
|
|
2222
|
-
this.clearTimeoutFn(s);
|
|
2223
|
-
});
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
/**
|
|
2227
|
-
* Called upon successful reconnect.
|
|
2228
|
-
*
|
|
2229
|
-
* @private
|
|
2230
|
-
*/
|
|
2231
|
-
onreconnect() {
|
|
2232
|
-
const e = this.backoff.attempts;
|
|
2233
|
-
this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
const E = {};
|
|
2237
|
-
function x(n, e) {
|
|
2238
|
-
typeof n == "object" && (e = n, n = void 0), e = e || {};
|
|
2239
|
-
const t = je(n, e.path || "/socket.io"), s = t.source, i = t.id, r = t.path, o = E[i] && r in E[i].nsps, a = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
|
|
2240
|
-
let h;
|
|
2241
|
-
return a ? h = new V(s, e) : (E[i] || (E[i] = new V(s, e)), h = E[i]), t.query && !e.query && (e.query = t.queryKey), h.socket(t.path, e);
|
|
2242
|
-
}
|
|
2243
|
-
Object.assign(x, {
|
|
2244
|
-
Manager: V,
|
|
2245
|
-
Socket: we,
|
|
2246
|
-
io: x,
|
|
2247
|
-
connect: x
|
|
2248
|
-
});
|
|
2249
|
-
const ft = "http://159.138.233.132:8080", m = class m {
|
|
2250
|
-
constructor() {
|
|
2251
|
-
A(this, "socket");
|
|
2252
|
-
this.socket = x(ft);
|
|
2253
|
-
}
|
|
2254
|
-
static getInstance() {
|
|
2255
|
-
return m.instance || (m.instance = new m()), m.instance;
|
|
2256
|
-
}
|
|
2257
|
-
};
|
|
2258
|
-
A(m, "instance");
|
|
2259
|
-
let F = m;
|
|
2260
|
-
class ut {
|
|
2261
|
-
constructor() {
|
|
2262
|
-
A(this, "socketInstance");
|
|
2263
|
-
this.socketInstance = F.getInstance();
|
|
2264
|
-
}
|
|
2265
|
-
joinRoom(e) {
|
|
2266
|
-
this.socketInstance.socket.emit("joinRoom", e);
|
|
2267
|
-
}
|
|
2268
|
-
leaveRoom(e) {
|
|
2269
|
-
this.socketInstance.socket.emit("leaveRoom", e), this.socketInstance.socket.disconnect();
|
|
2270
|
-
}
|
|
2271
|
-
confirmMessage(e, t) {
|
|
2272
|
-
return this.socketInstance.socket.emit("confirmMessage", e, t);
|
|
2273
|
-
}
|
|
2274
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2275
|
-
onMessageReceived(e, t) {
|
|
2276
|
-
e === "accountInfo" ? this.socketInstance.socket.on("accountInfo", (s) => {
|
|
2277
|
-
t(s);
|
|
2278
|
-
}) : e === "requestMessage" ? this.socketInstance.socket.on("requestMessage", (s) => {
|
|
2279
|
-
t(s);
|
|
2280
|
-
}) : e === "addressProvide" && this.socketInstance.socket.on("addressProvide", (s) => {
|
|
2281
|
-
t(s);
|
|
2282
|
-
});
|
|
2283
|
-
}
|
|
2284
|
-
offMessageReceived(e) {
|
|
2285
|
-
e === "accountInfo" ? this.socketInstance.socket.off("accountInfo") : e === "requestMessage" ? this.socketInstance.socket.off("requestMessage") : e === "addressProvide" && this.socketInstance.socket.off("addressProvide");
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
const lt = new ut();
|
|
2289
|
-
class pt {
|
|
2290
|
-
generateQrCode(e, t, s, i) {
|
|
2291
|
-
const r = J.lib.WordArray.random(16).toString(J.enc.Hex);
|
|
2292
|
-
let o = "";
|
|
2293
|
-
return e === "login" ? o = `http://172.30.1.61:3000/qrCode/scan?type=login&roomId=${r}&dapp=${t}&url=${s}&network=${i}` : e === "send" ? o = `zigap://send?roomId=${r}&dapp=${t}` : e === "provide" && (o = `zigap://provide?roomId=${r}&dapp=${t}`), lt.joinRoom(r), {
|
|
2294
|
-
qrCode: o,
|
|
2295
|
-
roomId: r
|
|
2296
|
-
};
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
const gt = new pt();
|
|
2300
|
-
export {
|
|
2301
|
-
gt as Q,
|
|
2302
|
-
lt as S
|
|
2303
|
-
};
|