Uncaught DOMException: Failed to set local answer sdp: Called in wrong state: STATE_INPROGRESS
See original GitHub issueI am getting this error (and others) when trying to re-initialize a video chat component. I have tried all manner of clearing the peer connection and reloading it.
Everything works fine on first attempt. Any subsequent attempts fail to load and get errors.
I am also getting errors: Cannot set remote answer in state stable Error: cannot signal after peer is destroyed
My code is as follows (angular 2).
@Component(
{
selector: 'vidcall',
inputs: ['chattingWith'],
template: `
<div id="vidiv" #vidiv>
<video #youvid></video>
<video #othvid></video>
</div>
`,
styles: [`
#vidiv{
display: flex;
justify-content:space-around;
}
`]
})
export class VideoComponent implements OnDestroy {
@ViewChild('youvid') youvid: any;
@ViewChild('othvid') othvid: any;
private chattingWith: UserModel;
private peer: any;
private mediaStream: any;
constructor(private srsvc: SRSvc) { }
private sizeVid() {
let w = Math.trunc(window.innerWidth / 3);
console.log('width ', w);
this.youvid.nativeElement.width = w;
this.othvid.nativeElement.width = w;
}
@HostListener('window:resize', ['$event'])
onResize(event) {
this.sizeVid();
}
onVideoInit(init: boolean) { //
this.sizeVid();
navigator.mediaDevices.getUserMedia({
video: true,
audio: false
})
.then(mediaStream => {
this.mediaStream = mediaStream;
console.log('create new peer');
this.peer = new window.SimplePeer(
{
initiator: init,
stream: mediaStream,
trickle: true
});
this.youvid.nativeElement.srcObject = mediaStream;
this.youvid.nativeElement.play();
// exchage peer data
this.peer.on('signal', data => {
console.log('on signal - initiator:', init);
this.srsvc.sendPeerData(this.chattingWith.fbid, data); // signalr websocket
})
this.peer.on('stream', data => {
console.log('on stream - initiator:', init);
this.othvid.nativeElement.srcObject = data;
this.othvid.nativeElement.play();
})
this.peer.on('close', () => {
console.log('on close - initiator:', init);
this.peer.destroy();
this.peer = null;
this.othvid.nativeElement.srcObject = null;
})
this.srsvc.recvPeerObservable.subscribe(resp => {
console.log('recv peer data siglr - initiator:', init);
if (this.peer) {
this.peer.signal(resp.peerData)
}
})
})
.catch(err => {
console.log('Simple Peer Error', err.name + ": " + err.message);
});
}
destroy() {
console.log('destroying peer', this.peer);
if (this.peer) {
this.peer.destroy();
this.peer = null;
}
if (this.mediaStream) {
for (let track of this.mediaStream.getTracks()) {
track.stop();
}
}
if (this.youvid.nativeElement.srcObject) {
this.youvid.nativeElement.srcObject = null;
}
if (this.othvid.nativeElement.srcObject) {
this.othvid.nativeElement.srcObject = null;
}
}
ngOnDestroy() {
this.destroy();
}
}
I am trying to clear the peer/connection via the “destroy()” method, and it is being run each time this component closes.
Please tell me what I am doing wrong in terms of closing and re-initializing the peer connection.
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Failed to set local answer sdp: Called in wrong state: kStable
I have been using a similar construct to build up the WebRTC connections between sender and receiver peers, by calling the method ...
Read more >RTCPeerConnection setting offer sdp does not match the ...
I have received answer sdp by negotiating offer sdp from peer in different process, ... Failed to set remote answer sdp: Called in...
Read more >Failed to set remote answer sdp: Called in wrong state ...
Coding example for the question WebRTC - Failed to set remote answer sdp: Called in wrong state: STATE_INPROGRESS-webrtc.
Read more >3410 - Failed to set remote offer sdp: Called in wrong state
Hi Braveyao, Thanks for the response, This was the offer SDP problem, instead of answer SDP, offer SDP is sent.
Read more >RTCPeerConnection.prototype.setLocalDescription
... 'RTCPeerConnection': Failed to set local answer sdp: Called in wrong state: stable" that is not a DOMException InvalidModificationError: property "code" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m struggling with this same issue and haven’t found a solution yet.
I have a test page which is similar to this example but I’ve added two buttons. One starts and streams audio. The other stops it.
If I click start, audio streams successfully. Clicking stop does exactly that. Then when I click start again I get the same error listed above.
It almost seems that the p.destroy() function is not shutting the connection down completely.
Any thoughts or tips would be greatly appreciated. ☺ And thanks for the library @feross .
👍