Created
April 24, 2011 23:08
-
-
Save aashay/939965 to your computer and use it in GitHub Desktop.
A NowJS implementation of an "addToChannel" method. This implementation is epic fail. For every N clients that connect, N "connect" events are fired. Not desirable at all.
This file contains hidden or 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
everyone.now.addToChannel = function(channel){ | |
//this client is trying to join a channel. | |
var group = nowjs.getGroup(channel); | |
group.on('connect', function(clientId){ | |
console.log("CONNECT EVENT TRIGGERED for " + clientId); | |
if(!channelList[clientId]){ | |
channelList[clientId] = [channel]; | |
console.log("New channel array created for " + channel + ", added " + clientId); | |
}else{ | |
channelList[clientId].push(channel); | |
console.log("Pushed " + clientId + " to channel " + channel); | |
} | |
}); | |
group.on('disconnect', function(clientId){ | |
console.log("SOME FKR DISCONNECTED from " + channel); | |
if(channelList[clientId]){ | |
channelList[clientId].pop(channel); | |
console.log(clientId + " removed from " + channel); | |
}else{ | |
console.log("HOLY SHIT CRITICAL ERROR WE DIDNT FIND THE CLIENT IN THE GROUPLIST"); | |
} | |
}); | |
isInChannel(channel,this.user.clientId,function(clientId, yes){ | |
if(!yes){ | |
console.log("Callback from isInChannel triggered, about to addUser for clientId " + clientId); | |
group.addUser(clientId); | |
console.log("AddUser complete for " + clientId); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment