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。离线整理了版式、链接和媒体显示。
