RTCRtpTransceiver.direction

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

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 currentDirection property.

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

RTCRtpSender 的行为 RTCRtpReceiver 的行为
"sendrecv" 可以发送 RTP 数据,如果另一个对等节点接受了连接,且至少有一个 sender 的处于编码状态,则发送数据。 可以接收 RTP 数据,如果有其他的对等节点接受数据,则接收数据。
"sendonly" 可以发送 RTP 数据,如果另一个对等节点接受了连接,且至少有一个 sender 的处于编码状态,则发送数据。 可以接收 RTP 数据,无论如何都不会接收数据。
"recvonly" 可以发送 RTP 数据,无论如何都不会发送数据。 可以接收 RTP 数据,如果有其他的对等节点接受数据,则接收数据。
"inactive" 可以发送 RTP 数据,无论如何都不会发送数据。 可以接收 RTP 数据,无论如何都不会接收数据。

异常

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 negotiationneeded 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

规范

Specification
WebRTC: Real-Time Communication in Browsers
# dom-rtcrtptransceiver-direction

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
direction
"stopped" value

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

参见