我如何在没有 localStream 的情况下创建对等连接? [英] How i create peer-connection without localStream?
问题描述
我只想实现一个客户端发送 mediaSteam,另一个接收 mediaSteam.所以接收器客户端不需要添加 localSteam.and 我只是编码 pc.addStream(null).但不起作用.我如何通过 WebRtc 实现这一点?
I just want achieve one client send mediaSteam and another received the mediaSteam. So Receiver client needn't add localSteam.and i just code pc.addStream(null).But not work. How i achieve this by WebRtc?
推荐答案
不要使用 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:
您需要指定这些 RTCOfferOptions 到 createOffer代码>:
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.
这篇关于我如何在没有 localStream 的情况下创建对等连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!