简体   繁体   English

Firefox WebRTC信号通知DOMException无法解析SDP

[英]Firefox WebRTC signaling DOMException Failed to parse SDP

I am using WebRTC data channels for networking in an HTML5 game. 我正在使用WebRTC数据通道在HTML5游戏中进行联网。 Though WebRTC can be used P2P the topology for this project is centralized client-server. 尽管可以使用WebRTC进行P2P,但该项目的拓扑结构是集中的客户端-服务器。 The server is a Node.js process that acts as a WebRTC peer. 该服务器是充当WebRTC对等方的Node.js进程。 The clients are browsers that make a 1-1 connection with the server. 客户端是与服务器建立1-1连接的浏览器。

I am using the simple-peer library to handle WebRTC on both client and server. 我正在使用简单对等库在客户端和服务器上处理WebRTC。 On the Node.js server I using the wrtc module as the peer connection instance. 在Node.js服务器上,我使用wrtc模块作为对等连接实例。 For the signaling handshake, I am using signalhub on both client and server. 对于信号交换 ,我在客户端和服务器上都使用signalhub

The following is some fake code that demonstrates how the handshake is setup 以下是一些伪代码,演示了如何设置握手

//client
var peer = new SimplePeer({initiator: true});
peer.on('signal', (signalPayload) => signalHub.broadcast('client_signal', signalPayload));
signalHub.subscribe('server_signal', function(signalPayload){ peer.signal(signalPayload) });

//server
signalHub.subscribe('client_signal', (signalPayload) => {
    peer = new Simplepeer({});
    peer.signal(signalPayload);

    peer.on('signal', (signalPayload) => signalHub.broadcast('server_signal', signalPayload));
})

The current setup Consistently works as expected in Chrome... 当前设置始终可以在Chrome中正常运行...

Firefox fails to establish a connection. Firefox无法建立连接。 Simple-peer's error handler throws an error peer.on('error', (err) => {}) 简单对等方的错误处理程序会引发错误对等方peer.on('error', (err) => {})

DOMException: "Failed to parse SDP: SDP Parse Error on line 6: No webrtc-datachannel token in m= media line, parse failed.

The specific signal payload that triggers this error looks like: 触发此错误的特定信号有效负载如下所示:

v=0
o=- 1575807233894551963 2 IN IP4 127.0.0.1
s=-
t=0 0
a=msid-semantic: WMS
m=application 0 UDP/DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=mid:0
a=sctpmap:5000 webrtc-datachannel 1024

This is the payload that the server sends to the client it is an 'answer' payload. 这是服务器发送给客户端的有效负载,它是“答案”有效负载。

The following is a complete comparison of Chrome vs Firefox offer and answer payloads 以下是Chrome与Firefox的offeranswer有效负载的完整比较

  • Chrome Offer to Node.js Chrome提供给Node.js
{
type: "offer",
sdp:
"v=0
o=- 5121147169778109884 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=ice-ufrag:CmIA
a=ice-pwd:jHCWR4JJquU/r8KXtP0cQ9YN
a=ice-options:trickle
a=fingerprint:sha-256 0C:AC:DB:40:8E:AD:58:D8:09:3B:66:94:63:1B:00:D0:09:BD:F3:72:BF:29:66:53:94:9B:67:22:A9:27:A0:35
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024
"
}
  • Firefox Offer to Node.js Firefox提供给Node.js
{
 type: "offer",
sdp:
"v=0
o=mozilla...THIS_IS_SDPARTA-64.0.2 6450781105440687594 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 54:5D:CF:E6:B6:B5:9B:60:C3:AB:F3:EC:5A:62:18:5E:13:F2:1A:23:86:03:BA:9D:D0:EA:67:7B:1C:5C:0A:2A\r\na=group:BUNDLE 0\r\na=ice-options:trickle
a=msid-semantic:WMS *
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=sendrecv
a=ice-pwd:c2217ee835bac1bdc0a765ebf1b5de2c
a=ice-ufrag:b0ceda3e
a=mid:0
a=setup:actpass
a=sctp-port:5000
a=max-message-size:1073741823"
}
  • Node.js Answer in response to Chrome Offer Node.js回答Chrome优惠
"v=0
o=- 4547471447226747141 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 62951 DTLS/SCTP 5000
c=IN IP4 192.168.1.159
b=AS:30
a=candidate:105744546 1 udp 2122260223 192.168.1.159 62951 typ host generation 0 network-id 1 network-cost 50
a=ice-ufrag:taPA
a=ice-pwd:Q/W3D4wgrRqMrfVT51yO3i5T
a=fingerprint:sha-256 2A:3C:A3:64:92:7D:32:F5:AB:5F:69:1F:C1:76:82:4C:97:A3:FE:CA:70:C5:E3:FA:FC:C0:11:FC:E3:DB:D5:1C
a=setup:active
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024"
  • Node.js answer in response to Firefox offer Node.js回答Firefox的提议
"v=0
o=- 1575807233894551963 2 IN IP4 127.0.0.1
s=-
t=0 0
a=msid-semantic: WMS
m=application 0 UDP/DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=mid:0
a=sctpmap:5000 webrtc-datachannel 1024"

