title: capture image when clicking on the button in javascript
body: <p>I want to start camera when clicking on the button and show the preview through javascript.</p>
  
  <pre><code> function emitStream() {
      // Asking permission to get the user media.
      // If permission granted, assign the stream to the HTML 5 video element.
      navigator.webkitGetUserMedia({
          video: true,
          audio: true
      }, function(stream) {
          that._video = document.querySelector('video');
          that._video.src = window.URL.createObjectURL(stream);
      });
  
  
      function takePicture() {
          // Assigning the video stream to the canvas to create a picture.
          that._canvas = document.querySelector('canvas');
          var context = that._canvas.getContext('2d');
          context.clearRect(0, 0, 0, 0);
          context.drawImage(that._video, 0, 0, 400, 300);
      }
  }
  </code></pre>