add an ending comma in console.xxx({_at,...}, '\n,')
				
					
				
			This commit is contained in:
		
							parent
							
								
									96c47325a6
								
							
						
					
					
						commit
						4f57a147a5
					
				| @ -10,10 +10,10 @@ const my = { | ||||
| module.exports = { | ||||
|   initSocket (webServer) { | ||||
|     my.wsServer = new ws.Server({ server: webServer }) | ||||
|     console.info({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CLOG', about: 'Base Socket Server is initialized.' }) | ||||
|     console.info({ _at: new Date().toJSON(), _from: 'Socket:initSocket', _type: 'CLOG', about: 'Base Socket Server is initialized.' }, '\n,') | ||||
| 
 | ||||
|     my.wsServer.on('connection', (socket, req) => { | ||||
|       //console.info({_at:new Date().toJSON(), _from: 'Socket', _type:'CLOG', about: `A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`})
 | ||||
|       //console.info({_at:new Date().toJSON(), _from: 'Socket:onConnection', _type:'CLOG', about: `A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`},'\n,')
 | ||||
| 
 | ||||
|       // socket.isAlive = true
 | ||||
|       // socket.on('pong', function() { this.isAlive = true })
 | ||||
| @ -23,12 +23,12 @@ module.exports = { | ||||
|         let dataObj | ||||
|         try { | ||||
|           dataObj = JSON.parse(data) | ||||
|           console.log({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CLOG', skevent: dataObj?.skevent, usid: socket.usid, dataObj }) | ||||
|           if (dataObj?.skevent === 'PING') { | ||||
|             return | ||||
|           } | ||||
|           console.log({ _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CLOG', usid: socket.usid, dataObj }, '\n,') | ||||
|         } catch (exception) { | ||||
|           console.error({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CERROR', about: 'Unable to parse socket message', data }) | ||||
|           return | ||||
|         } | ||||
|         if (dataObj.skevent === 'PING') { | ||||
|           console.error({ _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CERROR', about: 'Unable to parse socket message', data }, '\n,') | ||||
|           return | ||||
|         } | ||||
|         if (['SOCKET_OWNER', 'SOCKET_OWNER_RECONNECT'].includes(dataObj.skevent)) { | ||||
| @ -38,12 +38,12 @@ module.exports = { | ||||
|             my.socketPool[dataObj._passtokenSource.usid] = socket | ||||
|             socket.usid = dataObj._passtokenSource.usid | ||||
|             console.log({ | ||||
|               _at: new Date().toJSON(), _from: 'Socket', _type: 'CLOG', | ||||
|               _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CLOG', | ||||
|               skevent: dataObj.skevent, | ||||
|               usid: dataObj._passtokenSource.usid, | ||||
|               socketPool: Object.keys(my.socketPool)?.length, | ||||
|               socketClients: my.wsServer.clients.size | ||||
|             }) | ||||
|             }, '\n,') | ||||
|           } | ||||
|         } | ||||
| 
 | ||||
| @ -62,7 +62,7 @@ module.exports = { | ||||
|       // }, 60000)
 | ||||
| 
 | ||||
|       socket.on('close', () => { | ||||
|         //console.log({_at:new Date().toJSON(), _from: 'Socket', _type:'CLOG', usid: socket?.usid}) // don't know why, but this output happens too often without usid.
 | ||||
|         //console.log({_at:new Date().toJSON(), _from: 'Socket:onClose', _type:'CLOG', usid: socket?.usid},'\n,') // don't know why, but this output happens too often without usid.
 | ||||
|         delete my.socketPool[socket?.usid] | ||||
|         // clearInterval(heartbeat)
 | ||||
|       }) | ||||
| @ -89,7 +89,7 @@ module.exports = { | ||||
|       if (socket.readyState === socket.OPEN) { | ||||
|         socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj) | ||||
|       } else { | ||||
|         console.warn({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CWARN', msg: 'sendToAll: Failed sending to unconnected socket', dataObj, usid: socket.usid }) | ||||
|         console.warn({ _at: new Date().toJSON(), _from: 'Socket:sendToAll', _type: 'CWARN', msg: 'sendToAll: Failed sending to unconnected socket', dataObj, usid: socket.usid }, '\n,') | ||||
|         delete my.socketPool[socket.usid] | ||||
|       } | ||||
|     }) | ||||
| @ -100,7 +100,7 @@ module.exports = { | ||||
|     if (socket && socket.readyState === socket.OPEN) { | ||||
|       socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj) | ||||
|     } else { | ||||
|       console.warn({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CWARN', msg: 'sendToOne: Failed sending to unconnected socket', dataObj, usid }) | ||||
|       console.warn({ _at: new Date().toJSON(), _from: 'Socket:sendToOne', _type: 'CWARN', msg: 'sendToOne: Failed sending to unconnected socket', dataObj, usid }, '\n,') | ||||
|       delete my.socketPool[usid] | ||||
|     } | ||||
|   }, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user