mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
53 lines
No EOL
1.3 KiB
JavaScript
Executable file
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 + '/message', message);
|
|
}
|
|
|
|
return PipeToLobby;
|
|
|
|
}); |