RTCTransformEvent
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
TheRTCTransformEvent
of theWebRTC API represent an event that is fired in a dedicated worker when an encoded frame has been queued for processing by aWebRTC Encoded Transform.
The interface has atransformer
property that exposes a readable stream and a writable stream.A worker should read encoded frames fromtransformer.readable
, modify them as needed, and write them totransformer.writable
in the same order and without any duplication.
At time of writing there is just one event based onRTCTransformEvent
:rtctransform
.
Instance properties
SinceRTCTransformEvent
is based onEvent
, its properties are also available.
RTCTransformEvent.transformer
Read onlyReturns the
RTCRtpScriptTransformer
associated with the event.
Transform event types
There is only one type of transform event.
rtctransform
Thertctransform
event is fired at the worker global scope on construction of an associatedRTCRtpScriptTransform
, and whenever a new encoded video or audio frame is enqueued for processing.
You can add artctransform
event listener to be notified when the new frame is available using eitherDedicatedWorkerGlobalScope.addEventListener()
or theonrtctransform
event handler property.
Example
This example creates an event listener for thertctransform
event.
The example assumes we have aTransformStream
with anoptions
object passed from aRTCRtpScriptTransform
constructor in the main-thread.The code at the end shows how the stream is piped through the transform stream from thereadable
to thewritable
.
addEventListener("rtctransform", (event) => { let transform; // Select a transform based on passed options if (event.transformer.options.name === "senderTransform") { transform = createSenderTransform(); // A TransformStream (not shown) } else if (event.transformer.options.name === "receiverTransform") { transform = createReceiverTransform(); // A TransformStream (not shown) } // Pipe frames from the readable to writeable through TransformStream event.transformer.readable .pipeThrough(transform) .pipeTo(event.transformer.writable);});
Note that this code is part of a more complete example provided inUsing WebRTC Encoded Transforms.
Specifications
Specification |
---|
WebRTC Encoded Transform # rtctransformevent |