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

InvalidStateError Peer connection is closed #30

@unit-002

Description

@unit-002

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions