且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何在没有 localStream 的情况下创建对等连接?

更新时间:2022-11-02 23:06:16

不要使用 null 调用 pc.addStream.相反,只是不要调用它.

Don't call pc.addStream with null. Instead, just don't call it.

  • 当接收者也是回答者时,这就是全部.
  • 当接收者是提供者时,您需要做一些额外的工作:
  • When the receiver is also the answerer, this is all there is to it.
  • When the receiver is the offerer, you need a little extra work:

您需要指定这些 RTCOfferOptionscreateOffer代码>:

You need to specify these RTCOfferOptions to createOffer:

{ offerToReceiveVideo: true, offerToReceiveAudio: true }

原因是默认情况下,提供者只提供接收它正在发送的相同类型的流.我知道,这是一个愚蠢的默认值,但它给了报价者更多的控制权.从好的方面来说,始终指定这些选项并没有什么坏处,前提是它们符合您想要的行为.

The reason is that by default, the offerer only offers to receive the same kinds of streams it is sending. I know, a dumb default, but it gives the offerer a bit more control. On the upside, there's no harm in always specifying these options, if it matches your desired behavior.