Created
July 27, 2012 20:52
-
-
Save slickplaid/3190424 to your computer and use it in GitHub Desktop.
bored!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var visitors = 50; | |
var sockets = []; | |
(function($) { | |
$('body').append('<h1>Our Sockets: <span class="ourSockets">0</span></h1>'); | |
socket.on('countChanged', autoVisit); | |
function autoVisit(data) { | |
if(data.count < visitors) { | |
addVisitor(1); | |
} else if(data.count > visitors) { | |
removeVisitor(1); | |
} | |
var ourClients = sockets.length; | |
$('.ourSockets').text(ourClients); | |
}; | |
function addVisitor(count) { | |
sockets.push(io.connect('http://sreekumar.node.jit.su', {'force new connection':true})); | |
count--; | |
if(count > 0) { | |
addVisitor(count); | |
} | |
} | |
function removeVisitor(count) { | |
if(sockets.length === 0) return false; | |
var removed = sockets.pop(); | |
removed.disconnect(); | |
count--; | |
if(count > 0) { | |
removeVisitor(count); | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment