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 = {
 | 
					module.exports = {
 | 
				
			||||||
  initSocket (webServer) {
 | 
					  initSocket (webServer) {
 | 
				
			||||||
    my.wsServer = new ws.Server({ server: 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) => {
 | 
					    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.isAlive = true
 | 
				
			||||||
      // socket.on('pong', function() { this.isAlive = true })
 | 
					      // socket.on('pong', function() { this.isAlive = true })
 | 
				
			||||||
@ -23,12 +23,12 @@ module.exports = {
 | 
				
			|||||||
        let dataObj
 | 
					        let dataObj
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          dataObj = JSON.parse(data)
 | 
					          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') {
 | 
				
			||||||
        } catch (exception) {
 | 
					 | 
				
			||||||
          console.error({ _at: new Date().toJSON(), _from: 'Socket', _type: 'CERROR', about: 'Unable to parse socket message', data })
 | 
					 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        if (dataObj.skevent === 'PING') {
 | 
					          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:onMessage', _type: 'CERROR', about: 'Unable to parse socket message', data }, '\n,')
 | 
				
			||||||
          return
 | 
					          return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (['SOCKET_OWNER', 'SOCKET_OWNER_RECONNECT'].includes(dataObj.skevent)) {
 | 
					        if (['SOCKET_OWNER', 'SOCKET_OWNER_RECONNECT'].includes(dataObj.skevent)) {
 | 
				
			||||||
@ -38,12 +38,12 @@ module.exports = {
 | 
				
			|||||||
            my.socketPool[dataObj._passtokenSource.usid] = socket
 | 
					            my.socketPool[dataObj._passtokenSource.usid] = socket
 | 
				
			||||||
            socket.usid = dataObj._passtokenSource.usid
 | 
					            socket.usid = dataObj._passtokenSource.usid
 | 
				
			||||||
            console.log({
 | 
					            console.log({
 | 
				
			||||||
              _at: new Date().toJSON(), _from: 'Socket', _type: 'CLOG',
 | 
					              _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CLOG',
 | 
				
			||||||
              skevent: dataObj.skevent,
 | 
					              skevent: dataObj.skevent,
 | 
				
			||||||
              usid: dataObj._passtokenSource.usid,
 | 
					              usid: dataObj._passtokenSource.usid,
 | 
				
			||||||
              socketPool: Object.keys(my.socketPool)?.length,
 | 
					              socketPool: Object.keys(my.socketPool)?.length,
 | 
				
			||||||
              socketClients: my.wsServer.clients.size
 | 
					              socketClients: my.wsServer.clients.size
 | 
				
			||||||
            })
 | 
					            }, '\n,')
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -62,7 +62,7 @@ module.exports = {
 | 
				
			|||||||
      // }, 60000)
 | 
					      // }, 60000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      socket.on('close', () => {
 | 
					      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]
 | 
					        delete my.socketPool[socket?.usid]
 | 
				
			||||||
        // clearInterval(heartbeat)
 | 
					        // clearInterval(heartbeat)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
@ -89,7 +89,7 @@ module.exports = {
 | 
				
			|||||||
      if (socket.readyState === socket.OPEN) {
 | 
					      if (socket.readyState === socket.OPEN) {
 | 
				
			||||||
        socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj)
 | 
					        socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj)
 | 
				
			||||||
      } else {
 | 
					      } 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]
 | 
					        delete my.socketPool[socket.usid]
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
@ -100,7 +100,7 @@ module.exports = {
 | 
				
			|||||||
    if (socket && socket.readyState === socket.OPEN) {
 | 
					    if (socket && socket.readyState === socket.OPEN) {
 | 
				
			||||||
      socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj)
 | 
					      socket.send(typeof dataObj !== 'string' ? JSON.stringify(dataObj) : dataObj)
 | 
				
			||||||
    } else {
 | 
					    } 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]
 | 
					      delete my.socketPool[usid]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user