title: Closing webcam without reloading
body: <p>I'm a a beginner in web development and I’m working on a video chat app built with <code>create-react-app</code>. I’m using <code>recordRTC</code> library for record and stream from users’s webcam and microphone.
  When I stop recording, I also would like to close the webcam.</p>
  
  <pre><code>import React, { Component } from "react";
  import RecordRTC from "recordrtc";
  
  const captureUserMedia = callback =&gt; {
    const params = { audio: true, video: true };
    navigator.mediaDevices
      .getUserMedia(params)
      .then(callback)
      .catch((error) =&gt; {
        console.error(JSON.stringify(error));
      });
  };
  
  export default class Recorder extends Component {
    constructor(props) {
      super(props);
      this.recordVideo = null;
      this.videoRef = React.createRef();
    }
  
    componentDidMount = () =&gt; {
      captureUserMedia(stream =&gt; (this.videoRef.current.srcObject = stream));
    };
  
    startRecord = () =&gt; {
      captureUserMedia(stream =&gt; {
        this.recordVideo = RecordRTC(stream, { type: "video" });
        this.recordVideo.startRecording();
      });
    };
  
    stopRecord = () =&gt; {
      this.recordVideo.stopRecording();
      this.videoRef.current.srcObject.getTracks().forEach((track) =&gt; {
        track.stop();
      });
    };
      render() {
      return (
        &lt;div&gt;
          &lt;video ref={this.videoRef} autoPlay muted /&gt;
          &lt;div&gt;
            &lt;button onClick={this.startRecord}&gt;START&lt;/button&gt;
            &lt;button onClick={this.stopRecord}&gt;STOP&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      );
    }
  }
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/questions/11642926/stop-close-webcam-which-is-opened-by-navigator-getusermedia">here</a> a related post where I found this:</p>
  
  <pre><code>stream.getTracks().forEach((track) =&gt; {
      track.stop()
  })
  </code></pre>
  
  <p>This stop the stream but the red circle is still present on the navigator tab (chrome) and the webcam's light is still lightning. </p>
  
  <p>How can I do to turn off the webcam ?</p>
  
  <p>The only way i found is to force a reload but I don't really wanna do this ...</p>
  
  <p>If someone have an idea, please let me know.</p>
  
  <p>Thanks for your reply :)</p>