I had the same situation. So I used this technique.
(01) replace the local stream with the new video constraints.
(02) replaced the sender track with the new stream track.
function gotLocalStream(mediaStream) {
localVideo.srcObject = mediaStream;
const track = mediaStream.getVideoTracks()[0];
const constraints = track.getConstraints();
changePeerTrack()
};
async function startMyLocalStream(constraints){
return new Promise((resolve,reject)=>{
try{
if (localStream) {
localStream.getTracks().forEach(track => {
track.stop();
});
}
navigator.mediaDevices.getUserMedia(constraints)
.then(gotLocalStream)
.then(()=>{
resolve(true)
})
.catch(e => {
mediaError('getUserMedia', e.message, e.name);
});
}
catch (e){
//todo over constraints error
console.error(e);
reject(e);
}
})
}
function changePeerTrack(){
if(localPeerConnection){
localStream.getTracks().forEach( (track)=>{
var sender = localPeerConnection.getSenders().find(function(s) {
return s.track.kind == track.kind;
});
sender.replaceTrack(track);
});
}
}
/**
* change the video quality
**/
let constraints = {
video: {width: {exact: 1280}, height: {exact: 720}, facingMode: "user"}
}
startMyLocalStream(constraints)
It worked for me.
You can check your browser compatibilities here