react-signalr icon indicating copy to clipboard operation
react-signalr copied to clipboard

expose automaticReconnect retry delay options

Open developerdanwu opened this issue 10 months ago • 3 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I want to be able to specify the retryDelays as a prop and customise this behaviour too. In the current state of the package I am only able to pass automaticReconnect as a boolean value. Please let me know if this is a feature you would like to introduce into your package too. I would be more than happy to open a PR for this!

Here is the diff that solved my problem:

diff --git a/node_modules/react-signalr/lib/signalr/provider/types.d.ts b/node_modules/react-signalr/lib/signalr/provider/types.d.ts
index 54cb318..44d9365 100644
--- a/node_modules/react-signalr/lib/signalr/provider/types.d.ts
+++ b/node_modules/react-signalr/lib/signalr/provider/types.d.ts
@@ -11,6 +11,6 @@ export interface ProviderProps extends IHttpConnectionOptions {
     onClosed?: (error?: Error) => void;
     onOpen?: (connection: HubConnection) => void;
     onReconnect?: (connection: HubConnection) => void;
-    automaticReconnect?: boolean;
+    automaticReconnect?: boolean | number[]
 }
 //# sourceMappingURL=types.d.ts.map
\ No newline at end of file
diff --git a/node_modules/react-signalr/src/signalr/provider/types.ts b/node_modules/react-signalr/src/signalr/provider/types.ts
index 7afbbf5..3c975d6 100644
--- a/node_modules/react-signalr/src/signalr/provider/types.ts
+++ b/node_modules/react-signalr/src/signalr/provider/types.ts
@@ -12,5 +12,5 @@ export interface ProviderProps extends IHttpConnectionOptions {
   onClosed?: (error?: Error) => void;
   onOpen?: (connection: HubConnection) => void;
   onReconnect?: (connection: HubConnection) => void;
-  automaticReconnect?: boolean;
+  automaticReconnect?: boolean | number[];
 }
diff --git a/node_modules/react-signalr/src/signalr/utils.ts b/node_modules/react-signalr/src/signalr/utils.ts
index 3b87bdb..87245bf 100644
--- a/node_modules/react-signalr/src/signalr/utils.ts
+++ b/node_modules/react-signalr/src/signalr/utils.ts
@@ -16,7 +16,7 @@ function isConnectionConnecting(connection: HubConnection) {
 function createConnection(
   url: string,
   transportType: IHttpConnectionOptions,
-  automaticReconnect = true,
+  automaticReconnect:boolean | number[] = true,
 ) {
   let connectionBuilder = new HubConnectionBuilder().withUrl(
     url,
@@ -24,7 +24,11 @@ function createConnection(
   );
 
   if (automaticReconnect) {
-    connectionBuilder = connectionBuilder.withAutomaticReconnect();
+    if (Array.isArray(automaticReconnect)) {
+      connectionBuilder = connectionBuilder.withAutomaticReconnect(automaticReconnect);
+    } else {
+      connectionBuilder = connectionBuilder.withAutomaticReconnect();
+    }
   }
 
   if (transportType.logger) {

This issue body was partially generated by patch-package.

developerdanwu avatar Oct 18 '23 07:10 developerdanwu