componentDidMount() {
    // setting up webcam input
    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
      const webCamPromise = navigator.mediaDevices
        .getUserMedia({
          audio: false,
          video: {
            facingMode: "user",
            width: 800,
            height: 400
          }
        })
        .then(stream => {
          window.stream = stream;
          this.videoRef.current.srcObject = stream;
          return new Promise((resolve, reject) => {
            this.videoRef.current.onloadedmetadata = () => {
              resolve();
            };
          });
        });
      // load model and call the detectFrame function
      const modelPromise = cocoSsd.load();
      Promise.all([modelPromise, webCamPromise])
        .then(values => {
          this.detectFrame(this.videoRef.current, values[0]);
        })
        .catch(error => {
          console.error(error);
        });
    }
  }
/**
   * ComponentDidMount Runs when the component is first loaded
   * Setting up webcam input, loading model and calling DetectFrame which is
   * a recursive function so that it keeps detecting throughout the test
   */
ComponentDidMount Runs when the component is first loaded
Setting up webcam input, loading model and calling DetectFrame which is
a recursive function so that it keeps detecting throughout the test
ComponentDidMount Runs when the component is first loaded Setting up webcam input loading model and calling DetectFrame which is a recursive function so that it keeps detecting throughout the test
componentDidMount() {
    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
      const webCamPromise = navigator.mediaDevices
        .getUserMedia({
          audio: false,
          video: {
            facingMode: "user",
            width: 800,
            height: 400
          }
        })
        .then(stream => {
          window.stream = stream;
          this.videoRef.current.srcObject = stream;
          return new Promise((resolve, reject) => {
            this.videoRef.current.onloadedmetadata = () => {
              resolve();
            };
          });
        });
      const modelPromise = cocoSsd.load();
      Promise.all([modelPromise, webCamPromise])
        .then(values => {
          this.detectFrame(this.videoRef.current, values[0]);
        })
        .catch(error => {
          console.error(error);
        });
    }
  }
componentDidMount ( ) { if ( navigator . mediaDevices && navigator . mediaDevices . getUserMedia ) { const webCamPromise = navigator . mediaDevices . getUserMedia ( { audio : false , video : { facingMode : "user" , width : 800 , height : 400 } } ) . then ( stream => { window . stream = stream ; this . videoRef . current . srcObject = stream ; return new Promise ( ( resolve , reject ) => { this . videoRef . current . onloadedmetadata = ( ) => { resolve ( ) ; } ; } ) ; } ) ; const modelPromise = cocoSsd . load ( ) ; Promise . all ( [ modelPromise , webCamPromise ] ) . then ( values => { this . detectFrame ( this . videoRef . current , values [ 0 ] ) ; } ) . catch ( error => { console . error ( error ) ; } ) ; } }
ComponentDidMount Runs when the component is first loaded
 Setting up webcam input, loading model and calling DetectFrame which is
 a recursive function so that it keeps detecting throughout the test
ComponentDidMount Runs when the component is first loaded Setting up webcam input loading model and calling DetectFrame which is a recursive function so that it keeps detecting throughout the test
// setting up webcam input // load model and call the detectFrame function