@statewalker/webrun-streams-signaling 0.2.0 → 0.3.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/README.md +58 -26
- package/dist/byte-channel.d.ts +46 -5
- package/dist/byte-channel.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +264 -56
- package/dist/message-target.d.ts +7 -0
- package/dist/message-target.d.ts.map +1 -1
- package/dist/peer-connection.d.ts +2 -0
- package/dist/peer-connection.d.ts.map +1 -1
- package/dist/peer-manager.d.ts +13 -1
- package/dist/peer-manager.d.ts.map +1 -1
- package/dist/qr-signaling.d.ts.map +1 -1
- package/dist/room-manager.d.ts +3 -2
- package/dist/room-manager.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/byte-channel.ts +172 -33
- package/src/index.ts +8 -1
- package/src/message-target.ts +25 -0
- package/src/peer-connection.ts +13 -0
- package/src/peer-manager.ts +64 -10
- package/src/qr-signaling.ts +54 -12
- package/src/room-manager.ts +4 -4
- package/src/types.ts +8 -1
package/dist/index.js
CHANGED
|
@@ -85,86 +85,195 @@ const ROOM_EVENT = {
|
|
|
85
85
|
* multiplexing (`webrun-rpc`'s port stack, via `messageTargetOverByteChannel`) can run on top.
|
|
86
86
|
*/
|
|
87
87
|
/**
|
|
88
|
+
* `whenDrained` resolves once the bytes sent and not yet written out are at
|
|
89
|
+
* most this: the transport can take more. The same mark the ws, peerjs,
|
|
90
|
+
* livekit and webrtc adapters use.
|
|
91
|
+
*/
|
|
92
|
+
const DRAIN_LOW_WATER = 262144;
|
|
93
|
+
/**
|
|
88
94
|
* Wrap an established `RTCDataChannel` as a {@link ByteChannel}. Outbound bytes
|
|
89
|
-
* go through `channel.send`; inbound `message` events feed `recv`.
|
|
95
|
+
* go through `channel.send`; inbound `message` events feed `recv`. A message
|
|
96
|
+
* that is not bytes, or a `send` that fails (a closed channel, Chrome's full
|
|
97
|
+
* send queue), ends the channel: the stream above it lost a message.
|
|
98
|
+
* `bufferedAmount` is the data channel's; `whenDrained` waits for its
|
|
99
|
+
* `bufferedamountlow`.
|
|
90
100
|
*/
|
|
91
101
|
function byteChannelFromDataChannel(channel) {
|
|
92
102
|
const queue = makeByteQueue();
|
|
93
103
|
let closedResolve;
|
|
104
|
+
let ended = false;
|
|
94
105
|
const closed = new Promise((r) => {
|
|
95
106
|
closedResolve = r;
|
|
96
107
|
});
|
|
97
|
-
const
|
|
98
|
-
const
|
|
108
|
+
const drainWaiters = /* @__PURE__ */ new Set();
|
|
109
|
+
const onMessage = (ev) => {
|
|
110
|
+
if (ended) return;
|
|
111
|
+
let bytes;
|
|
112
|
+
try {
|
|
113
|
+
bytes = toBytes(ev.data);
|
|
114
|
+
} catch {
|
|
115
|
+
close();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
queue.push(bytes);
|
|
119
|
+
};
|
|
120
|
+
const onDrained = () => {
|
|
121
|
+
for (const w of [...drainWaiters]) w();
|
|
122
|
+
drainWaiters.clear();
|
|
123
|
+
};
|
|
124
|
+
const end = () => {
|
|
125
|
+
if (ended) return;
|
|
126
|
+
ended = true;
|
|
127
|
+
channel.removeEventListener("message", onMessage);
|
|
128
|
+
channel.removeEventListener("close", end);
|
|
129
|
+
channel.removeEventListener("bufferedamountlow", onDrained);
|
|
99
130
|
queue.done();
|
|
100
131
|
closedResolve();
|
|
132
|
+
onDrained();
|
|
133
|
+
};
|
|
134
|
+
const close = () => {
|
|
135
|
+
end();
|
|
136
|
+
try {
|
|
137
|
+
channel.close();
|
|
138
|
+
} catch {}
|
|
101
139
|
};
|
|
102
140
|
channel.binaryType = "arraybuffer";
|
|
141
|
+
channel.bufferedAmountLowThreshold = DRAIN_LOW_WATER;
|
|
103
142
|
channel.addEventListener("message", onMessage);
|
|
104
|
-
channel.addEventListener("close",
|
|
143
|
+
channel.addEventListener("close", end);
|
|
144
|
+
channel.addEventListener("bufferedamountlow", onDrained);
|
|
105
145
|
return {
|
|
106
146
|
send(bytes) {
|
|
147
|
+
if (ended) return;
|
|
107
148
|
try {
|
|
108
149
|
channel.send(bytes);
|
|
109
|
-
} catch {
|
|
150
|
+
} catch {
|
|
151
|
+
close();
|
|
152
|
+
}
|
|
110
153
|
},
|
|
111
154
|
recv: queue.recv,
|
|
112
155
|
closed,
|
|
113
|
-
close
|
|
114
|
-
|
|
115
|
-
channel.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
closedResolve();
|
|
156
|
+
close,
|
|
157
|
+
get bufferedAmount() {
|
|
158
|
+
return channel.bufferedAmount ?? 0;
|
|
159
|
+
},
|
|
160
|
+
whenDrained() {
|
|
161
|
+
if (ended || (channel.bufferedAmount ?? 0) <= 262144) return Promise.resolve();
|
|
162
|
+
return new Promise((resolve) => drainWaiters.add(resolve));
|
|
121
163
|
}
|
|
122
164
|
};
|
|
123
165
|
}
|
|
124
166
|
/**
|
|
167
|
+
* The topic a {@link byteChannelFromRoom} channel's packets carry, the same
|
|
168
|
+
* default as `webrun-streams-livekit`'s `messageTargetOverLiveKit`; packets on
|
|
169
|
+
* other topics are someone else's. The goodbye goes on this topic with
|
|
170
|
+
* `/close` appended, as there.
|
|
171
|
+
*/
|
|
172
|
+
const DEFAULT_ROOM_TOPIC = "webrun/port-stack";
|
|
173
|
+
/**
|
|
174
|
+
* The largest packet a {@link byteChannelFromRoom} channel publishes, as in
|
|
175
|
+
* `webrun-streams-livekit`: livekit-client (2.x) refuses a larger one.
|
|
176
|
+
*/
|
|
177
|
+
const DEFAULT_ROOM_MAX_FRAME_BYTES = 64e3;
|
|
178
|
+
/**
|
|
125
179
|
* Build a {@link ByteChannel} to a single room participant over a LiveKit-style
|
|
126
|
-
* `Room`. Outbound bytes are published to `peerId
|
|
127
|
-
* events from `peerId`
|
|
128
|
-
*
|
|
180
|
+
* `Room`. Outbound bytes are published reliably to `peerId` on the channel's
|
|
181
|
+
* topic; inbound `dataReceived` events from `peerId` on that topic feed
|
|
182
|
+
* `recv`. The packets and the goodbye follow `webrun-streams-livekit`'s
|
|
183
|
+
* conventions, so the port stack over this channel talks to one over
|
|
184
|
+
* `messageTargetOverLiveKit` with the same topic.
|
|
185
|
+
*
|
|
186
|
+
* The channel ends when the room disconnects, the participant leaves, the
|
|
187
|
+
* peer's goodbye arrives, a reliable publish fails, or a `send` exceeds
|
|
188
|
+
* `maxFrameBytes`. When it ends on this side, a goodbye on the close topic
|
|
189
|
+
* ends the peer's channel too: the room stays connected, so nothing else would.
|
|
190
|
+
* `bufferedAmount` counts bytes whose publish has not settled.
|
|
129
191
|
*/
|
|
130
|
-
function byteChannelFromRoom(room, peerId) {
|
|
192
|
+
function byteChannelFromRoom(room, peerId, options = {}) {
|
|
193
|
+
const topic = options.topic ?? "webrun/port-stack";
|
|
194
|
+
const closeTopic = `${topic}/close`;
|
|
195
|
+
const maxFrameBytes = options.maxFrameBytes ?? 64e3;
|
|
131
196
|
const queue = makeByteQueue();
|
|
132
197
|
let closedResolve;
|
|
133
198
|
const closed = new Promise((r) => {
|
|
134
199
|
closedResolve = r;
|
|
135
200
|
});
|
|
136
201
|
let ended = false;
|
|
202
|
+
let inFlight = 0;
|
|
203
|
+
const drainWaiters = /* @__PURE__ */ new Set();
|
|
204
|
+
const wakeDrainWaiters = () => {
|
|
205
|
+
if (inFlight > 262144 && !ended) return;
|
|
206
|
+
for (const w of [...drainWaiters]) w();
|
|
207
|
+
drainWaiters.clear();
|
|
208
|
+
};
|
|
137
209
|
const onData = (...args) => {
|
|
138
|
-
const payload = args
|
|
139
|
-
if (
|
|
140
|
-
if (
|
|
210
|
+
const [payload, participant, , packetTopic] = args;
|
|
211
|
+
if (ended || participant?.identity !== peerId) return;
|
|
212
|
+
if (packetTopic === closeTopic) {
|
|
213
|
+
end(false);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (packetTopic !== topic || payload == null) return;
|
|
217
|
+
let bytes;
|
|
218
|
+
try {
|
|
219
|
+
bytes = toBytes(payload);
|
|
220
|
+
} catch {
|
|
221
|
+
end(true);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
queue.push(bytes);
|
|
141
225
|
};
|
|
142
226
|
const onParticipantDisconnected = (...args) => {
|
|
143
|
-
if (args[0]?.identity === peerId) end();
|
|
227
|
+
if (args[0]?.identity === peerId) end(false);
|
|
144
228
|
};
|
|
145
|
-
const
|
|
229
|
+
const onDisconnected = () => end(false);
|
|
230
|
+
/** `tellPeer`: it ended on this side, and the room is still there to say so. */
|
|
231
|
+
const end = (tellPeer) => {
|
|
146
232
|
if (ended) return;
|
|
147
233
|
ended = true;
|
|
148
234
|
room.off(ROOM_EVENT.dataReceived, onData);
|
|
149
235
|
room.off(ROOM_EVENT.participantDisconnected, onParticipantDisconnected);
|
|
150
|
-
room.off(ROOM_EVENT.disconnected,
|
|
236
|
+
room.off(ROOM_EVENT.disconnected, onDisconnected);
|
|
151
237
|
queue.done();
|
|
152
238
|
closedResolve();
|
|
239
|
+
wakeDrainWaiters();
|
|
240
|
+
if (tellPeer) room.localParticipant.publishData(/* @__PURE__ */ new Uint8Array(0), {
|
|
241
|
+
reliable: true,
|
|
242
|
+
destinationIdentities: [peerId],
|
|
243
|
+
topic: closeTopic
|
|
244
|
+
}).catch(() => void 0);
|
|
153
245
|
};
|
|
154
246
|
room.on(ROOM_EVENT.dataReceived, onData);
|
|
155
247
|
room.on(ROOM_EVENT.participantDisconnected, onParticipantDisconnected);
|
|
156
|
-
room.on(ROOM_EVENT.disconnected,
|
|
248
|
+
room.on(ROOM_EVENT.disconnected, onDisconnected);
|
|
157
249
|
return {
|
|
158
250
|
send(bytes) {
|
|
159
251
|
if (ended) return;
|
|
252
|
+
if (bytes.byteLength > maxFrameBytes) {
|
|
253
|
+
end(true);
|
|
254
|
+
throw new RangeError(`webrun-streams-signaling: a ${bytes.byteLength}-byte packet exceeds maxFrameBytes (${maxFrameBytes})`);
|
|
255
|
+
}
|
|
256
|
+
const size = bytes.byteLength;
|
|
257
|
+
inFlight += size;
|
|
160
258
|
room.localParticipant.publishData(bytes, {
|
|
161
259
|
reliable: true,
|
|
162
|
-
destinationIdentities: [peerId]
|
|
163
|
-
|
|
260
|
+
destinationIdentities: [peerId],
|
|
261
|
+
topic
|
|
262
|
+
}).then(() => void 0, () => end(true)).finally(() => {
|
|
263
|
+
inFlight -= size;
|
|
264
|
+
wakeDrainWaiters();
|
|
265
|
+
});
|
|
164
266
|
},
|
|
165
267
|
recv: queue.recv,
|
|
166
268
|
closed,
|
|
167
|
-
close: end
|
|
269
|
+
close: () => end(true),
|
|
270
|
+
get bufferedAmount() {
|
|
271
|
+
return inFlight;
|
|
272
|
+
},
|
|
273
|
+
whenDrained() {
|
|
274
|
+
if (ended || inFlight <= 262144) return Promise.resolve();
|
|
275
|
+
return new Promise((resolve) => drainWaiters.add(resolve));
|
|
276
|
+
}
|
|
168
277
|
};
|
|
169
278
|
}
|
|
170
279
|
//#endregion
|
|
@@ -235,6 +344,24 @@ function messageTargetOverByteChannel(channel, options = {}) {
|
|
|
235
344
|
try {
|
|
236
345
|
channel.close();
|
|
237
346
|
} catch {}
|
|
347
|
+
},
|
|
348
|
+
get bufferedAmount() {
|
|
349
|
+
return channel.bufferedAmount ?? 0;
|
|
350
|
+
},
|
|
351
|
+
whenDrained() {
|
|
352
|
+
if (life.signal.aborted || !channel.whenDrained) return Promise.resolve();
|
|
353
|
+
const signal = life.signal;
|
|
354
|
+
return new Promise((resolve, reject) => {
|
|
355
|
+
const done = () => {
|
|
356
|
+
signal.removeEventListener("abort", done);
|
|
357
|
+
resolve();
|
|
358
|
+
};
|
|
359
|
+
signal.addEventListener("abort", done);
|
|
360
|
+
channel.whenDrained?.().then(done, (err) => {
|
|
361
|
+
signal.removeEventListener("abort", done);
|
|
362
|
+
reject(err);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
238
365
|
}
|
|
239
366
|
}
|
|
240
367
|
};
|
|
@@ -284,6 +411,10 @@ var PeerConnection = class {
|
|
|
284
411
|
getRole() {
|
|
285
412
|
return this.role;
|
|
286
413
|
}
|
|
414
|
+
/** Whether the remote description (the peer's offer or answer) has been applied. */
|
|
415
|
+
hasRemoteDescription() {
|
|
416
|
+
return this.remoteDescriptionSet;
|
|
417
|
+
}
|
|
287
418
|
getDataChannel() {
|
|
288
419
|
return this.dataChannel;
|
|
289
420
|
}
|
|
@@ -490,6 +621,7 @@ var PeerConnection = class {
|
|
|
490
621
|
const cleanup = () => {
|
|
491
622
|
this.off("open", onOpen);
|
|
492
623
|
this.off("error", onError);
|
|
624
|
+
this.off("stateChange", onState);
|
|
493
625
|
clearTimeout(timer);
|
|
494
626
|
};
|
|
495
627
|
const onOpen = () => {
|
|
@@ -502,8 +634,14 @@ var PeerConnection = class {
|
|
|
502
634
|
cleanup();
|
|
503
635
|
reject(error);
|
|
504
636
|
};
|
|
637
|
+
const onState = (state) => {
|
|
638
|
+
if (state !== "closed") return;
|
|
639
|
+
cleanup();
|
|
640
|
+
reject(/* @__PURE__ */ new Error("Connection closed before the data channel opened"));
|
|
641
|
+
};
|
|
505
642
|
this.on("open", onOpen);
|
|
506
643
|
this.on("error", onError);
|
|
644
|
+
this.on("stateChange", onState);
|
|
507
645
|
const timer = setTimeout(() => {
|
|
508
646
|
cleanup();
|
|
509
647
|
reject(/* @__PURE__ */ new Error(`Connection timeout after ${timeout}ms`));
|
|
@@ -549,10 +687,18 @@ var PeerManager = class {
|
|
|
549
687
|
}
|
|
550
688
|
/** Dial `peerId` and resolve with the established channel. */
|
|
551
689
|
async connect(peerId) {
|
|
690
|
+
const previous = this.connections.get(peerId);
|
|
691
|
+
if (previous) this.forget(peerId, previous);
|
|
552
692
|
const pc = this.makeConnection(peerId, "initiator");
|
|
553
693
|
const channel = pc.open();
|
|
554
|
-
|
|
555
|
-
|
|
694
|
+
try {
|
|
695
|
+
await pc.connect();
|
|
696
|
+
return await channel;
|
|
697
|
+
} catch (err) {
|
|
698
|
+
channel.catch(() => void 0);
|
|
699
|
+
this.forget(peerId, pc);
|
|
700
|
+
throw err;
|
|
701
|
+
}
|
|
556
702
|
}
|
|
557
703
|
/** Register a handler for inbound connections. Returns an unsubscribe fn. */
|
|
558
704
|
onConnection(handler) {
|
|
@@ -562,27 +708,52 @@ var PeerManager = class {
|
|
|
562
708
|
/** Tear down all connections and stop listening for signaling. */
|
|
563
709
|
close() {
|
|
564
710
|
this.unsubscribe();
|
|
565
|
-
|
|
711
|
+
const all = [...this.connections.values()];
|
|
566
712
|
this.connections.clear();
|
|
713
|
+
for (const pc of all) pc.close();
|
|
567
714
|
this.connectionHandlers.clear();
|
|
568
715
|
}
|
|
569
716
|
makeConnection(peerId, role) {
|
|
570
717
|
const pc = new PeerConnection(role, this.options);
|
|
571
718
|
pc.on("signal", (msg) => this.signaling.send(peerId, msg));
|
|
572
|
-
pc.on("close", () => this.
|
|
719
|
+
pc.on("close", () => this.forget(peerId, pc));
|
|
720
|
+
pc.on("stateChange", (state) => {
|
|
721
|
+
if (state === "failed" || state === "closed") this.forget(peerId, pc);
|
|
722
|
+
});
|
|
573
723
|
this.connections.set(peerId, pc);
|
|
574
724
|
return pc;
|
|
575
725
|
}
|
|
726
|
+
/** Close `pc` and drop it, unless a newer connection to `peerId` replaced it. */
|
|
727
|
+
forget(peerId, pc) {
|
|
728
|
+
if (this.connections.get(peerId) !== pc) return;
|
|
729
|
+
this.connections.delete(peerId);
|
|
730
|
+
pc.close();
|
|
731
|
+
}
|
|
732
|
+
fail(peerId, pc, err) {
|
|
733
|
+
const live = this.connections.get(peerId) === pc;
|
|
734
|
+
this.forget(peerId, pc);
|
|
735
|
+
if (!live) return;
|
|
736
|
+
const error = err instanceof Error ? err : new Error(String(err), { cause: err });
|
|
737
|
+
try {
|
|
738
|
+
this.options.onError?.(error, peerId);
|
|
739
|
+
} catch {}
|
|
740
|
+
}
|
|
576
741
|
onSignal(from, msg) {
|
|
577
742
|
let pc = this.connections.get(from);
|
|
743
|
+
if (pc && msg.type === "offer" && (pc.getRole() === "responder" || pc.hasRemoteDescription())) {
|
|
744
|
+
this.forget(from, pc);
|
|
745
|
+
pc = void 0;
|
|
746
|
+
}
|
|
578
747
|
if (!pc) {
|
|
579
748
|
if (msg.type !== "offer") return;
|
|
580
|
-
|
|
581
|
-
pc
|
|
749
|
+
const responder = this.makeConnection(from, "responder");
|
|
750
|
+
pc = responder;
|
|
751
|
+
responder.open().then((channel) => {
|
|
582
752
|
for (const handler of this.connectionHandlers) handler(from, channel);
|
|
583
|
-
});
|
|
753
|
+
}, (err) => this.fail(from, responder, err));
|
|
584
754
|
}
|
|
585
|
-
pc
|
|
755
|
+
const target = pc;
|
|
756
|
+
target.handleSignal(msg).catch((err) => this.fail(from, target, err));
|
|
586
757
|
}
|
|
587
758
|
};
|
|
588
759
|
//#endregion
|
|
@@ -618,13 +789,44 @@ function compressSdp(sdp) {
|
|
|
618
789
|
function expandSdp(compressed) {
|
|
619
790
|
return `${compressed.split("\n").join("\r\n")}\r\n`;
|
|
620
791
|
}
|
|
621
|
-
/**
|
|
792
|
+
/**
|
|
793
|
+
* Candidate attributes after `typ` that a connection needs: the related
|
|
794
|
+
* address of a srflx/relay candidate and the TCP type of a TCP one. Others
|
|
795
|
+
* (`generation`, `ufrag`, `network-id`, ...) are dropped to keep the QR small.
|
|
796
|
+
*/
|
|
797
|
+
const KEPT_CANDIDATE_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
798
|
+
"raddr",
|
|
799
|
+
"rport",
|
|
800
|
+
"tcptype"
|
|
801
|
+
]);
|
|
802
|
+
/** An `sdpMLineIndex` as it travels: empty for null. */
|
|
803
|
+
function indexToString(index) {
|
|
804
|
+
return index == null ? "" : String(index);
|
|
805
|
+
}
|
|
806
|
+
function indexFromString(text) {
|
|
807
|
+
if (!text) return null;
|
|
808
|
+
const index = Number.parseInt(text, 10);
|
|
809
|
+
return Number.isNaN(index) ? null : index;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Compress an ICE candidate to its essential parts. A candidate that carries
|
|
813
|
+
* attributes a connection needs (see {@link KEPT_CANDIDATE_ATTRIBUTES}) goes
|
|
814
|
+
* in the raw (`R:`) form, with only those attributes kept.
|
|
815
|
+
*/
|
|
622
816
|
function compressCandidate(candidate) {
|
|
623
817
|
const { candidate: c, sdpMid, sdpMLineIndex } = candidate;
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
818
|
+
const index = indexToString(sdpMLineIndex);
|
|
819
|
+
const match = c.match(/candidate:(\S+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+)\s+typ\s+(\S+)(.*)$/);
|
|
820
|
+
if (!match) return `R:${sdpMid ?? ""}:${index}:${c}`;
|
|
821
|
+
const [base, foundation, component, protocol, priority, ip, port, type, rest] = match;
|
|
822
|
+
const words = rest.trim().split(/\s+/).filter(Boolean);
|
|
823
|
+
const kept = [];
|
|
824
|
+
for (let i = 0; i + 1 < words.length; i += 2) if (KEPT_CANDIDATE_ATTRIBUTES.has(words[i])) kept.push(words[i], words[i + 1]);
|
|
825
|
+
if (kept.length) {
|
|
826
|
+
const head = base.slice(0, base.length - rest.length);
|
|
827
|
+
return `R:${sdpMid ?? ""}:${index}:${head} ${kept.join(" ")}`;
|
|
828
|
+
}
|
|
829
|
+
return `${foundation}|${component}|${protocol}|${priority}|${ip}|${port}|${type}|${sdpMid ?? ""}|${index}`;
|
|
628
830
|
}
|
|
629
831
|
/** Expand a compressed ICE candidate. */
|
|
630
832
|
function expandCandidate(compressed) {
|
|
@@ -633,7 +835,7 @@ function expandCandidate(compressed) {
|
|
|
633
835
|
return {
|
|
634
836
|
candidate: rest.join(":"),
|
|
635
837
|
sdpMid: sdpMid || null,
|
|
636
|
-
sdpMLineIndex:
|
|
838
|
+
sdpMLineIndex: indexFromString(sdpMLineIndexStr)
|
|
637
839
|
};
|
|
638
840
|
}
|
|
639
841
|
const parts = compressed.split("|");
|
|
@@ -642,7 +844,7 @@ function expandCandidate(compressed) {
|
|
|
642
844
|
return {
|
|
643
845
|
candidate: `candidate:${foundation} ${component} ${protocol} ${priority} ${ip} ${port} typ ${type}`,
|
|
644
846
|
sdpMid: sdpMid || null,
|
|
645
|
-
sdpMLineIndex:
|
|
847
|
+
sdpMLineIndex: indexFromString(sdpMLineIndexStr)
|
|
646
848
|
};
|
|
647
849
|
}
|
|
648
850
|
/** Create a compressed signal for QR code exchange. */
|
|
@@ -702,7 +904,6 @@ var QrSignaling = class {
|
|
|
702
904
|
/** Create an offer QR; `accept(answerQr)` finishes the handshake. */
|
|
703
905
|
async offer() {
|
|
704
906
|
const pc = new PeerConnection("initiator", this.connection);
|
|
705
|
-
const channel = pc.open();
|
|
706
907
|
await pc.connect();
|
|
707
908
|
await pc.waitForIceGathering();
|
|
708
909
|
const description = pc.getLocalDescription();
|
|
@@ -710,15 +911,22 @@ var QrSignaling = class {
|
|
|
710
911
|
return {
|
|
711
912
|
qr: encodeSignal(createCompressedSignal(this.sessionId, "initiator", description, pc.getCollectedCandidates())),
|
|
712
913
|
accept: async (answerQr) => {
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
candidate
|
|
721
|
-
|
|
914
|
+
const channel = pc.open();
|
|
915
|
+
try {
|
|
916
|
+
const parsed = parseCompressedSignal(decodeSignal(answerQr));
|
|
917
|
+
await pc.handleSignal({
|
|
918
|
+
type: "answer",
|
|
919
|
+
sdp: parsed.description.sdp
|
|
920
|
+
});
|
|
921
|
+
for (const candidate of parsed.candidates) await pc.handleSignal({
|
|
922
|
+
type: "candidate",
|
|
923
|
+
candidate
|
|
924
|
+
});
|
|
925
|
+
} catch (err) {
|
|
926
|
+
channel.catch(() => void 0);
|
|
927
|
+
pc.close();
|
|
928
|
+
throw err;
|
|
929
|
+
}
|
|
722
930
|
return channel;
|
|
723
931
|
}
|
|
724
932
|
};
|
|
@@ -830,10 +1038,10 @@ var RoomManager = class {
|
|
|
830
1038
|
} };
|
|
831
1039
|
} };
|
|
832
1040
|
}
|
|
833
|
-
/** Open a {@link ByteChannel} to a specific participant. */
|
|
834
|
-
async channelTo(peerId) {
|
|
1041
|
+
/** Open a {@link ByteChannel} to a specific participant (see {@link byteChannelFromRoom}). */
|
|
1042
|
+
async channelTo(peerId, options) {
|
|
835
1043
|
if (!this.room) throw new Error("channelTo() before join()");
|
|
836
|
-
return byteChannelFromRoom(this.room, peerId);
|
|
1044
|
+
return byteChannelFromRoom(this.room, peerId, options);
|
|
837
1045
|
}
|
|
838
1046
|
/** Leave the room: unsubscribe and disconnect. */
|
|
839
1047
|
async leave() {
|
|
@@ -847,4 +1055,4 @@ var RoomManager = class {
|
|
|
847
1055
|
}
|
|
848
1056
|
};
|
|
849
1057
|
//#endregion
|
|
850
|
-
export { DEFAULT_ICE_SERVERS, DEFAULT_MAX_MESSAGE_SIZE, PeerConnection, PeerManager, QrSignaling, ROOM_EVENT, RoomManager, byteChannelFromDataChannel, byteChannelFromRoom, createCompressedSignal, decodeSignal, encodeSignal, generateSessionId, messageTargetOverByteChannel, parseCompressedSignal };
|
|
1058
|
+
export { DEFAULT_ICE_SERVERS, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_ROOM_MAX_FRAME_BYTES, DEFAULT_ROOM_TOPIC, DRAIN_LOW_WATER, PeerConnection, PeerManager, QrSignaling, ROOM_EVENT, RoomManager, byteChannelFromDataChannel, byteChannelFromRoom, createCompressedSignal, decodeSignal, encodeSignal, generateSessionId, messageTargetOverByteChannel, parseCompressedSignal };
|
package/dist/message-target.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface ByteChannelMessageTarget {
|
|
|
19
19
|
postMessage(message: unknown): void;
|
|
20
20
|
/** Closes the channel. */
|
|
21
21
|
close(): Promise<void>;
|
|
22
|
+
/** The channel's `bufferedAmount`; 0 where it cannot tell. */
|
|
23
|
+
readonly bufferedAmount: number;
|
|
24
|
+
/**
|
|
25
|
+
* The channel's `whenDrained`: resolves once it can take more, or the pipe
|
|
26
|
+
* ended. Resolves at once over a channel without one.
|
|
27
|
+
*/
|
|
28
|
+
whenDrained(): Promise<void>;
|
|
22
29
|
};
|
|
23
30
|
/** Aborts when the channel closes. Pass it as `overPipe`'s `signal`. */
|
|
24
31
|
signal: AbortSignal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-target.d.ts","sourceRoot":"","sources":["../src/message-target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAAkB,CAAC;AAExD,qGAAqG;AACrG,MAAM,WAAW,wBAAwB;IACvC,sGAAsG;IACtG,MAAM,EAAE;QACN,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;QAC5D,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;QAC/D,6DAA6D;QAC7D,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;QACpC,0BAA0B;QAC1B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"message-target.d.ts","sourceRoot":"","sources":["../src/message-target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAAkB,CAAC;AAExD,qGAAqG;AACrG,MAAM,WAAW,wBAAwB;IACvC,sGAAsG;IACtG,MAAM,EAAE;QACN,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;QAC5D,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;QAC/D,6DAA6D;QAC7D,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;QACpC,0BAA0B;QAC1B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QACvB,8DAA8D;QAC9D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;QAChC;;;WAGG;QACH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B,CAAC;IACF,wEAAwE;IACxE,MAAM,EAAE,WAAW,CAAC;IACpB,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO,GACxC,wBAAwB,CA+E1B"}
|
|
@@ -32,6 +32,8 @@ export declare class PeerConnection {
|
|
|
32
32
|
constructor(role: PeerRole, options?: WebRtcConnectionOptions);
|
|
33
33
|
getState(): ConnectionState;
|
|
34
34
|
getRole(): PeerRole;
|
|
35
|
+
/** Whether the remote description (the peer's offer or answer) has been applied. */
|
|
36
|
+
hasRemoteDescription(): boolean;
|
|
35
37
|
getDataChannel(): RTCDataChannel | null;
|
|
36
38
|
on<K extends keyof PeerConnectionEvents>(event: K, listener: PeerConnectionEvents[K]): this;
|
|
37
39
|
off<K extends keyof PeerConnectionEvents>(event: K, listener: PeerConnectionEvents[K]): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-connection.d.ts","sourceRoot":"","sources":["../src/peer-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;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AAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI,CAQ1F;IAED,GAAG,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI,CAG3F;IAED,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,cAAc;IA0DtB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,QAAQ;IAOhB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB7B;IAED,uDAAuD;IACjD,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe3D;YAEa,WAAW;YAeX,YAAY;YASZ,eAAe;YAaf,wBAAwB;IAOtC;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBzC;IAED,mDAAmD;IACnD,mBAAmB,IAAI,kBAAkB,GAAG,IAAI,CAM/C;IAED,qDAAqD;IACrD,sBAAsB,IAAI,YAAY,EAAE,CAEvC;IAED;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAsC3B;IAED,kDAAkD;IAClD,KAAK,IAAI,IAAI,CAWZ;CACF"}
|
package/dist/peer-manager.d.ts
CHANGED
|
@@ -9,7 +9,16 @@
|
|
|
9
9
|
* and the ByteChannel result are new.
|
|
10
10
|
*/
|
|
11
11
|
import type { ByteChannel, SignalingTransport, WebRtcConnectionOptions } from "./types.js";
|
|
12
|
-
export type PeerManagerOptions = WebRtcConnectionOptions
|
|
12
|
+
export type PeerManagerOptions = WebRtcConnectionOptions & {
|
|
13
|
+
/**
|
|
14
|
+
* Called when a connection fails with no caller to tell: a signal it
|
|
15
|
+
* rejects (an offer during glare, malformed SDP or candidates), or an
|
|
16
|
+
* inbound connection whose channel never opens. The connection has already
|
|
17
|
+
* been closed and forgotten, so the peer can dial again. Errors are dropped
|
|
18
|
+
* when unset. A failed `connect()` rejects instead.
|
|
19
|
+
*/
|
|
20
|
+
onError?: (error: Error, peerId: string) => void;
|
|
21
|
+
};
|
|
13
22
|
export declare class PeerManager {
|
|
14
23
|
private readonly signaling;
|
|
15
24
|
private readonly options;
|
|
@@ -24,6 +33,9 @@ export declare class PeerManager {
|
|
|
24
33
|
/** Tear down all connections and stop listening for signaling. */
|
|
25
34
|
close(): void;
|
|
26
35
|
private makeConnection;
|
|
36
|
+
/** Close `pc` and drop it, unless a newer connection to `peerId` replaced it. */
|
|
37
|
+
private forget;
|
|
38
|
+
private fail;
|
|
27
39
|
private onSignal;
|
|
28
40
|
}
|
|
29
41
|
//# sourceMappingURL=peer-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-manager.d.ts","sourceRoot":"","sources":["../src/peer-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,WAAW,EAEX,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"peer-manager.d.ts","sourceRoot":"","sources":["../src/peer-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,WAAW,EAEX,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,kBAAkB,GAAG,uBAAuB,GAAG;IACzD;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IACjE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAwD;IAC3F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IAEzC,YAAY,SAAS,EAAE,kBAAkB,EAAE,OAAO,GAAE,kBAAuB,EAI1E;IAED,8DAA8D;IACxD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAclD;IAED,6EAA6E;IAC7E,YAAY,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAG3E;IAED,kEAAkE;IAClE,KAAK,IAAI,IAAI,CAMZ;IAED,OAAO,CAAC,cAAc;IAatB,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,IAAI;IAUZ,OAAO,CAAC,QAAQ;CA0BjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qr-signaling.d.ts","sourceRoot":"","sources":["../src/qr-signaling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAKpB,0CAA0C;AAC1C,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;
|
|
1
|
+
{"version":3,"file":"qr-signaling.d.ts","sourceRoot":"","sources":["../src/qr-signaling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAKpB,0CAA0C;AAC1C,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAwGD,uDAAuD;AACvD,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,kBAAkB,EAC/B,UAAU,EAAE,YAAY,EAAE,GACzB,gBAAgB,CAQlB;AAED,iCAAiC;AACjC,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,kBAAkB,CAAC;IAChC,UAAU,EAAE,YAAY,EAAE,CAAC;CAC5B,CAWA;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAG7D;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAI9D;AAED,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,uBAAuB,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IAErD,YAAY,OAAO,GAAE,kBAAuB,EAG3C;IAED,YAAY,IAAI,MAAM,CAErB;IAED,qEAAqE;IAC/D,KAAK,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;KAAE,CAAC,CA+BrF;IAED,8EAA8E;IACxE,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,CAAC,CAuB3E;CACF"}
|
package/dist/room-manager.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* injected via {@link RoomManagerOptions.roomFactory} (production:
|
|
11
11
|
* `() => new Room()`), so this module never hard-imports it.
|
|
12
12
|
*/
|
|
13
|
+
import { type ByteChannelFromRoomOptions } from "./byte-channel.js";
|
|
13
14
|
import type { ByteChannel, RoomManagerOptions } from "./types.js";
|
|
14
15
|
export declare class RoomManager {
|
|
15
16
|
private readonly options;
|
|
@@ -23,8 +24,8 @@ export declare class RoomManager {
|
|
|
23
24
|
join(room: string): Promise<void>;
|
|
24
25
|
/** Observe participant identities: those already present, then joiners. */
|
|
25
26
|
participants(): AsyncIterable<string>;
|
|
26
|
-
/** Open a {@link ByteChannel} to a specific participant. */
|
|
27
|
-
channelTo(peerId: string): Promise<ByteChannel>;
|
|
27
|
+
/** Open a {@link ByteChannel} to a specific participant (see {@link byteChannelFromRoom}). */
|
|
28
|
+
channelTo(peerId: string, options?: ByteChannelFromRoomOptions): Promise<ByteChannel>;
|
|
28
29
|
/** Leave the room: unsubscribe and disconnect. */
|
|
29
30
|
leave(): Promise<void>;
|
|
30
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-manager.d.ts","sourceRoot":"","sources":["../src/room-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"room-manager.d.ts","sourceRoot":"","sources":["../src/room-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,0BAA0B,EAAuB,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EAAE,WAAW,EAAY,kBAAkB,EAAuB,MAAM,YAAY,CAAC;AAGjG,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,IAAI,CAAyB;IAErC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,IAAI,CAA6C;IACzD,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAElD,YAAY,OAAO,EAAE,kBAAkB,EAEtC;IAED,sEAAsE;IAChE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBtC;IAED,2EAA2E;IAC3E,YAAY,IAAI,aAAa,CAAC,MAAM,CAAC,CAyCpC;IAED,8FAA8F;IACxF,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,WAAW,CAAC,CAG1F;IAED,kDAAkD;IAC5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ3B;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export type ByteChannel = {
|
|
|
18
18
|
recv: AsyncIterable<Uint8Array>;
|
|
19
19
|
closed: Promise<void>;
|
|
20
20
|
close(): void;
|
|
21
|
+
/** Bytes sent and not yet written out, where the transport can tell. */
|
|
22
|
+
readonly bufferedAmount?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves once the transport can take more (`bufferedAmount` at most a
|
|
25
|
+
* low-water mark) or the channel closed. Absent where it cannot tell.
|
|
26
|
+
*/
|
|
27
|
+
whenDrained?(): Promise<void>;
|
|
21
28
|
};
|
|
22
29
|
/** WebRTC peer role in the connection. */
|
|
23
30
|
export type PeerRole = "initiator" | "responder";
|
|
@@ -143,6 +150,7 @@ export interface RoomLocalParticipantLike {
|
|
|
143
150
|
publishData(data: Uint8Array, opts?: {
|
|
144
151
|
reliable?: boolean;
|
|
145
152
|
destinationIdentities?: string[];
|
|
153
|
+
topic?: string;
|
|
146
154
|
}): Promise<void>;
|
|
147
155
|
}
|
|
148
156
|
export interface RoomLike {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,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