<commit_before>"use strict";

var status = require('http-status-codes');
var addSocketResponse = require('./socket/response');
var addRequestMethods = require('./socket/request');
var addSocketKeys = require('./socket/keys');
var addSocketMethods = require('./socket/methods');

class WebsocketRest {
	constructor(){
		/**
		 * Websocket server instance.
		 * @type {null}
		 */
		this.socket = null;

		/**
		 * Verzion of your app. This data will exist in all responses to clients.
		 * @type {null}
		 */
		this.apiVersion = null;

		/**
		 * All registered modules.
		 * @type {{}}
		 */
		this.modules = {};

		/**
		 * All on connect to url events.
		 * @type {{}}
		 */
		this.onUrlConnect = {};

		/**
		 * All on close from url events.
		 * @type {{}}
		 */
		this.onUrlClose = {};

		this.onEvent = function(){};

		/**
		 * Winston logger instance
		 * @type {null}
		 */
		this._log = null;

		this._connectionsCheck();
	}

	/**
	 * Init function where you set socket server and apiVersion for responses.
	 *
	 * @param socket
	 * @param apiVersion
	 */
    init(socket, apiVersion) {
        this.socket = socket;
        this.apiVersion = apiVersion;
    }

	_connectionsCheck() {
		var self = this;
		setTimeout(function () {
			for (let i in self.socket.clients) {
				try {
					self.socket.clients[i].ping();
				} catch (err) {

				}
				self.socket.clients[i].pingsSent++;
				if (self.socket.clients[i].pingsSent >= 3) {
					self.onUrlClose[self.socket.clients[i].urlPath](self.socket.clients[i]);
					self.socket.clients.splice(i, 1);
				}
			}
			self._connectionsCheck();
		}, 500);
	}

	/**
	 * Register function that will execute every time message will come from client.
	 *
	 * @param fun
	 */
	registerOnEvent(fun){
		this.onEvent = fun;
	}

	/**
	 * Logger must have next methods.
	 *
	 * @param logger
	 */
	logger(logger){
		this._log = logger;
	}

	_connectionsCheck(){<commit_msg>Update pingsSent & timeout with close event.<commit_after>"use strict";

var status = require('http-status-codes');
var addSocketResponse = require('./socket/response');
var addRequestMethods = require('./socket/request');
var addSocketKeys = require('./socket/keys');
var addSocketMethods = require('./socket/methods');

class WebsocketRest {
	constructor(){
		/**
		 * Websocket server instance.
		 * @type {null}
		 */
		this.socket = null;

		/**
		 * Verzion of your app. This data will exist in all responses to clients.
		 * @type {null}
		 */
		this.apiVersion = null;

		/**
		 * All registered modules.
		 * @type {{}}
		 */
		this.modules = {};

		/**
		 * All on connect to url events.
		 * @type {{}}
		 */
		this.onUrlConnect = {};

		/**
		 * All on close from url events.
		 * @type {{}}
		 */
		this.onUrlClose = {};

		this.onEvent = function(){};

		/**
		 * Winston logger instance
		 * @type {null}
		 */
		this._log = null;

		this._connectionsCheck();
	}

	/**
	 * Init function where you set socket server and apiVersion for responses.
	 *
	 * @param socket
	 * @param apiVersion
	 */
    init(socket, apiVersion) {
        this.socket = socket;
        this.apiVersion = apiVersion;
    }

	_connectionsCheck() {
		var self = this;
		setTimeout(function () {
			for (let i in self.socket.clients) {
				try {
					self.socket.clients[i].ping();
				} catch (err) {

				}
				self.socket.clients[i].pingsSent++;
				if (self.socket.clients[i].pingsSent >= 5) {
					try{
						self.socket.clients[i].close();
					} catch (err){

					}
					self.onUrlClose[self.socket.clients[i].urlPath](self.socket.clients[i]);
					self.socket.clients.splice(i, 1);
				}
			}
			self._connectionsCheck();
		}, 1000);
	}

	/**
	 * Register function that will execute every time message will come from client.
	 *
	 * @param fun
	 */
	registerOnEvent(fun){
		this.onEvent = fun;
	}

	/**
	 * Logger must have next methods.
	 *
	 * @param logger
	 */
	logger(logger){
		this._log = logger;
	}

	_connectionsCheck(){
{'fraction_non_alphanumeric': 0.15669371196754564, 'fraction_numerical': 0.002789046653144016, 'mean_word_length': 2.6561631139944395, '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': '2716257', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1233, 'n_words': 302}