0.3.6 updated deps, cleaned up logging

http-server
David Kebler 2019-04-26 10:12:34 -07:00
parent 7226a9b137
commit feb6a93385
2 changed files with 14 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci/websocket",
"version": "0.3.5",
"version": "0.3.6",
"description": "JSON packet host websocket server",
"main": "src",
"scripts": {
@ -41,10 +41,10 @@
"nodemon": "^1.18.6"
},
"dependencies": {
"@uci-utils/logger": "0.0.13",
"@uci-utils/logger": "0.0.14",
"better-try-catch": "^0.6.2",
"clone": "^2.1.2",
"death": "^1.1.0",
"ws": "^6.1.3"
"ws": "^6.2.0"
}
}

View File

@ -36,7 +36,7 @@ class Socket extends WebSocket.Server {
async create() {
return new Promise((resolve, reject) => {
_ON_DEATH(async () => {
log.info('\nhe\'s dead jim')
log.error({method:'create', line:39, msg:'\nhe\'s dead jim'})
await this._destroy()
})
process.once('SIGUSR2', async () => {
@ -45,14 +45,13 @@ class Socket extends WebSocket.Server {
})
this.on('error', async err => {
log.fatal(err, 'socket server error')
console.error(err, 'socket server error')
log.error({method:'creaete', line:48, err:err, msg:'socket server error'})
reject(err)
})
this.on('listening', async () => {
this._listen()
log.info('websocket server created and listening at', this.address())
log.info({method:'create', line:54, msg:'websocket server created and listening at', address:this.address()})
resolve(
`websocket ready and listening at ${this.address().address}:${
this.address().port
@ -69,15 +68,15 @@ class Socket extends WebSocket.Server {
_listen() {
this.on('connection', async (socket, req) => {
let send = this._send.bind(socket)
log.info({ req: req }, 'new consumer connecting')
log.debug({method:'_listen', line:71, req: req, msg: 'new consumer connecting'})
socket.address = req.remoteAddress
socket.on('message', messageProcess.bind(this, socket))
async function messageProcess(client, strPacket) {
log.info({ packet: strPacket }, ' incoming packet on web socket side')
log.debug({method:'_listen', line:76, packet: strPacket, msg:' incoming packet on web socket side'})
let res = {}
let [err, packet] = btc(JSON.parse)(strPacket)
log.info('packet', err, packet)
log.debug({method:'_listen', line:79, error:err, packet:packet, msg:'parsed websocket packet'})
if (err) {
res = { error: `Could not parse JSON: ${packet}` }
} else {
@ -102,16 +101,17 @@ class Socket extends WebSocket.Server {
res._header.responder = { name: this.name, instanceID: this.id }
res._header.socket = this.address()
if (!res.cmd) res.cmd = 'reply' // by default return command is 'reply'
log.info({ packet: res }, await send(res))
let sres = await send(res)
log.debug({method:'_listen', line:105, packet: res, sendResponse:sres, msg:'packet reply send back to client'})
}
}) // end connected consumer
log.info('socket created')
log.debug('socket created')
} // end listen
async _destroy() {
log.info('closing down socket')
log.debug({method:'_listen', line:105, msg:'closing down socket'})
await this.close()
log.info('all connections closed....exiting')
log.debug({method:'_listen', line:105, msg:'all connections closed....exiting'})
process.exit()
}