@thatopen/services 0.0.1
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/CONTEXT.md +258 -0
- package/README.md +285 -0
- package/dist/built-in/index.d.ts +723 -0
- package/dist/cli/commands/create-tests.d.ts +3 -0
- package/dist/cli/commands/create.d.ts +3 -0
- package/dist/cli/commands/local-server.d.ts +3 -0
- package/dist/cli/commands/login.d.ts +3 -0
- package/dist/cli/commands/publish.d.ts +3 -0
- package/dist/cli/commands/run.d.ts +3 -0
- package/dist/cli/commands/serve-tests.d.ts +3 -0
- package/dist/cli/commands/serve.d.ts +3 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/lib/config.d.ts +25 -0
- package/dist/cli/lib/declarations.d.ts +19 -0
- package/dist/cli/lib/engine-script.d.ts +10 -0
- package/dist/cli/lib/execution-manager.d.ts +52 -0
- package/dist/cli/lib/zip.d.ts +6 -0
- package/dist/cli.js +11566 -0
- package/dist/core/client.d.ts +682 -0
- package/dist/core/client.test.d.ts +1 -0
- package/dist/core/platform-client.d.ts +106 -0
- package/dist/core/platform-client.test.d.ts +1 -0
- package/dist/core/request-error.d.ts +25 -0
- package/dist/core/request-error.test.d.ts +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.es.js +3310 -0
- package/dist/types/base.d.ts +9 -0
- package/dist/types/context.d.ts +20 -0
- package/dist/types/execution.d.ts +19 -0
- package/dist/types/files.d.ts +19 -0
- package/dist/types/item.dto.d.ts +24 -0
- package/dist/types/items.d.ts +57 -0
- package/dist/types/projects.d.ts +59 -0
- package/dist/types/response.d.ts +10 -0
- package/dist/types/storage.d.ts +11 -0
- package/dist/vite-env.d.ts +1 -0
- package/package.json +100 -0
- package/src/built-in/index.ts +755 -0
- package/src/cli/templates/bim/CONTEXT.md +244 -0
- package/src/cli/templates/bim/package.json +26 -0
- package/src/cli/templates/bim/src/app.ts +16 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/index.ts +91 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/src/index.ts +1 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/src/types.ts +5 -0
- package/src/cli/templates/bim/src/bim-components/index.ts +1 -0
- package/src/cli/templates/bim/src/globals.ts +1 -0
- package/src/cli/templates/bim/src/main.ts +90 -0
- package/src/cli/templates/bim/src/setups/cloud-runner.ts +13 -0
- package/src/cli/templates/bim/src/setups/index.ts +3 -0
- package/src/cli/templates/bim/src/setups/ui-manager.ts +27 -0
- package/src/cli/templates/bim/src/setups/viewports-manager.ts +22 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/index.ts +26 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/src/index.ts +1 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/src/types.ts +15 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/index.ts +37 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/src/index.ts +1 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/src/types.ts +14 -0
- package/src/cli/templates/bim/src/ui-components/index.ts +2 -0
- package/src/cli/templates/cloud/CONTEXT.md +205 -0
- package/src/cli/templates/cloud/_thatopen +5 -0
- package/src/cli/templates/cloud/declarations.json +4 -0
- package/src/cli/templates/cloud/package.json +22 -0
- package/src/cli/templates/cloud/src/main.ts +70 -0
- package/src/cli/templates/cloud-test/CONTEXT.md +56 -0
- package/src/cli/templates/cloud-test/_thatopen +5 -0
- package/src/cli/templates/cloud-test/package.json +22 -0
- package/src/cli/templates/cloud-test/src/main.ts +565 -0
- package/src/cli/templates/default/CONTEXT.md +92 -0
- package/src/cli/templates/default/package.json +15 -0
- package/src/cli/templates/default/src/main.ts +62 -0
- package/src/cli/templates/shared/_gitignore +4 -0
- package/src/cli/templates/shared/app/index.html +27 -0
- package/src/cli/templates/shared/app/tsconfig.json +16 -0
- package/src/cli/templates/shared/app/vite.config.js +23 -0
- package/src/cli/templates/shared/cloud/tsconfig.json +16 -0
- package/src/cli/templates/shared/cloud/vite.config.js +27 -0
- package/src/cli/templates/test/CONTEXT.md +53 -0
- package/src/cli/templates/test/package.json +25 -0
- package/src/cli/templates/test/src/main.ts +955 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,3310 @@
|
|
|
1
|
+
var Fe = Object.defineProperty;
|
|
2
|
+
var ge = (n) => {
|
|
3
|
+
throw TypeError(n);
|
|
4
|
+
};
|
|
5
|
+
var Ve = (n, e, t) => e in n ? Fe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
6
|
+
var _ = (n, e, t) => Ve(n, typeof e != "symbol" ? e + "" : e, t), j = (n, e, t) => e.has(n) || ge("Cannot " + t);
|
|
7
|
+
var G = (n, e, t) => (j(n, e, "read from private field"), t ? t.call(n) : e.get(n)), K = (n, e, t) => e.has(n) ? ge("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), we = (n, e, t, s) => (j(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t), c = (n, e, t) => (j(n, e, "access private method"), t);
|
|
8
|
+
const k = /* @__PURE__ */ Object.create(null);
|
|
9
|
+
k.open = "0";
|
|
10
|
+
k.close = "1";
|
|
11
|
+
k.ping = "2";
|
|
12
|
+
k.pong = "3";
|
|
13
|
+
k.message = "4";
|
|
14
|
+
k.upgrade = "5";
|
|
15
|
+
k.noop = "6";
|
|
16
|
+
const q = /* @__PURE__ */ Object.create(null);
|
|
17
|
+
Object.keys(k).forEach((n) => {
|
|
18
|
+
q[k[n]] = n;
|
|
19
|
+
});
|
|
20
|
+
const ee = { type: "error", data: "parser error" }, Ae = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Oe = typeof ArrayBuffer == "function", Se = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n && n.buffer instanceof ArrayBuffer, ue = ({ type: n, data: e }, t, s) => Ae && e instanceof Blob ? t ? s(e) : _e(e, s) : Oe && (e instanceof ArrayBuffer || Se(e)) ? t ? s(e) : _e(new Blob([e]), s) : s(k[n] + (e || "")), _e = (n, e) => {
|
|
21
|
+
const t = new FileReader();
|
|
22
|
+
return t.onload = function() {
|
|
23
|
+
const s = t.result.split(",")[1];
|
|
24
|
+
e("b" + (s || ""));
|
|
25
|
+
}, t.readAsDataURL(n);
|
|
26
|
+
};
|
|
27
|
+
function be(n) {
|
|
28
|
+
return n instanceof Uint8Array ? n : n instanceof ArrayBuffer ? new Uint8Array(n) : new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
29
|
+
}
|
|
30
|
+
let Y;
|
|
31
|
+
function Me(n, e) {
|
|
32
|
+
if (Ae && n.data instanceof Blob)
|
|
33
|
+
return n.data.arrayBuffer().then(be).then(e);
|
|
34
|
+
if (Oe && (n.data instanceof ArrayBuffer || Se(n.data)))
|
|
35
|
+
return e(be(n.data));
|
|
36
|
+
ue(n, !1, (t) => {
|
|
37
|
+
Y || (Y = new TextEncoder()), e(Y.encode(t));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const Ee = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", N = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
|
|
41
|
+
for (let n = 0; n < Ee.length; n++)
|
|
42
|
+
N[Ee.charCodeAt(n)] = n;
|
|
43
|
+
const He = (n) => {
|
|
44
|
+
let e = n.length * 0.75, t = n.length, s, r = 0, i, o, h, u;
|
|
45
|
+
n[n.length - 1] === "=" && (e--, n[n.length - 2] === "=" && e--);
|
|
46
|
+
const y = new ArrayBuffer(e), d = new Uint8Array(y);
|
|
47
|
+
for (s = 0; s < t; s += 4)
|
|
48
|
+
i = N[n.charCodeAt(s)], o = N[n.charCodeAt(s + 1)], h = N[n.charCodeAt(s + 2)], u = N[n.charCodeAt(s + 3)], d[r++] = i << 2 | o >> 4, d[r++] = (o & 15) << 4 | h >> 2, d[r++] = (h & 3) << 6 | u & 63;
|
|
49
|
+
return y;
|
|
50
|
+
}, Je = typeof ArrayBuffer == "function", le = (n, e) => {
|
|
51
|
+
if (typeof n != "string")
|
|
52
|
+
return {
|
|
53
|
+
type: "message",
|
|
54
|
+
data: Ce(n, e)
|
|
55
|
+
};
|
|
56
|
+
const t = n.charAt(0);
|
|
57
|
+
return t === "b" ? {
|
|
58
|
+
type: "message",
|
|
59
|
+
data: je(n.substring(1), e)
|
|
60
|
+
} : q[t] ? n.length > 1 ? {
|
|
61
|
+
type: q[t],
|
|
62
|
+
data: n.substring(1)
|
|
63
|
+
} : {
|
|
64
|
+
type: q[t]
|
|
65
|
+
} : ee;
|
|
66
|
+
}, je = (n, e) => {
|
|
67
|
+
if (Je) {
|
|
68
|
+
const t = He(n);
|
|
69
|
+
return Ce(t, e);
|
|
70
|
+
} else
|
|
71
|
+
return { base64: !0, data: n };
|
|
72
|
+
}, Ce = (n, e) => {
|
|
73
|
+
switch (e) {
|
|
74
|
+
case "blob":
|
|
75
|
+
return n instanceof Blob ? n : new Blob([n]);
|
|
76
|
+
case "arraybuffer":
|
|
77
|
+
default:
|
|
78
|
+
return n instanceof ArrayBuffer ? n : n.buffer;
|
|
79
|
+
}
|
|
80
|
+
}, Re = "", Ge = (n, e) => {
|
|
81
|
+
const t = n.length, s = new Array(t);
|
|
82
|
+
let r = 0;
|
|
83
|
+
n.forEach((i, o) => {
|
|
84
|
+
ue(i, !1, (h) => {
|
|
85
|
+
s[o] = h, ++r === t && e(s.join(Re));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}, Ke = (n, e) => {
|
|
89
|
+
const t = n.split(Re), s = [];
|
|
90
|
+
for (let r = 0; r < t.length; r++) {
|
|
91
|
+
const i = le(t[r], e);
|
|
92
|
+
if (s.push(i), i.type === "error")
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
return s;
|
|
96
|
+
};
|
|
97
|
+
function Ye() {
|
|
98
|
+
return new TransformStream({
|
|
99
|
+
transform(n, e) {
|
|
100
|
+
Me(n, (t) => {
|
|
101
|
+
const s = t.length;
|
|
102
|
+
let r;
|
|
103
|
+
if (s < 126)
|
|
104
|
+
r = new Uint8Array(1), new DataView(r.buffer).setUint8(0, s);
|
|
105
|
+
else if (s < 65536) {
|
|
106
|
+
r = new Uint8Array(3);
|
|
107
|
+
const i = new DataView(r.buffer);
|
|
108
|
+
i.setUint8(0, 126), i.setUint16(1, s);
|
|
109
|
+
} else {
|
|
110
|
+
r = new Uint8Array(9);
|
|
111
|
+
const i = new DataView(r.buffer);
|
|
112
|
+
i.setUint8(0, 127), i.setBigUint64(1, BigInt(s));
|
|
113
|
+
}
|
|
114
|
+
n.data && typeof n.data != "string" && (r[0] |= 128), e.enqueue(r), e.enqueue(t);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
let W;
|
|
120
|
+
function P(n) {
|
|
121
|
+
return n.reduce((e, t) => e + t.length, 0);
|
|
122
|
+
}
|
|
123
|
+
function L(n, e) {
|
|
124
|
+
if (n[0].length === e)
|
|
125
|
+
return n.shift();
|
|
126
|
+
const t = new Uint8Array(e);
|
|
127
|
+
let s = 0;
|
|
128
|
+
for (let r = 0; r < e; r++)
|
|
129
|
+
t[r] = n[0][s++], s === n[0].length && (n.shift(), s = 0);
|
|
130
|
+
return n.length && s < n[0].length && (n[0] = n[0].slice(s)), t;
|
|
131
|
+
}
|
|
132
|
+
function We(n, e) {
|
|
133
|
+
W || (W = new TextDecoder());
|
|
134
|
+
const t = [];
|
|
135
|
+
let s = 0, r = -1, i = !1;
|
|
136
|
+
return new TransformStream({
|
|
137
|
+
transform(o, h) {
|
|
138
|
+
for (t.push(o); ; ) {
|
|
139
|
+
if (s === 0) {
|
|
140
|
+
if (P(t) < 1)
|
|
141
|
+
break;
|
|
142
|
+
const u = L(t, 1);
|
|
143
|
+
i = (u[0] & 128) === 128, r = u[0] & 127, r < 126 ? s = 3 : r === 126 ? s = 1 : s = 2;
|
|
144
|
+
} else if (s === 1) {
|
|
145
|
+
if (P(t) < 2)
|
|
146
|
+
break;
|
|
147
|
+
const u = L(t, 2);
|
|
148
|
+
r = new DataView(u.buffer, u.byteOffset, u.length).getUint16(0), s = 3;
|
|
149
|
+
} else if (s === 2) {
|
|
150
|
+
if (P(t) < 8)
|
|
151
|
+
break;
|
|
152
|
+
const u = L(t, 8), y = new DataView(u.buffer, u.byteOffset, u.length), d = y.getUint32(0);
|
|
153
|
+
if (d > Math.pow(2, 21) - 1) {
|
|
154
|
+
h.enqueue(ee);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
r = d * Math.pow(2, 32) + y.getUint32(4), s = 3;
|
|
158
|
+
} else {
|
|
159
|
+
if (P(t) < r)
|
|
160
|
+
break;
|
|
161
|
+
const u = L(t, r);
|
|
162
|
+
h.enqueue(le(i ? u : W.decode(u), e)), s = 0;
|
|
163
|
+
}
|
|
164
|
+
if (r === 0 || r > n) {
|
|
165
|
+
h.enqueue(ee);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const $e = 4;
|
|
173
|
+
function g(n) {
|
|
174
|
+
if (n) return ze(n);
|
|
175
|
+
}
|
|
176
|
+
function ze(n) {
|
|
177
|
+
for (var e in g.prototype)
|
|
178
|
+
n[e] = g.prototype[e];
|
|
179
|
+
return n;
|
|
180
|
+
}
|
|
181
|
+
g.prototype.on = g.prototype.addEventListener = function(n, e) {
|
|
182
|
+
return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
|
|
183
|
+
};
|
|
184
|
+
g.prototype.once = function(n, e) {
|
|
185
|
+
function t() {
|
|
186
|
+
this.off(n, t), e.apply(this, arguments);
|
|
187
|
+
}
|
|
188
|
+
return t.fn = e, this.on(n, t), this;
|
|
189
|
+
};
|
|
190
|
+
g.prototype.off = g.prototype.removeListener = g.prototype.removeAllListeners = g.prototype.removeEventListener = function(n, e) {
|
|
191
|
+
if (this._callbacks = this._callbacks || {}, arguments.length == 0)
|
|
192
|
+
return this._callbacks = {}, this;
|
|
193
|
+
var t = this._callbacks["$" + n];
|
|
194
|
+
if (!t) return this;
|
|
195
|
+
if (arguments.length == 1)
|
|
196
|
+
return delete this._callbacks["$" + n], this;
|
|
197
|
+
for (var s, r = 0; r < t.length; r++)
|
|
198
|
+
if (s = t[r], s === e || s.fn === e) {
|
|
199
|
+
t.splice(r, 1);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
return t.length === 0 && delete this._callbacks["$" + n], this;
|
|
203
|
+
};
|
|
204
|
+
g.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, r = t.length; s < r; ++s)
|
|
211
|
+
t[s].apply(this, e);
|
|
212
|
+
}
|
|
213
|
+
return this;
|
|
214
|
+
};
|
|
215
|
+
g.prototype.emitReserved = g.prototype.emit;
|
|
216
|
+
g.prototype.listeners = function(n) {
|
|
217
|
+
return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
|
|
218
|
+
};
|
|
219
|
+
g.prototype.hasListeners = function(n) {
|
|
220
|
+
return !!this.listeners(n).length;
|
|
221
|
+
};
|
|
222
|
+
const H = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), b = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Xe = "arraybuffer";
|
|
223
|
+
function Be(n, ...e) {
|
|
224
|
+
return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
|
|
225
|
+
}
|
|
226
|
+
const Qe = b.setTimeout, Ze = b.clearTimeout;
|
|
227
|
+
function J(n, e) {
|
|
228
|
+
e.useNativeTimers ? (n.setTimeoutFn = Qe.bind(b), n.clearTimeoutFn = Ze.bind(b)) : (n.setTimeoutFn = b.setTimeout.bind(b), n.clearTimeoutFn = b.clearTimeout.bind(b));
|
|
229
|
+
}
|
|
230
|
+
const et = 1.33;
|
|
231
|
+
function tt(n) {
|
|
232
|
+
return typeof n == "string" ? st(n) : Math.ceil((n.byteLength || n.size) * et);
|
|
233
|
+
}
|
|
234
|
+
function st(n) {
|
|
235
|
+
let e = 0, t = 0;
|
|
236
|
+
for (let s = 0, r = n.length; s < r; 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 xe() {
|
|
241
|
+
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
242
|
+
}
|
|
243
|
+
function nt(n) {
|
|
244
|
+
let e = "";
|
|
245
|
+
for (let t in n)
|
|
246
|
+
n.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(n[t]));
|
|
247
|
+
return e;
|
|
248
|
+
}
|
|
249
|
+
function rt(n) {
|
|
250
|
+
let e = {}, t = n.split("&");
|
|
251
|
+
for (let s = 0, r = t.length; s < r; s++) {
|
|
252
|
+
let i = t[s].split("=");
|
|
253
|
+
e[decodeURIComponent(i[0])] = decodeURIComponent(i[1]);
|
|
254
|
+
}
|
|
255
|
+
return e;
|
|
256
|
+
}
|
|
257
|
+
class it extends Error {
|
|
258
|
+
constructor(e, t, s) {
|
|
259
|
+
super(e), this.description = t, this.context = s, this.type = "TransportError";
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class fe extends g {
|
|
263
|
+
/**
|
|
264
|
+
* Transport abstract constructor.
|
|
265
|
+
*
|
|
266
|
+
* @param {Object} opts - options
|
|
267
|
+
* @protected
|
|
268
|
+
*/
|
|
269
|
+
constructor(e) {
|
|
270
|
+
super(), this.writable = !1, J(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Emits an error.
|
|
274
|
+
*
|
|
275
|
+
* @param {String} reason
|
|
276
|
+
* @param description
|
|
277
|
+
* @param context - the error context
|
|
278
|
+
* @return {Transport} for chaining
|
|
279
|
+
* @protected
|
|
280
|
+
*/
|
|
281
|
+
onError(e, t, s) {
|
|
282
|
+
return super.emitReserved("error", new it(e, t, s)), this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Opens the transport.
|
|
286
|
+
*/
|
|
287
|
+
open() {
|
|
288
|
+
return this.readyState = "opening", this.doOpen(), this;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Closes the transport.
|
|
292
|
+
*/
|
|
293
|
+
close() {
|
|
294
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Sends multiple packets.
|
|
298
|
+
*
|
|
299
|
+
* @param {Array} packets
|
|
300
|
+
*/
|
|
301
|
+
send(e) {
|
|
302
|
+
this.readyState === "open" && this.write(e);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Called upon open
|
|
306
|
+
*
|
|
307
|
+
* @protected
|
|
308
|
+
*/
|
|
309
|
+
onOpen() {
|
|
310
|
+
this.readyState = "open", this.writable = !0, super.emitReserved("open");
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Called with data.
|
|
314
|
+
*
|
|
315
|
+
* @param {String} data
|
|
316
|
+
* @protected
|
|
317
|
+
*/
|
|
318
|
+
onData(e) {
|
|
319
|
+
const t = le(e, this.socket.binaryType);
|
|
320
|
+
this.onPacket(t);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Called with a decoded packet.
|
|
324
|
+
*
|
|
325
|
+
* @protected
|
|
326
|
+
*/
|
|
327
|
+
onPacket(e) {
|
|
328
|
+
super.emitReserved("packet", e);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Called upon close.
|
|
332
|
+
*
|
|
333
|
+
* @protected
|
|
334
|
+
*/
|
|
335
|
+
onClose(e) {
|
|
336
|
+
this.readyState = "closed", super.emitReserved("close", e);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
340
|
+
*
|
|
341
|
+
* @param onPause
|
|
342
|
+
*/
|
|
343
|
+
pause(e) {
|
|
344
|
+
}
|
|
345
|
+
createUri(e, t = {}) {
|
|
346
|
+
return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
|
|
347
|
+
}
|
|
348
|
+
_hostname() {
|
|
349
|
+
const e = this.opts.hostname;
|
|
350
|
+
return e.indexOf(":") === -1 ? e : "[" + e + "]";
|
|
351
|
+
}
|
|
352
|
+
_port() {
|
|
353
|
+
return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
|
|
354
|
+
}
|
|
355
|
+
_query(e) {
|
|
356
|
+
const t = nt(e);
|
|
357
|
+
return t.length ? "?" + t : "";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
class ot extends fe {
|
|
361
|
+
constructor() {
|
|
362
|
+
super(...arguments), this._polling = !1;
|
|
363
|
+
}
|
|
364
|
+
get name() {
|
|
365
|
+
return "polling";
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Opens the socket (triggers polling). We write a PING message to determine
|
|
369
|
+
* when the transport is open.
|
|
370
|
+
*
|
|
371
|
+
* @protected
|
|
372
|
+
*/
|
|
373
|
+
doOpen() {
|
|
374
|
+
this._poll();
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Pauses polling.
|
|
378
|
+
*
|
|
379
|
+
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
380
|
+
* @package
|
|
381
|
+
*/
|
|
382
|
+
pause(e) {
|
|
383
|
+
this.readyState = "pausing";
|
|
384
|
+
const t = () => {
|
|
385
|
+
this.readyState = "paused", e();
|
|
386
|
+
};
|
|
387
|
+
if (this._polling || !this.writable) {
|
|
388
|
+
let s = 0;
|
|
389
|
+
this._polling && (s++, this.once("pollComplete", function() {
|
|
390
|
+
--s || t();
|
|
391
|
+
})), this.writable || (s++, this.once("drain", function() {
|
|
392
|
+
--s || t();
|
|
393
|
+
}));
|
|
394
|
+
} else
|
|
395
|
+
t();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Starts polling cycle.
|
|
399
|
+
*
|
|
400
|
+
* @private
|
|
401
|
+
*/
|
|
402
|
+
_poll() {
|
|
403
|
+
this._polling = !0, this.doPoll(), this.emitReserved("poll");
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Overloads onData to detect payloads.
|
|
407
|
+
*
|
|
408
|
+
* @protected
|
|
409
|
+
*/
|
|
410
|
+
onData(e) {
|
|
411
|
+
const t = (s) => {
|
|
412
|
+
if (this.readyState === "opening" && s.type === "open" && this.onOpen(), s.type === "close")
|
|
413
|
+
return this.onClose({ description: "transport closed by the server" }), !1;
|
|
414
|
+
this.onPacket(s);
|
|
415
|
+
};
|
|
416
|
+
Ke(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* For polling, send a close packet.
|
|
420
|
+
*
|
|
421
|
+
* @protected
|
|
422
|
+
*/
|
|
423
|
+
doClose() {
|
|
424
|
+
const e = () => {
|
|
425
|
+
this.write([{ type: "close" }]);
|
|
426
|
+
};
|
|
427
|
+
this.readyState === "open" ? e() : this.once("open", e);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Writes a packets payload.
|
|
431
|
+
*
|
|
432
|
+
* @param {Array} packets - data packets
|
|
433
|
+
* @protected
|
|
434
|
+
*/
|
|
435
|
+
write(e) {
|
|
436
|
+
this.writable = !1, Ge(e, (t) => {
|
|
437
|
+
this.doWrite(t, () => {
|
|
438
|
+
this.writable = !0, this.emitReserved("drain");
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Generates uri for connection.
|
|
444
|
+
*
|
|
445
|
+
* @private
|
|
446
|
+
*/
|
|
447
|
+
uri() {
|
|
448
|
+
const e = this.opts.secure ? "https" : "http", t = this.query || {};
|
|
449
|
+
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = xe()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
let Ne = !1;
|
|
453
|
+
try {
|
|
454
|
+
Ne = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
455
|
+
} catch {
|
|
456
|
+
}
|
|
457
|
+
const at = Ne;
|
|
458
|
+
function ct() {
|
|
459
|
+
}
|
|
460
|
+
class ht extends ot {
|
|
461
|
+
/**
|
|
462
|
+
* XHR Polling constructor.
|
|
463
|
+
*
|
|
464
|
+
* @param {Object} opts
|
|
465
|
+
* @package
|
|
466
|
+
*/
|
|
467
|
+
constructor(e) {
|
|
468
|
+
if (super(e), typeof location < "u") {
|
|
469
|
+
const t = location.protocol === "https:";
|
|
470
|
+
let s = location.port;
|
|
471
|
+
s || (s = t ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || s !== e.port;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Sends data.
|
|
476
|
+
*
|
|
477
|
+
* @param {String} data to send.
|
|
478
|
+
* @param {Function} called upon flush.
|
|
479
|
+
* @private
|
|
480
|
+
*/
|
|
481
|
+
doWrite(e, t) {
|
|
482
|
+
const s = this.request({
|
|
483
|
+
method: "POST",
|
|
484
|
+
data: e
|
|
485
|
+
});
|
|
486
|
+
s.on("success", t), s.on("error", (r, i) => {
|
|
487
|
+
this.onError("xhr post error", r, i);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Starts a poll cycle.
|
|
492
|
+
*
|
|
493
|
+
* @private
|
|
494
|
+
*/
|
|
495
|
+
doPoll() {
|
|
496
|
+
const e = this.request();
|
|
497
|
+
e.on("data", this.onData.bind(this)), e.on("error", (t, s) => {
|
|
498
|
+
this.onError("xhr poll error", t, s);
|
|
499
|
+
}), this.pollXhr = e;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
class v extends g {
|
|
503
|
+
/**
|
|
504
|
+
* Request constructor
|
|
505
|
+
*
|
|
506
|
+
* @param {Object} options
|
|
507
|
+
* @package
|
|
508
|
+
*/
|
|
509
|
+
constructor(e, t, s) {
|
|
510
|
+
super(), this.createRequest = e, J(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Creates the XHR object and sends the request.
|
|
514
|
+
*
|
|
515
|
+
* @private
|
|
516
|
+
*/
|
|
517
|
+
_create() {
|
|
518
|
+
var e;
|
|
519
|
+
const t = Be(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
520
|
+
t.xdomain = !!this._opts.xd;
|
|
521
|
+
const s = this._xhr = this.createRequest(t);
|
|
522
|
+
try {
|
|
523
|
+
s.open(this._method, this._uri, !0);
|
|
524
|
+
try {
|
|
525
|
+
if (this._opts.extraHeaders) {
|
|
526
|
+
s.setDisableHeaderCheck && s.setDisableHeaderCheck(!0);
|
|
527
|
+
for (let r in this._opts.extraHeaders)
|
|
528
|
+
this._opts.extraHeaders.hasOwnProperty(r) && s.setRequestHeader(r, this._opts.extraHeaders[r]);
|
|
529
|
+
}
|
|
530
|
+
} catch {
|
|
531
|
+
}
|
|
532
|
+
if (this._method === "POST")
|
|
533
|
+
try {
|
|
534
|
+
s.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
535
|
+
} catch {
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
s.setRequestHeader("Accept", "*/*");
|
|
539
|
+
} catch {
|
|
540
|
+
}
|
|
541
|
+
(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 = () => {
|
|
542
|
+
var r;
|
|
543
|
+
s.readyState === 3 && ((r = this._opts.cookieJar) === null || r === void 0 || r.parseCookies(
|
|
544
|
+
// @ts-ignore
|
|
545
|
+
s.getResponseHeader("set-cookie")
|
|
546
|
+
)), s.readyState === 4 && (s.status === 200 || s.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
|
|
547
|
+
this._onError(typeof s.status == "number" ? s.status : 0);
|
|
548
|
+
}, 0));
|
|
549
|
+
}, s.send(this._data);
|
|
550
|
+
} catch (r) {
|
|
551
|
+
this.setTimeoutFn(() => {
|
|
552
|
+
this._onError(r);
|
|
553
|
+
}, 0);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
typeof document < "u" && (this._index = v.requestsCount++, v.requests[this._index] = this);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Called upon error.
|
|
560
|
+
*
|
|
561
|
+
* @private
|
|
562
|
+
*/
|
|
563
|
+
_onError(e) {
|
|
564
|
+
this.emitReserved("error", e, this._xhr), this._cleanup(!0);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Cleans up house.
|
|
568
|
+
*
|
|
569
|
+
* @private
|
|
570
|
+
*/
|
|
571
|
+
_cleanup(e) {
|
|
572
|
+
if (!(typeof this._xhr > "u" || this._xhr === null)) {
|
|
573
|
+
if (this._xhr.onreadystatechange = ct, e)
|
|
574
|
+
try {
|
|
575
|
+
this._xhr.abort();
|
|
576
|
+
} catch {
|
|
577
|
+
}
|
|
578
|
+
typeof document < "u" && delete v.requests[this._index], this._xhr = null;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Called upon load.
|
|
583
|
+
*
|
|
584
|
+
* @private
|
|
585
|
+
*/
|
|
586
|
+
_onLoad() {
|
|
587
|
+
const e = this._xhr.responseText;
|
|
588
|
+
e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Aborts the request.
|
|
592
|
+
*
|
|
593
|
+
* @package
|
|
594
|
+
*/
|
|
595
|
+
abort() {
|
|
596
|
+
this._cleanup();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
v.requestsCount = 0;
|
|
600
|
+
v.requests = {};
|
|
601
|
+
if (typeof document < "u") {
|
|
602
|
+
if (typeof attachEvent == "function")
|
|
603
|
+
attachEvent("onunload", Te);
|
|
604
|
+
else if (typeof addEventListener == "function") {
|
|
605
|
+
const n = "onpagehide" in b ? "pagehide" : "unload";
|
|
606
|
+
addEventListener(n, Te, !1);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function Te() {
|
|
610
|
+
for (let n in v.requests)
|
|
611
|
+
v.requests.hasOwnProperty(n) && v.requests[n].abort();
|
|
612
|
+
}
|
|
613
|
+
const ut = function() {
|
|
614
|
+
const n = Pe({
|
|
615
|
+
xdomain: !1
|
|
616
|
+
});
|
|
617
|
+
return n && n.responseType !== null;
|
|
618
|
+
}();
|
|
619
|
+
class lt extends ht {
|
|
620
|
+
constructor(e) {
|
|
621
|
+
super(e);
|
|
622
|
+
const t = e && e.forceBase64;
|
|
623
|
+
this.supportsBinary = ut && !t;
|
|
624
|
+
}
|
|
625
|
+
request(e = {}) {
|
|
626
|
+
return Object.assign(e, { xd: this.xd }, this.opts), new v(Pe, this.uri(), e);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function Pe(n) {
|
|
630
|
+
const e = n.xdomain;
|
|
631
|
+
try {
|
|
632
|
+
if (typeof XMLHttpRequest < "u" && (!e || at))
|
|
633
|
+
return new XMLHttpRequest();
|
|
634
|
+
} catch {
|
|
635
|
+
}
|
|
636
|
+
if (!e)
|
|
637
|
+
try {
|
|
638
|
+
return new b[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
639
|
+
} catch {
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const Le = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
|
|
643
|
+
class ft extends fe {
|
|
644
|
+
get name() {
|
|
645
|
+
return "websocket";
|
|
646
|
+
}
|
|
647
|
+
doOpen() {
|
|
648
|
+
const e = this.uri(), t = this.opts.protocols, s = Le ? {} : Be(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
649
|
+
this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
|
|
650
|
+
try {
|
|
651
|
+
this.ws = this.createSocket(e, t, s);
|
|
652
|
+
} catch (r) {
|
|
653
|
+
return this.emitReserved("error", r);
|
|
654
|
+
}
|
|
655
|
+
this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Adds event listeners to the socket
|
|
659
|
+
*
|
|
660
|
+
* @private
|
|
661
|
+
*/
|
|
662
|
+
addEventListeners() {
|
|
663
|
+
this.ws.onopen = () => {
|
|
664
|
+
this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
|
|
665
|
+
}, this.ws.onclose = (e) => this.onClose({
|
|
666
|
+
description: "websocket connection closed",
|
|
667
|
+
context: e
|
|
668
|
+
}), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
669
|
+
}
|
|
670
|
+
write(e) {
|
|
671
|
+
this.writable = !1;
|
|
672
|
+
for (let t = 0; t < e.length; t++) {
|
|
673
|
+
const s = e[t], r = t === e.length - 1;
|
|
674
|
+
ue(s, this.supportsBinary, (i) => {
|
|
675
|
+
try {
|
|
676
|
+
this.doWrite(s, i);
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
r && H(() => {
|
|
680
|
+
this.writable = !0, this.emitReserved("drain");
|
|
681
|
+
}, this.setTimeoutFn);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
doClose() {
|
|
686
|
+
typeof this.ws < "u" && (this.ws.onerror = () => {
|
|
687
|
+
}, this.ws.close(), this.ws = null);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Generates uri for connection.
|
|
691
|
+
*
|
|
692
|
+
* @private
|
|
693
|
+
*/
|
|
694
|
+
uri() {
|
|
695
|
+
const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
|
|
696
|
+
return this.opts.timestampRequests && (t[this.opts.timestampParam] = xe()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const z = b.WebSocket || b.MozWebSocket;
|
|
700
|
+
class pt extends ft {
|
|
701
|
+
createSocket(e, t, s) {
|
|
702
|
+
return Le ? new z(e, t, s) : t ? new z(e, t) : new z(e);
|
|
703
|
+
}
|
|
704
|
+
doWrite(e, t) {
|
|
705
|
+
this.ws.send(t);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
class dt extends fe {
|
|
709
|
+
get name() {
|
|
710
|
+
return "webtransport";
|
|
711
|
+
}
|
|
712
|
+
doOpen() {
|
|
713
|
+
try {
|
|
714
|
+
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
715
|
+
} catch (e) {
|
|
716
|
+
return this.emitReserved("error", e);
|
|
717
|
+
}
|
|
718
|
+
this._transport.closed.then(() => {
|
|
719
|
+
this.onClose();
|
|
720
|
+
}).catch((e) => {
|
|
721
|
+
this.onError("webtransport error", e);
|
|
722
|
+
}), this._transport.ready.then(() => {
|
|
723
|
+
this._transport.createBidirectionalStream().then((e) => {
|
|
724
|
+
const t = We(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), r = Ye();
|
|
725
|
+
r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
|
|
726
|
+
const i = () => {
|
|
727
|
+
s.read().then(({ done: h, value: u }) => {
|
|
728
|
+
h || (this.onPacket(u), i());
|
|
729
|
+
}).catch((h) => {
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
i();
|
|
733
|
+
const o = { type: "open" };
|
|
734
|
+
this.query.sid && (o.data = `{"sid":"${this.query.sid}"}`), this._writer.write(o).then(() => this.onOpen());
|
|
735
|
+
});
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
write(e) {
|
|
739
|
+
this.writable = !1;
|
|
740
|
+
for (let t = 0; t < e.length; t++) {
|
|
741
|
+
const s = e[t], r = t === e.length - 1;
|
|
742
|
+
this._writer.write(s).then(() => {
|
|
743
|
+
r && H(() => {
|
|
744
|
+
this.writable = !0, this.emitReserved("drain");
|
|
745
|
+
}, this.setTimeoutFn);
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
doClose() {
|
|
750
|
+
var e;
|
|
751
|
+
(e = this._transport) === null || e === void 0 || e.close();
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
const yt = {
|
|
755
|
+
websocket: pt,
|
|
756
|
+
webtransport: dt,
|
|
757
|
+
polling: lt
|
|
758
|
+
}, mt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, gt = [
|
|
759
|
+
"source",
|
|
760
|
+
"protocol",
|
|
761
|
+
"authority",
|
|
762
|
+
"userInfo",
|
|
763
|
+
"user",
|
|
764
|
+
"password",
|
|
765
|
+
"host",
|
|
766
|
+
"port",
|
|
767
|
+
"relative",
|
|
768
|
+
"path",
|
|
769
|
+
"directory",
|
|
770
|
+
"file",
|
|
771
|
+
"query",
|
|
772
|
+
"anchor"
|
|
773
|
+
];
|
|
774
|
+
function te(n) {
|
|
775
|
+
if (n.length > 8e3)
|
|
776
|
+
throw "URI too long";
|
|
777
|
+
const e = n, t = n.indexOf("["), s = n.indexOf("]");
|
|
778
|
+
t != -1 && s != -1 && (n = n.substring(0, t) + n.substring(t, s).replace(/:/g, ";") + n.substring(s, n.length));
|
|
779
|
+
let r = mt.exec(n || ""), i = {}, o = 14;
|
|
780
|
+
for (; o--; )
|
|
781
|
+
i[gt[o]] = r[o] || "";
|
|
782
|
+
return t != -1 && s != -1 && (i.source = e, i.host = i.host.substring(1, i.host.length - 1).replace(/;/g, ":"), i.authority = i.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), i.ipv6uri = !0), i.pathNames = wt(i, i.path), i.queryKey = _t(i, i.query), i;
|
|
783
|
+
}
|
|
784
|
+
function wt(n, e) {
|
|
785
|
+
const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
|
|
786
|
+
return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
|
|
787
|
+
}
|
|
788
|
+
function _t(n, e) {
|
|
789
|
+
const t = {};
|
|
790
|
+
return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, r, i) {
|
|
791
|
+
r && (t[r] = i);
|
|
792
|
+
}), t;
|
|
793
|
+
}
|
|
794
|
+
const se = typeof addEventListener == "function" && typeof removeEventListener == "function", U = [];
|
|
795
|
+
se && addEventListener("offline", () => {
|
|
796
|
+
U.forEach((n) => n());
|
|
797
|
+
}, !1);
|
|
798
|
+
class C extends g {
|
|
799
|
+
/**
|
|
800
|
+
* Socket constructor.
|
|
801
|
+
*
|
|
802
|
+
* @param {String|Object} uri - uri or options
|
|
803
|
+
* @param {Object} opts - options
|
|
804
|
+
*/
|
|
805
|
+
constructor(e, t) {
|
|
806
|
+
if (super(), this.binaryType = Xe, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
|
|
807
|
+
const s = te(e);
|
|
808
|
+
t.hostname = s.host, t.secure = s.protocol === "https" || s.protocol === "wss", t.port = s.port, s.query && (t.query = s.query);
|
|
809
|
+
} else t.host && (t.hostname = te(t.host).host);
|
|
810
|
+
J(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
|
|
811
|
+
const r = s.prototype.name;
|
|
812
|
+
this.transports.push(r), this._transportsByName[r] = s;
|
|
813
|
+
}), this.opts = Object.assign({
|
|
814
|
+
path: "/engine.io",
|
|
815
|
+
agent: !1,
|
|
816
|
+
withCredentials: !1,
|
|
817
|
+
upgrade: !0,
|
|
818
|
+
timestampParam: "t",
|
|
819
|
+
rememberUpgrade: !1,
|
|
820
|
+
addTrailingSlash: !0,
|
|
821
|
+
rejectUnauthorized: !0,
|
|
822
|
+
perMessageDeflate: {
|
|
823
|
+
threshold: 1024
|
|
824
|
+
},
|
|
825
|
+
transportOptions: {},
|
|
826
|
+
closeOnBeforeunload: !1
|
|
827
|
+
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = rt(this.opts.query)), se && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
|
|
828
|
+
this.transport && (this.transport.removeAllListeners(), this.transport.close());
|
|
829
|
+
}, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
|
|
830
|
+
this._onClose("transport close", {
|
|
831
|
+
description: "network connection lost"
|
|
832
|
+
});
|
|
833
|
+
}, U.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Creates transport of the given type.
|
|
837
|
+
*
|
|
838
|
+
* @param {String} name - transport name
|
|
839
|
+
* @return {Transport}
|
|
840
|
+
* @private
|
|
841
|
+
*/
|
|
842
|
+
createTransport(e) {
|
|
843
|
+
const t = Object.assign({}, this.opts.query);
|
|
844
|
+
t.EIO = $e, t.transport = e, this.id && (t.sid = this.id);
|
|
845
|
+
const s = Object.assign({}, this.opts, {
|
|
846
|
+
query: t,
|
|
847
|
+
socket: this,
|
|
848
|
+
hostname: this.hostname,
|
|
849
|
+
secure: this.secure,
|
|
850
|
+
port: this.port
|
|
851
|
+
}, this.opts.transportOptions[e]);
|
|
852
|
+
return new this._transportsByName[e](s);
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Initializes transport to use and starts probe.
|
|
856
|
+
*
|
|
857
|
+
* @private
|
|
858
|
+
*/
|
|
859
|
+
_open() {
|
|
860
|
+
if (this.transports.length === 0) {
|
|
861
|
+
this.setTimeoutFn(() => {
|
|
862
|
+
this.emitReserved("error", "No transports available");
|
|
863
|
+
}, 0);
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
const e = this.opts.rememberUpgrade && C.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
867
|
+
this.readyState = "opening";
|
|
868
|
+
const t = this.createTransport(e);
|
|
869
|
+
t.open(), this.setTransport(t);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Sets the current transport. Disables the existing one (if any).
|
|
873
|
+
*
|
|
874
|
+
* @private
|
|
875
|
+
*/
|
|
876
|
+
setTransport(e) {
|
|
877
|
+
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));
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Called when connection is deemed open.
|
|
881
|
+
*
|
|
882
|
+
* @private
|
|
883
|
+
*/
|
|
884
|
+
onOpen() {
|
|
885
|
+
this.readyState = "open", C.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Handles a packet.
|
|
889
|
+
*
|
|
890
|
+
* @private
|
|
891
|
+
*/
|
|
892
|
+
_onPacket(e) {
|
|
893
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing")
|
|
894
|
+
switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
|
|
895
|
+
case "open":
|
|
896
|
+
this.onHandshake(JSON.parse(e.data));
|
|
897
|
+
break;
|
|
898
|
+
case "ping":
|
|
899
|
+
this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
|
|
900
|
+
break;
|
|
901
|
+
case "error":
|
|
902
|
+
const t = new Error("server error");
|
|
903
|
+
t.code = e.data, this._onError(t);
|
|
904
|
+
break;
|
|
905
|
+
case "message":
|
|
906
|
+
this.emitReserved("data", e.data), this.emitReserved("message", e.data);
|
|
907
|
+
break;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Called upon handshake completion.
|
|
912
|
+
*
|
|
913
|
+
* @param {Object} data - handshake obj
|
|
914
|
+
* @private
|
|
915
|
+
*/
|
|
916
|
+
onHandshake(e) {
|
|
917
|
+
this.emitReserved("handshake", e), this.id = e.sid, this.transport.query.sid = e.sid, this._pingInterval = e.pingInterval, this._pingTimeout = e.pingTimeout, this._maxPayload = e.maxPayload, this.onOpen(), this.readyState !== "closed" && this._resetPingTimeout();
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Sets and resets ping timeout timer based on server pings.
|
|
921
|
+
*
|
|
922
|
+
* @private
|
|
923
|
+
*/
|
|
924
|
+
_resetPingTimeout() {
|
|
925
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
926
|
+
const e = this._pingInterval + this._pingTimeout;
|
|
927
|
+
this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
928
|
+
this._onClose("ping timeout");
|
|
929
|
+
}, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Called on `drain` event
|
|
933
|
+
*
|
|
934
|
+
* @private
|
|
935
|
+
*/
|
|
936
|
+
_onDrain() {
|
|
937
|
+
this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Flush write buffers.
|
|
941
|
+
*
|
|
942
|
+
* @private
|
|
943
|
+
*/
|
|
944
|
+
flush() {
|
|
945
|
+
if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
946
|
+
const e = this._getWritablePackets();
|
|
947
|
+
this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
952
|
+
* long-polling)
|
|
953
|
+
*
|
|
954
|
+
* @private
|
|
955
|
+
*/
|
|
956
|
+
_getWritablePackets() {
|
|
957
|
+
if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1))
|
|
958
|
+
return this.writeBuffer;
|
|
959
|
+
let t = 1;
|
|
960
|
+
for (let s = 0; s < this.writeBuffer.length; s++) {
|
|
961
|
+
const r = this.writeBuffer[s].data;
|
|
962
|
+
if (r && (t += tt(r)), s > 0 && t > this._maxPayload)
|
|
963
|
+
return this.writeBuffer.slice(0, s);
|
|
964
|
+
t += 2;
|
|
965
|
+
}
|
|
966
|
+
return this.writeBuffer;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
970
|
+
*
|
|
971
|
+
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
972
|
+
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
973
|
+
*
|
|
974
|
+
* @return {boolean}
|
|
975
|
+
* @private
|
|
976
|
+
*/
|
|
977
|
+
/* private */
|
|
978
|
+
_hasPingExpired() {
|
|
979
|
+
if (!this._pingTimeoutTime)
|
|
980
|
+
return !0;
|
|
981
|
+
const e = Date.now() > this._pingTimeoutTime;
|
|
982
|
+
return e && (this._pingTimeoutTime = 0, H(() => {
|
|
983
|
+
this._onClose("ping timeout");
|
|
984
|
+
}, this.setTimeoutFn)), e;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Sends a message.
|
|
988
|
+
*
|
|
989
|
+
* @param {String} msg - message.
|
|
990
|
+
* @param {Object} options.
|
|
991
|
+
* @param {Function} fn - callback function.
|
|
992
|
+
* @return {Socket} for chaining.
|
|
993
|
+
*/
|
|
994
|
+
write(e, t, s) {
|
|
995
|
+
return this._sendPacket("message", e, t, s), this;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Sends a message. Alias of {@link Socket#write}.
|
|
999
|
+
*
|
|
1000
|
+
* @param {String} msg - message.
|
|
1001
|
+
* @param {Object} options.
|
|
1002
|
+
* @param {Function} fn - callback function.
|
|
1003
|
+
* @return {Socket} for chaining.
|
|
1004
|
+
*/
|
|
1005
|
+
send(e, t, s) {
|
|
1006
|
+
return this._sendPacket("message", e, t, s), this;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Sends a packet.
|
|
1010
|
+
*
|
|
1011
|
+
* @param {String} type: packet type.
|
|
1012
|
+
* @param {String} data.
|
|
1013
|
+
* @param {Object} options.
|
|
1014
|
+
* @param {Function} fn - callback function.
|
|
1015
|
+
* @private
|
|
1016
|
+
*/
|
|
1017
|
+
_sendPacket(e, t, s, r) {
|
|
1018
|
+
if (typeof t == "function" && (r = t, t = void 0), typeof s == "function" && (r = s, s = null), this.readyState === "closing" || this.readyState === "closed")
|
|
1019
|
+
return;
|
|
1020
|
+
s = s || {}, s.compress = s.compress !== !1;
|
|
1021
|
+
const i = {
|
|
1022
|
+
type: e,
|
|
1023
|
+
data: t,
|
|
1024
|
+
options: s
|
|
1025
|
+
};
|
|
1026
|
+
this.emitReserved("packetCreate", i), this.writeBuffer.push(i), r && this.once("flush", r), this.flush();
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Closes the connection.
|
|
1030
|
+
*/
|
|
1031
|
+
close() {
|
|
1032
|
+
const e = () => {
|
|
1033
|
+
this._onClose("forced close"), this.transport.close();
|
|
1034
|
+
}, t = () => {
|
|
1035
|
+
this.off("upgrade", t), this.off("upgradeError", t), e();
|
|
1036
|
+
}, s = () => {
|
|
1037
|
+
this.once("upgrade", t), this.once("upgradeError", t);
|
|
1038
|
+
};
|
|
1039
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
|
|
1040
|
+
this.upgrading ? s() : e();
|
|
1041
|
+
}) : this.upgrading ? s() : e()), this;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Called upon transport error
|
|
1045
|
+
*
|
|
1046
|
+
* @private
|
|
1047
|
+
*/
|
|
1048
|
+
_onError(e) {
|
|
1049
|
+
if (C.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
|
|
1050
|
+
return this.transports.shift(), this._open();
|
|
1051
|
+
this.emitReserved("error", e), this._onClose("transport error", e);
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Called upon transport close.
|
|
1055
|
+
*
|
|
1056
|
+
* @private
|
|
1057
|
+
*/
|
|
1058
|
+
_onClose(e, t) {
|
|
1059
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
|
|
1060
|
+
if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), se && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
|
|
1061
|
+
const s = U.indexOf(this._offlineEventListener);
|
|
1062
|
+
s !== -1 && U.splice(s, 1);
|
|
1063
|
+
}
|
|
1064
|
+
this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
C.protocol = $e;
|
|
1069
|
+
class bt extends C {
|
|
1070
|
+
constructor() {
|
|
1071
|
+
super(...arguments), this._upgrades = [];
|
|
1072
|
+
}
|
|
1073
|
+
onOpen() {
|
|
1074
|
+
if (super.onOpen(), this.readyState === "open" && this.opts.upgrade)
|
|
1075
|
+
for (let e = 0; e < this._upgrades.length; e++)
|
|
1076
|
+
this._probe(this._upgrades[e]);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Probes a transport.
|
|
1080
|
+
*
|
|
1081
|
+
* @param {String} name - transport name
|
|
1082
|
+
* @private
|
|
1083
|
+
*/
|
|
1084
|
+
_probe(e) {
|
|
1085
|
+
let t = this.createTransport(e), s = !1;
|
|
1086
|
+
C.priorWebsocketSuccess = !1;
|
|
1087
|
+
const r = () => {
|
|
1088
|
+
s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (m) => {
|
|
1089
|
+
if (!s)
|
|
1090
|
+
if (m.type === "pong" && m.data === "probe") {
|
|
1091
|
+
if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
|
|
1092
|
+
return;
|
|
1093
|
+
C.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
|
|
1094
|
+
s || this.readyState !== "closed" && (d(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
|
|
1095
|
+
});
|
|
1096
|
+
} else {
|
|
1097
|
+
const w = new Error("probe error");
|
|
1098
|
+
w.transport = t.name, this.emitReserved("upgradeError", w);
|
|
1099
|
+
}
|
|
1100
|
+
}));
|
|
1101
|
+
};
|
|
1102
|
+
function i() {
|
|
1103
|
+
s || (s = !0, d(), t.close(), t = null);
|
|
1104
|
+
}
|
|
1105
|
+
const o = (m) => {
|
|
1106
|
+
const w = new Error("probe error: " + m);
|
|
1107
|
+
w.transport = t.name, i(), this.emitReserved("upgradeError", w);
|
|
1108
|
+
};
|
|
1109
|
+
function h() {
|
|
1110
|
+
o("transport closed");
|
|
1111
|
+
}
|
|
1112
|
+
function u() {
|
|
1113
|
+
o("socket closed");
|
|
1114
|
+
}
|
|
1115
|
+
function y(m) {
|
|
1116
|
+
t && m.name !== t.name && i();
|
|
1117
|
+
}
|
|
1118
|
+
const d = () => {
|
|
1119
|
+
t.removeListener("open", r), t.removeListener("error", o), t.removeListener("close", h), this.off("close", u), this.off("upgrading", y);
|
|
1120
|
+
};
|
|
1121
|
+
t.once("open", r), t.once("error", o), t.once("close", h), this.once("close", u), this.once("upgrading", y), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
|
|
1122
|
+
s || t.open();
|
|
1123
|
+
}, 200) : t.open();
|
|
1124
|
+
}
|
|
1125
|
+
onHandshake(e) {
|
|
1126
|
+
this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Filters upgrades, returning only those matching client transports.
|
|
1130
|
+
*
|
|
1131
|
+
* @param {Array} upgrades - server upgrades
|
|
1132
|
+
* @private
|
|
1133
|
+
*/
|
|
1134
|
+
_filterUpgrades(e) {
|
|
1135
|
+
const t = [];
|
|
1136
|
+
for (let s = 0; s < e.length; s++)
|
|
1137
|
+
~this.transports.indexOf(e[s]) && t.push(e[s]);
|
|
1138
|
+
return t;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
let Et = class extends bt {
|
|
1142
|
+
constructor(e, t = {}) {
|
|
1143
|
+
const s = typeof e == "object" ? e : t;
|
|
1144
|
+
(!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((r) => yt[r]).filter((r) => !!r)), super(e, s);
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
function Tt(n, e = "", t) {
|
|
1148
|
+
let s = n;
|
|
1149
|
+
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 = te(n)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
|
|
1150
|
+
const i = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
|
|
1151
|
+
return s.id = s.protocol + "://" + i + ":" + s.port + e, s.href = s.protocol + "://" + i + (t && t.port === s.port ? "" : ":" + s.port), s;
|
|
1152
|
+
}
|
|
1153
|
+
const vt = typeof ArrayBuffer == "function", kt = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, Ie = Object.prototype.toString, At = typeof Blob == "function" || typeof Blob < "u" && Ie.call(Blob) === "[object BlobConstructor]", Ot = typeof File == "function" || typeof File < "u" && Ie.call(File) === "[object FileConstructor]";
|
|
1154
|
+
function pe(n) {
|
|
1155
|
+
return vt && (n instanceof ArrayBuffer || kt(n)) || At && n instanceof Blob || Ot && n instanceof File;
|
|
1156
|
+
}
|
|
1157
|
+
function D(n, e) {
|
|
1158
|
+
if (!n || typeof n != "object")
|
|
1159
|
+
return !1;
|
|
1160
|
+
if (Array.isArray(n)) {
|
|
1161
|
+
for (let t = 0, s = n.length; t < s; t++)
|
|
1162
|
+
if (D(n[t]))
|
|
1163
|
+
return !0;
|
|
1164
|
+
return !1;
|
|
1165
|
+
}
|
|
1166
|
+
if (pe(n))
|
|
1167
|
+
return !0;
|
|
1168
|
+
if (n.toJSON && typeof n.toJSON == "function" && arguments.length === 1)
|
|
1169
|
+
return D(n.toJSON(), !0);
|
|
1170
|
+
for (const t in n)
|
|
1171
|
+
if (Object.prototype.hasOwnProperty.call(n, t) && D(n[t]))
|
|
1172
|
+
return !0;
|
|
1173
|
+
return !1;
|
|
1174
|
+
}
|
|
1175
|
+
function St(n) {
|
|
1176
|
+
const e = [], t = n.data, s = n;
|
|
1177
|
+
return s.data = ne(t, e), s.attachments = e.length, { packet: s, buffers: e };
|
|
1178
|
+
}
|
|
1179
|
+
function ne(n, e) {
|
|
1180
|
+
if (!n)
|
|
1181
|
+
return n;
|
|
1182
|
+
if (pe(n)) {
|
|
1183
|
+
const t = { _placeholder: !0, num: e.length };
|
|
1184
|
+
return e.push(n), t;
|
|
1185
|
+
} else if (Array.isArray(n)) {
|
|
1186
|
+
const t = new Array(n.length);
|
|
1187
|
+
for (let s = 0; s < n.length; s++)
|
|
1188
|
+
t[s] = ne(n[s], e);
|
|
1189
|
+
return t;
|
|
1190
|
+
} else if (typeof n == "object" && !(n instanceof Date)) {
|
|
1191
|
+
const t = {};
|
|
1192
|
+
for (const s in n)
|
|
1193
|
+
Object.prototype.hasOwnProperty.call(n, s) && (t[s] = ne(n[s], e));
|
|
1194
|
+
return t;
|
|
1195
|
+
}
|
|
1196
|
+
return n;
|
|
1197
|
+
}
|
|
1198
|
+
function Ct(n, e) {
|
|
1199
|
+
return n.data = re(n.data, e), delete n.attachments, n;
|
|
1200
|
+
}
|
|
1201
|
+
function re(n, e) {
|
|
1202
|
+
if (!n)
|
|
1203
|
+
return n;
|
|
1204
|
+
if (n && n._placeholder === !0) {
|
|
1205
|
+
if (typeof n.num == "number" && n.num >= 0 && n.num < e.length)
|
|
1206
|
+
return e[n.num];
|
|
1207
|
+
throw new Error("illegal attachments");
|
|
1208
|
+
} else if (Array.isArray(n))
|
|
1209
|
+
for (let t = 0; t < n.length; t++)
|
|
1210
|
+
n[t] = re(n[t], e);
|
|
1211
|
+
else if (typeof n == "object")
|
|
1212
|
+
for (const t in n)
|
|
1213
|
+
Object.prototype.hasOwnProperty.call(n, t) && (n[t] = re(n[t], e));
|
|
1214
|
+
return n;
|
|
1215
|
+
}
|
|
1216
|
+
const Rt = [
|
|
1217
|
+
"connect",
|
|
1218
|
+
// used on the client side
|
|
1219
|
+
"connect_error",
|
|
1220
|
+
// used on the client side
|
|
1221
|
+
"disconnect",
|
|
1222
|
+
// used on both sides
|
|
1223
|
+
"disconnecting",
|
|
1224
|
+
// used on the server side
|
|
1225
|
+
"newListener",
|
|
1226
|
+
// used by the Node.js EventEmitter
|
|
1227
|
+
"removeListener"
|
|
1228
|
+
// used by the Node.js EventEmitter
|
|
1229
|
+
];
|
|
1230
|
+
var f;
|
|
1231
|
+
(function(n) {
|
|
1232
|
+
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";
|
|
1233
|
+
})(f || (f = {}));
|
|
1234
|
+
class $t {
|
|
1235
|
+
/**
|
|
1236
|
+
* Encoder constructor
|
|
1237
|
+
*
|
|
1238
|
+
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
1239
|
+
*/
|
|
1240
|
+
constructor(e) {
|
|
1241
|
+
this.replacer = e;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Encode a packet as a single string if non-binary, or as a
|
|
1245
|
+
* buffer sequence, depending on packet type.
|
|
1246
|
+
*
|
|
1247
|
+
* @param {Object} obj - packet object
|
|
1248
|
+
*/
|
|
1249
|
+
encode(e) {
|
|
1250
|
+
return (e.type === f.EVENT || e.type === f.ACK) && D(e) ? this.encodeAsBinary({
|
|
1251
|
+
type: e.type === f.EVENT ? f.BINARY_EVENT : f.BINARY_ACK,
|
|
1252
|
+
nsp: e.nsp,
|
|
1253
|
+
data: e.data,
|
|
1254
|
+
id: e.id
|
|
1255
|
+
}) : [this.encodeAsString(e)];
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Encode packet as string.
|
|
1259
|
+
*/
|
|
1260
|
+
encodeAsString(e) {
|
|
1261
|
+
let t = "" + e.type;
|
|
1262
|
+
return (e.type === f.BINARY_EVENT || e.type === f.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;
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Encode packet as 'buffer sequence' by removing blobs, and
|
|
1266
|
+
* deconstructing packet into object with placeholders and
|
|
1267
|
+
* a list of buffers.
|
|
1268
|
+
*/
|
|
1269
|
+
encodeAsBinary(e) {
|
|
1270
|
+
const t = St(e), s = this.encodeAsString(t.packet), r = t.buffers;
|
|
1271
|
+
return r.unshift(s), r;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
class de extends g {
|
|
1275
|
+
/**
|
|
1276
|
+
* Decoder constructor
|
|
1277
|
+
*
|
|
1278
|
+
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
1279
|
+
*/
|
|
1280
|
+
constructor(e) {
|
|
1281
|
+
super(), this.reviver = e;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Decodes an encoded packet string into packet JSON.
|
|
1285
|
+
*
|
|
1286
|
+
* @param {String} obj - encoded packet
|
|
1287
|
+
*/
|
|
1288
|
+
add(e) {
|
|
1289
|
+
let t;
|
|
1290
|
+
if (typeof e == "string") {
|
|
1291
|
+
if (this.reconstructor)
|
|
1292
|
+
throw new Error("got plaintext data when reconstructing a packet");
|
|
1293
|
+
t = this.decodeString(e);
|
|
1294
|
+
const s = t.type === f.BINARY_EVENT;
|
|
1295
|
+
s || t.type === f.BINARY_ACK ? (t.type = s ? f.EVENT : f.ACK, this.reconstructor = new Bt(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
|
|
1296
|
+
} else if (pe(e) || e.base64)
|
|
1297
|
+
if (this.reconstructor)
|
|
1298
|
+
t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
|
|
1299
|
+
else
|
|
1300
|
+
throw new Error("got binary data when not reconstructing a packet");
|
|
1301
|
+
else
|
|
1302
|
+
throw new Error("Unknown type: " + e);
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Decode a packet String (JSON data)
|
|
1306
|
+
*
|
|
1307
|
+
* @param {String} str
|
|
1308
|
+
* @return {Object} packet
|
|
1309
|
+
*/
|
|
1310
|
+
decodeString(e) {
|
|
1311
|
+
let t = 0;
|
|
1312
|
+
const s = {
|
|
1313
|
+
type: Number(e.charAt(0))
|
|
1314
|
+
};
|
|
1315
|
+
if (f[s.type] === void 0)
|
|
1316
|
+
throw new Error("unknown packet type " + s.type);
|
|
1317
|
+
if (s.type === f.BINARY_EVENT || s.type === f.BINARY_ACK) {
|
|
1318
|
+
const i = t + 1;
|
|
1319
|
+
for (; e.charAt(++t) !== "-" && t != e.length; )
|
|
1320
|
+
;
|
|
1321
|
+
const o = e.substring(i, t);
|
|
1322
|
+
if (o != Number(o) || e.charAt(t) !== "-")
|
|
1323
|
+
throw new Error("Illegal attachments");
|
|
1324
|
+
s.attachments = Number(o);
|
|
1325
|
+
}
|
|
1326
|
+
if (e.charAt(t + 1) === "/") {
|
|
1327
|
+
const i = t + 1;
|
|
1328
|
+
for (; ++t && !(e.charAt(t) === "," || t === e.length); )
|
|
1329
|
+
;
|
|
1330
|
+
s.nsp = e.substring(i, t);
|
|
1331
|
+
} else
|
|
1332
|
+
s.nsp = "/";
|
|
1333
|
+
const r = e.charAt(t + 1);
|
|
1334
|
+
if (r !== "" && Number(r) == r) {
|
|
1335
|
+
const i = t + 1;
|
|
1336
|
+
for (; ++t; ) {
|
|
1337
|
+
const o = e.charAt(t);
|
|
1338
|
+
if (o == null || Number(o) != o) {
|
|
1339
|
+
--t;
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
if (t === e.length)
|
|
1343
|
+
break;
|
|
1344
|
+
}
|
|
1345
|
+
s.id = Number(e.substring(i, t + 1));
|
|
1346
|
+
}
|
|
1347
|
+
if (e.charAt(++t)) {
|
|
1348
|
+
const i = this.tryParse(e.substr(t));
|
|
1349
|
+
if (de.isPayloadValid(s.type, i))
|
|
1350
|
+
s.data = i;
|
|
1351
|
+
else
|
|
1352
|
+
throw new Error("invalid payload");
|
|
1353
|
+
}
|
|
1354
|
+
return s;
|
|
1355
|
+
}
|
|
1356
|
+
tryParse(e) {
|
|
1357
|
+
try {
|
|
1358
|
+
return JSON.parse(e, this.reviver);
|
|
1359
|
+
} catch {
|
|
1360
|
+
return !1;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
static isPayloadValid(e, t) {
|
|
1364
|
+
switch (e) {
|
|
1365
|
+
case f.CONNECT:
|
|
1366
|
+
return ve(t);
|
|
1367
|
+
case f.DISCONNECT:
|
|
1368
|
+
return t === void 0;
|
|
1369
|
+
case f.CONNECT_ERROR:
|
|
1370
|
+
return typeof t == "string" || ve(t);
|
|
1371
|
+
case f.EVENT:
|
|
1372
|
+
case f.BINARY_EVENT:
|
|
1373
|
+
return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && Rt.indexOf(t[0]) === -1);
|
|
1374
|
+
case f.ACK:
|
|
1375
|
+
case f.BINARY_ACK:
|
|
1376
|
+
return Array.isArray(t);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Deallocates a parser's resources
|
|
1381
|
+
*/
|
|
1382
|
+
destroy() {
|
|
1383
|
+
this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
class Bt {
|
|
1387
|
+
constructor(e) {
|
|
1388
|
+
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Method to be called when binary data received from connection
|
|
1392
|
+
* after a BINARY_EVENT packet.
|
|
1393
|
+
*
|
|
1394
|
+
* @param {Buffer | ArrayBuffer} binData - the raw binary data received
|
|
1395
|
+
* @return {null | Object} returns null if more binary data is expected or
|
|
1396
|
+
* a reconstructed packet object if all buffers have been received.
|
|
1397
|
+
*/
|
|
1398
|
+
takeBinaryData(e) {
|
|
1399
|
+
if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
|
|
1400
|
+
const t = Ct(this.reconPack, this.buffers);
|
|
1401
|
+
return this.finishedReconstruction(), t;
|
|
1402
|
+
}
|
|
1403
|
+
return null;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Cleans up binary packet reconstruction variables.
|
|
1407
|
+
*/
|
|
1408
|
+
finishedReconstruction() {
|
|
1409
|
+
this.reconPack = null, this.buffers = [];
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
function ve(n) {
|
|
1413
|
+
return Object.prototype.toString.call(n) === "[object Object]";
|
|
1414
|
+
}
|
|
1415
|
+
const xt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1416
|
+
__proto__: null,
|
|
1417
|
+
Decoder: de,
|
|
1418
|
+
Encoder: $t,
|
|
1419
|
+
get PacketType() {
|
|
1420
|
+
return f;
|
|
1421
|
+
}
|
|
1422
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1423
|
+
function E(n, e, t) {
|
|
1424
|
+
return n.on(e, t), function() {
|
|
1425
|
+
n.off(e, t);
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
const Nt = Object.freeze({
|
|
1429
|
+
connect: 1,
|
|
1430
|
+
connect_error: 1,
|
|
1431
|
+
disconnect: 1,
|
|
1432
|
+
disconnecting: 1,
|
|
1433
|
+
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
|
1434
|
+
newListener: 1,
|
|
1435
|
+
removeListener: 1
|
|
1436
|
+
});
|
|
1437
|
+
class qe extends g {
|
|
1438
|
+
/**
|
|
1439
|
+
* `Socket` constructor.
|
|
1440
|
+
*/
|
|
1441
|
+
constructor(e, t, s) {
|
|
1442
|
+
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();
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Whether the socket is currently disconnected
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* const socket = io();
|
|
1449
|
+
*
|
|
1450
|
+
* socket.on("connect", () => {
|
|
1451
|
+
* console.log(socket.disconnected); // false
|
|
1452
|
+
* });
|
|
1453
|
+
*
|
|
1454
|
+
* socket.on("disconnect", () => {
|
|
1455
|
+
* console.log(socket.disconnected); // true
|
|
1456
|
+
* });
|
|
1457
|
+
*/
|
|
1458
|
+
get disconnected() {
|
|
1459
|
+
return !this.connected;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Subscribe to open, close and packet events
|
|
1463
|
+
*
|
|
1464
|
+
* @private
|
|
1465
|
+
*/
|
|
1466
|
+
subEvents() {
|
|
1467
|
+
if (this.subs)
|
|
1468
|
+
return;
|
|
1469
|
+
const e = this.io;
|
|
1470
|
+
this.subs = [
|
|
1471
|
+
E(e, "open", this.onopen.bind(this)),
|
|
1472
|
+
E(e, "packet", this.onpacket.bind(this)),
|
|
1473
|
+
E(e, "error", this.onerror.bind(this)),
|
|
1474
|
+
E(e, "close", this.onclose.bind(this))
|
|
1475
|
+
];
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
* const socket = io();
|
|
1482
|
+
*
|
|
1483
|
+
* console.log(socket.active); // true
|
|
1484
|
+
*
|
|
1485
|
+
* socket.on("disconnect", (reason) => {
|
|
1486
|
+
* if (reason === "io server disconnect") {
|
|
1487
|
+
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
1488
|
+
* console.log(socket.active); // false
|
|
1489
|
+
* }
|
|
1490
|
+
* // else the socket will automatically try to reconnect
|
|
1491
|
+
* console.log(socket.active); // true
|
|
1492
|
+
* });
|
|
1493
|
+
*/
|
|
1494
|
+
get active() {
|
|
1495
|
+
return !!this.subs;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* "Opens" the socket.
|
|
1499
|
+
*
|
|
1500
|
+
* @example
|
|
1501
|
+
* const socket = io({
|
|
1502
|
+
* autoConnect: false
|
|
1503
|
+
* });
|
|
1504
|
+
*
|
|
1505
|
+
* socket.connect();
|
|
1506
|
+
*/
|
|
1507
|
+
connect() {
|
|
1508
|
+
return this.connected ? this : (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen(), this);
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Alias for {@link connect()}.
|
|
1512
|
+
*/
|
|
1513
|
+
open() {
|
|
1514
|
+
return this.connect();
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Sends a `message` event.
|
|
1518
|
+
*
|
|
1519
|
+
* This method mimics the WebSocket.send() method.
|
|
1520
|
+
*
|
|
1521
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
1522
|
+
*
|
|
1523
|
+
* @example
|
|
1524
|
+
* socket.send("hello");
|
|
1525
|
+
*
|
|
1526
|
+
* // this is equivalent to
|
|
1527
|
+
* socket.emit("message", "hello");
|
|
1528
|
+
*
|
|
1529
|
+
* @return self
|
|
1530
|
+
*/
|
|
1531
|
+
send(...e) {
|
|
1532
|
+
return e.unshift("message"), this.emit.apply(this, e), this;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Override `emit`.
|
|
1536
|
+
* If the event is in `events`, it's emitted normally.
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
* socket.emit("hello", "world");
|
|
1540
|
+
*
|
|
1541
|
+
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
1542
|
+
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
1543
|
+
*
|
|
1544
|
+
* // with an acknowledgement from the server
|
|
1545
|
+
* socket.emit("hello", "world", (val) => {
|
|
1546
|
+
* // ...
|
|
1547
|
+
* });
|
|
1548
|
+
*
|
|
1549
|
+
* @return self
|
|
1550
|
+
*/
|
|
1551
|
+
emit(e, ...t) {
|
|
1552
|
+
var s, r, i;
|
|
1553
|
+
if (Nt.hasOwnProperty(e))
|
|
1554
|
+
throw new Error('"' + e.toString() + '" is a reserved event name');
|
|
1555
|
+
if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
|
|
1556
|
+
return this._addToQueue(t), this;
|
|
1557
|
+
const o = {
|
|
1558
|
+
type: f.EVENT,
|
|
1559
|
+
data: t
|
|
1560
|
+
};
|
|
1561
|
+
if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
|
|
1562
|
+
const d = this.ids++, m = t.pop();
|
|
1563
|
+
this._registerAckCallback(d, m), o.id = d;
|
|
1564
|
+
}
|
|
1565
|
+
const h = (r = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || r === void 0 ? void 0 : r.writable, u = this.connected && !(!((i = this.io.engine) === null || i === void 0) && i._hasPingExpired());
|
|
1566
|
+
return this.flags.volatile && !h || (u ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* @private
|
|
1570
|
+
*/
|
|
1571
|
+
_registerAckCallback(e, t) {
|
|
1572
|
+
var s;
|
|
1573
|
+
const r = (s = this.flags.timeout) !== null && s !== void 0 ? s : this._opts.ackTimeout;
|
|
1574
|
+
if (r === void 0) {
|
|
1575
|
+
this.acks[e] = t;
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
const i = this.io.setTimeoutFn(() => {
|
|
1579
|
+
delete this.acks[e];
|
|
1580
|
+
for (let h = 0; h < this.sendBuffer.length; h++)
|
|
1581
|
+
this.sendBuffer[h].id === e && this.sendBuffer.splice(h, 1);
|
|
1582
|
+
t.call(this, new Error("operation has timed out"));
|
|
1583
|
+
}, r), o = (...h) => {
|
|
1584
|
+
this.io.clearTimeoutFn(i), t.apply(this, h);
|
|
1585
|
+
};
|
|
1586
|
+
o.withError = !0, this.acks[e] = o;
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Emits an event and waits for an acknowledgement
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* // without timeout
|
|
1593
|
+
* const response = await socket.emitWithAck("hello", "world");
|
|
1594
|
+
*
|
|
1595
|
+
* // with a specific timeout
|
|
1596
|
+
* try {
|
|
1597
|
+
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
1598
|
+
* } catch (err) {
|
|
1599
|
+
* // the server did not acknowledge the event in the given delay
|
|
1600
|
+
* }
|
|
1601
|
+
*
|
|
1602
|
+
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
1603
|
+
*/
|
|
1604
|
+
emitWithAck(e, ...t) {
|
|
1605
|
+
return new Promise((s, r) => {
|
|
1606
|
+
const i = (o, h) => o ? r(o) : s(h);
|
|
1607
|
+
i.withError = !0, t.push(i), this.emit(e, ...t);
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Add the packet to the queue.
|
|
1612
|
+
* @param args
|
|
1613
|
+
* @private
|
|
1614
|
+
*/
|
|
1615
|
+
_addToQueue(e) {
|
|
1616
|
+
let t;
|
|
1617
|
+
typeof e[e.length - 1] == "function" && (t = e.pop());
|
|
1618
|
+
const s = {
|
|
1619
|
+
id: this._queueSeq++,
|
|
1620
|
+
tryCount: 0,
|
|
1621
|
+
pending: !1,
|
|
1622
|
+
args: e,
|
|
1623
|
+
flags: Object.assign({ fromQueue: !0 }, this.flags)
|
|
1624
|
+
};
|
|
1625
|
+
e.push((r, ...i) => (this._queue[0], r !== null ? s.tryCount > this._opts.retries && (this._queue.shift(), t && t(r)) : (this._queue.shift(), t && t(null, ...i)), s.pending = !1, this._drainQueue())), this._queue.push(s), this._drainQueue();
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
1629
|
+
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
1630
|
+
*
|
|
1631
|
+
* @private
|
|
1632
|
+
*/
|
|
1633
|
+
_drainQueue(e = !1) {
|
|
1634
|
+
if (!this.connected || this._queue.length === 0)
|
|
1635
|
+
return;
|
|
1636
|
+
const t = this._queue[0];
|
|
1637
|
+
t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Sends a packet.
|
|
1641
|
+
*
|
|
1642
|
+
* @param packet
|
|
1643
|
+
* @private
|
|
1644
|
+
*/
|
|
1645
|
+
packet(e) {
|
|
1646
|
+
e.nsp = this.nsp, this.io._packet(e);
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Called upon engine `open`.
|
|
1650
|
+
*
|
|
1651
|
+
* @private
|
|
1652
|
+
*/
|
|
1653
|
+
onopen() {
|
|
1654
|
+
typeof this.auth == "function" ? this.auth((e) => {
|
|
1655
|
+
this._sendConnectPacket(e);
|
|
1656
|
+
}) : this._sendConnectPacket(this.auth);
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
1660
|
+
*
|
|
1661
|
+
* @param data
|
|
1662
|
+
* @private
|
|
1663
|
+
*/
|
|
1664
|
+
_sendConnectPacket(e) {
|
|
1665
|
+
this.packet({
|
|
1666
|
+
type: f.CONNECT,
|
|
1667
|
+
data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Called upon engine or manager `error`.
|
|
1672
|
+
*
|
|
1673
|
+
* @param err
|
|
1674
|
+
* @private
|
|
1675
|
+
*/
|
|
1676
|
+
onerror(e) {
|
|
1677
|
+
this.connected || this.emitReserved("connect_error", e);
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Called upon engine `close`.
|
|
1681
|
+
*
|
|
1682
|
+
* @param reason
|
|
1683
|
+
* @param description
|
|
1684
|
+
* @private
|
|
1685
|
+
*/
|
|
1686
|
+
onclose(e, t) {
|
|
1687
|
+
this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
1691
|
+
* the server.
|
|
1692
|
+
*
|
|
1693
|
+
* @private
|
|
1694
|
+
*/
|
|
1695
|
+
_clearAcks() {
|
|
1696
|
+
Object.keys(this.acks).forEach((e) => {
|
|
1697
|
+
if (!this.sendBuffer.some((s) => String(s.id) === e)) {
|
|
1698
|
+
const s = this.acks[e];
|
|
1699
|
+
delete this.acks[e], s.withError && s.call(this, new Error("socket has been disconnected"));
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Called with socket packet.
|
|
1705
|
+
*
|
|
1706
|
+
* @param packet
|
|
1707
|
+
* @private
|
|
1708
|
+
*/
|
|
1709
|
+
onpacket(e) {
|
|
1710
|
+
if (e.nsp === this.nsp)
|
|
1711
|
+
switch (e.type) {
|
|
1712
|
+
case f.CONNECT:
|
|
1713
|
+
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/)"));
|
|
1714
|
+
break;
|
|
1715
|
+
case f.EVENT:
|
|
1716
|
+
case f.BINARY_EVENT:
|
|
1717
|
+
this.onevent(e);
|
|
1718
|
+
break;
|
|
1719
|
+
case f.ACK:
|
|
1720
|
+
case f.BINARY_ACK:
|
|
1721
|
+
this.onack(e);
|
|
1722
|
+
break;
|
|
1723
|
+
case f.DISCONNECT:
|
|
1724
|
+
this.ondisconnect();
|
|
1725
|
+
break;
|
|
1726
|
+
case f.CONNECT_ERROR:
|
|
1727
|
+
this.destroy();
|
|
1728
|
+
const s = new Error(e.data.message);
|
|
1729
|
+
s.data = e.data.data, this.emitReserved("connect_error", s);
|
|
1730
|
+
break;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Called upon a server event.
|
|
1735
|
+
*
|
|
1736
|
+
* @param packet
|
|
1737
|
+
* @private
|
|
1738
|
+
*/
|
|
1739
|
+
onevent(e) {
|
|
1740
|
+
const t = e.data || [];
|
|
1741
|
+
e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
|
|
1742
|
+
}
|
|
1743
|
+
emitEvent(e) {
|
|
1744
|
+
if (this._anyListeners && this._anyListeners.length) {
|
|
1745
|
+
const t = this._anyListeners.slice();
|
|
1746
|
+
for (const s of t)
|
|
1747
|
+
s.apply(this, e);
|
|
1748
|
+
}
|
|
1749
|
+
super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Produces an ack callback to emit with an event.
|
|
1753
|
+
*
|
|
1754
|
+
* @private
|
|
1755
|
+
*/
|
|
1756
|
+
ack(e) {
|
|
1757
|
+
const t = this;
|
|
1758
|
+
let s = !1;
|
|
1759
|
+
return function(...r) {
|
|
1760
|
+
s || (s = !0, t.packet({
|
|
1761
|
+
type: f.ACK,
|
|
1762
|
+
id: e,
|
|
1763
|
+
data: r
|
|
1764
|
+
}));
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* Called upon a server acknowledgement.
|
|
1769
|
+
*
|
|
1770
|
+
* @param packet
|
|
1771
|
+
* @private
|
|
1772
|
+
*/
|
|
1773
|
+
onack(e) {
|
|
1774
|
+
const t = this.acks[e.id];
|
|
1775
|
+
typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Called upon server connect.
|
|
1779
|
+
*
|
|
1780
|
+
* @private
|
|
1781
|
+
*/
|
|
1782
|
+
onconnect(e, t) {
|
|
1783
|
+
this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this._drainQueue(!0), this.emitReserved("connect");
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Emit buffered events (received and emitted).
|
|
1787
|
+
*
|
|
1788
|
+
* @private
|
|
1789
|
+
*/
|
|
1790
|
+
emitBuffered() {
|
|
1791
|
+
this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
|
|
1792
|
+
this.notifyOutgoingListeners(e), this.packet(e);
|
|
1793
|
+
}), this.sendBuffer = [];
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Called upon server disconnect.
|
|
1797
|
+
*
|
|
1798
|
+
* @private
|
|
1799
|
+
*/
|
|
1800
|
+
ondisconnect() {
|
|
1801
|
+
this.destroy(), this.onclose("io server disconnect");
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Called upon forced client/server side disconnections,
|
|
1805
|
+
* this method ensures the manager stops tracking us and
|
|
1806
|
+
* that reconnections don't get triggered for this.
|
|
1807
|
+
*
|
|
1808
|
+
* @private
|
|
1809
|
+
*/
|
|
1810
|
+
destroy() {
|
|
1811
|
+
this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
1815
|
+
*
|
|
1816
|
+
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* const socket = io();
|
|
1820
|
+
*
|
|
1821
|
+
* socket.on("disconnect", (reason) => {
|
|
1822
|
+
* // console.log(reason); prints "io client disconnect"
|
|
1823
|
+
* });
|
|
1824
|
+
*
|
|
1825
|
+
* socket.disconnect();
|
|
1826
|
+
*
|
|
1827
|
+
* @return self
|
|
1828
|
+
*/
|
|
1829
|
+
disconnect() {
|
|
1830
|
+
return this.connected && this.packet({ type: f.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Alias for {@link disconnect()}.
|
|
1834
|
+
*
|
|
1835
|
+
* @return self
|
|
1836
|
+
*/
|
|
1837
|
+
close() {
|
|
1838
|
+
return this.disconnect();
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Sets the compress flag.
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* socket.compress(false).emit("hello");
|
|
1845
|
+
*
|
|
1846
|
+
* @param compress - if `true`, compresses the sending data
|
|
1847
|
+
* @return self
|
|
1848
|
+
*/
|
|
1849
|
+
compress(e) {
|
|
1850
|
+
return this.flags.compress = e, this;
|
|
1851
|
+
}
|
|
1852
|
+
/**
|
|
1853
|
+
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
1854
|
+
* ready to send messages.
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
1858
|
+
*
|
|
1859
|
+
* @returns self
|
|
1860
|
+
*/
|
|
1861
|
+
get volatile() {
|
|
1862
|
+
return this.flags.volatile = !0, this;
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
1866
|
+
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
1867
|
+
*
|
|
1868
|
+
* @example
|
|
1869
|
+
* socket.timeout(5000).emit("my-event", (err) => {
|
|
1870
|
+
* if (err) {
|
|
1871
|
+
* // the server did not acknowledge the event in the given delay
|
|
1872
|
+
* }
|
|
1873
|
+
* });
|
|
1874
|
+
*
|
|
1875
|
+
* @returns self
|
|
1876
|
+
*/
|
|
1877
|
+
timeout(e) {
|
|
1878
|
+
return this.flags.timeout = e, this;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1882
|
+
* callback.
|
|
1883
|
+
*
|
|
1884
|
+
* @example
|
|
1885
|
+
* socket.onAny((event, ...args) => {
|
|
1886
|
+
* console.log(`got ${event}`);
|
|
1887
|
+
* });
|
|
1888
|
+
*
|
|
1889
|
+
* @param listener
|
|
1890
|
+
*/
|
|
1891
|
+
onAny(e) {
|
|
1892
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1896
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
1897
|
+
*
|
|
1898
|
+
* @example
|
|
1899
|
+
* socket.prependAny((event, ...args) => {
|
|
1900
|
+
* console.log(`got event ${event}`);
|
|
1901
|
+
* });
|
|
1902
|
+
*
|
|
1903
|
+
* @param listener
|
|
1904
|
+
*/
|
|
1905
|
+
prependAny(e) {
|
|
1906
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
1910
|
+
*
|
|
1911
|
+
* @example
|
|
1912
|
+
* const catchAllListener = (event, ...args) => {
|
|
1913
|
+
* console.log(`got event ${event}`);
|
|
1914
|
+
* }
|
|
1915
|
+
*
|
|
1916
|
+
* socket.onAny(catchAllListener);
|
|
1917
|
+
*
|
|
1918
|
+
* // remove a specific listener
|
|
1919
|
+
* socket.offAny(catchAllListener);
|
|
1920
|
+
*
|
|
1921
|
+
* // or remove all listeners
|
|
1922
|
+
* socket.offAny();
|
|
1923
|
+
*
|
|
1924
|
+
* @param listener
|
|
1925
|
+
*/
|
|
1926
|
+
offAny(e) {
|
|
1927
|
+
if (!this._anyListeners)
|
|
1928
|
+
return this;
|
|
1929
|
+
if (e) {
|
|
1930
|
+
const t = this._anyListeners;
|
|
1931
|
+
for (let s = 0; s < t.length; s++)
|
|
1932
|
+
if (e === t[s])
|
|
1933
|
+
return t.splice(s, 1), this;
|
|
1934
|
+
} else
|
|
1935
|
+
this._anyListeners = [];
|
|
1936
|
+
return this;
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
1940
|
+
* e.g. to remove listeners.
|
|
1941
|
+
*/
|
|
1942
|
+
listenersAny() {
|
|
1943
|
+
return this._anyListeners || [];
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1947
|
+
* callback.
|
|
1948
|
+
*
|
|
1949
|
+
* Note: acknowledgements sent to the server are not included.
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
1953
|
+
* console.log(`sent event ${event}`);
|
|
1954
|
+
* });
|
|
1955
|
+
*
|
|
1956
|
+
* @param listener
|
|
1957
|
+
*/
|
|
1958
|
+
onAnyOutgoing(e) {
|
|
1959
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
1963
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
1964
|
+
*
|
|
1965
|
+
* Note: acknowledgements sent to the server are not included.
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
1969
|
+
* console.log(`sent event ${event}`);
|
|
1970
|
+
* });
|
|
1971
|
+
*
|
|
1972
|
+
* @param listener
|
|
1973
|
+
*/
|
|
1974
|
+
prependAnyOutgoing(e) {
|
|
1975
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
1979
|
+
*
|
|
1980
|
+
* @example
|
|
1981
|
+
* const catchAllListener = (event, ...args) => {
|
|
1982
|
+
* console.log(`sent event ${event}`);
|
|
1983
|
+
* }
|
|
1984
|
+
*
|
|
1985
|
+
* socket.onAnyOutgoing(catchAllListener);
|
|
1986
|
+
*
|
|
1987
|
+
* // remove a specific listener
|
|
1988
|
+
* socket.offAnyOutgoing(catchAllListener);
|
|
1989
|
+
*
|
|
1990
|
+
* // or remove all listeners
|
|
1991
|
+
* socket.offAnyOutgoing();
|
|
1992
|
+
*
|
|
1993
|
+
* @param [listener] - the catch-all listener (optional)
|
|
1994
|
+
*/
|
|
1995
|
+
offAnyOutgoing(e) {
|
|
1996
|
+
if (!this._anyOutgoingListeners)
|
|
1997
|
+
return this;
|
|
1998
|
+
if (e) {
|
|
1999
|
+
const t = this._anyOutgoingListeners;
|
|
2000
|
+
for (let s = 0; s < t.length; s++)
|
|
2001
|
+
if (e === t[s])
|
|
2002
|
+
return t.splice(s, 1), this;
|
|
2003
|
+
} else
|
|
2004
|
+
this._anyOutgoingListeners = [];
|
|
2005
|
+
return this;
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
2009
|
+
* e.g. to remove listeners.
|
|
2010
|
+
*/
|
|
2011
|
+
listenersAnyOutgoing() {
|
|
2012
|
+
return this._anyOutgoingListeners || [];
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Notify the listeners for each packet sent
|
|
2016
|
+
*
|
|
2017
|
+
* @param packet
|
|
2018
|
+
*
|
|
2019
|
+
* @private
|
|
2020
|
+
*/
|
|
2021
|
+
notifyOutgoingListeners(e) {
|
|
2022
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
2023
|
+
const t = this._anyOutgoingListeners.slice();
|
|
2024
|
+
for (const s of t)
|
|
2025
|
+
s.apply(this, e.data);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
function B(n) {
|
|
2030
|
+
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;
|
|
2031
|
+
}
|
|
2032
|
+
B.prototype.duration = function() {
|
|
2033
|
+
var n = this.ms * Math.pow(this.factor, this.attempts++);
|
|
2034
|
+
if (this.jitter) {
|
|
2035
|
+
var e = Math.random(), t = Math.floor(e * this.jitter * n);
|
|
2036
|
+
n = Math.floor(e * 10) & 1 ? n + t : n - t;
|
|
2037
|
+
}
|
|
2038
|
+
return Math.min(n, this.max) | 0;
|
|
2039
|
+
};
|
|
2040
|
+
B.prototype.reset = function() {
|
|
2041
|
+
this.attempts = 0;
|
|
2042
|
+
};
|
|
2043
|
+
B.prototype.setMin = function(n) {
|
|
2044
|
+
this.ms = n;
|
|
2045
|
+
};
|
|
2046
|
+
B.prototype.setMax = function(n) {
|
|
2047
|
+
this.max = n;
|
|
2048
|
+
};
|
|
2049
|
+
B.prototype.setJitter = function(n) {
|
|
2050
|
+
this.jitter = n;
|
|
2051
|
+
};
|
|
2052
|
+
class ie extends g {
|
|
2053
|
+
constructor(e, t) {
|
|
2054
|
+
var s;
|
|
2055
|
+
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, J(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 B({
|
|
2056
|
+
min: this.reconnectionDelay(),
|
|
2057
|
+
max: this.reconnectionDelayMax(),
|
|
2058
|
+
jitter: this.randomizationFactor()
|
|
2059
|
+
}), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
|
|
2060
|
+
const r = t.parser || xt;
|
|
2061
|
+
this.encoder = new r.Encoder(), this.decoder = new r.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
|
|
2062
|
+
}
|
|
2063
|
+
reconnection(e) {
|
|
2064
|
+
return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
|
|
2065
|
+
}
|
|
2066
|
+
reconnectionAttempts(e) {
|
|
2067
|
+
return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
|
|
2068
|
+
}
|
|
2069
|
+
reconnectionDelay(e) {
|
|
2070
|
+
var t;
|
|
2071
|
+
return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
|
|
2072
|
+
}
|
|
2073
|
+
randomizationFactor(e) {
|
|
2074
|
+
var t;
|
|
2075
|
+
return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
|
|
2076
|
+
}
|
|
2077
|
+
reconnectionDelayMax(e) {
|
|
2078
|
+
var t;
|
|
2079
|
+
return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
|
|
2080
|
+
}
|
|
2081
|
+
timeout(e) {
|
|
2082
|
+
return arguments.length ? (this._timeout = e, this) : this._timeout;
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Starts trying to reconnect if reconnection is enabled and we have not
|
|
2086
|
+
* started reconnecting yet
|
|
2087
|
+
*
|
|
2088
|
+
* @private
|
|
2089
|
+
*/
|
|
2090
|
+
maybeReconnectOnOpen() {
|
|
2091
|
+
!this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Sets the current transport `socket`.
|
|
2095
|
+
*
|
|
2096
|
+
* @param {Function} fn - optional, callback
|
|
2097
|
+
* @return self
|
|
2098
|
+
* @public
|
|
2099
|
+
*/
|
|
2100
|
+
open(e) {
|
|
2101
|
+
if (~this._readyState.indexOf("open"))
|
|
2102
|
+
return this;
|
|
2103
|
+
this.engine = new Et(this.uri, this.opts);
|
|
2104
|
+
const t = this.engine, s = this;
|
|
2105
|
+
this._readyState = "opening", this.skipReconnect = !1;
|
|
2106
|
+
const r = E(t, "open", function() {
|
|
2107
|
+
s.onopen(), e && e();
|
|
2108
|
+
}), i = (h) => {
|
|
2109
|
+
this.cleanup(), this._readyState = "closed", this.emitReserved("error", h), e ? e(h) : this.maybeReconnectOnOpen();
|
|
2110
|
+
}, o = E(t, "error", i);
|
|
2111
|
+
if (this._timeout !== !1) {
|
|
2112
|
+
const h = this._timeout, u = this.setTimeoutFn(() => {
|
|
2113
|
+
r(), i(new Error("timeout")), t.close();
|
|
2114
|
+
}, h);
|
|
2115
|
+
this.opts.autoUnref && u.unref(), this.subs.push(() => {
|
|
2116
|
+
this.clearTimeoutFn(u);
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
return this.subs.push(r), this.subs.push(o), this;
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Alias for open()
|
|
2123
|
+
*
|
|
2124
|
+
* @return self
|
|
2125
|
+
* @public
|
|
2126
|
+
*/
|
|
2127
|
+
connect(e) {
|
|
2128
|
+
return this.open(e);
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Called upon transport open.
|
|
2132
|
+
*
|
|
2133
|
+
* @private
|
|
2134
|
+
*/
|
|
2135
|
+
onopen() {
|
|
2136
|
+
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
2137
|
+
const e = this.engine;
|
|
2138
|
+
this.subs.push(
|
|
2139
|
+
E(e, "ping", this.onping.bind(this)),
|
|
2140
|
+
E(e, "data", this.ondata.bind(this)),
|
|
2141
|
+
E(e, "error", this.onerror.bind(this)),
|
|
2142
|
+
E(e, "close", this.onclose.bind(this)),
|
|
2143
|
+
// @ts-ignore
|
|
2144
|
+
E(this.decoder, "decoded", this.ondecoded.bind(this))
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Called upon a ping.
|
|
2149
|
+
*
|
|
2150
|
+
* @private
|
|
2151
|
+
*/
|
|
2152
|
+
onping() {
|
|
2153
|
+
this.emitReserved("ping");
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Called with data.
|
|
2157
|
+
*
|
|
2158
|
+
* @private
|
|
2159
|
+
*/
|
|
2160
|
+
ondata(e) {
|
|
2161
|
+
try {
|
|
2162
|
+
this.decoder.add(e);
|
|
2163
|
+
} catch (t) {
|
|
2164
|
+
this.onclose("parse error", t);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Called when parser fully decodes a packet.
|
|
2169
|
+
*
|
|
2170
|
+
* @private
|
|
2171
|
+
*/
|
|
2172
|
+
ondecoded(e) {
|
|
2173
|
+
H(() => {
|
|
2174
|
+
this.emitReserved("packet", e);
|
|
2175
|
+
}, this.setTimeoutFn);
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Called upon socket error.
|
|
2179
|
+
*
|
|
2180
|
+
* @private
|
|
2181
|
+
*/
|
|
2182
|
+
onerror(e) {
|
|
2183
|
+
this.emitReserved("error", e);
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Creates a new socket for the given `nsp`.
|
|
2187
|
+
*
|
|
2188
|
+
* @return {Socket}
|
|
2189
|
+
* @public
|
|
2190
|
+
*/
|
|
2191
|
+
socket(e, t) {
|
|
2192
|
+
let s = this.nsps[e];
|
|
2193
|
+
return s ? this._autoConnect && !s.active && s.connect() : (s = new qe(this, e, t), this.nsps[e] = s), s;
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Called upon a socket close.
|
|
2197
|
+
*
|
|
2198
|
+
* @param socket
|
|
2199
|
+
* @private
|
|
2200
|
+
*/
|
|
2201
|
+
_destroy(e) {
|
|
2202
|
+
const t = Object.keys(this.nsps);
|
|
2203
|
+
for (const s of t)
|
|
2204
|
+
if (this.nsps[s].active)
|
|
2205
|
+
return;
|
|
2206
|
+
this._close();
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* Writes a packet.
|
|
2210
|
+
*
|
|
2211
|
+
* @param packet
|
|
2212
|
+
* @private
|
|
2213
|
+
*/
|
|
2214
|
+
_packet(e) {
|
|
2215
|
+
const t = this.encoder.encode(e);
|
|
2216
|
+
for (let s = 0; s < t.length; s++)
|
|
2217
|
+
this.engine.write(t[s], e.options);
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Clean up transport subscriptions and packet buffer.
|
|
2221
|
+
*
|
|
2222
|
+
* @private
|
|
2223
|
+
*/
|
|
2224
|
+
cleanup() {
|
|
2225
|
+
this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
|
|
2226
|
+
}
|
|
2227
|
+
/**
|
|
2228
|
+
* Close the current socket.
|
|
2229
|
+
*
|
|
2230
|
+
* @private
|
|
2231
|
+
*/
|
|
2232
|
+
_close() {
|
|
2233
|
+
this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Alias for close()
|
|
2237
|
+
*
|
|
2238
|
+
* @private
|
|
2239
|
+
*/
|
|
2240
|
+
disconnect() {
|
|
2241
|
+
return this._close();
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* Called when:
|
|
2245
|
+
*
|
|
2246
|
+
* - the low-level engine is closed
|
|
2247
|
+
* - the parser encountered a badly formatted packet
|
|
2248
|
+
* - all sockets are disconnected
|
|
2249
|
+
*
|
|
2250
|
+
* @private
|
|
2251
|
+
*/
|
|
2252
|
+
onclose(e, t) {
|
|
2253
|
+
var s;
|
|
2254
|
+
this.cleanup(), (s = this.engine) === null || s === void 0 || s.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
|
|
2255
|
+
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Attempt a reconnection.
|
|
2258
|
+
*
|
|
2259
|
+
* @private
|
|
2260
|
+
*/
|
|
2261
|
+
reconnect() {
|
|
2262
|
+
if (this._reconnecting || this.skipReconnect)
|
|
2263
|
+
return this;
|
|
2264
|
+
const e = this;
|
|
2265
|
+
if (this.backoff.attempts >= this._reconnectionAttempts)
|
|
2266
|
+
this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
|
|
2267
|
+
else {
|
|
2268
|
+
const t = this.backoff.duration();
|
|
2269
|
+
this._reconnecting = !0;
|
|
2270
|
+
const s = this.setTimeoutFn(() => {
|
|
2271
|
+
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((r) => {
|
|
2272
|
+
r ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", r)) : e.onreconnect();
|
|
2273
|
+
}));
|
|
2274
|
+
}, t);
|
|
2275
|
+
this.opts.autoUnref && s.unref(), this.subs.push(() => {
|
|
2276
|
+
this.clearTimeoutFn(s);
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* Called upon successful reconnect.
|
|
2282
|
+
*
|
|
2283
|
+
* @private
|
|
2284
|
+
*/
|
|
2285
|
+
onreconnect() {
|
|
2286
|
+
const e = this.backoff.attempts;
|
|
2287
|
+
this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
const x = {};
|
|
2291
|
+
function F(n, e) {
|
|
2292
|
+
typeof n == "object" && (e = n, n = void 0), e = e || {};
|
|
2293
|
+
const t = Tt(n, e.path || "/socket.io"), s = t.source, r = t.id, i = t.path, o = x[r] && i in x[r].nsps, h = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
|
|
2294
|
+
let u;
|
|
2295
|
+
return h ? u = new ie(s, e) : (x[r] || (x[r] = new ie(s, e)), u = x[r]), t.query && !e.query && (e.query = t.queryKey), u.socket(t.path, e);
|
|
2296
|
+
}
|
|
2297
|
+
Object.assign(F, {
|
|
2298
|
+
Manager: ie,
|
|
2299
|
+
Socket: qe,
|
|
2300
|
+
io: F,
|
|
2301
|
+
connect: F
|
|
2302
|
+
});
|
|
2303
|
+
function Pt(n) {
|
|
2304
|
+
try {
|
|
2305
|
+
const e = JSON.parse(n);
|
|
2306
|
+
if (e && typeof e == "object") {
|
|
2307
|
+
const t = e;
|
|
2308
|
+
return {
|
|
2309
|
+
message: typeof t.message == "string" ? t.message : void 0,
|
|
2310
|
+
code: typeof t.code == "string" ? t.code : void 0,
|
|
2311
|
+
details: t.details
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
} catch {
|
|
2315
|
+
}
|
|
2316
|
+
return {};
|
|
2317
|
+
}
|
|
2318
|
+
class Lt extends Error {
|
|
2319
|
+
constructor(t, s, r) {
|
|
2320
|
+
const i = Pt(r);
|
|
2321
|
+
super(i.message ?? `${s || "Request failed"} (${t})`);
|
|
2322
|
+
_(this, "status");
|
|
2323
|
+
_(this, "code");
|
|
2324
|
+
_(this, "details");
|
|
2325
|
+
_(this, "body");
|
|
2326
|
+
this.name = "RequestError", this.status = t, this.code = i.code, this.details = i.details, this.body = r;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
const T = "item/folder", p = "item", O = "processor", R = "hidden", X = "FILE", Q = "TOOL", Z = "APP";
|
|
2330
|
+
var a, ae, l, S, V, M, ce, he, Ue;
|
|
2331
|
+
const ye = class ye {
|
|
2332
|
+
/**
|
|
2333
|
+
* Creates a new EngineServicesClient instance.
|
|
2334
|
+
* @param accessToken - API access token (obtained from the platform dashboard)
|
|
2335
|
+
* or an Auth0 JWT (when using `useBearer: true`).
|
|
2336
|
+
* @param apiUrl - Base URL of the API (e.g. "https://api.thatopen.com").
|
|
2337
|
+
* @param props - Optional configuration (retry count, auth mode, etc.).
|
|
2338
|
+
*/
|
|
2339
|
+
constructor(e, t, s) {
|
|
2340
|
+
K(this, a);
|
|
2341
|
+
_(this, "apiUrl");
|
|
2342
|
+
_(this, "accessToken");
|
|
2343
|
+
_(this, "wsUrl");
|
|
2344
|
+
_(this, "retries");
|
|
2345
|
+
_(this, "useBearer");
|
|
2346
|
+
_(this, "builtInGlobals", null);
|
|
2347
|
+
/**
|
|
2348
|
+
* URL of a local execution server (e.g. `http://localhost:4001`).
|
|
2349
|
+
* When set, execution methods are routed to this server instead of the cloud API.
|
|
2350
|
+
* Set to `null` to disable local routing and use the cloud API.
|
|
2351
|
+
*/
|
|
2352
|
+
_(this, "localServerUrl", null);
|
|
2353
|
+
/**
|
|
2354
|
+
* The platform context this client was created with.
|
|
2355
|
+
* Contains `appId`, `projectId`, `accessToken`, and `apiUrl`.
|
|
2356
|
+
* Populated automatically when using {@link fromPlatformContext}.
|
|
2357
|
+
*/
|
|
2358
|
+
_(this, "context");
|
|
2359
|
+
const { retries: r = 0, useBearer: i = !1, localServerUrl: o } = s || {};
|
|
2360
|
+
let h = t;
|
|
2361
|
+
if (h.charAt(h.length - 1) === "/" && (h = h.slice(0, -1)), this.apiUrl = `${h}/api`, this.accessToken = e, this.wsUrl = `${h}?accessToken=${e}`, this.retries = r, this.useBearer = i, this.context = { appId: "", projectId: "", accessToken: e, apiUrl: t }, o) {
|
|
2362
|
+
let u = o;
|
|
2363
|
+
u.charAt(u.length - 1) === "/" && (u = u.slice(0, -1)), this.localServerUrl = u;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* Creates a client from the platform context injected into
|
|
2368
|
+
* `window.__THATOPEN_CONTEXT__` by the That Open Platform.
|
|
2369
|
+
*
|
|
2370
|
+
* This is the recommended way to create a client inside platform apps.
|
|
2371
|
+
* It automatically reads the auth context and sets `useBearer: true`.
|
|
2372
|
+
*
|
|
2373
|
+
* @param props - Optional configuration (retry count, local server URL, etc.).
|
|
2374
|
+
* @returns A new EngineServicesClient instance.
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```ts
|
|
2378
|
+
* const client = EngineServicesClient.fromPlatformContext();
|
|
2379
|
+
* console.log(client.context.projectId);
|
|
2380
|
+
* ```
|
|
2381
|
+
*/
|
|
2382
|
+
static fromPlatformContext(e) {
|
|
2383
|
+
const t = (typeof window < "u" ? window.__THATOPEN_CONTEXT__ : null) || { appId: "", projectId: "", accessToken: "", apiUrl: "" }, s = new ye(t.accessToken, t.apiUrl, {
|
|
2384
|
+
...e,
|
|
2385
|
+
useBearer: !0
|
|
2386
|
+
});
|
|
2387
|
+
return s.context = t, s;
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* Sets the number of automatic retries for failed requests.
|
|
2391
|
+
* @param retries - Number of retries (0 = no retries).
|
|
2392
|
+
*/
|
|
2393
|
+
setRetries(e) {
|
|
2394
|
+
this.retries = e;
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Registers the global libraries that built-in components need at runtime.
|
|
2398
|
+
*
|
|
2399
|
+
* Call this once after importing your libraries. Then every subsequent
|
|
2400
|
+
* {@link initBuiltInComponent} call will use these globals automatically
|
|
2401
|
+
* — you no longer need to pass a `globals` argument to each one.
|
|
2402
|
+
*
|
|
2403
|
+
* @param globals - Map of global names to module namespaces.
|
|
2404
|
+
* Common keys: `OBC`, `OBF`, `BUI`, `CUI`, `THREE`, `FRAGS`, `MARKERJS`.
|
|
2405
|
+
*
|
|
2406
|
+
* @example
|
|
2407
|
+
* ```ts
|
|
2408
|
+
* import * as OBC from "@thatopen/components";
|
|
2409
|
+
* import * as OBF from "@thatopen/components-front";
|
|
2410
|
+
* import * as BUI from "@thatopen/ui";
|
|
2411
|
+
* import * as CUI from "@thatopen/ui-obc";
|
|
2412
|
+
* import * as THREE from "three";
|
|
2413
|
+
* import * as FRAGS from "@thatopen/fragments";
|
|
2414
|
+
*
|
|
2415
|
+
* client.setBuiltInGlobals({ OBC, OBF, BUI, CUI, THREE, FRAGS });
|
|
2416
|
+
*
|
|
2417
|
+
* // Now just pass the component — no globals needed:
|
|
2418
|
+
* await client.initBuiltInComponent(AppManager, components);
|
|
2419
|
+
* await client.initBuiltInComponent(ViewerToolbar, components);
|
|
2420
|
+
* await client.initBuiltInComponent(ModelsPanel, components);
|
|
2421
|
+
* ```
|
|
2422
|
+
*/
|
|
2423
|
+
setBuiltInGlobals(e) {
|
|
2424
|
+
this.builtInGlobals = e;
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Protected extension point for subclasses that need dynamic tokens
|
|
2428
|
+
* (e.g. `PlatformClient` with an auth provider callback). The default
|
|
2429
|
+
* returns the static token captured at construction time.
|
|
2430
|
+
*
|
|
2431
|
+
* When a subclass overrides this to call an async refresh function,
|
|
2432
|
+
* the new token is picked up on every request — expired tokens no
|
|
2433
|
+
* longer stick around.
|
|
2434
|
+
*/
|
|
2435
|
+
async resolveAccessToken() {
|
|
2436
|
+
return this.accessToken;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Protected extension hook for subclasses (e.g. `PlatformClient`) that
|
|
2440
|
+
* need to add HTTP methods against additional backend routes. Delegates
|
|
2441
|
+
* to the private `#requestApi` implementation so retry / auth / query-
|
|
2442
|
+
* cleaning logic is applied identically.
|
|
2443
|
+
*/
|
|
2444
|
+
async request(e, t, s) {
|
|
2445
|
+
return c(this, a, l).call(this, e, t, s);
|
|
2446
|
+
}
|
|
2447
|
+
// ─── Files ───────────────────────────────────────────────────────
|
|
2448
|
+
/**
|
|
2449
|
+
* Lists all files accessible by the current token.
|
|
2450
|
+
* @param filters - Optional filters for folder and archive status.
|
|
2451
|
+
* @returns Array of file items.
|
|
2452
|
+
*/
|
|
2453
|
+
async listFiles(e) {
|
|
2454
|
+
const { folderId: t, archived: s, projectId: r } = e || {};
|
|
2455
|
+
return t ? await c(this, a, l).call(this, "GET", `${T}/${t}/items`, { query: { itemType: X, archived: s } }) : await c(this, a, l).call(this, "GET", `${p}`, {
|
|
2456
|
+
query: {
|
|
2457
|
+
itemType: X,
|
|
2458
|
+
archived: s,
|
|
2459
|
+
...r && { projectId: r }
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Gets a single file by ID, optionally including version history.
|
|
2465
|
+
* @param fileId - The file's unique identifier.
|
|
2466
|
+
* @param props - Options such as whether to include versions.
|
|
2467
|
+
* @returns The file item, optionally with version history.
|
|
2468
|
+
*/
|
|
2469
|
+
async getFile(e, t) {
|
|
2470
|
+
return await c(this, a, he).call(this, e, t);
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Uploads a new file.
|
|
2474
|
+
* @param fileData - File content, name, and version tag.
|
|
2475
|
+
* @returns The created item and its first version.
|
|
2476
|
+
*/
|
|
2477
|
+
async createFile(e) {
|
|
2478
|
+
return await c(this, a, M).call(this, e, X);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Updates an existing file. Can rename, move to a different folder,
|
|
2482
|
+
* and/or upload a new version — all in a single call.
|
|
2483
|
+
* @param fileId - The file's unique identifier.
|
|
2484
|
+
* @param fileData - Properties to update (name, folderId, file, versionTag).
|
|
2485
|
+
* @returns The updated item and/or the new version.
|
|
2486
|
+
*/
|
|
2487
|
+
async updateFile(e, t) {
|
|
2488
|
+
return await c(this, a, ce).call(this, e, t);
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Archives (soft-deletes) a file. Can be recovered with {@link recoverFile}.
|
|
2492
|
+
* @param fileId - The file's unique identifier.
|
|
2493
|
+
*/
|
|
2494
|
+
async archiveFile(e) {
|
|
2495
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${e}`);
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Recovers a previously archived file.
|
|
2499
|
+
* @param fileId - The file's unique identifier.
|
|
2500
|
+
*/
|
|
2501
|
+
async recoverFile(e) {
|
|
2502
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${e}/recover`);
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Downloads a file's content. Returns the raw fetch Response.
|
|
2506
|
+
* @param fileId - The file's unique identifier.
|
|
2507
|
+
* @param params - Optional version selection parameters.
|
|
2508
|
+
* @returns A fetch Response containing the file data.
|
|
2509
|
+
*/
|
|
2510
|
+
async downloadFile(e, t) {
|
|
2511
|
+
return await c(this, a, V).call(this, e, t);
|
|
2512
|
+
}
|
|
2513
|
+
/**
|
|
2514
|
+
* Retrieves the free-JSON metadata for a specific file version.
|
|
2515
|
+
* Returns `{}` when the version exists but has no metadata.
|
|
2516
|
+
* @param fileId - The file's unique identifier.
|
|
2517
|
+
* @param versionTag - The version tag (e.g. "v1").
|
|
2518
|
+
* @param params - Optional flags such as `withDraft`.
|
|
2519
|
+
*/
|
|
2520
|
+
async getFileVersionMetadata(e, t, s) {
|
|
2521
|
+
const { withDraft: r } = s || {};
|
|
2522
|
+
return await c(this, a, l).call(this, "GET", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}/metadata`, {
|
|
2523
|
+
query: {
|
|
2524
|
+
...r && { withDraft: "true" }
|
|
2525
|
+
}
|
|
2526
|
+
});
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Replaces the metadata of a specific file version with the provided object.
|
|
2530
|
+
* @param fileId - The file's unique identifier.
|
|
2531
|
+
* @param versionTag - The version tag.
|
|
2532
|
+
* @param metadata - Free-JSON object (max 200 fields, 50-char keys/values).
|
|
2533
|
+
*/
|
|
2534
|
+
async updateFileVersionMetadata(e, t, s) {
|
|
2535
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}/metadata`, {
|
|
2536
|
+
body: JSON.stringify({ metadata: s }),
|
|
2537
|
+
contentType: "application/json"
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Clears all metadata from a specific file version.
|
|
2542
|
+
* @param fileId - The file's unique identifier.
|
|
2543
|
+
* @param versionTag - The version tag.
|
|
2544
|
+
*/
|
|
2545
|
+
async deleteFileVersionMetadata(e, t) {
|
|
2546
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}/metadata`);
|
|
2547
|
+
}
|
|
2548
|
+
// ─── Folders ─────────────────────────────────────────────────────
|
|
2549
|
+
/**
|
|
2550
|
+
* Lists all folders accessible by the current token.
|
|
2551
|
+
* @param params - Optional filters for parent folder and archive status.
|
|
2552
|
+
* @returns Array of folder items.
|
|
2553
|
+
*/
|
|
2554
|
+
async listFolders(e) {
|
|
2555
|
+
const { archived: t, parentFolderId: s, projectId: r } = e || {};
|
|
2556
|
+
return await c(this, a, l).call(this, "GET", T, {
|
|
2557
|
+
query: {
|
|
2558
|
+
parentFolderId: s,
|
|
2559
|
+
archived: t,
|
|
2560
|
+
...r && { projectId: r }
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Gets a single folder by ID.
|
|
2566
|
+
* @param folderId - The folder's unique identifier.
|
|
2567
|
+
*/
|
|
2568
|
+
async getFolder(e) {
|
|
2569
|
+
return await c(this, a, l).call(this, "GET", `${T}/${e}`);
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* Creates a new folder.
|
|
2573
|
+
* @param name - Display name for the folder.
|
|
2574
|
+
* @param parentId - Optional parent folder ID for nesting.
|
|
2575
|
+
* @returns The created folder.
|
|
2576
|
+
*/
|
|
2577
|
+
async createFolder(e, t, s) {
|
|
2578
|
+
return await c(this, a, l).call(this, "POST", T, {
|
|
2579
|
+
body: JSON.stringify({
|
|
2580
|
+
name: e,
|
|
2581
|
+
...t && { parentId: t },
|
|
2582
|
+
...s && { projectId: s }
|
|
2583
|
+
}),
|
|
2584
|
+
contentType: "application/json"
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* Renames a folder.
|
|
2589
|
+
* @param folderId - The folder's unique identifier.
|
|
2590
|
+
* @param updateFolderParams - New name for the folder.
|
|
2591
|
+
* @returns The updated folder.
|
|
2592
|
+
*/
|
|
2593
|
+
async updateFolder(e, t) {
|
|
2594
|
+
const { name: s } = t;
|
|
2595
|
+
return await c(this, a, l).call(this, "PUT", `${T}/${e}`, {
|
|
2596
|
+
body: JSON.stringify({ name: s }),
|
|
2597
|
+
contentType: "application/json"
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Archives (soft-deletes) a folder. Can be recovered with {@link recoverFolder}.
|
|
2602
|
+
* @param folderId - The folder's unique identifier.
|
|
2603
|
+
*/
|
|
2604
|
+
async archiveFolder(e) {
|
|
2605
|
+
return await c(this, a, l).call(this, "DELETE", `${T}/${e}`);
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Recovers a previously archived folder.
|
|
2609
|
+
* @param folderId - The folder's unique identifier.
|
|
2610
|
+
*/
|
|
2611
|
+
async recoverFolder(e) {
|
|
2612
|
+
return await c(this, a, l).call(this, "PUT", `${T}/${e}/recover`);
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Downloads an entire folder as a ZIP archive.
|
|
2616
|
+
* @param folderId - The folder's unique identifier.
|
|
2617
|
+
* @returns A fetch Response containing the ZIP data.
|
|
2618
|
+
*/
|
|
2619
|
+
async downloadFolder(e) {
|
|
2620
|
+
return await c(this, a, S).call(this, `${T}/${e}/download`);
|
|
2621
|
+
}
|
|
2622
|
+
// ─── Components ──────────────────────────────────────────────────
|
|
2623
|
+
/**
|
|
2624
|
+
* Lists all components (tools) accessible by the current token.
|
|
2625
|
+
* @param params - Optional filters for folder and version inclusion.
|
|
2626
|
+
* @returns Array of component items.
|
|
2627
|
+
*/
|
|
2628
|
+
async listComponents(e) {
|
|
2629
|
+
const { folderId: t, ShowVersions: s, projectId: r } = e || {};
|
|
2630
|
+
return t ? await c(this, a, l).call(this, "GET", `${T}/${t}/items`, {
|
|
2631
|
+
query: {
|
|
2632
|
+
itemType: Q,
|
|
2633
|
+
...s && { ShowVersions: s }
|
|
2634
|
+
}
|
|
2635
|
+
}) : await c(this, a, l).call(this, "GET", `${p}`, {
|
|
2636
|
+
query: {
|
|
2637
|
+
itemType: Q,
|
|
2638
|
+
...s && { ShowVersions: s },
|
|
2639
|
+
...r && { projectId: r }
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Gets a single component by ID, optionally including version history.
|
|
2645
|
+
* @param componentId - The component's unique identifier.
|
|
2646
|
+
* @param props - Options such as whether to include versions.
|
|
2647
|
+
*/
|
|
2648
|
+
async getComponent(e, t) {
|
|
2649
|
+
return await c(this, a, he).call(this, e, t);
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Creates a new component with the given file and version properties.
|
|
2653
|
+
* @param componentData - File content, name, version tag, and component-specific props.
|
|
2654
|
+
* @returns The created component item and its first version.
|
|
2655
|
+
*/
|
|
2656
|
+
async createComponent(e) {
|
|
2657
|
+
const { componentProps: t } = e;
|
|
2658
|
+
return await c(this, a, M).call(this, e, Q, t);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Updates an existing component. Can rename, move, and/or upload a new version.
|
|
2662
|
+
* @param componentId - The component's unique identifier.
|
|
2663
|
+
* @param componentData - Properties to update, including optional new componentProps.
|
|
2664
|
+
* @returns The updated item and/or new version.
|
|
2665
|
+
*/
|
|
2666
|
+
async updateComponent(e, t) {
|
|
2667
|
+
const { componentProps: s } = t;
|
|
2668
|
+
return await c(this, a, ce).call(this, e, t, s);
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Downloads a component's full ZIP file. Returns the raw fetch Response.
|
|
2672
|
+
* @param componentId - The component's unique identifier.
|
|
2673
|
+
* @param params - Optional version selection parameters.
|
|
2674
|
+
* @returns A fetch Response containing the ZIP data.
|
|
2675
|
+
*/
|
|
2676
|
+
async downloadComponent(e, t) {
|
|
2677
|
+
return await c(this, a, V).call(this, e, t);
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* Downloads only the JavaScript bundle from a component's ZIP.
|
|
2681
|
+
* This is the extracted `bundle` entry, returned as text.
|
|
2682
|
+
* @param componentId - The component's unique identifier.
|
|
2683
|
+
* @param params - Optional version selection parameters.
|
|
2684
|
+
* @returns A fetch Response containing the bundle JavaScript text.
|
|
2685
|
+
*/
|
|
2686
|
+
async downloadComponentBundle(e, t) {
|
|
2687
|
+
const { versionTag: s, withDraft: r } = t || {};
|
|
2688
|
+
return await c(this, a, S).call(this, `${p}/${e}/download/bundle`, {
|
|
2689
|
+
query: {
|
|
2690
|
+
...s && { versionTag: s },
|
|
2691
|
+
...r && { withDraft: r }
|
|
2692
|
+
}
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Archives (soft-deletes) a component. Can be recovered with {@link recoverComponent}.
|
|
2697
|
+
* @param componentId - The component's unique identifier.
|
|
2698
|
+
*/
|
|
2699
|
+
async archiveComponent(e) {
|
|
2700
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${e}`);
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Recovers a previously archived component.
|
|
2704
|
+
* @param componentId - The component's unique identifier.
|
|
2705
|
+
*/
|
|
2706
|
+
async recoverComponent(e) {
|
|
2707
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${e}/recover`);
|
|
2708
|
+
}
|
|
2709
|
+
// ─── Built-in Components ─────────────────────────────────────────
|
|
2710
|
+
/**
|
|
2711
|
+
* Fetches a built-in component's JavaScript bundle by name.
|
|
2712
|
+
* @param name - The built-in component name (e.g. "hello-world").
|
|
2713
|
+
* @returns The component's JavaScript source code as a string.
|
|
2714
|
+
*/
|
|
2715
|
+
async getBuiltInComponent(e) {
|
|
2716
|
+
return await (await c(this, a, S).call(this, `built-in/${e}/bundle`)).text();
|
|
2717
|
+
}
|
|
2718
|
+
/**
|
|
2719
|
+
* Fetches a built-in component bundle, evaluates it, and registers it
|
|
2720
|
+
* with the given `components` instance via `components.get()`.
|
|
2721
|
+
*
|
|
2722
|
+
* After calling this, retrieve the singleton instance with
|
|
2723
|
+
* `components.get(ComponentClass)`.
|
|
2724
|
+
*
|
|
2725
|
+
* @param component - The component class stub (must have a static `uuid`).
|
|
2726
|
+
* @param components - The OBC `Components` instance used to register the
|
|
2727
|
+
* component (must expose a `.get()` method).
|
|
2728
|
+
* @param globals - Map of global names to values that the component source
|
|
2729
|
+
* expects in scope (e.g. `{ OBC, BUI }`). If omitted, falls back to
|
|
2730
|
+
* globals registered via {@link setBuiltInGlobals}, then to
|
|
2731
|
+
* `window.ThatOpenCompany`.
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```ts
|
|
2735
|
+
* // Option 1: register globals once, then init without passing them
|
|
2736
|
+
* client.setBuiltInGlobals({ OBC, OBF, BUI, CUI, THREE, FRAGS });
|
|
2737
|
+
* await client.initBuiltInComponent(AppManager, components);
|
|
2738
|
+
* await client.initBuiltInComponent(ViewerToolbar, components);
|
|
2739
|
+
*
|
|
2740
|
+
* // Option 2: pass globals per component (still works)
|
|
2741
|
+
* await client.initBuiltInComponent(HelloWorld, components, { OBC, BUI });
|
|
2742
|
+
* ```
|
|
2743
|
+
*/
|
|
2744
|
+
async initBuiltInComponent(e, t, s) {
|
|
2745
|
+
const r = await this.getBuiltInComponent(e.uuid), i = s ?? this.builtInGlobals ?? (typeof window < "u" ? window.ThatOpenCompany : {}) ?? {}, o = Object.keys(i), h = o.map((m) => i[m]), y = new Function(...o, `${r}
|
|
2746
|
+
return main;`)(...h), d = (y == null ? void 0 : y.componentDefinition) ?? y;
|
|
2747
|
+
t.get(d);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* Loads multiple built-in components in parallel.
|
|
2751
|
+
*
|
|
2752
|
+
* Convenience wrapper around {@link initBuiltInComponent} that fetches
|
|
2753
|
+
* and registers all given component stubs concurrently.
|
|
2754
|
+
*
|
|
2755
|
+
* @param components - The OBC `Components` instance.
|
|
2756
|
+
* @param stubs - One or more component stubs (e.g. `AppManager`, `ViewportManager`).
|
|
2757
|
+
*
|
|
2758
|
+
* @example
|
|
2759
|
+
* ```ts
|
|
2760
|
+
* await client.initBuiltInComponents(components, AppManager, ViewportManager);
|
|
2761
|
+
* ```
|
|
2762
|
+
*/
|
|
2763
|
+
async initBuiltInComponents(e, ...t) {
|
|
2764
|
+
await Promise.all(
|
|
2765
|
+
t.map((s) => this.initBuiltInComponent(s, e))
|
|
2766
|
+
);
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* High-level helper that creates an OBC component system, initialises BUI,
|
|
2770
|
+
* loads built-in components, and starts the engine — all in one call.
|
|
2771
|
+
*
|
|
2772
|
+
* @param globals - Map of global names to module namespaces
|
|
2773
|
+
* (must include at least `OBC` and `BUI`).
|
|
2774
|
+
* @param builtIns - Built-in component stubs to load (e.g. `AppManager`, `ViewportManager`).
|
|
2775
|
+
* @returns An object containing the initialised `components` instance.
|
|
2776
|
+
*
|
|
2777
|
+
* @example
|
|
2778
|
+
* ```ts
|
|
2779
|
+
* const { components } = await client.setup(
|
|
2780
|
+
* { OBC, OBF, BUI, CUI, THREE, FRAGS },
|
|
2781
|
+
* AppManager, ViewportManager,
|
|
2782
|
+
* );
|
|
2783
|
+
*
|
|
2784
|
+
* const viewports = components.get(ViewportManager);
|
|
2785
|
+
* const { element, world } = await viewports.create();
|
|
2786
|
+
* ```
|
|
2787
|
+
*/
|
|
2788
|
+
async setup(e, ...t) {
|
|
2789
|
+
var o, h;
|
|
2790
|
+
const s = e.OBC, r = e.BUI;
|
|
2791
|
+
if (!(s != null && s.Components))
|
|
2792
|
+
throw new Error("globals.OBC must include Components");
|
|
2793
|
+
if (!(r != null && r.Manager)) throw new Error("globals.BUI must include Manager");
|
|
2794
|
+
const i = new s.Components();
|
|
2795
|
+
return r.Manager.init(), this.setBuiltInGlobals(e), await this.initBuiltInComponents(i, ...t), i.init(), (h = (o = this.context.appEventOrchestrator) == null ? void 0 : o.appLoaded) == null || h.call(o), { components: i };
|
|
2796
|
+
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Reports an error to the platform via the {@link AppEventOrchestrator.appError} callback.
|
|
2799
|
+
* @param code - Numeric error code.
|
|
2800
|
+
* @param data - Arbitrary error data to send to the platform.
|
|
2801
|
+
*/
|
|
2802
|
+
throwError(e, t) {
|
|
2803
|
+
var s, r;
|
|
2804
|
+
(r = (s = this.context.appEventOrchestrator) == null ? void 0 : s.appError) == null || r.call(s, e, t);
|
|
2805
|
+
}
|
|
2806
|
+
// ─── Apps ────────────────────────────────────────────────────────
|
|
2807
|
+
/**
|
|
2808
|
+
* Lists all apps accessible by the current token.
|
|
2809
|
+
* @param params - Optional filters for folder and version inclusion.
|
|
2810
|
+
* @returns Array of app items.
|
|
2811
|
+
*/
|
|
2812
|
+
async listApps(e) {
|
|
2813
|
+
const { folderId: t, ShowVersions: s, projectId: r } = e || {};
|
|
2814
|
+
return t ? await c(this, a, l).call(this, "GET", `${T}/${t}/items`, {
|
|
2815
|
+
query: {
|
|
2816
|
+
itemType: Z,
|
|
2817
|
+
...s && { ShowVersions: s }
|
|
2818
|
+
}
|
|
2819
|
+
}) : await c(this, a, l).call(this, "GET", `${p}`, {
|
|
2820
|
+
query: {
|
|
2821
|
+
itemType: Z,
|
|
2822
|
+
...s && { ShowVersions: s },
|
|
2823
|
+
...r && { projectId: r }
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Creates a new app with the given file and optional version properties.
|
|
2829
|
+
* @param appData - File content, name, version tag, and optional app-specific props.
|
|
2830
|
+
* @returns The created app item and its first version.
|
|
2831
|
+
*/
|
|
2832
|
+
async createApp(e) {
|
|
2833
|
+
const { appProps: t } = e;
|
|
2834
|
+
return await c(this, a, M).call(this, e, Z, t);
|
|
2835
|
+
}
|
|
2836
|
+
/**
|
|
2837
|
+
* Downloads an app's full ZIP file. Returns the raw fetch Response.
|
|
2838
|
+
* @param appId - The app's unique identifier.
|
|
2839
|
+
* @param params - Optional version selection parameters.
|
|
2840
|
+
* @returns A fetch Response containing the ZIP data.
|
|
2841
|
+
*/
|
|
2842
|
+
async downloadApp(e, t) {
|
|
2843
|
+
return await c(this, a, V).call(this, e, t);
|
|
2844
|
+
}
|
|
2845
|
+
/**
|
|
2846
|
+
* Downloads only the JavaScript bundle from an app's ZIP.
|
|
2847
|
+
* This is the extracted `bundle` entry, returned as text.
|
|
2848
|
+
* @param appId - The app's unique identifier.
|
|
2849
|
+
* @param params - Optional version selection parameters.
|
|
2850
|
+
* @returns A fetch Response containing the bundle JavaScript text.
|
|
2851
|
+
*/
|
|
2852
|
+
async downloadAppBundle(e, t) {
|
|
2853
|
+
const { versionTag: s, withDraft: r } = t || {};
|
|
2854
|
+
return await c(this, a, S).call(this, `${p}/${e}/download/bundle`, {
|
|
2855
|
+
query: {
|
|
2856
|
+
...s && { versionTag: s },
|
|
2857
|
+
...r && { withDraft: r }
|
|
2858
|
+
}
|
|
2859
|
+
});
|
|
2860
|
+
}
|
|
2861
|
+
/**
|
|
2862
|
+
* Archives (soft-deletes) an app.
|
|
2863
|
+
* @param appId - The app's unique identifier.
|
|
2864
|
+
*/
|
|
2865
|
+
async archiveApp(e) {
|
|
2866
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${e}`);
|
|
2867
|
+
}
|
|
2868
|
+
// ─── Execution ───────────────────────────────────────────────────
|
|
2869
|
+
/**
|
|
2870
|
+
* Triggers server-side execution of a cloud component.
|
|
2871
|
+
*
|
|
2872
|
+
* Pass `projectId` in `executionParams` when running the component in the
|
|
2873
|
+
* context of a specific project. The backend validates that the component
|
|
2874
|
+
* is linked to that project AND that the user has execute permission
|
|
2875
|
+
* there; a foreign `projectId` is rejected with 403. Omit `projectId` for
|
|
2876
|
+
* personal executions (ownership path).
|
|
2877
|
+
*
|
|
2878
|
+
* @param componentId - The component's unique identifier.
|
|
2879
|
+
* @param executionParams - Arbitrary parameters passed to the component's `main()` function. Include `projectId` to scope the execution.
|
|
2880
|
+
* @param versionTag - Optional version to execute (defaults to latest).
|
|
2881
|
+
* @returns An object containing the `executionId` to track progress.
|
|
2882
|
+
*/
|
|
2883
|
+
async executeComponent(e, t, s) {
|
|
2884
|
+
if (this.localServerUrl) {
|
|
2885
|
+
const r = `${this.localServerUrl}/api/${O}/${e}/execute`, i = await fetch(r, {
|
|
2886
|
+
method: "POST",
|
|
2887
|
+
headers: { "Content-Type": "application/json" },
|
|
2888
|
+
body: JSON.stringify(t)
|
|
2889
|
+
});
|
|
2890
|
+
if (!i.ok) {
|
|
2891
|
+
const o = await i.text().catch(() => "");
|
|
2892
|
+
throw new Error(`Local server request failed: ${i.status} - ${o}`);
|
|
2893
|
+
}
|
|
2894
|
+
return await i.json();
|
|
2895
|
+
}
|
|
2896
|
+
return await c(this, a, l).call(this, "POST", `${O}/${e}/execute`, {
|
|
2897
|
+
body: JSON.stringify(t),
|
|
2898
|
+
query: { ...s && { versionTag: s } },
|
|
2899
|
+
contentType: "application/json"
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Aborts a running execution.
|
|
2904
|
+
* @param executionId - The execution's unique identifier.
|
|
2905
|
+
*/
|
|
2906
|
+
async abortExecution(e) {
|
|
2907
|
+
if (this.localServerUrl) {
|
|
2908
|
+
const t = `${this.localServerUrl}/api/${O}/progress/${e}/abort`, s = await fetch(t, { method: "POST" });
|
|
2909
|
+
if (!s.ok) {
|
|
2910
|
+
const r = await s.text().catch(() => "");
|
|
2911
|
+
throw new Error(`Local server request failed: ${s.status} - ${r}`);
|
|
2912
|
+
}
|
|
2913
|
+
return await s.json();
|
|
2914
|
+
}
|
|
2915
|
+
return await c(this, a, l).call(this, "POST", `${O}/progress/${e}/abort`);
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* Lists all executions for a given component.
|
|
2919
|
+
*
|
|
2920
|
+
* When `projectId` is supplied, the backend scopes the query to that
|
|
2921
|
+
* project — returning only executions launched in that context AND
|
|
2922
|
+
* enforcing that the caller has access to the component there. Without
|
|
2923
|
+
* `projectId`, the caller's personal executions for the component are
|
|
2924
|
+
* returned.
|
|
2925
|
+
*
|
|
2926
|
+
* @param componentId - The component's unique identifier.
|
|
2927
|
+
* @param projectId - Optional project scope.
|
|
2928
|
+
* @returns Array of execution entities.
|
|
2929
|
+
*/
|
|
2930
|
+
async listExecutions(e, t) {
|
|
2931
|
+
if (this.localServerUrl) {
|
|
2932
|
+
const s = t ? `?projectId=${encodeURIComponent(t)}` : "", r = `${this.localServerUrl}/api/${O}/${e}/progress${s}`, i = await fetch(r);
|
|
2933
|
+
if (!i.ok) {
|
|
2934
|
+
const o = await i.text().catch(() => "");
|
|
2935
|
+
throw new Error(
|
|
2936
|
+
`Local server request failed: ${i.status} - ${o}`
|
|
2937
|
+
);
|
|
2938
|
+
}
|
|
2939
|
+
return await i.json();
|
|
2940
|
+
}
|
|
2941
|
+
return await c(this, a, l).call(this, "GET", `${O}/${e}/progress`, { query: { ...t && { projectId: t } } });
|
|
2942
|
+
}
|
|
2943
|
+
/**
|
|
2944
|
+
* Gets details of a specific execution, including its messages.
|
|
2945
|
+
* @param executionId - The execution's unique identifier.
|
|
2946
|
+
* @returns The execution entity with progress and result info.
|
|
2947
|
+
*/
|
|
2948
|
+
async getExecution(e) {
|
|
2949
|
+
if (this.localServerUrl) {
|
|
2950
|
+
const t = `${this.localServerUrl}/api/${O}/progress/${e}`, s = await fetch(t);
|
|
2951
|
+
if (!s.ok) {
|
|
2952
|
+
const r = await s.text().catch(() => "");
|
|
2953
|
+
throw new Error(`Local server request failed: ${s.status} - ${r}`);
|
|
2954
|
+
}
|
|
2955
|
+
return await s.json();
|
|
2956
|
+
}
|
|
2957
|
+
return await c(this, a, l).call(this, "GET", `${O}/progress/${e}`);
|
|
2958
|
+
}
|
|
2959
|
+
/**
|
|
2960
|
+
* Subscribes to real-time execution progress via WebSocket.
|
|
2961
|
+
* The callback fires on each progress update until the execution completes.
|
|
2962
|
+
* @param executionId - The execution's unique identifier.
|
|
2963
|
+
* @param onUpdateCallback - Callback invoked on each progress/result event.
|
|
2964
|
+
*/
|
|
2965
|
+
async onExecutionProgress(e, t) {
|
|
2966
|
+
const s = this.localServerUrl ? `${this.localServerUrl}?accessToken=${this.accessToken}` : this.wsUrl, r = await F(s, {
|
|
2967
|
+
...this.localServerUrl && { transports: ["websocket"] }
|
|
2968
|
+
});
|
|
2969
|
+
r.on("connect", function() {
|
|
2970
|
+
r.emit("executionSubscription", JSON.stringify({ executionId: e })), r.on("execution", (i) => {
|
|
2971
|
+
t(i);
|
|
2972
|
+
});
|
|
2973
|
+
}), r.on("connect_error", function(i) {
|
|
2974
|
+
console.log(i);
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
// ─── Hidden Files ────────────────────────────────────────────────
|
|
2978
|
+
/**
|
|
2979
|
+
* Creates a hidden file attached to a parent item (e.g., dependencies, assets).
|
|
2980
|
+
* @param file - The file to upload.
|
|
2981
|
+
* @param parentFileId - The parent item's unique identifier.
|
|
2982
|
+
* @returns The hidden file ID.
|
|
2983
|
+
*/
|
|
2984
|
+
async createHiddenFile(e, t) {
|
|
2985
|
+
const s = new FormData();
|
|
2986
|
+
return s.append("file", e), s.append("parentItemId", t), await c(this, a, l).call(this, "POST", `${p}/${R}`, {
|
|
2987
|
+
body: s
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* Deletes a hidden file by its ID.
|
|
2992
|
+
* @param hiddenId - The hidden file's unique identifier.
|
|
2993
|
+
*/
|
|
2994
|
+
async deleteHiddenFile(e) {
|
|
2995
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${R}/${e}`);
|
|
2996
|
+
}
|
|
2997
|
+
/**
|
|
2998
|
+
* Gets metadata for a hidden file.
|
|
2999
|
+
* @param hiddenId - The hidden file's unique identifier.
|
|
3000
|
+
*/
|
|
3001
|
+
async getHiddenFile(e) {
|
|
3002
|
+
return await c(this, a, l).call(this, "GET", `${p}/${R}/${e}`);
|
|
3003
|
+
}
|
|
3004
|
+
/**
|
|
3005
|
+
* Downloads a hidden file's content. Returns the raw fetch Response.
|
|
3006
|
+
* @param hiddenId - The hidden file's unique identifier.
|
|
3007
|
+
*/
|
|
3008
|
+
async downloadHiddenFile(e) {
|
|
3009
|
+
return await c(this, a, S).call(this, `${p}/${R}/${e}/download`);
|
|
3010
|
+
}
|
|
3011
|
+
/**
|
|
3012
|
+
* Lists all hidden files attached to a parent item.
|
|
3013
|
+
* @param parentFileId - The parent item's unique identifier.
|
|
3014
|
+
* @returns Array of hidden file entities.
|
|
3015
|
+
*/
|
|
3016
|
+
async getHiddenFilesByParent(e) {
|
|
3017
|
+
return await c(this, a, l).call(this, "GET", `${p}/${e}/${R}`);
|
|
3018
|
+
}
|
|
3019
|
+
/**
|
|
3020
|
+
* Deletes all hidden files attached to a parent item.
|
|
3021
|
+
* @param parentFileId - The parent item's unique identifier.
|
|
3022
|
+
*/
|
|
3023
|
+
async deleteHiddenFilesByParent(e) {
|
|
3024
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${e}/${R}`);
|
|
3025
|
+
}
|
|
3026
|
+
// ─── Icons ───────────────────────────────────────────────────────
|
|
3027
|
+
/**
|
|
3028
|
+
* Uploads or replaces the icon for an item (app, component, or file).
|
|
3029
|
+
* Accepts PNG, WebP, or ICO images up to 512 KB.
|
|
3030
|
+
* @param itemId - The item's unique identifier.
|
|
3031
|
+
* @param icon - The icon image file (File in browsers, Blob in Node.js).
|
|
3032
|
+
* @returns The updated item with `iconFileId` and `iconMimeType` set.
|
|
3033
|
+
*/
|
|
3034
|
+
async uploadItemIcon(e, t) {
|
|
3035
|
+
const s = new FormData();
|
|
3036
|
+
return s.append("icon", t), await c(this, a, l).call(this, "PUT", `${p}/${e}/icon`, { body: s });
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* Downloads the icon for an item as a binary stream.
|
|
3040
|
+
* @param itemId - The item's unique identifier.
|
|
3041
|
+
* @returns The raw Response (use `.blob()`, `.arrayBuffer()`, or pipe the body).
|
|
3042
|
+
*/
|
|
3043
|
+
async getItemIcon(e) {
|
|
3044
|
+
return await c(this, a, S).call(this, `${p}/${e}/icon`);
|
|
3045
|
+
}
|
|
3046
|
+
/**
|
|
3047
|
+
* Removes the icon from an item.
|
|
3048
|
+
* @param itemId - The item's unique identifier.
|
|
3049
|
+
* @returns The updated item with icon fields removed.
|
|
3050
|
+
*/
|
|
3051
|
+
async removeItemIcon(e) {
|
|
3052
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${e}/icon`);
|
|
3053
|
+
}
|
|
3054
|
+
// ─── General Item Operations ─────────────────────────────────────
|
|
3055
|
+
/**
|
|
3056
|
+
* Renames or moves an item (file, component, or app) without creating a new version.
|
|
3057
|
+
* @param itemId - The item's unique identifier.
|
|
3058
|
+
* @param params - New name and/or new folder ID.
|
|
3059
|
+
* @returns The updated item.
|
|
3060
|
+
*/
|
|
3061
|
+
async updateItem(e, t) {
|
|
3062
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${e}`, {
|
|
3063
|
+
body: JSON.stringify(t),
|
|
3064
|
+
contentType: "application/json"
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
/**
|
|
3068
|
+
* Creates a new version of an item by uploading a new file.
|
|
3069
|
+
* For APP and TOOL types, `extraProps` is required by the backend.
|
|
3070
|
+
* @param itemId - The item's unique identifier.
|
|
3071
|
+
* @param file - The new file to upload.
|
|
3072
|
+
* @param versionTag - Version tag for the new version (e.g. "v2").
|
|
3073
|
+
* @param extraProps - Version-specific properties (required for APP/TOOL types).
|
|
3074
|
+
* @param metadata - Optional free-JSON metadata to store on the new version.
|
|
3075
|
+
* @returns The created version.
|
|
3076
|
+
*/
|
|
3077
|
+
async createVersion(e, t, s, r, i) {
|
|
3078
|
+
const o = new FormData();
|
|
3079
|
+
return o.append("file", t), o.append("versionTag", s), r && o.append("extraProps", JSON.stringify(r)), i && o.append("metadata", JSON.stringify(i)), await c(this, a, l).call(this, "POST", `${p}/${e}/version`, { body: o });
|
|
3080
|
+
}
|
|
3081
|
+
/**
|
|
3082
|
+
* Lists versions of an item. Pass `archived: true` to fetch only archived
|
|
3083
|
+
* versions, `false` to fetch only active ones, or omit to receive both.
|
|
3084
|
+
* @param itemId - The item's unique identifier.
|
|
3085
|
+
* @param params - Optional `{ archived }` filter.
|
|
3086
|
+
* @returns Array of versions, sorted by creation date descending.
|
|
3087
|
+
*/
|
|
3088
|
+
async listVersions(e, t = {}) {
|
|
3089
|
+
return await c(this, a, l).call(this, "GET", `${p}/${encodeURIComponent(e)}/versions`, { query: t });
|
|
3090
|
+
}
|
|
3091
|
+
/**
|
|
3092
|
+
* Archives a version of an item. Archived versions remain available via
|
|
3093
|
+
* `listVersions({ archived: true })` and can be recovered or permanently
|
|
3094
|
+
* deleted. Cleanup runs daily and removes archived versions older than the
|
|
3095
|
+
* platform retention period.
|
|
3096
|
+
* @param itemId - The item's unique identifier.
|
|
3097
|
+
* @param versionTag - The version's tag (e.g. "v2").
|
|
3098
|
+
* @returns The archived version.
|
|
3099
|
+
*/
|
|
3100
|
+
async archiveVersion(e, t) {
|
|
3101
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}/archive`);
|
|
3102
|
+
}
|
|
3103
|
+
/**
|
|
3104
|
+
* Recovers a previously archived version, restoring it to the active list.
|
|
3105
|
+
* @param itemId - The item's unique identifier.
|
|
3106
|
+
* @param versionTag - The version's tag (e.g. "v2").
|
|
3107
|
+
* @returns The recovered version.
|
|
3108
|
+
*/
|
|
3109
|
+
async recoverVersion(e, t) {
|
|
3110
|
+
return await c(this, a, l).call(this, "PUT", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}/recover`);
|
|
3111
|
+
}
|
|
3112
|
+
/**
|
|
3113
|
+
* Permanently deletes a version, including its file in object storage.
|
|
3114
|
+
* The version must be archived first; otherwise the call is rejected.
|
|
3115
|
+
* @param itemId - The item's unique identifier.
|
|
3116
|
+
* @param versionTag - The version's tag (e.g. "v2").
|
|
3117
|
+
*/
|
|
3118
|
+
async deleteVersion(e, t) {
|
|
3119
|
+
return await c(this, a, l).call(this, "DELETE", `${p}/${encodeURIComponent(e)}/version/${encodeURIComponent(t)}`);
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
a = new WeakSet(), ae = function(e) {
|
|
3123
|
+
return `${this.apiUrl}/${e}`;
|
|
3124
|
+
}, l = async function(e, t, s) {
|
|
3125
|
+
const { body: r, query: i, contentType: o, retries: h } = s || {}, u = c(this, a, ae).call(this, t), y = c(this, a, Ue).call(this, i), d = await this.resolveAccessToken(), m = {
|
|
3126
|
+
...y,
|
|
3127
|
+
...this.useBearer ? {} : { accessToken: d }
|
|
3128
|
+
};
|
|
3129
|
+
try {
|
|
3130
|
+
const w = await fetch(
|
|
3131
|
+
u + "?" + new URLSearchParams(m).toString(),
|
|
3132
|
+
{
|
|
3133
|
+
method: e,
|
|
3134
|
+
headers: {
|
|
3135
|
+
Accept: "application/json",
|
|
3136
|
+
...o && { "Content-Type": o },
|
|
3137
|
+
...this.useBearer && { Authorization: `Bearer ${d}` }
|
|
3138
|
+
},
|
|
3139
|
+
...r && { body: r }
|
|
3140
|
+
}
|
|
3141
|
+
);
|
|
3142
|
+
if (!w.ok) {
|
|
3143
|
+
const A = await w.text().then((De) => De).catch(() => "");
|
|
3144
|
+
throw new Lt(
|
|
3145
|
+
w.status,
|
|
3146
|
+
w.statusText,
|
|
3147
|
+
A
|
|
3148
|
+
);
|
|
3149
|
+
}
|
|
3150
|
+
return w.json().then((A) => A).catch(() => {
|
|
3151
|
+
});
|
|
3152
|
+
} catch (w) {
|
|
3153
|
+
let A = h ?? this.retries;
|
|
3154
|
+
if (A)
|
|
3155
|
+
return A = A - 1, await c(this, a, l).call(this, e, t, {
|
|
3156
|
+
...s,
|
|
3157
|
+
retries: A
|
|
3158
|
+
});
|
|
3159
|
+
throw w;
|
|
3160
|
+
}
|
|
3161
|
+
}, S = async function(e, t) {
|
|
3162
|
+
const { query: s } = t || {}, r = c(this, a, ae).call(this, e), i = await this.resolveAccessToken(), o = {
|
|
3163
|
+
...s,
|
|
3164
|
+
...this.useBearer ? {} : { accessToken: i }
|
|
3165
|
+
};
|
|
3166
|
+
return await fetch(
|
|
3167
|
+
r + "?" + new URLSearchParams(o).toString(),
|
|
3168
|
+
{
|
|
3169
|
+
method: "GET",
|
|
3170
|
+
...this.useBearer && {
|
|
3171
|
+
headers: { Authorization: `Bearer ${i}` }
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
);
|
|
3175
|
+
}, V = async function(e, t) {
|
|
3176
|
+
const { versionTag: s, withDraft: r } = t || {};
|
|
3177
|
+
return await c(this, a, S).call(this, `${p}/${e}/download`, {
|
|
3178
|
+
query: {
|
|
3179
|
+
...s && { versionTag: s },
|
|
3180
|
+
...r && { withDraft: r }
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
}, M = async function(e, t, s) {
|
|
3184
|
+
const { name: r, versionTag: i, parentFolderId: o, projectId: h, file: u, metadata: y } = e, d = new FormData();
|
|
3185
|
+
return d.append("file", u), d.append("name", r), d.append("versionTag", i), d.append("itemType", t), o && d.append("folderId", o), h && d.append("projectId", h), s && d.append("extraProps", JSON.stringify(s)), y && d.append("metadata", JSON.stringify(y)), await c(this, a, l).call(this, "POST", p, {
|
|
3186
|
+
body: d
|
|
3187
|
+
});
|
|
3188
|
+
}, ce = async function(e, t, s) {
|
|
3189
|
+
const { name: r, versionTag: i, parentFolderId: o, file: h, metadata: u } = t;
|
|
3190
|
+
let y, d;
|
|
3191
|
+
if (h) {
|
|
3192
|
+
const m = new FormData();
|
|
3193
|
+
m.append("file", h), i && m.append("versionTag", i), s && m.append("extraProps", JSON.stringify(s)), u && m.append("metadata", JSON.stringify(u)), d = await c(this, a, l).call(this, "POST", `${p}/${e}/version`, {
|
|
3194
|
+
body: m
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
if (r || o) {
|
|
3198
|
+
const m = {
|
|
3199
|
+
...r && { name: r },
|
|
3200
|
+
...o && { folderId: o }
|
|
3201
|
+
}, w = JSON.stringify(m);
|
|
3202
|
+
y = await c(this, a, l).call(this, "PUT", `${p}/${e}`, {
|
|
3203
|
+
body: w,
|
|
3204
|
+
contentType: "application/json"
|
|
3205
|
+
});
|
|
3206
|
+
}
|
|
3207
|
+
return { item: y, version: d };
|
|
3208
|
+
}, he = async function(e, t) {
|
|
3209
|
+
const { showVersions: s = !1 } = t || {};
|
|
3210
|
+
return await c(this, a, l).call(this, "GET", `${p}/${e}`, {
|
|
3211
|
+
query: { showVersions: s }
|
|
3212
|
+
});
|
|
3213
|
+
}, Ue = function(e) {
|
|
3214
|
+
return e && Object.entries(e).filter(([, t]) => t !== void 0).reduce(
|
|
3215
|
+
(t, [s, r]) => (t[s] = r, t),
|
|
3216
|
+
{}
|
|
3217
|
+
);
|
|
3218
|
+
};
|
|
3219
|
+
let oe = ye;
|
|
3220
|
+
const I = "project";
|
|
3221
|
+
var $;
|
|
3222
|
+
const me = class me extends oe {
|
|
3223
|
+
/**
|
|
3224
|
+
* @param token - A bearer JWT, OR a function returning the current JWT
|
|
3225
|
+
* (sync or async). When a function is passed, it's invoked before every
|
|
3226
|
+
* request — ideal for token-refreshing sources like Auth0.
|
|
3227
|
+
* @param apiUrl - Base URL of the API (e.g. `https://api.thatopen.com`).
|
|
3228
|
+
* @param props - Optional client configuration. `useBearer` is forced to
|
|
3229
|
+
* `true` and cannot be overridden.
|
|
3230
|
+
*/
|
|
3231
|
+
constructor(t, s, r) {
|
|
3232
|
+
super(typeof t == "string" ? t : "", s, { ...r, useBearer: !0 });
|
|
3233
|
+
K(this, $);
|
|
3234
|
+
typeof t == "function" && we(this, $, t);
|
|
3235
|
+
}
|
|
3236
|
+
async resolveAccessToken() {
|
|
3237
|
+
return G(this, $) ? await G(this, $).call(this) : super.resolveAccessToken();
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Creates a client from the platform context injected into
|
|
3241
|
+
* `window.__THATOPEN_CONTEXT__` by the That Open Platform. Recommended
|
|
3242
|
+
* entry point for apps running inside the platform's iframe — the context
|
|
3243
|
+
* carries a fresh JWT on every navigation.
|
|
3244
|
+
*/
|
|
3245
|
+
static fromPlatformContext(t) {
|
|
3246
|
+
const s = (typeof window < "u" ? window.__THATOPEN_CONTEXT__ : null) || { appId: "", projectId: "", accessToken: "", apiUrl: "" }, r = new me(s.accessToken, s.apiUrl, t);
|
|
3247
|
+
return r.context = s, r;
|
|
3248
|
+
}
|
|
3249
|
+
// ─── Projects (JWT-only backend routes) ──────────────────────────
|
|
3250
|
+
/**
|
|
3251
|
+
* Gets a project by ID. JWT-only — lives here because
|
|
3252
|
+
* `GET /project/:id` is guarded by `AccountActiveGuard + ProjectAccessGuard`.
|
|
3253
|
+
*/
|
|
3254
|
+
async getProject(t) {
|
|
3255
|
+
return await this.request("GET", `${I}/${t}`);
|
|
3256
|
+
}
|
|
3257
|
+
/**
|
|
3258
|
+
* Gets the full project data (users, roles, files, folders) for a project.
|
|
3259
|
+
* User data is stripped of sensitive fields server-side.
|
|
3260
|
+
*/
|
|
3261
|
+
async getProjectData(t) {
|
|
3262
|
+
return await this.request(
|
|
3263
|
+
"GET",
|
|
3264
|
+
`${I}/${t}/data`
|
|
3265
|
+
);
|
|
3266
|
+
}
|
|
3267
|
+
// ─── Permissions (JWT-only backend routes) ───────────────────────
|
|
3268
|
+
/**
|
|
3269
|
+
* Checks whether the caller has a specific permission within a project.
|
|
3270
|
+
* Returns `{ hasPermission, scope }` where `scope` is `'global'` for
|
|
3271
|
+
* admin/owner, `'project'` for a role broad grant, `'entity'` for a
|
|
3272
|
+
* per-entity override, `'none'` for denied.
|
|
3273
|
+
*/
|
|
3274
|
+
async checkPermission(t) {
|
|
3275
|
+
return await this.request(
|
|
3276
|
+
"GET",
|
|
3277
|
+
`${I}/permissions/check`,
|
|
3278
|
+
{ query: t }
|
|
3279
|
+
);
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* Batch variant of {@link checkPermission}. Evaluates multiple checks in a
|
|
3283
|
+
* single round-trip; results come back in the same order as `checks`.
|
|
3284
|
+
*/
|
|
3285
|
+
async checkPermissionBatch(t) {
|
|
3286
|
+
return (await this.request("POST", `${I}/permissions/check/batch`, {
|
|
3287
|
+
body: JSON.stringify({ checks: t }),
|
|
3288
|
+
contentType: "application/json"
|
|
3289
|
+
})).results;
|
|
3290
|
+
}
|
|
3291
|
+
};
|
|
3292
|
+
$ = new WeakMap();
|
|
3293
|
+
let ke = me;
|
|
3294
|
+
const Ut = {
|
|
3295
|
+
MAX_FIELDS: 200,
|
|
3296
|
+
MAX_KEY_LENGTH: 50,
|
|
3297
|
+
MAX_VALUE_LENGTH: 50
|
|
3298
|
+
}, Dt = { uuid: "2e32d873-02c9-421c-8743-d8a5ca6ad38a" }, Ft = { uuid: "b0b5e2a2-0b3a-4a6b-8b1c-0b1c4a6b8b1c" }, Vt = { uuid: "2c4ae432-fc24-43e9-9783-0c960c674e96" }, Mt = { uuid: "3c2a9f34-8b6c-4d1b-8f7a-1e4a5b2c9f08" }, Ht = { uuid: "234f1416-528d-452a-9cc9-a16c5239b2eb" }, Jt = { uuid: "def81d43-6b44-4f4a-9c08-7649486112a4" };
|
|
3299
|
+
export {
|
|
3300
|
+
Dt as AppManager,
|
|
3301
|
+
oe as EngineServicesClient,
|
|
3302
|
+
Ft as FileList,
|
|
3303
|
+
Vt as HelloWorld,
|
|
3304
|
+
Ut as METADATA_LIMITS,
|
|
3305
|
+
ke as PlatformClient,
|
|
3306
|
+
Lt as RequestError,
|
|
3307
|
+
Mt as TabbedNavigation,
|
|
3308
|
+
Ht as UIManager,
|
|
3309
|
+
Jt as ViewportsManager
|
|
3310
|
+
};
|