I recently restructured my working webRtc code, replacing some deprecated APIs and some other restructuring. It continues to work in Chrome but not in Firefox anymore. The basic structure of the code is shown below:
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) {...});
The remote video is not seen in Firefox, irrespective of whether the Firefox browser is a caller or a callee. I suspect that it has to do with some sequencing of event handlers but cannot locate which one...