extended client server communication

This commit is contained in:
logsol 2012-07-08 04:29:14 +02:00
parent 94f63fc7b2
commit 81d2aa4ddc
12 changed files with 156 additions and 86 deletions

View file

@ -1,4 +1,4 @@
define(["Protocol/Parser"], function(Parser) {
define(["Protocol/Helper"], function(ProtocolHelper) {
function User(socketLink, coordinator) {
@ -12,33 +12,36 @@ define(["Protocol/Parser"], function(Parser) {
User.prototype.init = function(socketLink){
var self = this;
socketLink.on('message', function(message){
this.onMessage(message);
self.onMessage(message);
});
socketLink.on('disconnect', function(){
this.onDisconnect();
self.onDisconnect();
});
}
User.prototype.setChannel = function(channel){
this.channel = channel;
this.sendCommand('joinSuccess', channel.name);
}
User.prototype.send = function(message){
message = Parser.encode(message);
User.prototype.sendCommand = function(command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
User.prototype.onMessage = function(){
var commands = Parser.decode(message);
for(var command in commands) {
this.processControlCommand(command, commands[command]);
}
User.prototype.onMessage = function(message){
var self = this;
ProtocolHelper.runCommands(message, function(command, options){
self.processControlCommand(command, options);
});
}
User.prototype.onDisconnect = function(){
return null;
this.coordinator.removeUser(this);
}
User.prototype.processControlCommand = function(command, options){