We can see that the Firefox answer payload looks odd. 我们可以看到Firefox的答案负载看起来很奇怪。 It is missing the fingerprint and other a= fields. 它缺少fingerprint和其他a=字段。 Additionally, it does include the m= field which is odd that it would then throw the DOMException claiming it can't be parsed. 另外,它确实包含m=字段,这很奇怪,然后它抛出DOMException声明无法解析它。

Non-browser end-point doesn't support v21 SCTP offer, giving malformed answer 非浏览器端点不支持v21 SCTP报价,给出格式错误的答案

It looks like the webrtc code on your server (the remote end-point in your setup) doesn't support the newer m=application format Firefox's offer uses, and produces an incorrect answer in that case, which Firefox chokes on, as Firefox expects an answer in the new format to its new-format offer: 看起来您服务器上的webrtc代码(设置中的远程端点)不支持Firefox提供的较新的m=application格式,并且在这种情况下会产生错误的答案,这正是Firefox期望的,Firefox对此感到窒息以新格式为其新格式产品提供的答案:

  • Firefox Offer: Firefox优惠:
 m=application 9 UDP/DTLS/SCTP webrtc-datachannel a=sctp-port:5000 

Firefox (63+) here is using a newer version 21+ of the SCTP SDP draft , from 2017. Firefox(63+)使用的是2017年以来SCTP SDP草案的21+较新版本

Chrome uses the older version 05 of the SCTP SDP draft , from 2013: Chrome使用了2013年以来的SCTP SDP草案的旧版本05

  • Chrome Offer: Chrome优惠:
 m=application 9 DTLS/SCTP 5000 a=sctpmap:5000 webrtc-datachannel 1024 

Unfortunately, this is a breaking change. 不幸的是,这是一个重大变化。 The old parser expects to find a number ( 5000 ) in the m-line, where the new parser expects webrtc-datachannel . 旧解析器希望在m行中找到一个数字( 5000 ),新解析器希望在其中webrtc-datachannel Read more about it here . 在此处了解更多信息。

When Firefox is the answerer, it'll respond to both (old answer to old offer, new answer to new), great! 当Firefox作为回答者时,它会同时响应这两个问题(旧提议的旧答案,新提议的新答案),太好了! But when Firefox is the offerer—which is the case here—it sends out a new offer and expects a new answer in return (Chrome, BTW, knows how to answer new offers, even though it does not yet emit them itself). 但是,当Firefox是要约人时(在这种情况下),它发出一个新要约并期望得到一个新的答案(Chrome,BTW知道如何回答新要约,即使它本身并未发出请求)。

Workarounds 解决方法

Ideally, you'll want to update your server to emit the right answer. 理想情况下,您需要更新服务器以发出正确的答案。 In lieu of that, it should work if you make Firefox the answerer. 取而代之的是,如果将Firefox作为应答器,它应该可以工作。

If that's not an option, it might work to munge the SDP between the two formats: You'd need to alter Firefox's offer to the old format before the server sees it, and its answer back to the new format before setting it with setRemoteDescription in Firefox. 如果这不是一个选择,则可以在两种格式之间调整SDP:在服务器看到Firefox之前,您需要将Firefox的报价更改为旧格式,然后在使用setRemoteDescription对其进行设置之前,将其答案恢复为新格式。火狐浏览器。

Based on the comment below the question I think it is now clear that the wrtc Node module does not understand the new SCTP SDP format used by newer versions of Firefox. 基于下面问题的评论,我认为现在很清楚wrtc Node模块不理解较新版本的Firefox使用的新SCTP SDP格式。 The wrtc module needs to be fixed then and updated. 然后需要修复wrtc模块并进行更新。

I see you opened https://github.com/node-webrtc/node-webrtc/issues/483 already. 我看到您已经打开https://github.com/node-webrtc/node-webrtc/issues/483 I think that is way to get this fixed/working. 我认为这是解决问题的方法。

The only way to get such an answer from Chrome is if you use its proprietary rtp datachannel like this: 从Chrome获得此类答案的唯一方法是,如果您使用其专有的rtp数据通道,如下所示:

var pc = new RTCPeerConnection(null, {optional: [{RtpDataChannels: true}]});
pc.setRemoteDescription({type: 'offer', sdp: 'v=0\no=mozilla...THIS_IS_SDPARTA-64.0.2 6450781105440687594 0 IN IP4 0.0.0.0\ns=-\nt=0 0\na=sendrecv\na=fingerprint:sha-256 54:5D:CF:E6:B6:B5:9B:60:C3:AB:F3:EC:5A:62:18:5E:13:F2:1A:23:86:03:BA:9D:D0:EA:67:7B:1C:5C:0A:2A\r\na=group:BUNDLE 0\r\na=ice-options:trickle\na=msid-semantic:WMS *\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\nc=IN IP4 0.0.0.0\na=sendrecv\na=ice-pwd:c2217ee835bac1bdc0a765ebf1b5de2c\na=ice-ufrag:b0ceda3e\na=mid:0\na=setup:actpass\na=sctp-port:5000\na=max-message-size:1073741823\n'})

followed by createAnswer. 其次是createAnswer。

Don't do this. 不要这样 The rtp data channel is inferior to standard data channel in all aspects. rtp数据通道在所有方面均低于标准数据通道。 Don't use it. 不要使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM