修复不能正确解析来自服务器的切断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) readCHN:push(op)
SOCK:close() SOCK:close()
if type(res)=='string'then if type(res)=='string'then
res=JSON.decode(res) readCHN:push(res)--Warning: with 2 bytes close code
readCHN:push(res and res.reason or"WS Error")
else else
readCHN:push("WS Error") readCHN:push("WS Error")
end end

View File

@@ -80,11 +80,11 @@ end
--WS close message --WS close message
local function wsCloseMessage(message) local function wsCloseMessage(message)
local mes=JSON.decode(message) local mes=JSON.decode(message:sub(3))
if mes then 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 else
LOG.print(text.wsClose.."",'warn') LOG.print(text.wsClose,'error')
end end
end end