The rtctransform
event is fired at a worker's DedicatedWorkerGlobalScope
object when an encoded video or audio frame has been queued for processing by a WebRTC Encoded Transform.
The event's transformer
property returns a RTCRtpScriptTransformer
that exposes the ReadableStream
on which the frame is queued, and a WritableStream
where the frame can be written to inject it back into the WebRTC pipeline.
This event is not cancellable and does not bubble.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener("rtctransform", (event) => {});
onrtctransform = (event) => {};
This interface also inherits properties from its parent, Event
.
-
RTCTransformEvent.transformer
Read only
-
Returns the RTCRtpScriptTransformer
associated with the event.
The following code snippet shows a handler for the rtctransform
event in the worker, added to the global scope using addEventListener()
. The event.transformer
is a RTCRtpScriptTransformer
, the worker side counterpart to RTCRtpScriptTransform
.
addEventListener("rtctransform", (event) => {
let transform;
if (event.transformer.options.name == "senderTransform")
transform = createSenderTransform();
else if (event.transformer.options.name == "receiverTransform")
transform = createReceiverTransform();
else return;
event.transformer.readable
.pipeThrough(transform)
.pipeTo(event.transformer.writable);
});
The rtctransform
event is fired when an encoded frame is enqueued on the RTCRtpScriptTransformer
and just once when the transformer's corresponding RTCRtpScriptTransformer
is constructed. The code first determines what transform to apply using name
value passed in the options (this allows RTCRtpScriptTransform
instances added to the incoming and outgoing WebRTC pipelines to share a single worker). Encoded frames are then piped from the readable, through the selected transform TransformStream
, to a writeable. The actual tranforming code is not shown.
Note that this code is part of a more complete example provided in Using WebRTC Encoded Transforms.