@nsshunt/stsrunnerframework 2.0.30 → 2.0.31

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
@@ -9974,6 +9974,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
9974
9974
  #socket;
9975
9975
  #reconnectTimeout = 2e3;
9976
9976
  #ackTimeout = 5e3;
9977
+ #reconnectTimeoutVal = void 0;
9977
9978
  constructor(name) {
9978
9979
  super();
9979
9980
  this.#name = name;
@@ -10046,7 +10047,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10046
10047
  return this;
10047
10048
  }
10048
10049
  SetupSocket() {
10049
- if (!this.#address) throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
10050
+ if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
10050
10051
  this.#EstablishSocketConnect();
10051
10052
  return this;
10052
10053
  }
@@ -10056,17 +10057,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10056
10057
  EngineReconnect(attempt) {}
10057
10058
  #EstablishSocketConnect() {
10058
10059
  if (this.#socket !== void 0) {
10059
- if (this.#socket.connected === true) this.#socket.disconnect();
10060
- this.#socket = void 0;
10061
- if (isNode) setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10062
- else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10060
+ this.ResetSocket();
10061
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10062
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10063
10063
  return;
10064
10064
  }
10065
10065
  let socketOptions;
10066
10066
  if (isNode) {
10067
10067
  socketOptions = { transports: ["websocket"] };
10068
10068
  if (this.#agentManager) {
10069
- if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
10069
+ if (!this.#address) {
10070
+ const message = `SocketIoClient:#EstablishSocketConnect(): Error: [address not provided when using agentManager]`;
10071
+ this.LogErrorMessage(message);
10072
+ throw new Error(message);
10073
+ }
10070
10074
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
10071
10075
  }
10072
10076
  } else socketOptions = { transports: ["websocket"] };
@@ -10077,30 +10081,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10077
10081
  if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
10078
10082
  this.#socket = lookup(this.#address, socketOptions);
10079
10083
  this.#socket.io.on("error", (err) => {
10080
- this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10084
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10081
10085
  this.EngineError(err);
10082
10086
  });
10083
10087
  this.#socket.io.on("reconnect_error", (err) => {
10084
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10088
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10085
10089
  this.EngineReconnectError(err);
10086
10090
  });
10087
10091
  this.#socket.on("connect_error", (err) => {
10088
- this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10092
+ this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10089
10093
  this.EngineConnectError(err);
10090
10094
  });
10091
10095
  this.#socket.io.on("reconnect", (attempt) => {
10092
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10096
+ this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10093
10097
  this.EngineReconnect(attempt);
10094
10098
  });
10095
10099
  this.#socket.on("connect", () => {
10096
10100
  if (this.#socket) {
10097
- this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10101
+ this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10098
10102
  setTimeout(() => {
10099
10103
  this.SocketConnect(this.#socket);
10100
10104
  }, 0);
10101
10105
  this.SetupSocketEvents(this.#socket);
10102
10106
  } else {
10103
- const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10107
+ const errorMessage = "SocketIoClient:on(\"connect\"): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10104
10108
  this.LogErrorMessage(errorMessage);
10105
10109
  this.SocketConnectError(new Error(errorMessage));
10106
10110
  }
@@ -10110,33 +10114,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10110
10114
  this.SocketDisconnect(reason);
10111
10115
  switch (reason) {
10112
10116
  case "io server disconnect":
10113
- this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10114
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10115
- this.#socket = void 0;
10116
- if (isNode) {
10117
- if (this.#agentManager) this.#agentManager.ResetAgent();
10118
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10119
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10117
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10118
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10119
+ this.ResetSocket();
10120
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10121
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10120
10122
  break;
10121
10123
  case "io client disconnect":
10122
- this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10123
- this.LogDebugMessage("The connection will not be re-established automatically.");
10124
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10125
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will not be re-established automatically.");
10126
+ this.ResetSocket();
10124
10127
  break;
10125
10128
  case "transport close":
10126
10129
  case "ping timeout":
10127
10130
  case "transport error":
10128
- this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
10129
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10130
- if (this.#socket) this.#socket.disconnect();
10131
- this.#socket = void 0;
10132
- if (isNode) {
10133
- if (this.#agentManager) this.#agentManager?.ResetAgent();
10134
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10135
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10131
+ this.LogDebugMessage(`SocketIoClient:on("disconnect"): Server unexpectedly disconnected. Reason: [${reason}]`);
10132
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10133
+ this.ResetSocket();
10134
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10135
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10136
10136
  break;
10137
10137
  }
10138
10138
  });
10139
10139
  }
10140
+ ResetSocket = () => {
10141
+ try {
10142
+ if (this.#reconnectTimeoutVal !== void 0) {
10143
+ clearTimeout(this.#reconnectTimeoutVal);
10144
+ this.#reconnectTimeoutVal = void 0;
10145
+ }
10146
+ if (this.#socket) {
10147
+ this.#socket.removeAllListeners();
10148
+ this.#socket.io.removeAllListeners();
10149
+ if (this.#socket.connected === true) this.#socket.disconnect();
10150
+ if (isNode) {
10151
+ if (this.#agentManager) this.#agentManager.ResetAgent();
10152
+ }
10153
+ this.#socket = void 0;
10154
+ }
10155
+ } catch (error) {
10156
+ const errorMessage = `SocketIoClient:ResetSocket(): Error: [${error}]`;
10157
+ this.LogErrorMessage(errorMessage);
10158
+ this.SocketConnectError(new Error(errorMessage));
10159
+ }
10160
+ };
10140
10161
  };
10141
10162
  //#endregion
10142
10163
  //#region src/wsevents.ts