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 枚举。

The transceiver's current direction is indicated by the currentDirection 特性。

句法

var direction = RTCRtpTransceiver.direction
					

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

RTCRtpTransceiverDirection type is an enumeration of string values. Each describes how the transceiver's associated RTCRtpSender and RTCRtpReceiver behave as shown in the table below.

RTCRtpSender behavior RTCRtpReceiver behavior
"sendrecv" Offers to send RTP data, and will do so if the other peer accepts the connection and at least one of the sender's encodings is active 1 . Offers to receive RTP data, and does so if the other peer accepts.
"sendonly" Offers to send RTP data, and will do so if the other peer accepts the connection and at least one of the sender's encodings is active 1 . Does not offer to receive RTP data and will not do so.
"recvonly" Does not offer to send RTP data, and will not do so. Offers to receive RTP data, and will do so if the other peer offers.
"inactive" Does not offer to send RTP data, and will not do so. Does not offer to receive RTP data and will not do so.

[1] To determine if a sender has at least one active encoding, the 用户代理 gets its parameters using RTCRtpSender.getParameters() , then looks at the parameters' encodings property; if any of the listed encodings has its active 特性被设为 true , the sender has an active encoding.

异常

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

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

用法注意事项

Setting the direction

When you change the value of direction 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

direction 用于 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
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpTransceiver.direction' in that specification.
候选推荐

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
direction Chrome 69 Edge 不支持 No Firefox 59 IE 不支持 No Opera 不支持 No Safari Yes WebView Android 69 Chrome Android 69 Firefox Android 59 Opera Android 不支持 No Safari iOS Yes Samsung Internet Android 10.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: