@nsshunt/stsfhirclient 1.1.17 → 1.1.19

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.
@@ -4810,21 +4810,33 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4810
4810
  #socketIoCustomPath;
4811
4811
  #authToken;
4812
4812
  #socket;
4813
+ #reconnectTimeout = 2e3;
4814
+ // default
4813
4815
  constructor(name) {
4814
4816
  super();
4815
4817
  this.#name = name;
4816
4818
  }
4819
+ get logPrefix() {
4820
+ return `SocketIoClient[${this.#name}]:`;
4821
+ }
4817
4822
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4818
4823
  LogDebugMessage(message) {
4819
- if (this.#logger) this.#logger.debug(message);
4824
+ if (this.#logger) this.#logger.debug(`${this.logPrefix}${message}`);
4820
4825
  }
4821
4826
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4822
4827
  LogErrorMessage(message) {
4823
- if (this.#logger) this.#logger.error(message);
4828
+ if (this.#logger) this.#logger.error(`${this.logPrefix}${message}`);
4829
+ }
4830
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4831
+ LogWarningMessage(message) {
4832
+ if (this.#logger) this.#logger.warn(`${this.logPrefix}${message}`);
4824
4833
  }
4825
4834
  get name() {
4826
4835
  return this.#name;
4827
4836
  }
4837
+ get reconnectTimeout() {
4838
+ return this.#reconnectTimeout;
4839
+ }
4828
4840
  get agentManager() {
4829
4841
  return this.#agentManager;
4830
4842
  }
@@ -4863,6 +4875,10 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4863
4875
  this.#agentManager = agentManager;
4864
4876
  return this;
4865
4877
  }
4878
+ WithReconnectTimeout(reconnectTimeout) {
4879
+ this.#reconnectTimeout = reconnectTimeout;
4880
+ return this;
4881
+ }
4866
4882
  SetupSocket() {
4867
4883
  if (!this.#address) {
4868
4884
  throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
@@ -4870,14 +4886,18 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4870
4886
  this.#EstablishSocketConnect();
4871
4887
  return this;
4872
4888
  }
4889
+ // Engine Errors / Events
4890
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4891
+ EngineError(error) {
4892
+ }
4873
4893
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4874
- ConnectCallBack(socket) {
4894
+ EngineReconnectError(error) {
4875
4895
  }
4876
4896
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4877
- SocketEventsCallBack(socket) {
4897
+ EngineConnectError(error) {
4878
4898
  }
4879
4899
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4880
- ErrorCallBack(error) {
4900
+ EngineReconnect(attempt) {
4881
4901
  }
4882
4902
  /*
4883
4903
  emit<Ev extends EventNames<ClientToServerEvents>>(ev: Ev, ...args: EventParams<ClientToServerEvents, Ev>): Socket<ServerToClientEvents, ClientToServerEvents> {
@@ -4895,9 +4915,9 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4895
4915
  }
4896
4916
  this.#socket = void 0;
4897
4917
  if (isNode) {
4898
- setTimeout(() => this.#EstablishSocketConnect(), 100).unref();
4918
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
4899
4919
  } else {
4900
- setTimeout(() => this.#EstablishSocketConnect(), 100);
4920
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
4901
4921
  }
4902
4922
  return;
4903
4923
  }
@@ -4908,7 +4928,7 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4908
4928
  };
4909
4929
  if (this.#agentManager) {
4910
4930
  if (!this.#address) {
4911
- throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided when using agentManager]`);
4931
+ throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
4912
4932
  }
4913
4933
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
4914
4934
  }
@@ -4929,58 +4949,63 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4929
4949
  }
4930
4950
  this.#socket = lookup(this.#address, socketOptions);
4931
4951
  this.#socket.io.on("error", (err) => {
4932
- this.LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
4952
+ this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
4953
+ this.EngineError(err);
4933
4954
  });
4934
4955
  this.#socket.io.on("reconnect_error", (err) => {
4935
- this.LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
4956
+ this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
4957
+ this.EngineReconnectError(err);
4936
4958
  });
4937
4959
  this.#socket.on("connect_error", (err) => {
4938
- this.LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
4960
+ this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
4961
+ this.EngineConnectError(err);
4939
4962
  });
4940
4963
  this.#socket.io.on("reconnect", (attempt) => {
4941
- this.LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
4964
+ this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
4965
+ this.EngineReconnect(attempt);
4942
4966
  });
4943
4967
  this.#socket.on("connect", () => {
4944
4968
  if (this.#socket) {
4945
- this.LogDebugMessage(`SocketIoClientHelper(): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
4969
+ this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
4946
4970
  setTimeout(() => {
4947
- this.ConnectCallBack(this.#socket);
4971
+ this.SocketConnect(this.#socket);
4948
4972
  }, 0);
4949
- this.SocketEventsCallBack(this.#socket);
4973
+ this.SetupSocketEvents(this.#socket);
4950
4974
  } else {
4951
- const errorMessage = "SocketIoClientHelper(): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
4975
+ const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
4952
4976
  this.LogErrorMessage(errorMessage);
4953
- this.ErrorCallBack(new Error(errorMessage));
4977
+ this.SocketConnectError(new Error(errorMessage));
4954
4978
  }
4955
4979
  });
4956
4980
  this.#socket.on("disconnect", (reason) => {
4957
- this.LogDebugMessage("SocketIoClientHelper(): socket disconnect: " + reason);
4981
+ this.LogDebugMessage("socket disconnect: " + reason);
4982
+ this.SocketDisconnect(reason);
4958
4983
  switch (reason) {
4959
4984
  case "io server disconnect":
4960
4985
  {
4961
- this.LogDebugMessage("SocketIoClientHelper(): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
4962
- this.LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
4986
+ this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
4987
+ this.LogDebugMessage("The connection will be re-established when the server becomes available.");
4963
4988
  this.#socket = void 0;
4964
4989
  if (isNode) {
4965
4990
  if (this.#agentManager) {
4966
4991
  this.#agentManager.ResetAgent();
4967
4992
  }
4968
- setTimeout(() => this.#EstablishSocketConnect(), 100).unref();
4993
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
4969
4994
  } else {
4970
- setTimeout(() => this.#EstablishSocketConnect(), 100);
4995
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
4971
4996
  }
4972
4997
  }
4973
4998
  break;
4974
4999
  case "io client disconnect":
4975
- this.LogDebugMessage("SocketIoClientHelper(): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
4976
- this.LogDebugMessage("SocketIoClientHelper(): The connection will not be re-established automatically.");
5000
+ this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
5001
+ this.LogDebugMessage("The connection will not be re-established automatically.");
4977
5002
  break;
4978
5003
  case "transport close":
4979
5004
  case "ping timeout":
4980
5005
  case "transport error":
4981
5006
  {
4982
- this.LogDebugMessage(`SocketIoClientHelper(): Server unexpectedly disconnected. Reason: [${reason}]`);
4983
- this.LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
5007
+ this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
5008
+ this.LogDebugMessage("The connection will be re-established when the server becomes available.");
4984
5009
  if (this.#socket) {
4985
5010
  this.#socket.disconnect();
4986
5011
  }
@@ -4989,9 +5014,9 @@ class SocketIoClient extends tinyEmitterExports.TinyEmitter {
4989
5014
  if (this.#agentManager) {
4990
5015
  this.#agentManager?.ResetAgent();
4991
5016
  }
4992
- setTimeout(() => this.#EstablishSocketConnect(), 100).unref();
5017
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
4993
5018
  } else {
4994
- setTimeout(() => this.#EstablishSocketConnect(), 100);
5019
+ setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
4995
5020
  }
4996
5021
  }
4997
5022
  break;
@@ -5043,16 +5068,20 @@ class FhirSocketClient extends SocketIoClient {
5043
5068
  this.#options = options;
5044
5069
  this.#SetupWSSClient();
5045
5070
  }
5046
- ConnectCallBack(socket) {
5071
+ SocketConnect(socket) {
5047
5072
  this.LogDebugMessage(chalk.green(`FhirSocketClient:#OnSocketConnected(): ID: [${this.#id}] clientName: [${this.name}]: --> connected`));
5048
5073
  if (this.#options.joinRooms.length > 0 && socket) {
5049
5074
  socket.emit("__STSjoinRoom", this.#options.joinRooms);
5050
5075
  }
5051
5076
  }
5052
- ErrorCallBack(error) {
5077
+ SocketError(error) {
5053
5078
  this.LogErrorMessage(`FhirSocketClient:#SetupWSSClient(): Error clientName: [${this.name}]: SetupClientSideSocket call back: Error: [${error}]`);
5054
5079
  }
5055
- SocketEventsCallBack(socket) {
5080
+ SocketConnectError(error) {
5081
+ }
5082
+ SocketDisconnect(reason) {
5083
+ }
5084
+ SetupSocketEvents(socket) {
5056
5085
  }
5057
5086
  #SetupWSSClient = async () => {
5058
5087
  console.log(chalk.yellow(`FhirSocketClient:#SetupWSSClient(): ID: [${this.#id}] clientName: [${this.name}] Starting ...`));