removed node-fork, using native child_process now, the API is the same

This commit is contained in:
Jeena Paradies 2012-07-23 01:11:18 +02:00
parent 25653b4d58
commit b5b10ba0b9
3 changed files with 29 additions and 7 deletions

View file

@ -6,9 +6,10 @@ define([
function(GameController, NotificationCenter) {
function Channel(coordinatorLink) {
var self = this;
this.coordinatorLink = coordinatorLink;
this.coordinatorLink.receive = this.onMessage;
this.coordinatorLink.receive = function(message) { self.onMessage(message) };
this.users = {};
@ -26,15 +27,22 @@ function(GameController, NotificationCenter) {
return true;
}
// Messages look like:
// {chanel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
Channel.prototype.onMessage = function(message) {
for(var recipient in message) {
switch(recipient) {
case 'user':
this.users[message.id].onMessage(message.user);
break;
case 'id': // Do nothing, it is needed by the user
break;
case 'channel':
this.onMessage(message.channel);
this.onCommand(message.channel);
break;
default:
throw 'unknown recipient';
@ -42,6 +50,21 @@ function(GameController, NotificationCenter) {
}
}
};
Channel.prototype.onCommand = function(message) {
for(var command in message) {
switch(command) {
case 'setName':
this.name = message[command];
console.log("Chanel name set to '" + this.name + "'");
break;
default:
throw 'unknown command';
break;
}
}
};
/*
Channel.prototype.addUser = function(user){
var userIds = Object.keys(this.users);

View file

@ -1,12 +1,12 @@
define([
"Lobby/User",
"Game/Server/Channel",
"node-fork"
"child_process"
],
function(User, Channel, nodeFork) {
function(User, Channel, childProcess) {
var fork = nodeFork.fork;
var fork = childProcess.fork;
function Coordinator() {
this.channels = {};

View file

@ -17,8 +17,7 @@
"dependencies": {
"socket.io": ">= 0.9.6",
"node-static": ">= 0.6.0",
"requirejs": ">= 2.0.2",
"node-fork": ">= 0.4.2"
"requirejs": ">= 2.0.2"
},
"devDependencies": {},
"optionalDependencies": {},