Last active
December 18, 2015 19:09
-
-
Save adrianseeley/5830884 to your computer and use it in GitHub Desktop.
how do i connect to that crazy socket load balancer?
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 udid = 'TESTUDID' + Math.random(); | |
function establish_connection (url) { | |
var socket = io.connect(url || 'http://localhost'); | |
socket.on('connect', function() { | |
socket.emit('authenticate', {udid: udid, was_transferred_already: url ? 1 : 0}, function (res) { | |
if (res.hasOwnProperty('transfer')) { | |
console.log('transfering to: ' + res.transfer); | |
socket.disconnect(); | |
return establish_connection(res.transfer); | |
} else { | |
console.log('accepted to: ' + url); | |
socket.on(..whatever..) | |
socket.emit(..whatever..) | |
} | |
}); | |
}); | |
}; | |
establish_connection(); // call without a url, the url is to be filled by a transfer if one occurs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment