logging and cleanup

This commit is contained in:
Dave Horton
2022-03-07 13:54:47 -05:00
parent 172dc1aaa7
commit 72225791b9

View File

@@ -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) {