chuck.js/app/Game/Server/PipeToLobby.js
2013-01-05 06:16:42 +01:00

53 lines
No EOL
1.3 KiB
JavaScript
Executable file

define([
"Game/Core/NotificationCenter",
"Game/Server/Channel"
],
function (NotificationCenter, Channel) {
function PipeToLobby (process) {
var self = this;
this.channel = null;
this.process = process;
NotificationCenter.on('process/message', this.send, this);
process.on('message', function (message, handle) {
for(var method in message.data) {
switch(method) {
case 'CREATE':
self.channel = new Channel(this, message.data[method]);
break;
case 'KILL':
self.channel.destroy();
process.exit(0);
break;
default:
self.onMessage(message);
break;
}
}
});
}
PipeToLobby.prototype.send = function (recipient, data) {
var message = {
recipient: recipient,
data: data
}
this.process.send(message);
};
PipeToLobby.prototype.onMessage = function (message) {
NotificationCenter.trigger(message.recipient + '/controlCommand', message);
}
return PipeToLobby;
});