title: "what is the proper way to disconnect peers using simple-peer.js library and stop streaming between those peers? "
body: <p>i hope y'all will be fine,</p>
  
  <p>I am a beginner in webRTC sorry if my question feels like a noob one but i was wondering that is there any proper way to close the connection among peers especially using simple-peer.js,  looking forward for your awesome replies</p>
  
  <p>here is my sample react code,</p>
  
  <pre><code> if (navigator.getUserMedia) {
              navigator.getUserMedia({ audio: { echoCancellation: true }, video: true }, stream =&gt; {
  
                  let peer = new Peer({
                      initiator: this.props.isInitiator,
                      stream
                  });
  
                  this.localStream.current.srcObject = stream;
                  this.localStream.current.play();
  
                  peer.on('signal', (data) =&gt; {
                      socket.emit('offer', { data: JSON.stringify(data), conversation_id: this.props.conversation_id })
                  });
  
                  socket.on('offer', (data) =&gt; {
                      peer.signal(JSON.parse(data))
                  })
  
                  socket.on('DESTROY-VIDEO-CALL-SESSION', () =&gt; {
                      stream.getTracks().forEach(track =&gt; track.stop());
                      peer.removeAllListeners();
                      peer.destroy();
                  });
  
                  peer.on('stream', (streamData) =&gt; {
                      this.remoteStream.current.srcObject = streamData;
                      this.remoteStream.current.play();
                  });
  
                  this.setState({
                      endCall: () =&gt; {
                          socket.emit('VIDEO-CALL-ENDED', this.props.conversation_id);
                      }
                  })
  
              }, error =&gt; {
                  alert('Please allow video and audio permission to make this call')
              });
  }
  </code></pre>