-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbidirectionalstreams_serial.js
34 lines (32 loc) · 1.11 KB
/
bidirectionalstreams_serial.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
WebTransport = WebTransport || QuicTransport;
if (!('outgoingBidirectionalStreams' in WebTransport.prototype)) {
Object.defineProperty(WebTransport.prototype, 'outgoingBidirectionalStreams', {
get() {
const transport = this;
if (!this._outgoingBidirectionalStreams) {
this._outgoingBidirectionalStreams = new WritableStream({
async write(stream) {
const {writable, readable} = await transport.createBidirectionalStream();
await stream.readable.pipeTo(writable);
await readable.pipeTo(stream.writable);
}
});
}
return this._outgoingBidirectionalStreams;
}
});
}
if (!('bidirectionalStreams' in WebTransport.prototype)) {
Object.defineProperty(WebTransport.prototype, 'bidirectionalStreams', {
get() {
const transport = this;
if (!this._bidirectionalStreams) {
this._bidirectionalStreams = Object.freeze({
readable: transport.incomingBidirectionalStreams,
writable: transport.outgoingBidirectionalStreams
});
}
return this._bidirectionalStreams;
}
});
}