mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
refactored Server and Lobby
This commit is contained in:
parent
42475c9b38
commit
d83376d5c7
26 changed files with 29 additions and 29 deletions
|
|
@ -1,55 +0,0 @@
|
|||
define([
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"child_process"
|
||||
],
|
||||
|
||||
function (Nc, childProcess) {
|
||||
|
||||
var fork = childProcess.fork;
|
||||
|
||||
function PipeToChannel (channelName) {
|
||||
|
||||
this.channelPipe = null;
|
||||
|
||||
try {
|
||||
this.channelPipe = fork('channel.js');
|
||||
} catch (err) {
|
||||
throw 'Failed to fork channel! (' + err + ')';
|
||||
}
|
||||
|
||||
console.checkpoint('creating channel process for ' + channelName);
|
||||
|
||||
this.send('channel/' + channelName, { CREATE: channelName });
|
||||
|
||||
this.channelPipe.on('message', this.onMessage.bind(this));
|
||||
|
||||
var self = this;
|
||||
}
|
||||
|
||||
// While creating user
|
||||
PipeToChannel.prototype.send = function (recipient, data) {
|
||||
var message = {
|
||||
recipient: recipient,
|
||||
data: data
|
||||
}
|
||||
|
||||
this.channelPipe.send(message);
|
||||
}
|
||||
|
||||
// If user already created
|
||||
PipeToChannel.prototype.sendToUser = function (id, data) {
|
||||
var message = {
|
||||
recipient: "user/" + id,
|
||||
data: data
|
||||
}
|
||||
|
||||
this.channelPipe.send(message);
|
||||
}
|
||||
|
||||
PipeToChannel.prototype.onMessage = function (message) {
|
||||
Nc.trigger(message.recipient + '/message', message.data);
|
||||
}
|
||||
|
||||
return PipeToChannel;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue