chuck.js/app/Lobby/PipeToChannel.js
2012-08-29 16:11:43 +02:00

41 lines
No EOL
905 B
JavaScript
Executable file

define([
//"Game/Core/NotificationCenter",
"child_process"
],
function (childProcess) {
var fork = childProcess.fork;
function PipeToChannel (channelName) {
this.channelProcess = null;
try {
this.channelProcess = fork('channel.js');
} catch (err) {
throw 'Failed to fork channel! (' + err + ')';
}
this.send('channel/' + channelName, 'CREATE');
this.channelProcess.on('message', this.onMessage.bind(this));
var self = this;
}
PipeToChannel.prototype.send = function (recipient, data) {
var message = {
recipient: recipient,
data: data
}
this.channelProcess.send(message);
}
PipeToChannel.prototype.onMessage = function (message) {
NotficationCenter.trigger(message.recipient + '/message', message.data);
}
return PipeToChannel;
});