The following example shows how RTCRtpScriptTransformer.readable
is piped through a TransformStream
to RTCRtpScriptTransformer.writable
.
addEventListener("rtctransform", (event) => {
let transform;
// Select a transform based on passed options
if (event.transformer.options.name == "senderTransform")
transform = createSenderTransform(); // A TransformStream
else if (event.transformer.options.name == "receiverTransform")
transform = createReceiverTransform(); // A TransformStream
else return;
// Pipe frames from the readable to writeable through TransformStream
event.transformer.readable
.pipeThrough(transform)
.pipeTo(event.transformer.writable);
});
The code implements a handler for the rtctransform
event, which is fired at the global worker object on construction of the corresponding RTCRtpScriptTransform
, and when new frames are enqueued for processing. event.transformer
is the RTCRtpScriptTransformer
that has the writable
and readable
properties.
An different TransformStream
is created to process outgoing and incoming frames, using createSenderTransform()
or createReceiverTransform()
, respectively (implementations not shown). The event handler chooses the correct transform stream to use based on options passed through from the RTCRtpScriptTransform
constructor and assigns it to transform
.
The code calls ReadableStream.pipeThrough()
on the readable
to pipe encoded frames through the selected TransformStream
, and then ReadableStream.pipeTo()
to pipe them to the RTCRtpScriptTransformer.writable
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3