From 72225791b9641d337a52c61b1b81f9e812ff97c8 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 7 Mar 2022 13:54:47 -0500 Subject: [PATCH] logging and cleanup --- lib/utils/ws-requestor.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index baa33296..1d15ef19 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -80,11 +80,13 @@ class WsRequestor extends BaseRequestor { data: {...payload} }; - this.logger.debug({obj}, `websocket: sending (${url})`); + //this.logger.debug({obj}, `websocket: sending (${url})`); /* simple notifications */ if (['call:status', 'jambonz:error'].includes(type)) { - this.ws.send(JSON.stringify(obj)); + this.ws.send(JSON.stringify(obj), () => { + this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`); + }); return; } @@ -114,7 +116,9 @@ class WsRequestor extends BaseRequestor { }); /* send the message */ - this.ws.send(JSON.stringify(obj)); + this.ws.send(JSON.stringify(obj), () => { + this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`); + }); }); } @@ -126,10 +130,15 @@ class WsRequestor extends BaseRequestor { this.ws.close(); this.ws.removeAllListeners(); } + + for (const [msgid, obj] of this.messagesInFlight) { + obj.failure(`abandoning msgid ${msgid} since we have closed the socket`); + } + this.messagesInFlight.clear(); + } catch (err) { this.logger.info({err}, 'WsRequestor: Error closing socket'); } - this.logger.info('WsRequestor:close socket closed'); } _connect() { @@ -222,7 +231,7 @@ class WsRequestor extends BaseRequestor { const obj = JSON.parse(content); const {type, msgid, command, queueCommand = false, data} = obj; - this.logger.debug({obj}, 'websocket: received'); + this.logger.debug({obj}, 'WsRequestor:request websocket: received'); assert.ok(type, 'type property not supplied'); switch (type) {