Finished nc (notification center topic style refactoring) - fixes #60

This commit is contained in:
logsol 2014-03-17 23:12:08 +01:00
parent cacd5d74c0
commit 76d9450257
9 changed files with 67 additions and 30 deletions

View file

@ -11,7 +11,7 @@ function (User, Channel, PipeToChannel, Nc, Settings) {
function Coordinator() {
this.channelPipes = {};
Nc.on(Nc.ns.server.events.controlCommand + "coordinator", this.onMessage, this);
Nc.on(Nc.ns.server.events.controlCommand.coordinator, this.onMessage, this);
console.checkpoint('create Coordinator');
}

View file

@ -39,7 +39,7 @@ function (Nc, childProcess) {
// If user already created
PipeToChannel.prototype.sendToUser = function (id, data) {
var message = {
recipient: "user/" + id,
recipient: id,
data: data
}
@ -47,7 +47,15 @@ function (Nc, childProcess) {
}
PipeToChannel.prototype.onMessage = function (message) {
Nc.trigger(Nc.ns.server.events.controlCommand + message.recipient, message.data);
switch(message.recipient) {
case 'coordinator':
Nc.trigger(Nc.ns.server.events.controlCommand.coordinator, message.data);
break;
default:
Nc.trigger(Nc.ns.server.events.controlCommand.user + message.recipient, message.data);
break;
}
}
return PipeToChannel;

View file

@ -16,7 +16,7 @@ function (Parent, ProtocolHelper, Nc) {
socketLink.on('message', this.onMessage.bind(this));
socketLink.on('disconnect', this.onDisconnect.bind(this));
Nc.on(Nc.ns.server.to.client.message.send + id, this.socketLink.send, this.socketLink);
Nc.on(Nc.ns.server.events.controlCommand.user + this.id, this.socketLink.send, this.socketLink);
}
User.prototype = Object.create(Parent.prototype);
@ -65,6 +65,7 @@ function (Parent, ProtocolHelper, Nc) {
this.channelPipe.send('channel', { addUser: userOptions });
};
/* FIXME: watch out and check in wich direction game and control commands flow */
User.prototype.onGameCommand = function(options) {
// repacking for transport via pipe
var message = ProtocolHelper.encodeCommand("gameCommand", options);
@ -73,7 +74,7 @@ function (Parent, ProtocolHelper, Nc) {
User.prototype.onPing = function(timestamp) {
var message = ProtocolHelper.encodeCommand("pong", timestamp);
Nc.trigger(Nc.ns.server.to.client.message.send + id, message);
Nc.trigger(Nc.ns.server.events.controlCommand.user + this.id, message);
};
return User;