跳到主要内容

4.2.3. setDirection

4.2.3. setDirection

setDirection 方法设置收发器的方向, 这会影响未来对 createOffer 和 createAnswer 的调用中关联的 "m=" 部分的 direction 属性。direction 的允许值为 "recvonly", "sendrecv", "sendonly" 和 "inactive", 镜像 [RFC4566] 第 6 节中定义的同名方向属性。

在创建 offer 时, 收发器方向直接反映在输出中, 即使对于重新 offer 也是如此。在创建 answer 时, 收发器方向与提供的方向相交, 如下面第 5.3 节所述。

请注意, 虽然 setDirection 立即设置收发器的 direction 属性(第 4.2.4 节), 但此属性不会立即影响收发器的 RtpSender 是否会发送或其 RtpReceiver 是否会接收。生效的方向由 currentDirection 属性表示, 仅在应用 answer 时更新。