mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
optimize web socket interface, add some test case for ws
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user