Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

InvalidStateError Peer connection is closed #30

Open
unit-002 opened this issue Mar 14, 2021 · 0 comments
Open

InvalidStateError Peer connection is closed #30

unit-002 opened this issue Mar 14, 2021 · 0 comments

Comments

@unit-002
Copy link

unit-002 commented Mar 14, 2021

I am having this error when I hangup the media stream if I don't use

document.location.reload(true);

but currently I use history.push('/') when I cancel the stream to route to the home page. Though stream gets stopped or cancelled but I get this error.

Uncaught (in promise) DOMException: Peer connection is closed

I am using the same hangup code to cancel the stream except the document.location.reload(true);

async function hangUp(e) {
  const tracks = document.querySelector('#localVideo').srcObject.getTracks();
  tracks.forEach(track => {
    track.stop();
  });

  if (remoteStream) {
    remoteStream.getTracks().forEach(track => track.stop());
  }

  if (peerConnection) {
    peerConnection.close();
  }

  document.querySelector('#localVideo').srcObject = null;
  document.querySelector('#remoteVideo').srcObject = null;

  history.push('/');
}

How do I properly cancel the stream and route to another page without getting this error?

I am using this for my ReactJS project and the browser I'm currently using is firefox.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant