add an ending comma in console.xxx({_at,...}, '\n,')
				
					
				
			This commit is contained in:
		
							parent
							
								
									e0ba1e32be
								
							
						
					
					
						commit
						7cb60d71b0
					
				
							
								
								
									
										12
									
								
								rpcsocket.js
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								rpcsocket.js
									
									
									
									
									
								
							@ -14,14 +14,14 @@ const DAD = (module.exports = class RpcSocket extends ws {
 | 
				
			|||||||
    ws.sid = randomBytes(16).toString('hex')
 | 
					    ws.sid = randomBytes(16).toString('hex')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ws.onmessage = async ({ data }) => {
 | 
					    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 {
 | 
					      try {
 | 
				
			||||||
        let { rpcType, rpcHow, rpcWhat, randomEvent, rpcResult } = JSON.parse(data)
 | 
					        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) {
 | 
					        switch (rpcType) {
 | 
				
			||||||
          case 'SEND_REQUEST':
 | 
					          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)
 | 
					            if (ws.hasOwnProperty(rpcHow)) rpcResult = await ws[rpcHow](rpcWhat)
 | 
				
			||||||
            else rpcResult = { _state: 'ERROR', _stateMsg: `unknown rpcHow=${rpcHow}` }
 | 
					            else rpcResult = { _state: 'ERROR', _stateMsg: `unknown rpcHow=${rpcHow}` }
 | 
				
			||||||
            if (randomEvent) {
 | 
					            if (randomEvent) {
 | 
				
			||||||
@ -30,7 +30,7 @@ const DAD = (module.exports = class RpcSocket extends ws {
 | 
				
			|||||||
            break
 | 
					            break
 | 
				
			||||||
          case 'SEND_RESULT':
 | 
					          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)
 | 
					            ws.emit(randomEvent, rpcResult)
 | 
				
			||||||
            break
 | 
					            break
 | 
				
			||||||
          case 'SEND_NOTIFY':
 | 
					          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})
 | 
					            // console.log({ _at: new Date().toJSON(),about:'被调方 收到 SEND_NOFITY', rpcHow, rpcWhat})
 | 
				
			||||||
            if (ws.hasOwnProperty(rpcHow)) ws[rpcHow](rpcWhat)
 | 
					            if (ws.hasOwnProperty(rpcHow)) ws[rpcHow](rpcWhat)
 | 
				
			||||||
            else if (ws.eventNames().indexOf(rpcHow) >= 0) ws.emit(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
 | 
					            break
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      } catch (exception) {
 | 
					      } 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
 | 
					        return
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user