<commit_before>var listen = function(io){

	var self = this;
	var socketMap = {};
	
	io.sockets.on('connection', function (socket) {
		
		console.log("New connection", socket.id);
		
		var oldDate = Date.now();
		socketMap[socket.id] = {socket:socket, latency:0, lastTime:0};
		
		//This sends entire socket pool. Own ID is filtered out on front end.
		socket.broadcast.emit('new', {pool:Object.keys(socketMap), origin: socket.id});
		socket.emit('confirm', {pool:Object.keys(socketMap), origin: socket.id});
		
		socketMap[socket.id].lastTime = Date.now();
		socket.emit('ping', 0);
		
		socket.on('data', function (data) {
			console.log(socket.id, data, (Date.now()-oldDate));
			oldDate = Date.now(); 
			
			socket.broadcast.emit('data', {pool:Object.keys(socketMap), origin: socket.id, tick: data.tick, data:data.client_data});
		});		
		
		socket.on('ping', function (data) {
			socketMap[socket.id].latency = Date.now() - socketMap[socket.id].lastTime;
			console.log("RTT is about " + socketMap[socket.id].latency + "ms");
		});
		
		socket.on('disconnect', function(){
			console.log(socket.id, 'disconnected');

			delete socketMap[socket.id];
			socket.broadcast.emit('gone', {pool:Object.keys(socketMap), origin: socket.id}); 
			
			//console.log(socketMap);
		})
	});
}

exports.listen = listen;<commit_msg>Initial steps towards server side callback implementation<commit_after>var catchAllCb;

var on = function(event, cb){
	io.sockets.on(event, cb);
};

var listen = function(io, cb){

	var self = this, socketMap = {};
	catchAllCb = cb ? cb : function(){};
	
	io.sockets.on('connection', function (socket) {
		
		console.log("New connection", socket.id);
		var oldDate = Date.now();
		socketMap[socket.id] = {socket:socket, latency:0, lastTime:0};
		
		//This sends entire socket pool. Own ID is filtered out on front end.
		socket.broadcast.emit('new', {pool:Object.keys(socketMap), origin: socket.id});
		socket.emit('confirm', {pool:Object.keys(socketMap), origin: socket.id});
		
		socketMap[socket.id].lastTime = Date.now();
		socket.emit('ping', 0);
		
		socket.on('data', function (data) {
			console.log(socket.id, data, (Date.now()-oldDate));
			oldDate = Date.now(); 
			
			socket.broadcast.emit('data', {pool:Object.keys(socketMap), origin: socket.id, tick: data.tick, data:data.client_data});
		});		
		
		socket.on('ping', function (data) {
			socketMap[socket.id].latency = Date.now() - socketMap[socket.id].lastTime;
			console.log("RTT is about " + socketMap[socket.id].latency + "ms");
		});
		
		socket.on('disconnect', function(){
			console.log(socket.id, 'disconnected');

			delete socketMap[socket.id];
			socket.broadcast.emit('gone', {pool:Object.keys(socketMap), origin: socket.id}); 
			
			//console.log(socketMap);
		})
	});
};

exports.listen = listen;
{'fraction_non_alphanumeric': 0.18207782934666192, 'fraction_numerical': 0.0021420921099607284, 'mean_word_length': 4.169741697416974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7442796', 'n_tokens_mistral': 1055, 'n_tokens_neox': 922, 'n_words': 187}