我应该通过哪些 WebRTC 约束和选项才能获得 Firefox 和 Google Chrome 之间的互操作性
-
21-12-2019 - |
题
我正在为 LAN 构建一个聊天应用程序。我使用 WebRTC,但无法让 Firefox 和 Google Chrome 进行互操作。我不知道应该传递给 RTCPeerConnection createOffer/createAnswer 的确切参数。
我做了下面的测试 火狐31 和 谷歌浏览器 36 在同一台计算机上 Fedora Linux 20
RTCPeerConnection 创建如下: pc = new RTCPeerConnection(null, RTC_PC_OPTIONS);
答案/报价的创建方式如下: pc.createOffer(onsuccess, onfail, CONSTRAINTS);
我的问题是:哪些参数(RTC_PC_OPTIONS
和 CONSTRAINTS
)我应该通过以获得两个浏览器之间的互操作性吗?
测试1
RTC_PC_OPTIONS = undefined
CONSTRAINTS = undefined
FFx2FFx FFx2Chrome Chrome2FFx Chrome2Chrome
------- ---------- ---------- -------------
dataChannel setup ok ok ok ok
dataChannel send/recv ok ok ok ok
Video stream ok ok err [1] ok
测试2
MDN recomands this value for RTC_PC_OPTIONS
RTC_PC_OPTIONS = {
optional: [
{DtlsSrtpKeyAgreement: true},
{RtpDataChannels: true}
]
};
CONSTRAINTS = undefined
FFx2FFx FFx2Chrome Chrome2FFx Chrome2Chrome
------- ---------- ---------- -------------
dataChannel setup ok err [2] err [3] ok
dataChannel send/recv ok - - ok
Video stream ok - - err [4]
^~~~~~~~~~~~~~~~^
^
i used datachannel to do signaling for the video TRCPeerConnection,
that is why these were not tested
测试3
RTC_PC_OPTIONS = undefined
CONSTRAINTS = { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }
FFx2FFx FFx2Chrome Chrome2FFx Chrome2Chrome
------- ---------- ---------- -------------
dataChannel setup ok ok ok err [5]
dataChannel send/recv ok ok ok -
Video stream err [6] ok err [6] -
- Chrome 创建报价并将其发送给 FFx,FFx 接收报价,创建答案并将其发送给 chrome,
chrome 收到答案。但onaddstream在firefox中没有触发
- chrome收到FFx发送的offer后,会在控制台记录一个错误:
Failed to set remote offer sdp: Session error code: ERROR_CONTENT. Session error description: Failed to set data send codecs..
- Chrome 发送报价,FFx 发送答案,
chrome 收到此错误: Failed to parse SessionDescription. m=application 35224 RTP/SAVPF Expects at least 4 fields.
FFx 收到此错误: ICE failed, see about:webrtc for more details
在 about:webrtc
:
Local candidate Remote candidate ICE State Priority Nominated Selected
a.b.c.d:35224/udp(host) a.b.c.d:45895/udp(host) frozen 9115005270282354000
- Chrome_1 收到错误:
Uncaught NetworkError: Failed to execute 'send' on 'RTCDataChannel': Could not send data
chrome_2 收到错误:
Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added.
- 调用者发送报价,被调用者收到错误:
Failed to set remote offer sdp: Session error code: ERROR_CONTENT. Session error description: Failed to set data send codecs.
- 像[1]一样,一切正常,但 onaddstream 未触发
解决方案
所以,有几件事:
- MDN 页面显示的 RTPDataChannels 已经非常过时了(让我知道 URL)。Firefox 和 Chrome 现在都支持规范 DataChannels。我相信 DTLSSRTPKeyAgreement 也是如此
- 确保在 createOffer() 之前调用 createDataChannel()
- 是纯视频还是视频+音频?如果我记得没有触发 onAddStream,我们最近修复了纯视频流的错误。这可以解释 1 和[6]我认为。看 错误 1035067, ,登陆 Nightly 和 Aurora (FF33);我已经要求升级到 Beta/32
- 如果我记得的话,“需要 4 个字段”问题是 Firefox 中的错误 - 您运行的是哪个版本?我们确实在 30(?) 中修复了一个错误,其中末尾有一个不需要的空格,导致 chrome 拒绝它 - 他们修补了它以避免它,我们修复了它。
尝试使用 FF Beta 和 Nightly (http://nightly.mozilla.org/)。当您报告此类问题时,请注明您使用的浏览器版本!:-)