<commit_before>var socket = io.connect();
performance.now = performance.now || performance.webkitNow; // hack added by SD!

startbtn.disabled = false;
callbtn.disabled = true;
stoptransbtn.disabled = true;
stopreceivebtn.disabled = true;

var localstream; //the stream of audio/video coming from this browser

var outgoing; // peer connection for data out
var incoming; // peer connection for data in
var debug = true; // true to log messages

var currentUser = null;

//signin and signout buttons
var signinLink = document.getElementById('signin');
if (signinLink) {
  signinLink.onclick = function() {
    if(navigator.id) {
      if(currentUser) {
        navigator.id.logout();
      }
      else navigator.id.request();
    }
  };
}

socket.on('successfulSignin', function(email) {
  currentUser = email;
  if(email) signin.innerHTML = "<span>Logout of " + email + "</span>";
});

socket.on('successfulSignout', function() {
  currentUser = null;
  window.location.reload();
});

socket.on('failedSignout', function(err) {
  alert("Signout failure: " + err);
});

socket.on('failedSignin', function(err) {
  currentUser = null;
  navigator.id.logout();
  alert("Signin failure: " + err);
});

if(navigator.id) {
  navigator.id.watch({
    loggedInUser: currentUser,
    onlogin: function(assertion) {
      socket.emit('signin', { assertion: assertion });
    },
    onlogout: function() {
      socket.emit('signout');
    }
  });
}

function trace(text) {
  // This function is used for logging.
  if (text[text.length - 1] == '\n') {
    text = text.substring(0, text.length - 1);
  }
  console.log((performance.now() / 1000).toFixed(3) + ": " + text);
}

function gotStream(stream){
  if(debug) trace("Received local stream");
  vid1.src = window.URL.createObjectURL(stream); // add preview
  localstream = stream;
  callbtn.disabled = false;
}

function start() {
  trace("Requesting local stream");
  startbtn.disabled = true;

  navigator.getUserMedia({audio:true, video:true}, gotStream, function() {});
}

function call() {
  callbtn.disabled = true;
  stoptransbtn.disabled = false;
  if(debug) trace("Starting call");

  // temporary hacks to cope with API change
  if (!!localstream.videoTracks && !localstream.getVideoTracks) {
    localstream.getVideoTracks = function(){
      return this.videoTracks;
    };
  }
  if (!!localstream.audioTracks && !localstream.getAudioTracks) {
    localstream.getAudioTracks = function() {
      return this.audioTracks;
    };
  }

  if (localstream.getVideoTracks().length > 0)
    if(debug) trace('Using Video device: ' + localstream.getVideoTracks()[0].label);
  if (localstream.getAudioTracks().length > 0)
    if(debug) trace('Using Audio device: ' + localstream.getAudioTracks()[0].label);

  outgoing = new RTCPeerConnection(null);
  if(debug) trace("Created local peer connection object outgoing");
  outgoing.onicecandidate = iceCallback1;

  socket.emit('offer');

  outgoing.addStream(localstream);

  if(debug) trace("Adding Local Stream to peer connection");

  setTimeout(function() {
    outgoing.createOffer(gotDescription1, null, null);
  }, 1000);
}

function gotDescription1(desc) {
  outgoing.setLocalDescription(new RTCSessionDescription(desc));
  if(debug) trace("Offer from outgoing \n" + desc.sdp);
  //send offer!
  socket.emit('sendOfferDescription', JSON.stringify({ 'desc' : desc }));
}

function gotDescription2(desc) {
  incoming.setLocalDescription(new RTCSessionDescription(desc));
  if(debug) trace("Answer from incoming \n" + desc.sdp);
  //send back!
  socket.emit('sendAnswerDescription', JSON.stringify({ 'desc' : desc }));
}

function stopTransmitting() {
  outgoing.close();
  outgoing = null;
  stoptransbtn.disabled = true;
  callbtn.disabled = false;
  socket.emit('IStoppedTransmitting');
}

function stopReceiving() {
  incoming.close();<commit_msg>Clean up client<commit_after>var socket = io.connect();
performance.now = performance.now || performance.webkitNow; // hack added by SD!
startbtn.disabled = false;
callbtn.disabled = true;
stoptransbtn.disabled = true;
stopreceivebtn.disabled = true;

var localstream; //the stream of audio/video coming from this browser
var outgoing; // peer connection for data out
var incoming; // peer connection for data in
var debug = true; // true to log messages
var currentUser = null;

//signin and signout buttons
var signinLink = document.getElementById('signin');
if (signinLink) {
  signinLink.onclick = function() {
    if(navigator.id) {
      if(currentUser) {
        navigator.id.logout();
      }
      else navigator.id.request();
    }
  };
}

socket.on('successfulSignin', function(email) {
  currentUser = email;
  if(email) signin.innerHTML = "<span>Logout of " + email + "</span>";
});

socket.on('successfulSignout', function() {
  currentUser = null;
  window.location.reload();
});

socket.on('failedSignout', function(err) {
  // alert("Signout failure: " + err);
});

socket.on('failedSignin', function(err) {
  currentUser = null;
  navigator.id.logout();
  // alert("Signin failure: " + err);
});

if(navigator.id) {
  navigator.id.watch({
    loggedInUser: currentUser,
    onlogin: function(assertion) {
      socket.emit('signin', { assertion: assertion });
    },
    onlogout: function() {
      socket.emit('signout');
    }
  });
}

function trace(text) {
  // This function is used for logging.
  if (text[text.length - 1] == '\n') {
    text = text.substring(0, text.length - 1);
  }
  console.log((performance.now() / 1000).toFixed(3) + ": " + text);
}

function gotStream(stream){
  if(debug) trace("Received local stream");
  vid1.src = window.URL.createObjectURL(stream); // add preview
  localstream = stream;
  callbtn.disabled = false;
}

function start() {
  trace("Requesting local stream");
  startbtn.disabled = true;
  navigator.getUserMedia({audio:true, video:true}, gotStream, function() {});
}

function call() {
  callbtn.disabled = true;
  stoptransbtn.disabled = false;
  if(debug) trace("Starting call");

  // temporary hacks to cope with API change
  if (!!localstream.videoTracks && !localstream.getVideoTracks) {
    localstream.getVideoTracks = function(){
      return this.videoTracks;
    };
  }
  if (!!localstream.audioTracks && !localstream.getAudioTracks) {
    localstream.getAudioTracks = function() {
      return this.audioTracks;
    };
  }

  if (localstream.getVideoTracks().length > 0)
    if(debug) trace('Using Video device: ' + localstream.getVideoTracks()[0].label);
  if (localstream.getAudioTracks().length > 0)
    if(debug) trace('Using Audio device: ' + localstream.getAudioTracks()[0].label);

  outgoing = new RTCPeerConnection(null);
  if(debug) trace("Created local peer connection object outgoing");
  outgoing.onicecandidate = iceCallback1;
  socket.emit('offer');
  outgoing.addStream(localstream);
  if(debug) trace("Adding Local Stream to peer connection");
  setTimeout(function() {
    outgoing.createOffer(gotDescription1, null, null);
  }, 1000);
}

function gotDescription1(desc) {
  outgoing.setLocalDescription(new RTCSessionDescription(desc));
  if(debug) trace("Offer from outgoing \n" + desc.sdp);
  //send offer!
  socket.emit('sendOfferDescription', JSON.stringify({ 'desc' : desc }));
}

function gotDescription2(desc) {
  incoming.setLocalDescription(new RTCSessionDescription(desc));
  if(debug) trace("Answer from incoming \n" + desc.sdp);
  //send back!
  socket.emit('sendAnswerDescription', JSON.stringify({ 'desc' : desc }));
}

function stopTransmitting() {
  outgoing.close();
  outgoing = null;
  stoptransbtn.disabled = true;
  callbtn.disabled = false;
  socket.emit('IStoppedTransmitting');
}

function stopReceiving() {
  incoming.close();
{'fraction_non_alphanumeric': 0.14783060535203948, 'fraction_numerical': 0.005455962587685113, 'mean_word_length': 4.219661016949153, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '2801304', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2413, 'n_words': 539}