0.3.11 update/change to new event names connection:consumer and log (from status)

master
David Kebler 2019-12-08 14:54:40 -08:00
parent 4fcdc4166a
commit 87fba5c955
2 changed files with 7 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci/websocket",
"version": "0.3.10",
"version": "0.3.11",
"description": "JSON packet host websocket server",
"main": "src",
"scripts": {

View File

@ -81,19 +81,19 @@ class Socket extends Server {
this.on('error', err => {
this.errorCount +=1 // log errors here
this.errors.push(err)
if(this.errorCount>2) this.emit('status', {level:'warn',msg:'something bad maybe going on, 3 errors', errors:this.errors})
if(this.errorCount>2) this.emit('log', {level:'warn',msg:'something bad maybe going on, 3 errors', errors:this.errors})
if(this.errorCount>5) {
let errors = {level:'fatal',msg:'something fatal is going on, 6 errors', errors:this.errors}
log.fatal(errors)
this.listening=false
this.emit('status', {active:this.active})
this.emit('status', errors)
this.emit('log', {active:this.active})
this.emit('log', errors)
}
})
this.wss = new WSS({server:this})
this.wss.on('error', err => {this.emit('error', err)}) // bubble up errors
this.wss.on('connection', this._connectionHandler.bind(this))
this.emit('status',{active:this.active})
this.emit('log',{active:this.active})
resolve(`websocket ready and listening at ${this.address().address}:${this.address().port}`)
})
super.listen(this.opts)
@ -161,7 +161,7 @@ class Socket extends Server {
removeconsumer (id) {
let consumer = this.consumers.get(id)
this.emit('consumer-connection',{state:'disconnected', id:consumer.id, name:consumer.name, socketSide:true})
this.emit('connection:consumer',{state:'disconnected', name:consumer.name})
clearInterval(consumer._ping)
consumer.removeAllListeners()
log.warn({msg:`consumer ${id}:${consumer.name} removed from server tracking`, id:id, name:consumer.name, curconsumerCount:this.consumers.size})
@ -257,8 +257,7 @@ class Socket extends Server {
this._send(consumer,this.opts.conPacket) // send a packet command on to consumer on connection
}
this.emit('consumer-connection',{state:'connected', consumer:consumer})
this.emit('status',{level:'info', msg:'a consumer connected', name:consumer.name, id:consumer.id})
this.emit('connection:consumer',{state:'connected', name:consumer.name, id:consumer.id})
consumer._ping = setInterval( () => {
consumer.ping(JSON.stringify({pingInterval:this.pingInterval}))