mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
extended client server communication
This commit is contained in:
parent
94f63fc7b2
commit
81d2aa4ddc
12 changed files with 156 additions and 86 deletions
25
lib/Protocol/Helper.js
Normal file
25
lib/Protocol/Helper.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
define(["Protocol/Parser"], function(Parser) {
|
||||
|
||||
var Helper = {}
|
||||
|
||||
Helper.encodeCommand = function(command, options){
|
||||
return Parser.encode(Helper.assemble(command, options));
|
||||
}
|
||||
|
||||
Helper.assemble = function(command, options){
|
||||
var commands = {};
|
||||
commands[command] = options;
|
||||
return commands;
|
||||
}
|
||||
|
||||
Helper.runCommands = function(message, callback){
|
||||
var commands = Parser.decode(message);
|
||||
|
||||
for(var command in commands) {
|
||||
callback(command, commands[command]);
|
||||
}
|
||||
}
|
||||
|
||||
return Helper;
|
||||
|
||||
});
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
define(function() {
|
||||
|
||||
function Parser() {
|
||||
}
|
||||
var Parser = {};
|
||||
|
||||
Parser.prototype.encode = function(message){
|
||||
Parser.encode = function(message){
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
|
||||
Parser.prototype.decode = function(message){
|
||||
Parser.decode = function(message){
|
||||
return JSON.parse(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue