修复不能正确解析来自服务器的切断ws消息

This commit is contained in:
MrZ626
2021-05-12 22:14:37 +08:00
parent 0f61c8db8b
commit ef2346efa0
2 changed files with 4 additions and 5 deletions

View File

@@ -188,8 +188,7 @@ while true do--Running
readCHN:push(op)
SOCK:close()
if type(res)=='string'then
res=JSON.decode(res)
readCHN:push(res and res.reason or"WS Error")
readCHN:push(res)--Warning: with 2 bytes close code
else
readCHN:push("WS Error")
end

View File

@@ -80,11 +80,11 @@ end
--WS close message
local function wsCloseMessage(message)
local mes=JSON.decode(message)
local mes=JSON.decode(message:sub(3))
if mes then
LOG.print(("%s [%s] %s"):format(text.wsClose,mes.type or"unknown type",mes.reason or""),'warn')
LOG.print(("%s [%s] %s"):format(text.wsClose,mes.type or"unknown type",mes.reason or""),'error')
else
LOG.print(text.wsClose.."",'warn')
LOG.print(text.wsClose,'error')
end
end