I am getting this error in my catch
block when I do myPeerConnection.createAnswer()
PeerConnection cannot create an answer in a state other than have-remote-offer or have-local-pranswer.
I am using socket.io as the signalling server. I am following the tutorial from MDN
Here's my code:
myPeerConnection.setRemoteDescription(desc).then(() => {
return navigator.mediaDevices.getUserMedia(mediaConstraints);
}).then((stream) => {
localStream = stream;
document.getElementById("localVideo").srcObject = localStream;
return myPeerConnection.addStream(localStream);
}).then(() => {
return myPeerConnection.createAnswer(); //No error when removed this then chain
}).then((answer) => {
return myPeerConnection.setLocalDescription(answer); // No error when removed this then chain
}).then(() => {
socket.emit('video-answer', {
sdp: myPeerConnection.localDescription
});
}).catch(handleGetUserMediaError);
The answer here didn't helped me either.
I have uploaded the whole project on Github. You can look at the script file here.
Any help is appreciated.