@nsshunt/stsinstrumentmanagerclient 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -147,10 +147,8 @@ class RequestLoggerMiddleware extends STSOptionsBase {
147
147
  "UpdateInstrument_AR_DEC"
148
148
  /* UpdateInstrument_AR_DEC */
149
149
  );
150
- let timeInMs = 0;
151
- const end = process.hrtime(start);
152
- timeInMs = (end[0] * 1e9 + end[1]) / 1e6;
153
- timeInMs = parseFloat(timeInMs.toFixed(4));
150
+ const end = performance.now() - start;
151
+ const timeInMs = parseFloat(end.toFixed(4));
154
152
  this.#tinyEmitter.emit("UpdateInstrument_DH_VAL", timeInMs);
155
153
  this.#tinyEmitter.emit("UpdateInstrument_D_VAL", timeInMs);
156
154
  console.log(`-->>ZZZ: ${timeInMs}`);
@@ -169,9 +167,15 @@ class RequestLoggerMiddleware extends STSOptionsBase {
169
167
  */
170
168
  Middleware = async (req, res, next) => {
171
169
  if (this.options.ignoresocketio && req.originalUrl.includes("socket.io")) {
172
- return;
170
+ return next();
173
171
  }
174
- const start = process.hrtime();
172
+ const start = performance.now();
173
+ let completed = false;
174
+ const completeOnce = () => {
175
+ if (completed) return;
176
+ completed = true;
177
+ this.#RequestCompleted(start);
178
+ };
175
179
  this.#tinyEmitter.emit(
176
180
  "UpdateInstrument_AR_INC"
177
181
  /* UpdateInstrument_AR_INC */
@@ -186,12 +190,13 @@ class RequestLoggerMiddleware extends STSOptionsBase {
186
190
  );
187
191
  req.on("aborted", () => {
188
192
  });
189
- req.on("close", () => {
190
- this.#RequestCompleted(start);
191
- });
192
193
  req.on("end", () => {
193
194
  });
195
+ res.on("close", () => {
196
+ completeOnce();
197
+ });
194
198
  res.on("finish", () => {
199
+ completeOnce();
195
200
  });
196
201
  next();
197
202
  };