<commit_before>/*
 * Say Cheese!
 * <NAME>, 2012
 * http://leemach.in, http://new-bamboo.co.uk
 *
 * Minimal javascript library for integrating a webcam and snapshots into your app.
 *
 * Handles starting up the webcam and rendering the element, and also capturing shots
 * in a separate canvas element.
 *
 * Depends on video and canvas, and of course, getUserMedia. It's unlikely to work
 * on anything but the newest browsers.
 */

var SayCheese = (function() {

  var SayCheese;
  
  /* Check for the existence of the userMedia feature. */
  function userMediaFeatureExists() {
    return 'getUserMedia' in navigator ||  'webkitGetUserMedia' in navigator;
  };

  SayCheese = function SayCheese() {
    if (userMediaFeatureExists()) {
      // do something
    } else {
      // should make this more graceful in future
      throw new Error("getUserMedia() is not supported in this browser");
    }

    return this;
  };

  /* the getUserMedia function is different on Webkit browsers, so we have to
   * do a bit of faffing about to make sure we call the right one.
   */
  SayCheese.prototype.getUserMedia = function getUserMedia(success, error) {
    return (function() {
      // have to re-bind navigator because the context will be lost, and
      // we'll get illegal invocation errors.
      return (navigator.getUserMedia || navigator.webkitGetUserMedia).bind(navigator);
    })().call(this, { video: true }, success, error);
  };

  /* Webkit behaves differently as regards getting a proper video URL. So we have
   * to have another check for it.
   */
  SayCheese.prototype.getStreamUrl = function getStreamUrl(stream) {
    url = (function() {
      return (window.URL || window.webkitURL);
    })();
    
    return (url && url.createObjectURL) ? url.createObjectURL(stream) : stream;
  };

  /* The viewfinder is the element we use to preview the webcam stream */
  SayCheese.prototype.createVideo = function() {
    element = document.createElement('video');
    element.autoplay = true;
    return element;
  };

  /* The canvas is used for taking 'photos' */
  SayCheese.prototype.createCanvas = function() {
    element = document.createElement('canvas');
    return element;
  };

  /* Start up the stream, if possible */
  SayCheese.prototype.start = function start() {
    var success = function userMediaSuccess(stream) {
     this.viewfinder = this.createVideo();
     this.viewfinder.src = this.getStreamUrl(stream);
     document.appendChild(this.viewfinder);
    }.bind(this);

    /* error is also called when someone denies access */
    var error = function userMediaError() {
      console.log('nooooooooo');
    }.bind(this);

    this.getUserMedia(success, error);<commit_msg>More cleanup, making function declarations explicit<commit_after>/*
 * Say Cheese!
 * <NAME>, 2012
 * http://leemach.in, http://new-bamboo.co.uk
 *
 * Minimal javascript library for integrating a webcam and snapshots into your app.
 *
 * Handles starting up the webcam and rendering the element, and also capturing shots
 * in a separate canvas element.
 *
 * Depends on video and canvas, and of course, getUserMedia. It's unlikely to work
 * on anything but the newest browsers.
 */

var SayCheese = (function() {

  var SayCheese;
  
  /* Check for the existence of the userMedia feature. */
  function userMediaFeatureExists() {
    return 'getUserMedia' in navigator ||  'webkitGetUserMedia' in navigator;
  };

  SayCheese = function SayCheese() {
    if (userMediaFeatureExists()) {
      // do something
    } else {
      // should make this more graceful in future
      throw new Error("getUserMedia() is not supported in this browser");
    }

    return this;
  };

  /* the getUserMedia function is different on Webkit browsers, so we have to
   * do a bit of faffing about to make sure we call the right one.
   */
  SayCheese.prototype.getUserMedia = function getUserMedia(success, error) {
    return (function() {
      // have to re-bind navigator because the context will be lost, and
      // we'll get illegal invocation errors.
      return (navigator.getUserMedia || navigator.webkitGetUserMedia).bind(navigator);
    })().call(this, { video: true }, success, error);
  };

  /* Webkit behaves differently as regards getting a proper video URL. So we have
   * to have another check for it.
   */
  SayCheese.prototype.getStreamUrl = function getStreamUrl(stream) {
    url = (function() {
      return (window.URL || window.webkitURL);
    })();
    
    return (url && url.createObjectURL) ? url.createObjectURL(stream) : stream;
  };

  /* The viewfinder is the element we use to preview the webcam stream */
  SayCheese.prototype.createVideo = function createVideo() {
    element = document.createElement('video');
    element.autoplay = true;
    return element;
  };

  /* The canvas is used for taking 'photos' */
  SayCheese.prototype.createCanvas = function createCanvas() {
    element = document.createElement('canvas');
    return element;
  };

  /* Start up the stream, if possible */
  SayCheese.prototype.start = function start() {
    var success = function userMediaSuccess(stream) {
     this.viewfinder = this.createVideo();
     this.viewfinder.src = this.getStreamUrl(stream);
     document.appendChild(this.viewfinder);
    }.bind(this);

    /* error is also called when someone denies access */
    var error = function error() {
      console.log('nooooooooo');
    }.bind(this);

    this.getUserMedia(success, error);
{'fraction_non_alphanumeric': 0.10667396061269147, 'fraction_numerical': 0.0014587892049598833, 'mean_word_length': 3.2453560371517027, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4460289', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1512, 'n_words': 526}