{"size": 2186, "ext": "js", "max_stars_repo_path": "src/js/bundle.js", "max_stars_repo_name": "AthenaHack/FrontEnd", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/bundle.js", "max_issues_repo_name": "AthenaHack/FrontEnd", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/bundle.js", "max_forks_repo_name": "AthenaHack/FrontEnd", "max_forks_repo_forks_event_min_datetime": "2018-10-28T17:41:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-28T17:41:49.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.325, "max_line_length": 145, "alphanum_fraction": 0.6134492223}
/*
Modules
*/
global.jQuery = require('jquery');
const $ = require('jquery');
const foundation = require('../../node_modules/foundation-sites/dist/js/foundation.js');
const vid = require('capture-video-frame');

$(document).foundation();

console.log("Started");

// Video Capture
$('#captureButton').click(function() {
  console.log("Click!");
  setInterval(function() {
    var frame = vid.captureVideoFrame('myvid', 'png');
    $('#myimg').attr('src', frame.dataUri);

    // Upload the image...
    var formData = new FormData();
    formData.append('file', frame.blob, 'my-screenshot.' + frame.format);

    postImage(frame.blob);
  }, 3000);
});

function postImage(img) {
  $(function() {
    $.ajax({
      url: "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.1/Prediction/1b2d3c17-e84b-4769-a621-a568c861c644/image/nostore?",
      beforeSend: function(xhrObj){
        // Request headers
        xhrObj.setRequestHeader("Content-Type","multipart/form-data");
        xhrObj.setRequestHeader("Prediction-key","1520f4222658422aa646244d79a66ef7");
      },
      type: "POST",
      processData: false,
      // Request body
      data: img,
    })
    .done(function(data) {
      console.log("success");
      var prob = data.Predictions[0].Probability;
      console.log(data);
      $('#mydata').text(prob);
      if (prob > 0.9) {
        $.ajax({
          url: "/alert",
          type: "POST"
        }).done(function() {
          alert("SHOOTER DETECTED");
        });
      }

    })
    .fail(function(data) {
      console.log("error");
      console.log(data);
    });
  });
}

// URI to Image Converter
function convertURIToImageData(URI) {
  return new Promise(function(resolve, reject) {
    if (URI == null) return reject();
    var canvas = document.createElement('canvas'),
    context = canvas.getContext('2d'),
    image = new Image();
    image.addEventListener('load', function() {
      canvas.width = image.width;
      canvas.height = image.height;
      context.drawImage(image, 0, 0, canvas.width, canvas.height);
      resolve(context.getImageData(0, 0, canvas.width, canvas.height));
    }, false);
    image.src = URI;
  });
}
