Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created September 1, 2010 18:56
Show Gist options
  • Save 3rd-Eden/561160 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/561160 to your computer and use it in GitHub Desktop.
// instead of using .broadcast we are looping of the clients to see if they are in the correct channel
broadcast = function( response ){
var clientList = client.listener.clients,
length = clientList.length, i;
for( i = 0; i < length; i++ ){
if( clientList[i] && ( clientList[i].sessionId && clientList[i].sessionId !== sessionId && clientList[i] !== client ) && clientList[i].channel && clientList[i].channel == client.channel ){
clientList[i].send( response );
}
}
},
// get the first availble client, as it will be marked as tracker
firstAvailable = function( response ){
var clientList = client.listener.clients,
length = clientList.length, i;
for( i = 0; i < length; i++ ){
if( clientList[i] && ( clientList[i].sessionId && clientList[i].sessionId !== sessionId && clientList[i] !== client ) && clientList[i].channel && clientList[i].channel == client.channel ){
clientList[i].send( response );
return;
}
}
},
// continue to only broadcast to this user
bySessionId = function( response, sess ){
var clientList = client.listener.clients,
length = clientList.length, i;
for( i = 0; i < length; i++ ){
if( clientList[i] && ( clientList[i].sessionId && clientList[i].sessionId == sess ) && clientList[i] !== client ){
clientList[i].send( response );
return;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment