<commit_before>document.addEventListener('DOMContentLoaded', onDOMContentLoaded, false);
var video, videoBtn, burstBtn, photoBtn;

var screenshotPreviewer;
var recordingTimer;
var recordingDurationViewer;

var localMediaStream = null;

function onDOMContentLoaded() {
  video = document.querySelector('#camera');
  videoBtn = document.querySelector('#video-button'),
  burstBtn = document.querySelector('#burst-button'),
  photoBtn = document.querySelector('#photo-button');
  screenshotPreviewer = document.querySelector('#screenshot-previewer');
  recordingDurationViewer = document.querySelector('#recording-duration');

  if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
    alert('Sorry, your browser does not support getUserMedia()');
    return false;
  }
  var constraints = { 
    audio: true, 
    video: true
  };
  navigator.mediaDevices.getUserMedia(constraints).then(function(mediaStream) {
    /* use the stream */  
    localMediaStream = mediaStream;
    video.srcObject = mediaStream;
    video.onloadedmetadata = function() {
      video.play();
    };
    // Defaults to Single Photo mode
    photoBtn.classList.add('active');
    addEventListeners();
  }).catch(handleGetUserMediaError);
}

function addEventListeners() {
  videoBtn.addEventListener('click', onVideoButtonClick, false);
  burstBtn.addEventListener('click', onBurstButtonClick, false);
  photoBtn.addEventListener('click', onPhotoButtonClick, false);
  
  screenshotPreviewer.addEventListener('transitionend', function() {
    // Resume video playback
    video.play();
    // Restore screenshot previewer
    screenshotPreviewer.style.removeProperty('visibility');
    screenshotPreviewer.style.removeProperty('background-image');
    screenshotPreviewer.classList.remove('slideLeft');
  }, false);
}

function onVideoButtonClick(e) {
  let targetClassList = videoBtn.classList;
  
  videoBtn.classList.add('active');
  burstBtn.classList.remove('active');
  photoBtn.classList.remove('active');
  
  if (targetClassList.contains('ready')) {
    targetClassList.remove('ready');
    targetClassList.add('recording');
    
    showRecordingDuration();
    
    // Hide the other two buttons
    burstBtn.classList.add('hidden');
    photoBtn.classList.add('hidden');
    
  } else {
    targetClassList.remove('recording');
    targetClassList.add('ready');
    
    // Show the other two buttons
    burstBtn.classList.remove('hidden');
    photoBtn.classList.remove('hidden');
    
    hideRecordingDuration();
  }
}

function onBurstButtonClick(e) {
  videoBtn.classList.remove('active', 'ready', 'recording');
  burstBtn.classList.add('active');
  photoBtn.classList.remove('active');
}

function onPhotoButtonClick(e) {
  video.pause();
  videoBtn.classList.remove('active', 'ready', 'recording');
  burstBtn.classList.remove('active');
  photoBtn.classList.add('active');
  
  if (!localMediaStream) return false;
  
  var canvas = document.createElement('canvas');
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;<commit_msg>Add video recording support<commit_after>document.addEventListener('DOMContentLoaded', onDOMContentLoaded, false);
var video, videoBtn, burstBtn, photoBtn;

var screenshotPreviewer;
var chunks = [];
var mediaRecorder;
var recordingTimer;
var recordingDurationViewer;

var localMediaStream = null;

function onDOMContentLoaded() {
  video = document.querySelector('#camera');
  videoBtn = document.querySelector('#video-button'),
  burstBtn = document.querySelector('#burst-button'),
  photoBtn = document.querySelector('#photo-button');
  screenshotPreviewer = document.querySelector('#screenshot-previewer');
  recordingDurationViewer = document.querySelector('#recording-duration');

  if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
    alert('Sorry, your browser does not support getUserMedia()');
    return false;
  }
  var constraints = { 
    audio: true, 
    video: true
  };
  navigator.mediaDevices.getUserMedia(constraints).then(function(mediaStream) {
    /* use the stream */  
    mediaRecorder = new MediaRecorder(mediaStream);
    mediaRecorder.ondataavailable = function(e) {
      chunks.push(e.data);
    };
    mediaRecorder.onstop = function(e) {
      var blob = new Blob(chunks, { type: 'video/webm' });
      chunks = [];
      downloadFile('yuanvideo-'+(Date.now())+'.webm', URL.createObjectURL(blob));
    };
    
    localMediaStream = mediaStream;
    video.srcObject = mediaStream;
    video.onloadedmetadata = function() {
      video.play();
    };
    // Defaults to Single Photo mode
    photoBtn.classList.add('active');
    addEventListeners();
  }).catch(handleGetUserMediaError);
}

function addEventListeners() {
  videoBtn.addEventListener('click', onVideoButtonClick, false);
  burstBtn.addEventListener('click', onBurstButtonClick, false);
  photoBtn.addEventListener('click', onPhotoButtonClick, false);
  
  screenshotPreviewer.addEventListener('transitionend', function() {
    // Resume video playback
    video.play();
    // Restore screenshot previewer
    screenshotPreviewer.style.removeProperty('visibility');
    screenshotPreviewer.style.removeProperty('background-image');
    screenshotPreviewer.classList.remove('slideLeft');
  }, false);
}

function onVideoButtonClick(e) {
  let targetClassList = videoBtn.classList;
  
  videoBtn.classList.add('active');
  burstBtn.classList.remove('active');
  photoBtn.classList.remove('active');
  
  if (targetClassList.contains('ready')) {
    mediaRecorder.start();
    
    targetClassList.remove('ready');
    targetClassList.add('recording');
    
    showRecordingDuration();
    
    // Hide the other two buttons
    burstBtn.classList.add('hidden');
    photoBtn.classList.add('hidden');
    
  } else {
    if ( mediaRecorder.state !== "inactive") {
      mediaRecorder.stop();
    }
    
    targetClassList.remove('recording');
    targetClassList.add('ready');
    
    // Show the other two buttons
    burstBtn.classList.remove('hidden');
    photoBtn.classList.remove('hidden');
    
    hideRecordingDuration();
  }
}

function onBurstButtonClick(e) {
  videoBtn.classList.remove('active', 'ready', 'recording');
  burstBtn.classList.add('active');
  photoBtn.classList.remove('active');
}

function onPhotoButtonClick(e) {
  video.pause();
  videoBtn.classList.remove('active', 'ready', 'recording');
  burstBtn.classList.remove('active');
  photoBtn.classList.add('active');
  
  if (!localMediaStream) return false;
  
  var canvas = document.createElement('canvas');
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
{'fraction_non_alphanumeric': 0.1343867569601204, 'fraction_numerical': 0.0, 'mean_word_length': 4.580184718723761, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5636024', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1924, 'n_words': 326}