add an ending comma in console.xxx({_at,...}, '\n,')

This commit is contained in:
Luk 2024-02-05 11:41:21 +08:00
parent e0ba1e32be
commit 7cb60d71b0

View File

@ -14,14 +14,14 @@ const DAD = (module.exports = class RpcSocket extends ws {
ws.sid = randomBytes(16).toString('hex')
ws.onmessage = async ({ data }) => {
// console.log({ _at: new Date().toJSON(), about:'[onmessage] 被调用在 data =', data})
// console.log({ _at: new Date().toJSON(), about:'[onmessage] 被调用在 data =', data}, '\n,')
try {
let { rpcType, rpcHow, rpcWhat, randomEvent, rpcResult } = JSON.parse(data)
// console.log({ _at: new Date().toJSON(), about:'message data parsed', rpcType, rpcHow, rpcWhat, randomEvent, rpcResult})
// console.log({ _at: new Date().toJSON(), about:'message data parsed', rpcType, rpcHow, rpcWhat, randomEvent, rpcResult}, '\n,')
switch (rpcType) {
case 'SEND_REQUEST':
// 接收到异步的远程调用
// console.log({ _at: new Date().toJSON(), about:'被调方 收到 SEND_REQUEST', rpcHow, rpcWhat})
// console.log({ _at: new Date().toJSON(), about:'被调方 收到 SEND_REQUEST', rpcHow, rpcWhat}, '\n,')
if (ws.hasOwnProperty(rpcHow)) rpcResult = await ws[rpcHow](rpcWhat)
else rpcResult = { _state: 'ERROR', _stateMsg: `unknown rpcHow=${rpcHow}` }
if (randomEvent) {
@ -30,7 +30,7 @@ const DAD = (module.exports = class RpcSocket extends ws {
break
case 'SEND_RESULT':
// 接收到远程返回的结果
// console.log({ _at: new Date().toJSON(),about:'主调方 收到 SEND_RESULT', rpcResult})
// console.log({ _at: new Date().toJSON(),about:'主调方 收到 SEND_RESULT', rpcResult}, '\n,')
ws.emit(randomEvent, rpcResult)
break
case 'SEND_NOTIFY':
@ -39,11 +39,11 @@ const DAD = (module.exports = class RpcSocket extends ws {
// console.log({ _at: new Date().toJSON(),about:'被调方 收到 SEND_NOFITY', rpcHow, rpcWhat})
if (ws.hasOwnProperty(rpcHow)) ws[rpcHow](rpcWhat)
else if (ws.eventNames().indexOf(rpcHow) >= 0) ws.emit(rpcHow, rpcWhat)
else console.error({ _at: new Date().toJSON(), about: '[onmessage] unknown rpc', rpcHow, rpcWhat })
else console.error({ _at: new Date().toJSON(), about: '[onmessage] unknown rpc', rpcHow, rpcWhat }, '\n,')
break
}
} catch (exception) {
console.error({ _at: new Date().toJSON(), about: '[onmessage] invalid rpc data', data, exception })
console.error({ _at: new Date().toJSON(), about: '[onmessage] invalid rpc data', data, exception }, '\n,')
return
}
}