From aeae1df3fac6861769bfb7f17b4dd6254af8e96e Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 15 Mar 2020 15:48:34 -0700 Subject: [PATCH] 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 --- package.json | 9 +++++---- src/socket.js | 16 ++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index a76e436..87b61a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/websocket", - "version": "0.3.15", + "version": "0.4.0", "description": "JSON packet host websocket server", "main": "src", "scripts": { @@ -33,8 +33,8 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "esm": "^3.2.25", - "mocha": "^6.2.2", - "nodemon": "^2.0.0" + "mocha": "^7.1.0", + "nodemon": "^2.0.2" }, "dependencies": { "@uci-utils/logger": "0.0.16", @@ -42,6 +42,7 @@ "better-try-catch": "^0.6.2", "clone": "^2.1.2", "death": "^1.1.0", - "ws": "^7.2.0" + "p-reflect": "^2.1.0", + "ws": "^7.2.3" } } diff --git a/src/socket.js b/src/socket.js index eaedefa..c7877cf 100644 --- a/src/socket.js +++ b/src/socket.js @@ -34,7 +34,7 @@ class Socket extends Server { this.pingInterval = opts.pingInterval === false ? opts.pingInterval : (opts.pingInterval * 1000 || 5000) this.nextconsumerID = 0 // incrementer for default initial consumer ID this.consumers = new Map() - this.conPackets = opts.conPackets || opts.conPacket + this.conPackets = opts.conPackets || [opts.conPacket] this.errors = [] this.errorCount = 0 this.create = this.create.bind(this) @@ -287,15 +287,11 @@ class Socket extends Server { } } - if (this.conPackets) { - this.conPackets = Array.isArray(this.conPackets) ? this.conPackets : [this.conPackets] - log.debug({method:'_listen', line:171, conPackets: this.conPackets, msg:'pushing a preset packets to just connected consumer'}) - this.conPackets.forEach(packet => { - if (packet) { - packet._header = {type:'on connection packet', id: 'pushed'} - this._send(consumer,packet) // send a packet command on to consumer on connection - } - }) + if (this.conPackets.length) { + for (let packet of this.conPackets) { + packet._header = {type:'on connection packet', id: 'pushed'} + await 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})