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