mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
41 lines
No EOL
905 B
JavaScript
Executable file
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;
|
|
|
|
}); |