关于RTCRtpTransceiver.direction

355 阅读1分钟

记得5年前在开发一款基于web的音频系统时,客户要求客户端只是聆听,不能发出任何udp语音包,静音包也不行,当时采用了jssip,在收取到local description的时候,自行改了sdp的内容,a=sendonly。今天看了下,其实webrtc标准已经有api可以实现,这便是RTCRtpTransceiver.direction。

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() (en-US) 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