wsServer.on('request', function(request) { var connection = request.accept('echo-protocol', request.origin); console.log((new Date()) + ' Connection accepted.'); if(firstPacket.length){ /** * Every user will get beginnig of stream **/ firstPacket.map(function(packet, index){ connection.sendBytes(packet); }); } /** * Add this user to collection */ wsClients.push(connection); connection.on('close', function(reasonCode, description) { console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.'); }); });