mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added checkpoint output, setting up a channel
This commit is contained in:
parent
dd154aa576
commit
c2ed00cb9b
10 changed files with 115 additions and 79 deletions
|
|
@ -8,25 +8,29 @@ define([
|
|||
function (User, Channel, PipeToChannel, NotificationCenter) {
|
||||
|
||||
function Coordinator () {
|
||||
this.channels = {};
|
||||
this.channelPipes = {};
|
||||
this.lobbyUsers = {};
|
||||
|
||||
console.checkpoint('create Coordinator');
|
||||
}
|
||||
|
||||
Coordinator.prototype.createUser = function (socketLink) {
|
||||
var user = new User(socketLink, this);
|
||||
console.checkpoint('creating user');
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToLobby = function (user) {
|
||||
if(user.channelProcess) {
|
||||
if(user.channelPipe) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
console.checkpoint('assign user to lobby');
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToChannel = function (user, channelName) {
|
||||
|
||||
if(user.channelProcess) {
|
||||
if(user.channelPipe) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
|
||||
|
|
@ -35,40 +39,55 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
|
|||
return false;
|
||||
}
|
||||
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
channel = new PipeToChannel(channelName);
|
||||
this.channels[channelName] = channel;
|
||||
|
||||
NotificationCenter.on('channel/' + channelName + '/message', function (data) {
|
||||
channel.send('channel', data);
|
||||
}, this);
|
||||
|
||||
NotificationCenter.on('user/joined', function (user) {
|
||||
NotificationCenter.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
|
||||
channel.send(recipient, data);
|
||||
}, this);
|
||||
}, this);
|
||||
|
||||
NotificationCenter.on('user/left', function (user) {
|
||||
|
||||
}, this);
|
||||
var channelPipe = this.channelPipes[channelName];
|
||||
if(!channelPipe) {
|
||||
this.createPipe(channelName);
|
||||
}
|
||||
|
||||
//channel.addUser(user);
|
||||
//user.setChannel(channel);
|
||||
NotificationCenter.trigger('user/joined', user);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.removeUser = function (user) {
|
||||
|
||||
user.channel.send('user/' + user.id + '/left');
|
||||
NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
|
||||
//user.channel.send('user/' + user.id + '/left');
|
||||
//NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.createPipe = function(channelName) {
|
||||
|
||||
var channelPipe = new PipeToChannel(channelName);
|
||||
this.channelPipes[channelName] = channelPipe;
|
||||
|
||||
|
||||
NotificationCenter.on('channel/' + channelName + '/message', function (data) {
|
||||
channelPipe.send('channel', data);
|
||||
}, this);
|
||||
|
||||
// sending info to user
|
||||
NotificationCenter.on('user/joined', function (user) {
|
||||
/*
|
||||
NotificationCenter.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
|
||||
channelPipe.send(recipient, data);
|
||||
}, this);
|
||||
*/
|
||||
|
||||
channelPipe.send('channel', { addUser: user.id });
|
||||
|
||||
}, this);
|
||||
|
||||
NotificationCenter.on('user/left', function (user) {
|
||||
|
||||
}, this);
|
||||
|
||||
return channelPipe;
|
||||
};
|
||||
|
||||
return Coordinator;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue