<commit_before>$(function(event)
{
  var txtUri = $('#txtUri');
  var btnConnect = $('#btnConnect');
  var btnTerminate = $('#btnTerminate');
  var localVideo = $('#localVideo');
  var remoteVideo = $('#remoteVideo');
  var divLog = $('#divLog');


  function error(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    msg = '<span style="color: #FF0000">'+msg+'</span>';

    divLog.html(divLog.html() + msg + '<br>');
  }

  function info(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    msg = '<span style="color: #0000FF">'+msg+'</span>';

    divLog.html(divLog.html() + msg + '<br>');
  }

  function log(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    divLog.html(divLog.html() + msg + '<br>');
  }


  /**
   * Set and enable the terminate button
   *
   * @param {WebRtcContent} conn: WebRTC streamming connection
   */
  function setTerminate(conn)
  {
    // Enable and init button to terminate the connection
    btnTerminate.one('click', function(event)
    {
      // Disable terminate button
      btnTerminate.attr('disabled', true);

      // Terminate the connection
      conn.terminate();

      log("Connection terminated by user");

      // Enable connect button
      btnConnect.attr('disabled', false);
      txtUri.attr('disabled', false);
    });
  }


  btnConnect.on('click', function(event)
  {
    // Disable connect button
    btnConnect.attr('disabled', true);
    txtUri.attr('disabled', true);

    // Create a new connection
    var uri = txtUri.val();
    var conn = new WebRtcContent(uri);

    log("Connection created pointing to '"+uri+"'");

    // Set and enable the terminate button
    setTerminate(conn);

    // Set connection success and error events
    conn.onopen = function(event)
    {
      log("Connection openned");

      // Set the incoming stream on the video tag
      remoteVideo.attr('src', event.stream);

      // Enable terminate button
      btnTerminate.attr('disabled', false);
    };
    conn.onclose = function(event)
    {
      log("Connection clossed");
    };

    conn.onMediaEvent = function(event)
    {
      info("MediaEvent: "+JSON.stringify(event.data))
    }

    conn.onerror = function(event)
    {
      // Enable connect button
      btnConnect.attr('disabled', false);
      txtUri.attr('disabled', false);

      // Notify to the user of the error
      error(event.message);
      console.error(event);
    };
  });
});<commit_msg>Function to unify enable and disable of URL input & connect button<commit_after>$(function(event)
{
  var txtUri = $('#txtUri');
  var btnConnect = $('#btnConnect');
  var btnTerminate = $('#btnTerminate');
  var localVideo = $('#localVideo');
  var remoteVideo = $('#remoteVideo');
  var divLog = $('#divLog');


  function error(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    msg = '<span style="color: #FF0000">'+msg+'</span>';

    divLog.html(divLog.html() + msg + '<br>');
  }

  function info(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    msg = '<span style="color: #0000FF">'+msg+'</span>';

    divLog.html(divLog.html() + msg + '<br>');
  }

  function log(msg)
  {
    // Sanitize the input
    msg = msg.replace(/</g, '&lt;');

    divLog.html(divLog.html() + msg + '<br>');
  }


  /**
   * Disable connect button
   */
  function disableInput(value)
  {
    btnConnect.attr('disabled', value);
    txtUri.attr('disabled', value);
  }


  /**
   * Set and enable the terminate button
   *
   * @param {WebRtcContent} conn: WebRTC streamming connection
   */
  function setTerminate(conn)
  {
    // Enable and init button to terminate the connection
    btnTerminate.one('click', function(event)
    {
      // Disable terminate button
      btnTerminate.attr('disabled', true);

      // Terminate the connection
      conn.terminate();

      log("Connection terminated by user");

      // Enable connect button
      disableInput(false);
    });
  }


  btnConnect.on('click', function(event)
  {
    // Disable connect button
    disableInput(true);

    // Create a new connection
    var uri = txtUri.val();
    var conn = new WebRtcContent(uri);

    log("Connection created pointing to '"+uri+"'");

    // Set and enable the terminate button
    setTerminate(conn);

    // Set connection success and error events
    conn.onopen = function(event)
    {
      log("Connection openned");

      // Set the incoming stream on the video tag
      remoteVideo.attr('src', event.stream);

      // Enable terminate button
      btnTerminate.attr('disabled', false);
    };
    conn.onclose = function(event)
    {
      log("Connection clossed");
    };

    conn.onMediaEvent = function(event)
    {
      info("MediaEvent: "+JSON.stringify(event.data))
    }

    conn.onerror = function(event)
    {
      // Enable connect button
      disableInput(false);

      // Notify to the user of the error
      error(event.message);
      console.error(event);
    };
  });
});
{'fraction_non_alphanumeric': 0.15829046299960428, 'fraction_numerical': 0.0031658092599920855, 'mean_word_length': 2.6710239651416123, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, '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': '3776676', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1532, 'n_words': 384}