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.
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 theRTCRtpReceiver
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 |
浏览器兼容性
BCD tables only load in the browser