title: Open Close Camera with same button Javascript
body: <p>I have a problem. When I click the camera button (there is the code below) I can open the camera, but how can I turn the camera off when I click the same button.</p>
  <p>A part of my code.</p>
  <p>button :
  <code>&lt;a type=&quot;button&quot; onclick=&quot;cameraOff()&quot; name=&quot;button&quot; id=&quot;button&quot;&gt; &lt;i class=&quot;fas fa-video fa-2x cam-btn&quot;&gt;&lt;/i&gt; &lt;/a&gt; </code></p>
  <pre><code>&lt;video id=&quot;video&quot; width=&quot;640&quot; height=&quot;480&quot; autoplay&gt;&lt;/video&gt;
  
  &lt;script&gt;
      function cameraOff() {
  
          var video = document.getElementById('video');
          if (navigator.mediaDevices &amp;&amp; navigator.mediaDevices.getUserMedia) {
              navigator.mediaDevices.getUserMedia({
                  video: true
              }).then(function(stream) {
                  video.srcObject = stream;
                  video.play();
              });
          }
      }
  &lt;/script&gt;
  </code></pre>