mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Added communication structure
This commit is contained in:
parent
980af70259
commit
94f63fc7b2
10 changed files with 292 additions and 129 deletions
45
lib/Server/Coordinator.js
Normal file
45
lib/Server/Coordinator.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
define(["Server/User", "Server/Channel"], function(User, Channel) {
|
||||
|
||||
function Coordinator() {
|
||||
this.channels = {};
|
||||
this.lobbyUsers = {};
|
||||
}
|
||||
|
||||
Coordinator.prototype.createUser = function(socketLink){
|
||||
var user = new User(socketLink, this);
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToLobby = function(user){
|
||||
if(user.channel) {
|
||||
user.channel.releaseUser(user);
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToChannel = function(user, channelName){
|
||||
if(user.channel) {
|
||||
user.channel.releaseUser(user);
|
||||
}
|
||||
|
||||
if(!Channel.validateName(channelName)){
|
||||
//TODO send validation error
|
||||
return false;
|
||||
}
|
||||
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
channel = new Channel(channelName);
|
||||
this.channels[channelName] = channel;
|
||||
}
|
||||
|
||||
channel.addUser(user);
|
||||
user.setChannel(channel);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
|
||||
return Coordinator;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue