WebRTC:一对一audio呼叫不在不同的机器上工作

我正在尝试使用webRTC(使用websockets发送信号)实现一对一的audio通话。 但是,当我尝试在一个系统使用多个选项卡的铬(本地主机)时,它的工作原理。 当我尝试从另一台机器上打我的服务器时,它会进行初始握手,但是不会发生呼叫。

但是,当我尝试更改标签,并更改约束video约束。 即使我们试图从其他机器访问(即video通话),它也能正常工作。

我最初认为这是因为如果防火墙,但当video通话工作,我感到困惑。

这是我的代码:

// Constraints to get audio stream only $scope.constraints = { audio: { mandatory: { googEchoCancellation: true }, optional: [] }, video:false }; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; // success Callback of getUserMedia(), stream variable is the audio stream. $scope.successCallback = function (stream) { if (window.URL) { myVideo.src = window.URL.createObjectURL(stream); // converting media stream to Blob URL. } else { myVideo.src = stream; } //attachMediaStream(audioTag, stream); localStream = stream; if (initiator) maybeStart(); else doAnswer(); }; // failure Callback of getUserMedia() $scope.failureCallback = function (error) { console.log('navigator.getUserMedia Failed: ', error); }; var initiator, started = false; $("#call").click(function () { socket.emit("message", undefined); initiator = true; navigator.getUserMedia($scope.constraints, $scope.successCallback, $scope.failureCallback); }); var channelReady = false; socket.on('message', function (data) { channelReady = true; if (data) { if (data.type === 'offer') { if (!initiator) { $("#acceptCall").show(); $("#acceptCall").click(function(){ if (!initiator && !started) { var pc_config = { iceServers: [ { url: "stun:stun.l.google.com:19302" }, { url: "turn:numb.viagenie.ca", credential: "drfunk", username: "toadums@hotmail.com"} ] }; pc = new webkitRTCPeerConnection(pc_config); pc.onicecandidate = onIceCandidate; pc.onaddstream = onRemoteStreamAdded; } pc.setRemoteDescription(new RTCSessionDescription(data)); $scope.acceptCall(); }); } } else if (data.type === 'answer' && started) { pc.onaddstream = onRemoteStreamAdded; pc.setRemoteDescription(new RTCSessionDescription(data)); } else if (data.type === 'candidate' && started) { var candidate = new RTCIceCandidate({ sdpMLineIndex: data.label, candidate: data.candidate }); pc.addIceCandidate(candidate); } else if (data.type === 'bye' && started) { console.log("Bye"); } } }); function onRemoteStreamAdded(event) { othersVideo.src = URL.createObjectURL(event.stream); }; var sdpConstraints = { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': false } }; function doAnswer() { pc.addStream(localStream); pc.createAnswer(gotDescription,null,sdpConstraints); } function gotDescription(desc) { pc.setLocalDescription(desc); socket.send(desc); } function maybeStart() { if (!started && localStream && channelReady) createPeerConnection(); pc.addStream(localStream); started = true; if (initiator) doCall(); } $scope.acceptCall = function () { navigator.getUserMedia($scope.constraints, $scope.successCallback, $scope.failureCallback); } function createPeerConnection() { var pc_config = { iceServers: [ { url: "stun:stun.l.google.com:19302" }, { url: "turn:numb.viagenie.ca", credential: "drfunk", username: "toadums@hotmail.com"} ] }; pc = new webkitRTCPeerConnection(pc_config); pc.onicecandidate = onIceCandidate; console.log("Created RTCPeerConnnection with config:\n" + " \"" + JSON.stringify(pc_config) + "\"."); }; function doCall() { $scope.caller = true; pc.createOffer(setLocalAndSendMessage,null,sdpConstraints); }; function setLocalAndSendMessage(sessionDescription) { pc.setLocalDescription(sessionDescription); socket.send(sessionDescription); } function onIceCandidate(event) { if (event.candidate) { socket.emit('message', { type: 'candidate', label: event.candidate.sdpMLineIndex, id: event.candidate.sdpMid, candidate: event.candidate.candidate }); } else { console.log("End of candidates."); } }