我最近重新构建了我的webRtc代码,取代了一些已弃用的API和其他一些重组。它继续在Chrome中运行,但不再在Firefox中运行。代码的基本结构如下所示:
navigator.mediaDevices.getUserMedia ({ audio: true, video: true })
.then(function(localMediaStream) {
//Show local media
document.getElementById("myVideoMedia").srcObject = localMediaStream;
//create peerConnection
peerConnection = new RTCPeerConnection({
"iceServers": [{"url": "stun:stun.l.google.com:19302"}]
});
peerConnection.ontrack = function(event) {
remoteStream = event.streams[0];
document.getElementById("remoteVideoElement").srcObject = remoteStream;
};
peerConnection.onicecandidate = function (event) {
if (event.candidate != null) {
//Send ice candidate to peer connection..
}
};
peerConnection.addStream(localMediaStream);
//Show remote media
document.getElementById("remoteVideoElement").srcObject = remoteStream;
//If caller, send video invite to callee to do the above in its browser
//if callee, having received video invite, send message to caller to request sdpOffer
});
//When (on caller's side) request to send sdpOffer is received
var sdpOffer = new RTCSessionDescription (offer);
peerConnection.setLocalDescription (sdpOffer)
.then (function() {
//send sdpOffer
});
//When (on callee's side) sdpOffer is received
peerConnection.setRemoteDescription(remoteSdpOffer)
.then(function() {
peerConnection.createAnswer()
.then(function(sdpAnswer) {
var sdpAnswer = new RTCSessionDescription(sdpAnswer);
//send sdpAnswer
peerConnection.setLocalDescription(sdpAnswer)
.then(function(){
...
})
//When ICE candidate is received
peerConnection.addIceCandidate(new RTCIceCandidate(iceCandidate))
.then(function() { //console.log("Remote Ice candidate added");
})
.catch(function(err) {...});
无论Firefox浏览器是呼叫者还是被叫者,都不会在Firefox中看到远程视频。我怀疑它与事件处理程序的一些排序有关但无法找到哪一个......