WebRTC和RTCPeerConnection适用于Chrome,但不适用于Firefox

时间:2017-12-08 14:17:49

标签: google-chrome firefox webrtc

我正在两个浏览器之间进行视频通信,最近我遇到了Firefox的奇怪行为。

我有一个非常简单的RTCPeerConnection示例:

https://jsfiddle.net/twardakm/bokj6gca/

它在Chrome上运行得非常好,但在Firefox上则不然。请注意,这些浏览器使用不同的事件来启动流( ontrack vs onaddstream )。要在jsfiddle中测试特定浏览器上的代码,您必须对另一个部分进行注释。

var pc1 = new RTCPeerConnection(),
pc2 = new RTCPeerConnection();

var add = (pc, can) => can && pc.addIceCandidate(can).catch(failed);
pc1.onicecandidate = e => add(pc2, e.candidate);
pc2.onicecandidate = e => add(pc1, e.candidate);

//      FIREFOX
pc2.ontrack = function(e) {
    console.log("ontrack");
    v2.srcObject = e.streams[0];
    v2.play();
};

//      CHROME
/*pc2.onaddstream = function (e) {
    console.log("onaddstream");
    v2.srcObject = e.stream;
    v2.play();
};*/

pc1.oniceconnectionstatechange = e => log(pc1.iceConnectionState);

function start() {
    navigator.mediaDevices.getUserMedia({
            video: true,
            audio: false
        })
        .then(stream => pc1.addStream(v1.srcObject = stream))
        .then(() => pc1.createOffer())
        .then(offer => pc1.setLocalDescription(offer))
        .then(() => pc2.setRemoteDescription(pc1.localDescription))
        .then(() => pc2.createAnswer())
        .then(answer => pc2.setLocalDescription(answer))
        .then(() => pc1.setRemoteDescription(pc2.localDescription))
        .catch(failed);
}

function onTrack() {

};

var log = msg => div.innerHTML += "<p>" + msg + "</p>";
var failed = e => log(e + ", line " + e.lineNumber);

我现在正在研究这个问题几天,而且我的想法已经用完了。我相信有些基本的东西我只是看不到:)

提前感谢您的帮助!

编辑:这是我的日志:webrtc

Exit UDP socket connected
UDP socket error:Internal error at /build/firefox-Pa1eQI/firefox-57.0~b9/dom/network/UDPSocketParent.cpp:283 this=0x7fc9db14cc00
/build/firefox-Pa1eQI/firefox-57.0~b9/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:617 function nr_socket_multi_tcp_listen failed with error 3
ICE(PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): failed to create passive TCP host candidate: 3
/build/firefox-Pa1eQI/firefox-57.0~b9/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:617 function nr_socket_multi_tcp_listen failed with error 3
ICE(PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): failed to create passive TCP host candidate: 3
Exit UDP socket connected
UDP socket error:Internal error at /build/firefox-Pa1eQI/firefox-57.0~b9/dom/network/UDPSocketParent.cpp:283 this=0x7fc9e69ba400
/build/firefox-Pa1eQI/firefox-57.0~b9/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:617 function nr_socket_multi_tcp_listen failed with error 3
ICE(PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): failed to create passive TCP host candidate: 3
ICE(PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no streams with non-empty check lists
ICE(PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no streams with pre-answer requests
ICE(PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953848021 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no checks to start
ICE(PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no streams with non-empty check lists
ICE(PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no streams with pre-answer requests
ICE(PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/)): peer (PC:1512747953846868 (id=2147483738 url=https://fiddle.jshell.net/twardakm/bokj6gca/show/):default) no checks to start

+++++++ END ++++++++

0 个答案:

没有答案