server.js
// simple route to register the clients
simple route to register the clients
simple route to register the clients
function addClientConnection(playerName, res, req) {
    const fiveMINS = 5 * 60 * 1000;
    req.socket.setTimeout(fiveMINS);
    res.writeHead(200, {
        'Content-Type': 'text/event-stream',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive'
    });
    res.write('\n');
    if (!openConnections.has(playerName)) {
        openConnections.set(playerName, res);
        console.log('AUTO adding player ', playerName);
    } else {
        console.log('AUTO have player ', playerName);
    }
    req.on("close", function() { removeResFromConnections(playerName, res); });
}
function addClientConnection ( playerName , res , req ) { const fiveMINS = 5 * 60 * 1000 ; req . socket . setTimeout ( fiveMINS ) ; res . writeHead ( 200 , { 'Content-Type' : 'text/event-stream' , 'Cache-Control' : 'no-cache' , 'Connection' : 'keep-alive' } ) ; res . write ( '\n' ) ; if ( ! openConnections . has ( playerName ) ) { openConnections . set ( playerName , res ) ; console . log ( 'AUTO adding player ' , playerName ) ; } else { console . log ( 'AUTO have player ' , playerName ) ; } req . on ( "close" , function ( ) { removeResFromConnections ( playerName , res ) ; } ) ; }
simple route to register the clients
simple route to register the clients
// set timeout as high as possible // send headers for event-stream connection // see spec for more information // push this res object to our global variable //console.log('two'); //openConnections.push(res); // When the request is closed, e.g. the browser window // is closed. We search through the open connections // array and remove this connection. //console.log('three');