<commit_before>// Require
var WebSocketServer = require('ws').Server;

// Config
var DEBUG = true;
var PORT = 5000;
var EXPIRATION_MS = 1000 * 60 * 10;  // 10 minutes

/********************************* Helper *************************************/

function Log(message) {
  if(DEBUG) console.log(message);
}

/********************************* Server *************************************/

var server;
var clients = [];

function handleTimedOut(client) {
  // Remove timed out client
  var index = clients.indexOf(client);
  if(index > -1) {
    Log('Removing inactive client ' + client.id);
    client.socket.close();
    clients.splice(index, 1);
    Log('Total clients: ' + clients.length);
  } else {
    Log('Expired client not found!');
  }
}

function refreshClientTimeout(client) {
  Log('Refreshing client ' + client.id);
  clearTimeout(client.timeoutId);

  // Set a new one
  var timeoutId = setTimeout(handleTimedOut, EXPIRATION_MS, client);
  client.timeoutId = timeoutId;
}

function addClient(socket) {
  // Create new client object
  var client = { 
    'id': Math.floor(Math.random() * 1000000),
    'socket': socket
  };
  // Set timeout ID
  var timeoutId = setTimeout(handleTimedOut, EXPIRATION_MS, client);<commit_msg>Clear manually disconnected client's timeout<commit_after>// Require
var WebSocketServer = require('ws').Server;

// Config
var DEBUG = true;
var PORT = 5000;
var EXPIRATION_MS = 1000 * 60 * 10;  // 10 minutes

/********************************* Helper *************************************/

function Log(message) {
  if(DEBUG) console.log(message);
}

/********************************* Server *************************************/

var server;
var clients = [];

function handleTimedOut(client) {
  // Remove timed out client
  var index = clients.indexOf(client);
  if(index > -1) {
    Log('Removing inactive client ' + client.id);
    client.socket.close();
    clearTimeout(client.timeoutId);
    clients.splice(index, 1);
    Log('Total clients: ' + clients.length);
  } else {
    Log('Expired client not found!');
  }
}

function refreshClientTimeout(client) {
  Log('Refreshing client ' + client.id);
  clearTimeout(client.timeoutId);

  // Set a new one
  var timeoutId = setTimeout(handleTimedOut, EXPIRATION_MS, client);
  client.timeoutId = timeoutId;
}

function addClient(socket) {
  // Create new client object
  var client = { 
    'id': Math.floor(Math.random() * 1000000),
    'socket': socket
  };
  // Set timeout ID
  var timeoutId = setTimeout(handleTimedOut, EXPIRATION_MS, client);
{'fraction_non_alphanumeric': 0.2293218345746766, 'fraction_numerical': 0.01803214425715406, 'mean_word_length': 4.21881390593047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3551899', 'n_tokens_mistral': 812, 'n_tokens_neox': 753, 'n_words': 190}