mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
removed node-fork, using native child_process now, the API is the same
This commit is contained in:
parent
25653b4d58
commit
b5b10ba0b9
3 changed files with 29 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue