agent-yes 1.98.0 → 1.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SUPPORTED_CLIS-C-cenkTG.js +8 -0
- package/dist/{SUPPORTED_CLIS-C0a9K6I5.js → SUPPORTED_CLIS-DIHMEdRx.js} +2 -2
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{serve-DPY37v0u.js → serve-C4fZSjh9.js} +22 -14
- package/dist/{share-D-r6y3xD.js → share-BsCeIfQM.js} +19 -2
- package/dist/{subcommands-D4Muugfr.js → subcommands-BKY3nQV4.js} +2 -2
- package/dist/{subcommands-fCkYXyTe.js → subcommands-dnjUZ9nY.js} +1 -1
- package/dist/{ts-BuFWTNL9.js → ts-CUn393DD.js} +2 -2
- package/dist/{versionChecker-CpNUvHBx.js → versionChecker-BWdncsn6.js} +2 -2
- package/lab/ui/index.html +221 -98
- package/lab/ui/room-client.js +328 -239
- package/package.json +1 -1
- package/ts/serve.ts +38 -10
- package/ts/share.ts +29 -1
- package/dist/SUPPORTED_CLIS-BtLklR5y.js +0 -8
package/lab/ui/room-client.js
CHANGED
|
@@ -1,97 +1,105 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k() {
|
|
2
2
|
return crypto.randomUUID();
|
|
3
3
|
}
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var g = 60000,
|
|
5
|
+
u = 1e4,
|
|
6
|
+
L = 1000,
|
|
7
|
+
b = 120000,
|
|
8
|
+
O = 25000;
|
|
9
|
+
class j {
|
|
7
10
|
opts;
|
|
8
11
|
peerId;
|
|
9
12
|
ws = null;
|
|
10
13
|
closed = !1;
|
|
11
|
-
reconnectDelay =
|
|
14
|
+
reconnectDelay = L;
|
|
12
15
|
reconnectTimer = null;
|
|
16
|
+
dormant = !1;
|
|
13
17
|
heartbeat = null;
|
|
14
18
|
stableTimer = null;
|
|
15
19
|
openedAt = 0;
|
|
16
|
-
constructor(
|
|
17
|
-
this.opts =
|
|
18
|
-
this.peerId =
|
|
20
|
+
constructor(z) {
|
|
21
|
+
this.opts = z;
|
|
22
|
+
this.peerId = z.peerId ?? k();
|
|
19
23
|
}
|
|
20
24
|
connect() {
|
|
21
25
|
((this.closed = !1), this.attachWakeListeners(), this.open());
|
|
22
26
|
}
|
|
23
27
|
onWake = () => {
|
|
24
28
|
if (this.closed) return;
|
|
25
|
-
let
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
29
|
+
let z = this.ws?.readyState;
|
|
30
|
+
if (z === 1) return;
|
|
31
|
+
if (z === 0) {
|
|
28
32
|
try {
|
|
29
33
|
this.ws?.close();
|
|
30
34
|
} catch {}
|
|
31
35
|
return;
|
|
32
36
|
}
|
|
33
|
-
if (this.reconnectTimer != null)
|
|
37
|
+
if (this.dormant || this.reconnectTimer != null)
|
|
38
|
+
((this.dormant = !1), this.clearReconnectTimer(), this.open());
|
|
34
39
|
};
|
|
40
|
+
hidden() {
|
|
41
|
+
return globalThis.document?.visibilityState === "hidden";
|
|
42
|
+
}
|
|
35
43
|
attachWakeListeners() {
|
|
36
44
|
globalThis.document?.addEventListener("visibilitychange", this.onWake);
|
|
37
|
-
let
|
|
38
|
-
(
|
|
45
|
+
let Q = globalThis.window;
|
|
46
|
+
(Q?.addEventListener("focus", this.onWake), Q?.addEventListener("online", this.onWake));
|
|
39
47
|
}
|
|
40
48
|
detachWakeListeners() {
|
|
41
49
|
globalThis.document?.removeEventListener("visibilitychange", this.onWake);
|
|
42
|
-
let
|
|
43
|
-
(
|
|
50
|
+
let Q = globalThis.window;
|
|
51
|
+
(Q?.removeEventListener("focus", this.onWake), Q?.removeEventListener("online", this.onWake));
|
|
44
52
|
}
|
|
45
53
|
roomUrl() {
|
|
46
54
|
return `${this.opts.url.replace(/\/+$/, "")}/room/${encodeURIComponent(this.opts.token)}`;
|
|
47
55
|
}
|
|
48
56
|
open() {
|
|
49
|
-
let
|
|
50
|
-
this.ws =
|
|
51
|
-
let
|
|
52
|
-
if (
|
|
57
|
+
let z = new WebSocket(this.roomUrl());
|
|
58
|
+
this.ws = z;
|
|
59
|
+
let Q = setTimeout(() => {
|
|
60
|
+
if (z.readyState === 0)
|
|
53
61
|
try {
|
|
54
|
-
|
|
62
|
+
z.close();
|
|
55
63
|
} catch {}
|
|
56
|
-
},
|
|
57
|
-
((
|
|
58
|
-
(clearTimeout(
|
|
64
|
+
}, u);
|
|
65
|
+
((z.onopen = () => {
|
|
66
|
+
(clearTimeout(Q),
|
|
59
67
|
(this.openedAt = Date.now()),
|
|
60
68
|
this.clearStableTimer(),
|
|
61
69
|
(this.stableTimer = setTimeout(() => {
|
|
62
|
-
this.reconnectDelay =
|
|
63
|
-
},
|
|
64
|
-
let
|
|
70
|
+
this.reconnectDelay = L;
|
|
71
|
+
}, g)));
|
|
72
|
+
let Y = {
|
|
65
73
|
type: "hello",
|
|
66
74
|
role: this.opts.role,
|
|
67
75
|
peerId: this.peerId,
|
|
68
76
|
...(this.opts.meta ? { meta: this.opts.meta } : {}),
|
|
69
77
|
};
|
|
70
|
-
(
|
|
78
|
+
(z.send(JSON.stringify(Y)), this.startHeartbeat(), this.opts.onOpen?.());
|
|
71
79
|
}),
|
|
72
|
-
(
|
|
73
|
-
let
|
|
80
|
+
(z.onmessage = (Y) => {
|
|
81
|
+
let Z;
|
|
74
82
|
try {
|
|
75
|
-
|
|
83
|
+
Z = JSON.parse(String(Y.data));
|
|
76
84
|
} catch {
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
|
-
if (
|
|
80
|
-
else if (
|
|
87
|
+
if (Z.type === "peers") this.opts.onPeers?.(Z.peers);
|
|
88
|
+
else if (Z.type === "signal") this.opts.onSignal?.(Z.from, Z.data);
|
|
81
89
|
}),
|
|
82
|
-
(
|
|
83
|
-
(clearTimeout(
|
|
84
|
-
let
|
|
90
|
+
(z.onclose = (Y) => {
|
|
91
|
+
(clearTimeout(Q), this.clearStableTimer(), this.stopHeartbeat());
|
|
92
|
+
let Z = this.openedAt ? Date.now() - this.openedAt : 0;
|
|
85
93
|
if (
|
|
86
94
|
((this.openedAt = 0),
|
|
87
|
-
this.opts.onClose?.({ code:
|
|
95
|
+
this.opts.onClose?.({ code: Y?.code ?? 0, reason: Y?.reason ?? "", ms: Z }),
|
|
88
96
|
!this.closed)
|
|
89
97
|
)
|
|
90
98
|
this.scheduleReconnect();
|
|
91
99
|
}),
|
|
92
|
-
(
|
|
100
|
+
(z.onerror = () => {
|
|
93
101
|
try {
|
|
94
|
-
|
|
102
|
+
z.close();
|
|
95
103
|
} catch {}
|
|
96
104
|
}));
|
|
97
105
|
}
|
|
@@ -101,7 +109,7 @@ class U {
|
|
|
101
109
|
try {
|
|
102
110
|
this.ws?.send(JSON.stringify({ type: "ping" }));
|
|
103
111
|
} catch {}
|
|
104
|
-
},
|
|
112
|
+
}, O)));
|
|
105
113
|
}
|
|
106
114
|
stopHeartbeat() {
|
|
107
115
|
if (this.heartbeat != null) (clearInterval(this.heartbeat), (this.heartbeat = null));
|
|
@@ -110,29 +118,39 @@ class U {
|
|
|
110
118
|
if (this.stableTimer != null) (clearTimeout(this.stableTimer), (this.stableTimer = null));
|
|
111
119
|
}
|
|
112
120
|
scheduleReconnect() {
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
if (this.hidden()) {
|
|
122
|
+
this.dormant = !0;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let z = Math.round(this.reconnectDelay * (0.75 + Math.random() * 0.5));
|
|
126
|
+
((this.reconnectDelay = Math.min(this.reconnectDelay * 2, b)),
|
|
115
127
|
this.clearReconnectTimer(),
|
|
116
128
|
(this.reconnectTimer = setTimeout(() => {
|
|
117
|
-
if (((this.reconnectTimer = null),
|
|
118
|
-
|
|
129
|
+
if (((this.reconnectTimer = null), this.closed)) return;
|
|
130
|
+
if (this.hidden()) {
|
|
131
|
+
this.dormant = !0;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.open();
|
|
135
|
+
}, z)));
|
|
119
136
|
}
|
|
120
137
|
clearReconnectTimer() {
|
|
121
138
|
if (this.reconnectTimer != null)
|
|
122
139
|
(clearTimeout(this.reconnectTimer), (this.reconnectTimer = null));
|
|
123
140
|
}
|
|
124
|
-
sendSignal(
|
|
125
|
-
let
|
|
126
|
-
this.ws?.send(JSON.stringify(
|
|
141
|
+
sendSignal(z, Q) {
|
|
142
|
+
let Y = { type: "signal", to: z, data: Q };
|
|
143
|
+
this.ws?.send(JSON.stringify(Y));
|
|
127
144
|
}
|
|
128
|
-
updateMeta(
|
|
129
|
-
if (((this.opts.meta =
|
|
130
|
-
let
|
|
131
|
-
this.ws.send(JSON.stringify(
|
|
145
|
+
updateMeta(z) {
|
|
146
|
+
if (((this.opts.meta = z), this.ws?.readyState === 1)) {
|
|
147
|
+
let Q = { type: "meta", meta: z };
|
|
148
|
+
this.ws.send(JSON.stringify(Q));
|
|
132
149
|
}
|
|
133
150
|
}
|
|
134
151
|
close() {
|
|
135
152
|
((this.closed = !0),
|
|
153
|
+
(this.dormant = !1),
|
|
136
154
|
this.detachWakeListeners(),
|
|
137
155
|
this.clearReconnectTimer(),
|
|
138
156
|
this.stopHeartbeat(),
|
|
@@ -143,20 +161,22 @@ class U {
|
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
163
|
var A = ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"],
|
|
146
|
-
|
|
164
|
+
N = "codehost",
|
|
165
|
+
_ = "codehost-bulk";
|
|
147
166
|
class B {
|
|
148
167
|
opts;
|
|
149
168
|
pc;
|
|
150
169
|
channel = null;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
170
|
+
bulk = null;
|
|
171
|
+
constructor(z) {
|
|
172
|
+
this.opts = z;
|
|
173
|
+
((this.pc = new RTCPeerConnection({ iceServers: A.map((Q) => ({ urls: Q })) })),
|
|
174
|
+
(this.pc.onicecandidate = (Q) => {
|
|
175
|
+
if (Q.candidate)
|
|
156
176
|
this.opts.sendSignal({
|
|
157
177
|
kind: "candidate",
|
|
158
|
-
candidate:
|
|
159
|
-
mid:
|
|
178
|
+
candidate: Q.candidate.candidate,
|
|
179
|
+
mid: Q.candidate.sdpMid ?? "0",
|
|
160
180
|
});
|
|
161
181
|
}),
|
|
162
182
|
(this.pc.onconnectionstatechange = () => {
|
|
@@ -164,286 +184,355 @@ class B {
|
|
|
164
184
|
}));
|
|
165
185
|
}
|
|
166
186
|
async start() {
|
|
167
|
-
let
|
|
168
|
-
((
|
|
169
|
-
(this.channel =
|
|
170
|
-
(
|
|
171
|
-
(
|
|
172
|
-
let
|
|
173
|
-
(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
187
|
+
let z = this.pc.createDataChannel(N, { ordered: !0 });
|
|
188
|
+
((z.binaryType = "arraybuffer"),
|
|
189
|
+
(this.channel = z),
|
|
190
|
+
(z.onopen = () => this.opts.onOpen?.(z)),
|
|
191
|
+
(z.onclose = () => this.opts.onClose?.()));
|
|
192
|
+
let Q = this.pc.createDataChannel(_, { ordered: !0 });
|
|
193
|
+
((Q.binaryType = "arraybuffer"), (this.bulk = Q));
|
|
194
|
+
let Y = await this.pc.createOffer();
|
|
195
|
+
(await this.pc.setLocalDescription(Y),
|
|
196
|
+
this.opts.sendSignal({ kind: "offer", type: "offer", sdp: Y.sdp ?? "" }));
|
|
197
|
+
}
|
|
198
|
+
async handleSignal(z) {
|
|
199
|
+
let Q = z;
|
|
200
|
+
if (!Q || typeof Q !== "object") return;
|
|
201
|
+
if (Q.kind === "answer") await this.pc.setRemoteDescription({ type: "answer", sdp: Q.sdp });
|
|
202
|
+
else if (Q.kind === "candidate")
|
|
181
203
|
try {
|
|
182
|
-
await this.pc.addIceCandidate({ candidate:
|
|
183
|
-
} catch (
|
|
184
|
-
console.error("[rtc] addIceCandidate failed:",
|
|
204
|
+
await this.pc.addIceCandidate({ candidate: Q.candidate, sdpMid: Q.mid });
|
|
205
|
+
} catch (Y) {
|
|
206
|
+
console.error("[rtc] addIceCandidate failed:", Y);
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
209
|
get dataChannel() {
|
|
188
210
|
return this.channel;
|
|
189
211
|
}
|
|
212
|
+
get bulkChannel() {
|
|
213
|
+
return this.bulk;
|
|
214
|
+
}
|
|
215
|
+
async selectedPath() {
|
|
216
|
+
try {
|
|
217
|
+
let z = await this.pc.getStats(),
|
|
218
|
+
Q = null;
|
|
219
|
+
z.forEach((q) => {
|
|
220
|
+
if (q.type === "transport" && q.selectedCandidatePairId) Q = q.selectedCandidatePairId;
|
|
221
|
+
});
|
|
222
|
+
let Y = null;
|
|
223
|
+
if (
|
|
224
|
+
(z.forEach((q) => {
|
|
225
|
+
if (
|
|
226
|
+
Q ? q.id === Q : q.type === "candidate-pair" && q.state === "succeeded" && q.nominated
|
|
227
|
+
)
|
|
228
|
+
Y = q;
|
|
229
|
+
}),
|
|
230
|
+
!Y)
|
|
231
|
+
)
|
|
232
|
+
return null;
|
|
233
|
+
let { localCandidateId: Z, remoteCandidateId: $ } = Y,
|
|
234
|
+
G = !0,
|
|
235
|
+
V = 0;
|
|
236
|
+
if (
|
|
237
|
+
(z.forEach((q) => {
|
|
238
|
+
if (q.id === Z || q.id === $) {
|
|
239
|
+
if ((V++, q.candidateType !== "host")) G = !1;
|
|
240
|
+
}
|
|
241
|
+
}),
|
|
242
|
+
V < 2)
|
|
243
|
+
)
|
|
244
|
+
return null;
|
|
245
|
+
return G ? "lan" : "p2p";
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
190
250
|
close() {
|
|
191
251
|
try {
|
|
192
252
|
this.channel?.close();
|
|
193
253
|
} catch {}
|
|
254
|
+
try {
|
|
255
|
+
this.bulk?.close();
|
|
256
|
+
} catch {}
|
|
194
257
|
try {
|
|
195
258
|
this.pc.close();
|
|
196
259
|
} catch {}
|
|
197
260
|
}
|
|
198
261
|
}
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
function
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
if (((
|
|
205
|
-
return
|
|
262
|
+
var y = new TextEncoder(),
|
|
263
|
+
S = new TextDecoder();
|
|
264
|
+
function P(z, Q, Y) {
|
|
265
|
+
let Z = Y?.byteLength ?? 0,
|
|
266
|
+
$ = new Uint8Array(5 + Z);
|
|
267
|
+
if ((($[0] = z), new DataView($.buffer).setUint32(1, Q >>> 0, !1), Y && Z)) $.set(Y, 5);
|
|
268
|
+
return $;
|
|
206
269
|
}
|
|
207
|
-
function
|
|
208
|
-
return
|
|
270
|
+
function J(z, Q, Y) {
|
|
271
|
+
return P(z, Q, y.encode(JSON.stringify(Y)));
|
|
209
272
|
}
|
|
210
|
-
function
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return { op:
|
|
273
|
+
function T(z) {
|
|
274
|
+
let Q = z instanceof Uint8Array ? z : new Uint8Array(z),
|
|
275
|
+
Y = Q[0],
|
|
276
|
+
Z = new DataView(Q.buffer, Q.byteOffset, Q.byteLength).getUint32(1, !1),
|
|
277
|
+
$ = Q.subarray(5);
|
|
278
|
+
return { op: Y, streamId: Z, payload: $ };
|
|
216
279
|
}
|
|
217
|
-
function
|
|
218
|
-
return JSON.parse(
|
|
280
|
+
function U(z) {
|
|
281
|
+
return JSON.parse(S.decode(z));
|
|
219
282
|
}
|
|
220
|
-
function
|
|
221
|
-
return
|
|
283
|
+
function E(z) {
|
|
284
|
+
return S.decode(z);
|
|
222
285
|
}
|
|
223
|
-
function*
|
|
224
|
-
for (let
|
|
286
|
+
function* C(z) {
|
|
287
|
+
for (let Q = 0; Q < z.byteLength; Q += 65531) yield z.slice(Q, Math.min(Q + 65531, z.byteLength));
|
|
225
288
|
}
|
|
226
|
-
function
|
|
227
|
-
if (
|
|
228
|
-
let
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
for (let
|
|
232
|
-
return
|
|
289
|
+
function f(z) {
|
|
290
|
+
if (z.length === 1) return z[0];
|
|
291
|
+
let Q = z.reduce(($, G) => $ + G.byteLength, 0),
|
|
292
|
+
Y = new Uint8Array(Q),
|
|
293
|
+
Z = 0;
|
|
294
|
+
for (let $ of z) (Y.set($, Z), (Z += $.byteLength));
|
|
295
|
+
return Y;
|
|
233
296
|
}
|
|
234
|
-
function*
|
|
235
|
-
let
|
|
236
|
-
while (
|
|
237
|
-
yield
|
|
297
|
+
function* H(z, Q, Y) {
|
|
298
|
+
let Z = 0;
|
|
299
|
+
while (Y.byteLength - Z > 65531) (yield P(13, Q, Y.subarray(Z, Z + 65531)), (Z += 65531));
|
|
300
|
+
yield P(z, Q, Y.subarray(Z));
|
|
238
301
|
}
|
|
239
|
-
class
|
|
302
|
+
class F {
|
|
240
303
|
pending = new Map();
|
|
241
|
-
cont(
|
|
242
|
-
let
|
|
243
|
-
if (
|
|
244
|
-
else this.pending.set(
|
|
304
|
+
cont(z, Q) {
|
|
305
|
+
let Y = this.pending.get(z);
|
|
306
|
+
if (Y) Y.push(Q.slice());
|
|
307
|
+
else this.pending.set(z, [Q.slice()]);
|
|
245
308
|
}
|
|
246
|
-
finish(
|
|
247
|
-
let
|
|
248
|
-
if (!
|
|
249
|
-
return (this.pending.delete(
|
|
309
|
+
finish(z, Q) {
|
|
310
|
+
let Y = this.pending.get(z);
|
|
311
|
+
if (!Y) return Q;
|
|
312
|
+
return (this.pending.delete(z), Y.push(Q), f(Y));
|
|
250
313
|
}
|
|
251
|
-
drop(
|
|
252
|
-
this.pending.delete(
|
|
314
|
+
drop(z) {
|
|
315
|
+
this.pending.delete(z);
|
|
253
316
|
}
|
|
254
317
|
}
|
|
255
|
-
class
|
|
318
|
+
class R {
|
|
256
319
|
channel;
|
|
320
|
+
bulk;
|
|
257
321
|
nextStreamId = 1;
|
|
258
322
|
https = new Map();
|
|
259
323
|
wss = new Map();
|
|
260
|
-
wsRx = new
|
|
324
|
+
wsRx = new F();
|
|
261
325
|
textEncoder = new TextEncoder();
|
|
262
|
-
constructor(
|
|
263
|
-
this.channel =
|
|
264
|
-
|
|
326
|
+
constructor(z, Q = null) {
|
|
327
|
+
this.channel = z;
|
|
328
|
+
this.bulk = Q;
|
|
329
|
+
if (
|
|
330
|
+
((z.binaryType = "arraybuffer"),
|
|
331
|
+
z.addEventListener("message", (Y) => this.onFrame(Y.data)),
|
|
332
|
+
Q)
|
|
333
|
+
)
|
|
334
|
+
((Q.binaryType = "arraybuffer"), Q.addEventListener("message", (Y) => this.onFrame(Y.data)));
|
|
265
335
|
}
|
|
266
336
|
allocId() {
|
|
267
|
-
let
|
|
268
|
-
return ((this.nextStreamId = (this.nextStreamId + 1) >>> 0 || 1),
|
|
337
|
+
let z = this.nextStreamId;
|
|
338
|
+
return ((this.nextStreamId = (this.nextStreamId + 1) >>> 0 || 1), z);
|
|
269
339
|
}
|
|
270
|
-
onFrame(
|
|
271
|
-
if (typeof
|
|
272
|
-
let { op:
|
|
273
|
-
switch (
|
|
340
|
+
onFrame(z) {
|
|
341
|
+
if (typeof z === "string") return;
|
|
342
|
+
let { op: Q, streamId: Y, payload: Z } = T(z);
|
|
343
|
+
switch (Q) {
|
|
274
344
|
case 4:
|
|
275
|
-
this.https.get(
|
|
345
|
+
this.https.get(Y)?.onHead(U(Z));
|
|
276
346
|
break;
|
|
277
347
|
case 5:
|
|
278
|
-
this.https.get(
|
|
348
|
+
this.https.get(Y)?.onBody(Z.slice());
|
|
279
349
|
break;
|
|
280
350
|
case 6:
|
|
281
|
-
(this.https.get(
|
|
351
|
+
(this.https.get(Y)?.onEnd(), this.https.delete(Y));
|
|
282
352
|
break;
|
|
283
353
|
case 12: {
|
|
284
|
-
let
|
|
285
|
-
if (
|
|
354
|
+
let $ = this.https.get(Y);
|
|
355
|
+
if ($) ($.onError(U(Z).message), this.https.delete(Y));
|
|
286
356
|
break;
|
|
287
357
|
}
|
|
288
358
|
case 8: {
|
|
289
|
-
let
|
|
290
|
-
this.wss.get(
|
|
359
|
+
let $ = U(Z);
|
|
360
|
+
this.wss.get(Y)?.onOpenAck($.ok, $.protocol);
|
|
291
361
|
break;
|
|
292
362
|
}
|
|
293
363
|
case 13:
|
|
294
|
-
this.wsRx.cont(
|
|
364
|
+
this.wsRx.cont(Y, Z);
|
|
295
365
|
break;
|
|
296
366
|
case 9:
|
|
297
|
-
this.wss.get(
|
|
367
|
+
this.wss.get(Y)?.onText(E(this.wsRx.finish(Y, Z)));
|
|
298
368
|
break;
|
|
299
369
|
case 10:
|
|
300
|
-
this.wss.get(
|
|
370
|
+
this.wss.get(Y)?.onBin(this.wsRx.finish(Y, Z).slice());
|
|
301
371
|
break;
|
|
302
372
|
case 11: {
|
|
303
|
-
let
|
|
304
|
-
(this.wsRx.drop(
|
|
305
|
-
this.wss.get(
|
|
306
|
-
this.wss.delete(
|
|
373
|
+
let $ = U(Z);
|
|
374
|
+
(this.wsRx.drop(Y),
|
|
375
|
+
this.wss.get(Y)?.onClose($.code ?? 1000, $.reason ?? ""),
|
|
376
|
+
this.wss.delete(Y));
|
|
307
377
|
break;
|
|
308
378
|
}
|
|
309
379
|
}
|
|
310
380
|
}
|
|
311
|
-
fetch(
|
|
312
|
-
let
|
|
313
|
-
return new Promise((
|
|
314
|
-
let
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
start: (
|
|
318
|
-
|
|
319
|
-
},
|
|
320
|
-
});
|
|
321
|
-
if (
|
|
322
|
-
(this.https.set(X, {
|
|
323
|
-
onHead: (Y) => {
|
|
324
|
-
((D = Y),
|
|
325
|
-
Z(
|
|
326
|
-
new Response(j, {
|
|
327
|
-
status: Y.status === 204 || Y.status === 304 ? Y.status : Y.status,
|
|
328
|
-
statusText: Y.statusText,
|
|
329
|
-
headers: Y.headers,
|
|
330
|
-
}),
|
|
331
|
-
));
|
|
332
|
-
},
|
|
333
|
-
onBody: (Y) => {
|
|
334
|
-
try {
|
|
335
|
-
$?.enqueue(Y);
|
|
336
|
-
} catch {}
|
|
337
|
-
},
|
|
338
|
-
onEnd: () => {
|
|
339
|
-
try {
|
|
340
|
-
$?.close();
|
|
341
|
-
} catch {}
|
|
342
|
-
if (!D) V(Error("stream ended before head"));
|
|
343
|
-
},
|
|
344
|
-
onError: (Y) => {
|
|
345
|
-
try {
|
|
346
|
-
$?.error(Error(Y));
|
|
347
|
-
} catch {}
|
|
348
|
-
if (!D) V(Error(Y));
|
|
381
|
+
fetch(z, Q, Y, Z) {
|
|
382
|
+
let $ = this.allocId();
|
|
383
|
+
return new Promise((G, V) => {
|
|
384
|
+
let q = null,
|
|
385
|
+
D = null,
|
|
386
|
+
X = new ReadableStream({
|
|
387
|
+
start: (K) => {
|
|
388
|
+
D = K;
|
|
349
389
|
},
|
|
350
390
|
}),
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
391
|
+
v = typeof DecompressionStream < "u" ? { ...Y, "x-codehost-accept-gzip": "1" } : Y;
|
|
392
|
+
this.https.set($, {
|
|
393
|
+
onHead: (K) => {
|
|
394
|
+
q = K;
|
|
395
|
+
let x = new Headers(K.headers),
|
|
396
|
+
M = X;
|
|
397
|
+
if (x.get("content-encoding") === "gzip")
|
|
398
|
+
((M = X.pipeThrough(new DecompressionStream("gzip"))),
|
|
399
|
+
x.delete("content-encoding"),
|
|
400
|
+
x.delete("content-length"));
|
|
401
|
+
G(
|
|
402
|
+
new Response(M, {
|
|
403
|
+
status: K.status === 204 || K.status === 304 ? K.status : K.status,
|
|
404
|
+
statusText: K.statusText,
|
|
405
|
+
headers: x,
|
|
406
|
+
}),
|
|
407
|
+
);
|
|
408
|
+
},
|
|
409
|
+
onBody: (K) => {
|
|
410
|
+
try {
|
|
411
|
+
D?.enqueue(K);
|
|
412
|
+
} catch {}
|
|
413
|
+
},
|
|
414
|
+
onEnd: () => {
|
|
415
|
+
try {
|
|
416
|
+
D?.close();
|
|
417
|
+
} catch {}
|
|
418
|
+
if (!q) V(Error("stream ended before head"));
|
|
419
|
+
},
|
|
420
|
+
onError: (K) => {
|
|
421
|
+
try {
|
|
422
|
+
D?.error(Error(K));
|
|
423
|
+
} catch {}
|
|
424
|
+
if (!q) V(Error(K));
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
let W = this.bulk?.readyState === "open" ? this.bulk : this.channel;
|
|
428
|
+
if ((this.sendOn(W, J(1, $, { method: z, path: Q, headers: v })), Z && Z.byteLength))
|
|
429
|
+
for (let K of C(Z)) this.sendOn(W, P(2, $, K));
|
|
430
|
+
this.sendOn(W, P(3, $));
|
|
356
431
|
});
|
|
357
432
|
}
|
|
358
|
-
openWs(
|
|
359
|
-
let
|
|
433
|
+
openWs(z, Q, Y) {
|
|
434
|
+
let Z = this.allocId();
|
|
360
435
|
return (
|
|
361
|
-
this.wss.set(
|
|
362
|
-
this.send(
|
|
436
|
+
this.wss.set(Z, Y),
|
|
437
|
+
this.send(J(7, Z, { path: z, protocols: Q })),
|
|
363
438
|
{
|
|
364
|
-
sendText: (
|
|
365
|
-
for (let
|
|
439
|
+
sendText: ($) => {
|
|
440
|
+
for (let G of H(9, Z, this.textEncoder.encode($))) this.send(G);
|
|
366
441
|
},
|
|
367
|
-
sendBin: (
|
|
368
|
-
for (let
|
|
442
|
+
sendBin: ($) => {
|
|
443
|
+
for (let G of H(10, Z, $)) this.send(G);
|
|
369
444
|
},
|
|
370
|
-
close: (
|
|
371
|
-
(this.send(
|
|
445
|
+
close: ($, G) => {
|
|
446
|
+
(this.send(J(11, Z, { code: $, reason: G })), this.wss.delete(Z));
|
|
372
447
|
},
|
|
373
448
|
}
|
|
374
449
|
);
|
|
375
450
|
}
|
|
376
|
-
send(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
451
|
+
send(z) {
|
|
452
|
+
this.sendOn(this.channel, z);
|
|
453
|
+
}
|
|
454
|
+
sendOn(z, Q) {
|
|
455
|
+
if (z.readyState === "open") {
|
|
456
|
+
let Y = new Uint8Array(Q.byteLength);
|
|
457
|
+
(Y.set(Q), z.send(Y.buffer));
|
|
380
458
|
}
|
|
381
459
|
}
|
|
382
460
|
get ready() {
|
|
383
461
|
return this.channel.readyState === "open";
|
|
384
462
|
}
|
|
385
463
|
}
|
|
386
|
-
var
|
|
387
|
-
|
|
464
|
+
var I = "wss://signal.codehost.dev",
|
|
465
|
+
h = 1e4;
|
|
466
|
+
class w {
|
|
388
467
|
peers = [];
|
|
389
468
|
signaling;
|
|
390
469
|
rtcs = new Map();
|
|
391
470
|
tunnels = new Map();
|
|
471
|
+
dialFailedAt = new Map();
|
|
392
472
|
closed = !1;
|
|
393
|
-
constructor(
|
|
394
|
-
((this.signaling = new
|
|
395
|
-
url:
|
|
396
|
-
token:
|
|
473
|
+
constructor(z) {
|
|
474
|
+
((this.signaling = new j({
|
|
475
|
+
url: z.signalUrl ?? I,
|
|
476
|
+
token: z.token,
|
|
397
477
|
role: "viewer",
|
|
398
|
-
onOpen: () =>
|
|
399
|
-
onClose: () =>
|
|
400
|
-
onPeers: (
|
|
401
|
-
((this.peers =
|
|
478
|
+
onOpen: () => z.onStatus?.(!0),
|
|
479
|
+
onClose: () => z.onStatus?.(!1),
|
|
480
|
+
onPeers: (Q) => {
|
|
481
|
+
((this.peers = Q.filter((Y) => Y.role === "server")), z.onPeers?.(this.peers));
|
|
402
482
|
},
|
|
403
|
-
onSignal: (
|
|
483
|
+
onSignal: (Q, Y) => void this.rtcs.get(Q)?.handleSignal(Y),
|
|
404
484
|
})),
|
|
405
485
|
this.signaling.connect());
|
|
406
486
|
}
|
|
407
|
-
async fetch(
|
|
408
|
-
let
|
|
409
|
-
|
|
410
|
-
return
|
|
411
|
-
}
|
|
412
|
-
dial(
|
|
413
|
-
let
|
|
414
|
-
if (
|
|
415
|
-
let
|
|
416
|
-
|
|
487
|
+
async fetch(z, Q, Y, Z = {}) {
|
|
488
|
+
let $ = await this.dial(z),
|
|
489
|
+
G = typeof Z.body === "string" ? new TextEncoder().encode(Z.body) : Z.body;
|
|
490
|
+
return $.fetch(Q, Y, Z.headers ?? {}, G);
|
|
491
|
+
}
|
|
492
|
+
dial(z) {
|
|
493
|
+
let Q = this.tunnels.get(z);
|
|
494
|
+
if (Q) return Q;
|
|
495
|
+
let Y = this.dialFailedAt.get(z);
|
|
496
|
+
if (Y != null && Date.now() - Y < h)
|
|
497
|
+
return Promise.reject(Error("dial failed recently; cooling down"));
|
|
498
|
+
let Z = () => {
|
|
499
|
+
(this.tunnels.delete(z), this.rtcs.get(z)?.close(), this.rtcs.delete(z));
|
|
417
500
|
},
|
|
418
|
-
|
|
419
|
-
let
|
|
420
|
-
(
|
|
501
|
+
$ = new Promise((G, V) => {
|
|
502
|
+
let q = setTimeout(() => {
|
|
503
|
+
(Z(), V(Error("dial timed out")));
|
|
421
504
|
}, 15000),
|
|
422
505
|
D = new B({
|
|
423
|
-
sendSignal: (
|
|
424
|
-
onOpen: (
|
|
425
|
-
(clearTimeout(
|
|
506
|
+
sendSignal: (X) => this.signaling.sendSignal(z, X),
|
|
507
|
+
onOpen: (X) => {
|
|
508
|
+
(clearTimeout(q), this.dialFailedAt.delete(z), G(new R(X, D.bulkChannel)));
|
|
426
509
|
},
|
|
427
|
-
onClose:
|
|
428
|
-
onState: (
|
|
429
|
-
if (
|
|
510
|
+
onClose: Z,
|
|
511
|
+
onState: (X) => {
|
|
512
|
+
if (X === "failed" || X === "disconnected") Z();
|
|
430
513
|
},
|
|
431
514
|
});
|
|
432
|
-
(this.rtcs.set(
|
|
433
|
-
D.start().catch((
|
|
434
|
-
(clearTimeout(
|
|
515
|
+
(this.rtcs.set(z, D),
|
|
516
|
+
D.start().catch((X) => {
|
|
517
|
+
(clearTimeout(q), Z(), V(X));
|
|
435
518
|
}));
|
|
436
519
|
});
|
|
437
|
-
return (
|
|
520
|
+
return (
|
|
521
|
+
this.tunnels.set(z, $),
|
|
522
|
+
$.catch(() => {
|
|
523
|
+
(this.dialFailedAt.set(z, Date.now()), this.tunnels.delete(z));
|
|
524
|
+
}),
|
|
525
|
+
$
|
|
526
|
+
);
|
|
438
527
|
}
|
|
439
528
|
close() {
|
|
440
529
|
if (this.closed) return;
|
|
441
530
|
this.closed = !0;
|
|
442
|
-
for (let
|
|
531
|
+
for (let z of this.rtcs.values()) z.close();
|
|
443
532
|
(this.rtcs.clear(), this.tunnels.clear(), this.signaling.close());
|
|
444
533
|
}
|
|
445
534
|
}
|
|
446
|
-
function
|
|
447
|
-
return new
|
|
535
|
+
function zz(z) {
|
|
536
|
+
return new w(z);
|
|
448
537
|
}
|
|
449
|
-
export {
|
|
538
|
+
export { zz as joinRoom, I as DEFAULT_SIGNAL_URL, w as CodehostRoom };
|