<commit_before>// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==

var lichess = window.lichess = window.lichess || {};

lichess.getParameterByName = function(name) {
  var match = RegExp('[?&]' + name + '=([^&]*)').exec(location.search);
  return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
};

lichess.StrongSocket = function(url, version, settings) {
  var self = this;
  self.settings = $.extend(true, {}, lichess.StrongSocket.defaults, settings);
  self.url = url;
  self.version = version;
  self.options = self.settings.options;
  self.ws = null;
  self.pingSchedule = null;
  self.connectSchedule = null;
  self.ackableMessages = [];
  self.lastPingTime = self.now();
  self.currentLag = 0;
  self.averageLag = 0;
  self.tryOtherUrl = false;
  self.autoReconnect = true;
  self.debug('Debug is enabled');
  if (self.options.resetUrl || self.options.prodPipe) {
    lichess.storage.remove(self.options.baseUrlKey);
  }
  if (self.options.prodPipe) {
    self.options.baseUrls = ['socket.en.lichess.org:9021'];
  }
  self.connect();
  window.addEventListener('unload', function() {
    self.destroy();
  });
};
lichess.StrongSocket.available = window.WebSocket || window.MozWebSocket;
lichess.StrongSocket.sri = Math.random().toString(36).substring(2);
lichess.StrongSocket.defaults = {
  events: {
    fen: function(e) {
      $('.live_' + e.id).each(function() {
        lichess.parseFen($(this).data("fen", e.fen).data("lastmove", e.lm));
      });
    }
  },
  params: {
    sri: lichess.StrongSocket.sri
  },
  options: {
    name: "unnamed",
    pingMaxLag: 8000, // time to wait for pong before reseting the connection
    pingDelay: 1000, // time between pong and ping
    autoReconnectDelay: 2000,
    lagTag: false, // jQuery object showing ping lag
    ignoreUnknownMessages: true,
    baseUrls: ['socket.' + document.domain].concat(
      ($('body').data('ports') + '').split(',').map(function(port) {
        return 'socket.' + document.domain + ':' + port;
      })),
    onFirstConnect: $.noop,
    baseUrlKey: 'surl3'
  }
};
lichess.StrongSocket.prototype = {
  connect: function() {
    var self = this;
    self.destroy();
    self.autoReconnect = true;
    var fullUrl = "ws://" + self.baseUrl() + self.url + "?" + $.param($.extend(self.settings.params, {
      version: self.version
    }));
    self.debug("connection attempt to " + fullUrl, true);
    try {
      if (window.MozWebSocket) self.ws = new MozWebSocket(fullUrl);
      else if (window.WebSocket) self.ws = new WebSocket(fullUrl);
      else throw "[lila] no websockets found on this browser!";

      self.ws.onerror = function(e) {
        self.onError(e);
      };
      self.ws.onclose = function(e) {
        if (self.autoReconnect) {
          self.debug('Will autoreconnect in ' + self.options.autoReconnectDelay);
          self.scheduleConnect(self.options.autoReconnectDelay);
        }
      };
      self.ws.onopen = function() {
        self.debug("connected to " + fullUrl, true);
        self.onSuccess();
        $('body').removeClass('offline');
        self.pingNow();
        $('body').trigger('socket.open');
        if ($('#user_tag').length) setTimeout(function() {
          self.send("following_onlines");
        }, 500);
        var resend = self.ackableMessages;
        self.ackableMessages = [];
        resend.forEach(function(x) {
          self.send(x.t, x.d);
        });
      };
      self.ws.onmessage = function(e) {
        var m = JSON.parse(e.data);
        if (m.t == "n") {
          self.pong();<commit_msg>simulate crappy network to try and reproduce #428 - no luck<commit_after>// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==

var lichess = window.lichess = window.lichess || {};

lichess.getParameterByName = function(name) {
  var match = RegExp('[?&]' + name + '=([^&]*)').exec(location.search);
  return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
};

lichess.StrongSocket = function(url, version, settings) {
  var self = this;
  self.settings = $.extend(true, {}, lichess.StrongSocket.defaults, settings);
  self.url = url;
  self.version = version;
  self.options = self.settings.options;
  self.ws = null;
  self.pingSchedule = null;
  self.connectSchedule = null;
  self.ackableMessages = [];
  self.lastPingTime = self.now();
  self.currentLag = 0;
  self.averageLag = 0;
  self.tryOtherUrl = false;
  self.autoReconnect = true;
  self.debug('Debug is enabled');
  if (self.options.resetUrl || self.options.prodPipe) {
    lichess.storage.remove(self.options.baseUrlKey);
  }
  if (self.options.prodPipe) {
    self.options.baseUrls = ['socket.en.lichess.org:9021'];
  }
  self.connect();
  window.addEventListener('unload', function() {
    self.destroy();
  });
};
lichess.StrongSocket.available = window.WebSocket || window.MozWebSocket;
lichess.StrongSocket.sri = Math.random().toString(36).substring(2);
lichess.StrongSocket.defaults = {
  events: {
    fen: function(e) {
      $('.live_' + e.id).each(function() {
        lichess.parseFen($(this).data("fen", e.fen).data("lastmove", e.lm));
      });
    }
  },
  params: {
    sri: lichess.StrongSocket.sri
  },
  options: {
    name: "unnamed",
    pingMaxLag: 8000, // time to wait for pong before reseting the connection
    pingDelay: 1000, // time between pong and ping
    autoReconnectDelay: 2000,
    lagTag: false, // jQuery object showing ping lag
    ignoreUnknownMessages: true,
    baseUrls: ['socket.' + document.domain].concat(
      ($('body').data('ports') + '').split(',').map(function(port) {
        return 'socket.' + document.domain + ':' + port;
      })),
    onFirstConnect: $.noop,
    baseUrlKey: 'surl3'
  }
};
lichess.StrongSocket.prototype = {
  connect: function() {
    var self = this;
    self.destroy();
    self.autoReconnect = true;
    var fullUrl = "ws://" + self.baseUrl() + self.url + "?" + $.param($.extend(self.settings.params, {
      version: self.version
    }));
    self.debug("connection attempt to " + fullUrl, true);
    try {
      if (window.MozWebSocket) self.ws = new MozWebSocket(fullUrl);
      else if (window.WebSocket) self.ws = new WebSocket(fullUrl);
      else throw "[lila] no websockets found on this browser!";

      self.ws.onerror = function(e) {
        self.onError(e);
      };
      self.ws.onclose = function(e) {
        if (self.autoReconnect) {
          self.debug('Will autoreconnect in ' + self.options.autoReconnectDelay);
          self.scheduleConnect(self.options.autoReconnectDelay);
        }
      };
      self.ws.onopen = function() {
        self.debug("connected to " + fullUrl, true);
        self.onSuccess();
        $('body').removeClass('offline');
        self.pingNow();
        $('body').trigger('socket.open');
        if ($('#user_tag').length) setTimeout(function() {
          self.send("following_onlines");
        }, 500);
        var resend = self.ackableMessages;
        self.ackableMessages = [];
        resend.forEach(function(x) {
          self.send(x.t, x.d);
        });
      };
      self.ws.onmessage = function(e) {
        var m = JSON.parse(e.data);
        // if (Math.random() > 0.5) {
        //   console.log(m, 'skip');
        //   return;
        // }
        if (m.t == "n") {
          self.pong();
{'fraction_non_alphanumeric': 0.16836804137743297, 'fraction_numerical': 0.007758268681094325, 'mean_word_length': 2.8796198521647307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1847140', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2385, 'n_words': 446}