RTCPeerConnection.createAnswer() - Failed to set remote video description send parameters for m-section with mid='2'

SuperYegorius

New Member
I'm developing WebRTC javascript application. This is what I do to reproduce this error: I have Chrome and Mozilla browsers where I run test. Chrome browser starts audio call to Mozilla. This works fine! Then I try to share my screen from Chrome to Mozilla with this code:

if(avStream.getVideoTracks().length>0) {
myConnection.getSenders().forEach(async sender => {
if(sender.track && sender.track.kind === 'video')await sender.replaceTrack(tracks[0]);
} );
}
else {
sStream.getVideoTracks().forEach( function (track) {
myConnection.addTrack( track, sStream );
} );
}

and:
myConnection.onnegotiationneeded = e => myConnection.createOffer().then(offer => {
send( { type: "offer", offer: offer } )
myConnection.setLocalDescription( offer )
} )

and it works! But if then I would try to share my screen back from Mozilla to Chrome I receive this error in Chrome: Failed to set remote video description send parameters for m-section with mid='2' in this part of code:

function onOffer(offer, name) {
connectedUser = name;

myConnection.setRemoteDescription(new RTCSessionDescription(offer));

myConnection.createAnswer(function (answer) {
console.log('Sending An Answer');
myConnection.setLocalDescription(answer);
send({ type: "answer", answer: answer });
}, function (error) {
alert("oops...error"); //<!-- this alert fires up!
console.log(error)
});
}

But this is not all! If I try to do everything again - I mean if I reload both browser windows, make an audio call between Chrome and Mozilla and start screen share from Mozilla to Chrome (in the first description I tried to screen share from Chrome to Mozilla) and then will start screen share back from Chrome to Mozilla everything works fine! Can anyone explain to me what is wrong and why I cant screen share back from Mozilla to Chrome in the first case!
Any help appreciated! Thanks!
 
Top