WebRTC设置远程描述错误

3
我希望测试我C++应用程序和浏览器javascript之间的连接。目前没有服务器参与,我正在使用标准IO进行信令处理。问题在于当我尝试将由本地应用程序生成的SDP传递给javascript创建答案时,我会收到错误信息(在setRemoteDescription调用时生成)。
OperationError: Failed to parse SessionDescription. a=sctpmap:5000 webrtc-datachannel 1024 Invalid SDP line.

这里是JavaScript代码:
function input() {
  var stdin = document.getElementById('stdin');
  var input = stdin.value;
  stdin.value = '';
  return input;
}
function answer() {
  peerConnection = new RTCPeerConnection(pcConfig);
  peerConnection.onicecandidate = onIceCandidate;
  peerConnection.ondatachannel  = onDataChannel;
  peerConnection.oniceconnectionstatechange = onIceConnectionStateChange;
  var buff = input();
  var sdpOffer = {
    type: "offer",
    sdp: buff
  }
  peerConnection.setRemoteDescription(sdpOffer).then(() => onSetRemoteSuccess(peerConnection), onSetSessionDescriptionError);
  peerConnection.createAnswer().then(onCreateAnswerSuccess, onCreateSessionDescriptionError);
}

以及样例SDP:

v=0
o=- 8612289788290620730 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 49168 DTLS/SCTP 5000
c=IN IP4 77.114.92.160
a=candidate:1774547698 1 udp 2113937151 77.114.92.160 49168 typ host generation 0 network-cost 50
a=ice-ufrag:yzpQ
a=ice-pwd:UDjI4/ifwEV4mbZnfjbJrRW1
a=ice-options:trickle
a=fingerprint:sha-256 3C:60:34:BA:24:44:36:72:10:DF:E4:8C:00:0B:C1:3D:87:12:65:4D:AC:FF:09:F2:DD:22:BD:A8:3C:90:F1:F8
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024

两个本地应用程序之间的连接正常工作,所以我猜问题出在 JavaScript 代码中。我会感激任何建议。


它在Firefox中运行良好,问题出现在Google Chrome中。有什么建议吗? - Fake
1
你找到解决办法了吗?我也遇到了同样的问题。 - umarbilal
我最终使用socket.io创建了一个简单的服务器,并且它运行良好。我不记得具体问题是什么,但将服务器作为信令服务涉及到了帮助。 - Fake
1个回答

1
在最后一行a=sctpmap:5000 webrtc-datachannel 1024后添加一个换行符。

验证了在Chrome中缺少换行符可能会导致问题! - Mohammad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接