chore: update test code for websocket

This commit is contained in:
xiaofeng.mxf
2021-08-30 00:27:17 +08:00
parent 42e43fca7b
commit 570acb6519
5 changed files with 127 additions and 371 deletions

View File

@@ -84,7 +84,7 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
const clientMsgQueue = [];
const serverInfo = getWsReqInfo(wsReq);
// proxy-layer websocket client
const proxyWs = new WebSocket(serverInfo.url, '', {
const proxyWs = new WebSocket(serverInfo.url, {
rejectUnauthorized: !self.dangerouslyIgnoreUnauthorized,
headers: serverInfo.noWsHeaders
});
@@ -106,13 +106,8 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
*/
const sendProxyMessage = (finalMsg) => {
const message = finalMsg.data;
if (proxyWs.readyState === 1) {
// if there still are msg queue consuming, keep it going
if (clientMsgQueue.length > 0) {
clientMsgQueue.push(message);
} else {
proxyWs.send(message);
}
if (proxyWs.readyState === 1 && clientMsgQueue.length === 0) {
proxyWs.send(message);
} else {
clientMsgQueue.push(message);
}
@@ -120,7 +115,6 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
/**
* consume the message in queue when the proxy ws is not ready yet
* will handle them from the first one-by-one
*/
const consumeMsgQueue = () => {
while (clientMsgQueue.length > 0) {