0.3.0 bumping to .3 with upcoming 3-2020 deployment of lighting system.

no apparent bugs
master
David Kebler 2020-03-15 14:32:35 -07:00
parent 0d578958a8
commit 70fee6fc7c
3 changed files with 15 additions and 22 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci/socket", "name": "@uci/socket",
"version": "0.2.33", "version": "0.3.0",
"description": "JSON packet intra(named)/inter(TCP) host communication over socket", "description": "JSON packet intra(named)/inter(TCP) host communication over socket",
"main": "src", "main": "src",
"scripts": { "scripts": {
@ -43,8 +43,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",
@ -52,7 +52,7 @@
"clone": "^2.1.2", "clone": "^2.1.2",
"death": "^1.1.0", "death": "^1.1.0",
"delay": "^4.3.0", "delay": "^4.3.0",
"make-dir": "^3.0.0", "make-dir": "^3.0.2",
"p-reflect": "^2.1.0" "p-reflect": "^2.1.0"
} }
} }

View File

@ -70,7 +70,6 @@ class SocketConsumer extends Socket {
this._connection = 'offline' this._connection = 'offline'
this._first = true // first connection or not this._first = true // first connection or not
this._pingTimeout // value sent from socket upon connect this._pingTimeout // value sent from socket upon connect
console.log('consumer.js @uci/socket package tag 0.2.33')
} }
get connected() { return this._connected} get connected() { return this._connected}
@ -190,7 +189,6 @@ class SocketConsumer extends Socket {
if (err) if (err)
resolve({error: 'unable to serialize packet for sending',packet: packet}) resolve({error: 'unable to serialize packet for sending',packet: packet})
if (this.active && this.writable) { if (this.active && this.writable) {
console.log('writable can write')
let res2 = await this.__write(res) let res2 = await this.__write(res)
if (res2.error) resolve(res2) if (res2.error) resolve(res2)
// if no write error then wait for send response // if no write error then wait for send response
@ -295,7 +293,6 @@ async function handshake (packet) {
this.notify('handshake') this.notify('handshake')
const authPacket = Object.assign(this._authenticate() || {}, {_authenticate:true, data:this._data}) const authPacket = Object.assign(this._authenticate() || {}, {_authenticate:true, data:this._data})
// console.log('----------------authentication packet---------------',authPacket) // console.log('----------------authentication packet---------------',authPacket)
console.log('authenticate writable',this.writable)
let res ={} let res ={}
if (!this.writable) res.error ='socket stream not writable' if (!this.writable) res.error ='socket stream not writable'
else res = await this._authenticateSend(authPacket) else res = await this._authenticateSend(authPacket)

View File

@ -66,7 +66,7 @@ export default function socketClass(Server) {
this.pingInterval = opts.pingInterval === false ? 0 : (opts.pingInterval * 1000 || 5000) this.pingInterval = opts.pingInterval === false ? 0 : (opts.pingInterval * 1000 || 5000)
this.consumers = new Map() // track consumers (i.e. clients) TODO use a Map this.consumers = new Map() // track consumers (i.e. clients) TODO use a Map
this.nextConsumerID = 0 // incrementer for default initial consumer ID this.nextConsumerID = 0 // incrementer for default initial consumer ID
this.conPackets = opts.conPackets || opts.conPacket this.conPackets = opts.conPackets || [opts.conPacket]
this.opts = opts // for use to recover from selected errors this.opts = opts // for use to recover from selected errors
this.errorCount = 0 this.errorCount = 0
//self bindings //self bindings
@ -80,7 +80,6 @@ export default function socketClass(Server) {
class: 'Socket', class: 'Socket',
id: this.id id: this.id
}) })
console.log('socket-class: @uci/socket package tag 0.2.33')
} // end constructor } // end constructor
@ -113,7 +112,7 @@ export default function socketClass(Server) {
log.info({method:'create', line:99, res: res, socket: this.opts.path, msg:'socket already exists.....deleted'}) log.info({method:'create', line:99, res: res, socket: this.opts.path, msg:'socket already exists.....deleted'})
// try again // try again
this.removeAllListeners('listening') this.removeAllListeners('listening')
return await this.create() resolve(await this.create())
} }
log.error({method:'create', line:102, err: err, msg:'error deleting socket. Can not establish a socket'}) log.error({method:'create', line:102, err: err, msg:'error deleting socket. Can not establish a socket'})
} }
@ -123,7 +122,7 @@ export default function socketClass(Server) {
await mkdir(path.dirname(this.opts.path)) await mkdir(path.dirname(this.opts.path))
log.debug({method:'create', line:109, socket: this.opts.path, msg:'directory created'}) log.debug({method:'create', line:109, socket: this.opts.path, msg:'directory created'})
this.removeAllListeners('listening') this.removeAllListeners('listening')
return await this.create() resolve(await this.create())
} }
// otherwise fatally exit // otherwise fatally exit
log.error({method:'create', line:113, err:err, opts:this.opts, msg:`error creating socket server ${this.name}`}) log.error({method:'create', line:113, err:err, opts:this.opts, msg:`error creating socket server ${this.name}`})
@ -251,7 +250,7 @@ export default function socketClass(Server) {
if (opts.consumer) opts.consumers = [opts.consumer] if (opts.consumer) opts.consumers = [opts.consumer]
consumers = Array.from(this.consumers).filter(([sid,consumer]) => consumers = Array.from(this.consumers).filter(([sid,consumer]) =>
opts.consumers.some(con=> { opts.consumers.some(con=> {
console.log(consumer.sid,consumer.data,con) // console.log('filtering consumers', consumer.sid,consumer.data,con)
return ( return (
con === ( (consumer.data ||{}).name || (consumer.data ||{}).id ) || con === ( (consumer.data ||{}).name || (consumer.data ||{}).id ) ||
con.sid=== sid || con.sid=== sid ||
@ -412,18 +411,15 @@ export default function socketClass(Server) {
// all's set enable main incoming message processor // all's set enable main incoming message processor
stream.on('message', messageProcess.bind(this, consumer)) stream.on('message', messageProcess.bind(this, consumer))
if (this.conPackets) { if (this.conPackets.length) {
this.conPackets = Array.isArray(this.conPackets) ? this.conPackets : [this.conPackets] // console.log({conPackets: this.conPackets, msg:'pushing preset packets to just connected consumer'})
log.debug({method:'_listen', line:171, conPacket: this.opts.conPacket, msg:'pushing a preset command to just connected consumer'}) for (let packet of this.conPackets) {
// FIXME, don't use forEach and use promise map. 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('log',{level:'info', msg:'a consumer connected and authenticated', name:consumer.name, id:consumer.id}) this.emit('log',{level:'info', msg:'a consumer connected and authenticated', name:consumer.name, id:consumer.id})
this.emit('connection:consumer',{state:'connected', msg:`consumer ${(consumer.data ||{}).name} connected and authenticated to socket ${this.id}`, this.emit('connection:consumer',{state:'connected', msg:`consumer ${(consumer.data ||{}).name} connected and authenticated to socket ${this.id}`,
name:(consumer.data ||{}).name ||(consumer.data ||{}).id || consumer.sid, name:(consumer.data ||{}).name ||(consumer.data ||{}).id || consumer.sid,