added lobby, nickname fixes #44, channel name

This commit is contained in:
Jeena 2014-02-25 00:55:16 +01:00
parent aa4535cb0c
commit da913c4709
10 changed files with 285 additions and 68 deletions

52
app/Lobby/Api.js Normal file
View file

@ -0,0 +1,52 @@
define([
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Protocol/Helper"
],
function (NotificationCenter, ProtocolHelper) {
function Api(coordinator) {
this.coordinator = coordinator;
this.isError = false;
this.output = null;
}
Api.prototype.handleCall = function(queryParameters) {
var command;
try {
var message = JSON.parse(queryParameters);
command = message.command;
} catch(e) {
console.error(e)
}
var output = null;
switch(command) {
case "getChannels":
output = this.coordinator.getChannels();
break;
default:
this.isError = true;
output = "Command not found";
break;
}
this.output = output;
}
Api.prototype.getOutput = function() {
var output = {};
var key = this.isError ? "error" : "success";
output[key] = this.output;
return JSON.stringify(output);
};
Api.prototype.getContentType = function() {
return "application/json";
};
return Api;
});

View file

@ -92,6 +92,16 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
return channelPipe;
};
Coordinator.prototype.getChannels = function(options) {
var list = [];
for (var channelName in this.channelPipes) {
list.push({
name: channelName
});
}
return list;
};
return Coordinator;
});

View file

@ -13,6 +13,7 @@ function (NotificationCenter, childProcess) {
try {
this.channelPipe = fork('channel.js');
console.log(this.channelPipe)
} catch (err) {
throw 'Failed to fork channel! (' + err + ')';
}

View file

@ -20,11 +20,7 @@ function (Parent, ProtocolHelper, NotificationCenter) {
}
User.prototype = Object.create(Parent.prototype);
User.prototype.setChannelProcess = function (channelProcess) {
this.channelProcess = channelProcess;
}
// Socket callbacks