optimize web socket interface, add some test case for ws

This commit is contained in:
OttoMao
2015-04-27 16:23:12 +08:00
parent 8e7aef70ae
commit f98721c482
8 changed files with 91 additions and 70 deletions

View File

@@ -23,23 +23,18 @@ function resToMsg(msg,cb){
}
if(jsonData.type == "reqBody" && jsonData.id){
result.type ="body";
GLOBAL.recorder.getBodyUTF8(jsonData.id, function(err, data){
if(err){
result = {
type : "body",
content : {
id : null,
body : null,
error : err.toString()
}
result.content = {
id : null,
body : null,
error : err.toString()
};
}else{
result = {
type : "body",
content : {
id : jsonData.id,
body : data
}
result.content = {
id : jsonData.id,
body : data
};
}
cb && cb(result);
@@ -75,13 +70,22 @@ function wsServer(config){
});
});
wss.on("close",function(){});
GLOBAL.recorder.on("update",function(data){
wss && wss.broadcast({
type : "update",
content: data
});
try{
wss && wss.broadcast({
type : "update",
content: data
});
}catch(e){
console.log("ws error");
console.log(e);
}
});
//Iconv-lite warning: decode()-ing strings is deprecated. Refer to https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding
return wss;
}