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

RTCRtpTransceiver.direction

· 52CE 我爱测

The RTCRtpTransceiver property **`direction`** is a string which indicates the transceiver's preferred directionality. Its value must be one of the strings defined by the RTCRtpTransceiverDirection enumeration.

WebRTC

The RTCRtpTransceiver property direction is a string which indicates the transceiver's preferred directionality. Its value must be one of the strings defined by the RTCRtpTransceiverDirection enumeration.

The transceiver's current direction is indicated by the RTCRtpTransceiver.currentDirection property.

值

A String whose value is one of the strings which are a member of the RTCRtpTransceiverDirection enumerated type, indicating the transceiver's preferred direction.

<table class="standard-table"> <thead> <tr> <th scope="row">值</th> <th scope="col"><code>RTCRtpSender</code> 的行为</th> <th scope="col"><code>RTCRtpReceiver</code> 的行为</th> </tr> </thead> <tbody> <tr> <th scope="row"><code>"sendrecv"</code></th> <td> 可以发送 RTP 数据,如果另一个对等节点接受了连接,且至少有一个 sender 的处于编码状态,则发送数据。 </td> <td> 可以接收 RTP 数据,如果有其他的对等节点接受数据,则接收数据。 </td> </tr> <tr> <th scope="row"><code>"sendonly"</code></th> <td> 可以发送 RTP 数据,如果另一个对等节点接受了连接,且至少有一个 sender 的处于编码状态,则发送数据。 </td> <td><em>不</em>可以接收 RTP 数据,无论如何都不会接收数据。</td> </tr> <tr> <th scope="row"><code>"recvonly"</code></th> <td><em>不</em>可以发送 RTP 数据,无论如何都不会发送数据。</td> <td> 可以接收 RTP 数据,如果有其他的对等节点接受数据,则接收数据。 </td> </tr> <tr> <th scope="row"><code>"inactive"</code></th> <td><em>不</em>可以发送 RTP 数据,无论如何都不会发送数据。</td> <td><em>不</em>可以接收 RTP 数据,无论如何都不会接收数据。</td> </tr> </tbody> </table>

异常

When setting the value of direction, the following exceptions can occur:

  • InvalidStateError
    • : Either the receiver's RTCPeerConnection is closed or the RTCRtpReceiver is stopped.

Usage notes

Setting the direction

When you change the value of direction, an InvalidStateError exception will occur if the connection is closed or the receiver is stopped.

If the new value of direction is in fact different from the existing value, renegotiation of the connection is required, so a RTCPeerConnection/negotiationneeded_event event is sent to the RTCPeerConnection.

Effect on offers and answers

The value of direction is used by RTCPeerConnection.createOffer() or RTCPeerConnection.createAnswer() in order to generate the SDP generated by each of those methods. The SDP contains an a-line which specifies the directionality. For example, if the direction is specified as "sendrecv", the corresponding SDP a-line is:

a=sendrecv

规范

浏览器兼容性

参见

  • RTCRtpTransceiver.currentDirection

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

资料来源与适用范围

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

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

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