0.4.0 refactor how connect packets are handled to match socket package

bump to  0.4.0 in anticipation of 3-2020 deplogyment of light code
master
David Kebler 2020-03-15 15:48:34 -07:00
parent 84cd362751
commit aeae1df3fa
2 changed files with 11 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci/websocket", "name": "@uci/websocket",
"version": "0.3.15", "version": "0.4.0",
"description": "JSON packet host websocket server", "description": "JSON packet host websocket server",
"main": "src", "main": "src",
"scripts": { "scripts": {
@ -33,8 +33,8 @@
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"esm": "^3.2.25", "esm": "^3.2.25",
"mocha": "^6.2.2", "mocha": "^7.1.0",
"nodemon": "^2.0.0" "nodemon": "^2.0.2"
}, },
"dependencies": { "dependencies": {
"@uci-utils/logger": "0.0.16", "@uci-utils/logger": "0.0.16",
@ -42,6 +42,7 @@
"better-try-catch": "^0.6.2", "better-try-catch": "^0.6.2",
"clone": "^2.1.2", "clone": "^2.1.2",
"death": "^1.1.0", "death": "^1.1.0",
"ws": "^7.2.0" "p-reflect": "^2.1.0",
"ws": "^7.2.3"
} }
} }

View File

@ -34,7 +34,7 @@ class Socket extends Server {
this.pingInterval = opts.pingInterval === false ? opts.pingInterval : (opts.pingInterval * 1000 || 5000) this.pingInterval = opts.pingInterval === false ? opts.pingInterval : (opts.pingInterval * 1000 || 5000)
this.nextconsumerID = 0 // incrementer for default initial consumer ID this.nextconsumerID = 0 // incrementer for default initial consumer ID
this.consumers = new Map() this.consumers = new Map()
this.conPackets = opts.conPackets || opts.conPacket this.conPackets = opts.conPackets || [opts.conPacket]
this.errors = [] this.errors = []
this.errorCount = 0 this.errorCount = 0
this.create = this.create.bind(this) this.create = this.create.bind(this)
@ -287,15 +287,11 @@ class Socket extends Server {
} }
} }
if (this.conPackets) { if (this.conPackets.length) {
this.conPackets = Array.isArray(this.conPackets) ? this.conPackets : [this.conPackets] for (let packet of this.conPackets) {
log.debug({method:'_listen', line:171, conPackets: this.conPackets, msg:'pushing a preset packets to just connected consumer'}) packet._header = {type:'on connection packet', id: 'pushed'}
this.conPackets.forEach(packet => { await this._send(consumer,packet) // send a packet command on to consumer on connection
if (packet) { }
packet._header = {type:'on connection packet', id: 'pushed'}
this._send(consumer,packet) // send a packet command on to consumer on connection
}
})
} }
this.emit('connection:consumer',{state:'connected', name:consumer.name, id:consumer.id}) this.emit('connection:consumer',{state:'connected', name:consumer.name, id:consumer.id})