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

RTCTransformEvent

· 52CE 我爱测

The **`RTCTransformEvent`** of the WebRTC API represent an event that is fired in a dedicated worker when an encoded frame has been queued for processing by a WebRTC Encoded Transform.

WebRTC

The RTCTransformEvent of the WebRTC API represent an event that is fired in a dedicated worker when an encoded frame has been queued for processing by a WebRTC Encoded Transform.

The interface has a RTCTransformEvent.transformer property that exposes a readable stream and a writable stream. A worker should read encoded frames from transformer.readable, modify them as needed, and write them to transformer.writable in the same order and without any duplication.

At time of writing there is just one event based on RTCTransformEvent: DedicatedWorkerGlobalScope.rtctransform_event.

Instance properties

Since RTCTransformEvent is based on Event, its properties are also available.

  • RTCTransformEvent.transformer
    • : Returns the RTCRtpScriptTransformer associated with the event.

Transform event types

There is only one type of transform event.

rtctransform

The DedicatedWorkerGlobalScope.rtctransform_event event is fired at the worker global scope on construction of an associated RTCRtpScriptTransform, and whenever a new encoded video or audio frame is enqueued for processing.

You can add a rtctransform event listener to be notified when the new frame is available using either EventTarget.addEventListener or the onrtctransform event handler property.

Example

This example creates an event listener for the DedicatedWorkerGlobalScope.rtctransform_event event.

The example assumes we have a TransformStream with an options object passed from a RTCRtpScriptTransform constructor in the main-thread. The code at the end shows how the stream is piped through the transform stream from the readable to the writable.

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 in Using WebRTC Encoded Transforms.

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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