<commit_before>/*
	Node server for Tjube.Ninja.
	The server generates a unique room id when a user connects and allows the remotes to send data to the screen(s).
*/

var express = require( "express" ),
	app = express(),
	server = require( "http" ).Server( app ),
	io = require( "socket.io" )( server ),
	roomIdLength = 3,
	roomIdRegex = "[a-z0-9]{"+roomIdLength+"}";

server.listen( 1337 );
console.log( "server started on port 1337" );

// Serve static files
app.use( express.static( __dirname + "/static" ) );

// Show room select/create screen
app.get( "/", function ( req, res ) {
	var roomId = generateUniqueRoomId();
	if( roomId ) res.redirect( "/room/" + roomId );
	else res.status( 503 ).send( "Server is crowded, please try again later :)" );
});

// Show about page
app.get( "/about", function ( req, res ) {
	res.sendFile( __dirname + "/about.html" );
});

// Show public screen
app.get( "/room/:room("+roomIdRegex+")", function ( req, res ) {
		res.sendFile( __dirname + "/screen.html" );
});

// Show remote screen
app.get( "/add/:room("+roomIdRegex+")", function ( req, res ) {
	res.sendFile( __dirname + "/remote.html" );
});

// Communicate with clients
io.on( "connection", function ( socket ) {
	socket.room = socket.request.headers.referer.replace( "http://"+socket.request.headers.host+"/", "" ).split("/")[1];
	socket.join( socket.room );
	console.log( "A user connected to room "+socket.room );
	
	socket.on( "cueVideo", function ( id ) {
		socket.broadcast.to( socket.room ).emit( "cueVideo",  id );
		socket.emit( "addedVideo",  id );
		console.log( "User added video "+id+" to room "+socket.room );
	});
});

// Tries 10 times to generate a unique (not currently in use) room id of a length specified by roomIdLength
function generateUniqueRoomId() {
	var id = "";
	for(var i = 0; i < 10; i++) {
		var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
		for( var i=0; i < roomIdLength; i++ ) id += possible.charAt(Math.floor(Math.random() * possible.length));
		if( !io.sockets.adapter.rooms.hasOwnProperty( id ) ) return id;
	} 
	return false;
}<commit_msg>Removed console logs since they didn't add anything usefull<commit_after>/*
	Node server for Tjube.Ninja.
	The server generates a unique room id when a user connects and allows the remotes to send data to the screen(s).
*/

var express = require( "express" ),
	app = express(),
	server = require( "http" ).Server( app ),
	io = require( "socket.io" )( server ),
	roomIdLength = 3,
	roomIdRegex = "[a-z0-9]{"+roomIdLength+"}";

server.listen( 1337 );
console.log( "server started on port 1337" );

// Serve static files
app.use( express.static( __dirname + "/static" ) );

// Show room select/create screen
app.get( "/", function ( req, res ) {
	var roomId = generateUniqueRoomId();
	if( roomId ) res.redirect( "/room/" + roomId );
	else res.status( 503 ).send( "Server is crowded, please try again later :)" );
});

// Show about page
app.get( "/about", function ( req, res ) {
	res.sendFile( __dirname + "/about.html" );
});

// Show public screen
app.get( "/room/:room("+roomIdRegex+")", function ( req, res ) {
		res.sendFile( __dirname + "/screen.html" );
});

// Show remote screen
app.get( "/add/:room("+roomIdRegex+")", function ( req, res ) {
	res.sendFile( __dirname + "/remote.html" );
});

// Communicate with clients
io.on( "connection", function ( socket ) {
	socket.room = socket.request.headers.referer.replace( "http://"+socket.request.headers.host+"/", "" ).split("/")[1];
	socket.join( socket.room );
	
	socket.on( "cueVideo", function ( id ) {
		socket.broadcast.to( socket.room ).emit( "cueVideo",  id );
		socket.emit( "addedVideo",  id );
	});
});

// Tries 10 times to generate a unique (not currently in use) room id of a length specified by roomIdLength
function generateUniqueRoomId() {
	var id = "";
	for(var i = 0; i < 10; i++) {
		var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
		for( var i=0; i < roomIdLength; i++ ) id += possible.charAt(Math.floor(Math.random() * possible.length));
		if( !io.sockets.adapter.rooms.hasOwnProperty( id ) ) return id;
	} 
	return false;
}
{'fraction_non_alphanumeric': 0.17619745845552298, 'fraction_numerical': 0.015151515151515152, 'mean_word_length': 3.901796407185629, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1126858', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1370, 'n_words': 409}