<commit_before>const http   = require('http');
const server = http.createServer();
const io     = require('socket.io')(server);

io.on('connection', socket => {

	socket.emit('uid', socket.id);

	// Unicast SDP
	socket.on('sdp', data => {
		if (data.to == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('sdp', data);
	});

	// Unicast ICE
	socket.on('ice', data => {
		if (data.to == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('ice', data);
	});

	// Join room
	socket.on('join', data => {
		if (data.rid == null)
			return;

		socket.join(data.rid);
		data.uid = socket.id;
		socket.broadcast.to(data.rid).emit('join', data);
	});

	// Unicast hail
	socket.on('hail', data => {
		if (data.to == null || data.rid == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('hail', data);
	});

	// Broadcast leave
	socket.on('leave', data => {
		if (data.rid == null)
			return;

		socket.leave(data.rid);
		data.uid = socket.id;
		socket.broadcast.emit('leave', data);
	});

	// Broadcast disconnect
	socket.on('disconnect', () => {
		socket.broadcast.emit('leave', {
			uid: socket.id
		});
	});

});

server.listen(process.env.PORT || 8081);<commit_msg>Only send leave events to sockets sharing rooms<commit_after>const http   = require('http');
const server = http.createServer();
const io     = require('socket.io')(server);

io.on('connection', socket => {

	socket.emit('uid', socket.id);

	// Unicast SDP
	socket.on('sdp', data => {
		if (data.to == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('sdp', data);
	});

	// Unicast ICE
	socket.on('ice', data => {
		if (data.to == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('ice', data);
	});

	// Multicast join
	socket.on('join', data => {
		if (data.rid == null)
			return;

		socket.join(data.rid);
		data.uid = socket.id;
		socket.broadcast.to(data.rid).emit('join', data);
	});

	// Unicast hail
	socket.on('hail', data => {
		if (data.to == null || data.rid == null)
			return;

		data.from = socket.id;
		socket.broadcast.to(data.to).emit('hail', data);
	});

	// Multicast leave
	socket.on('leave', data => {
		if (data.rid == null)
			return;

		socket.leave(data.rid);
		data.uid = socket.id;
		socket.broadcast.to(data.rid).emit('leave', data);
	});

	// Multicast disconnect
	socket.on('disconnect', () => {
		Object.keys(socket.rooms).forEach(room => {
			socket.broadcast.to(room).emit('leave', {
				uid: socket.id
			});
		});
	});

});

server.listen(process.env.PORT || 8081);
{'fraction_non_alphanumeric': 0.2089723926380368, 'fraction_numerical': 0.003067484662576687, 'mean_word_length': 3.270049099836334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '1107293', 'n_tokens_mistral': 1074, 'n_tokens_neox': 969, 'n_words': 177}