大网数据广告活动
Web 标准与前端开发

DedicatedWorkerGlobalScope: rtctransform event

· 52CE 我爱测

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 API/Using Encoded Transforms.

WebRTCdedicated

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 API/Using Encoded Transforms.

The event's RTCTransformEvent.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.

Syntax

Use the event name in EventTarget/addEventListener:

addEventListener("rtctransform", (event) => { })

Alternatively, assign to the event handler property of the interface:

onrtctransform = (event) => { }

Event type

A RTCTransformEvent. Inherits from Event.

RTCTransformEvent

Example

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;
  // 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 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 transforming code is not shown.

Note that this code is part of a more complete example provided in WebRTC API/Using Encoded Transforms.

Specifications

Browser compatibility

See also

  • WebRTC API/Using Encoded Transforms

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。