@ancon/wildcat-utils 1.43.1 → 1.43.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.43.1",
3
+ "version": "1.43.2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -10,6 +10,7 @@ declare class SignalR {
10
10
  private logger;
11
11
  private backoff;
12
12
  private reconnectAttempt;
13
+ private shouldReconnect;
13
14
  groups: string[];
14
15
  constructor(options: SignalRConfig);
15
16
  info: (message: string, data?: any) => void;
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var d=(r,e,t)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(d(r,typeof e!="symbol"?e+"":e,t),t);const h=require("@microsoft/signalr"),a=require("@ancon/wildcat-types"),f=require("../shared/wait.js"),u=require("../api/generateBackoffWithEqualJitter.js");require("../number/randomIntFromInterval.js");class g{constructor(e){n(this,"internalEvents");n(this,"signalREvents");n(this,"hubConnection");n(this,"clientId");n(this,"logger");n(this,"backoff",[]);n(this,"reconnectAttempt",0);n(this,"groups");n(this,"info",(e,t)=>{var i;(i=this.logger)==null||i.info(e,t)});n(this,"generateBackoff",()=>{this.backoff=u(50,500,5e3),this.info("Generated new backoff")});n(this,"reconnect",async()=>{try{this.info("Attempting to reconnect...",{attempt:this.reconnectAttempt+1}),await this.connect(!0),this.info("Reconnected"),this.reconnectAttempt=0}catch{if(this.backoff[this.reconnectAttempt]!=null){const t=this.backoff[this.reconnectAttempt];if(t!=null)await f(t);else throw new Error("Could not resolve ms from backoff")}else{this.reconnectAttempt>0&&this.info("Ran out of backoff intervals, restarting backoff..."),this.reconnectAttempt=0,this.generateBackoff();const t=this.backoff[this.reconnectAttempt];if(t!=null)await f(t);else throw new Error("Could not resolve ms from backoff")}this.reconnectAttempt+=1,await this.reconnect()}});n(this,"buildInitialListeners",()=>{this.hubConnection.onclose(()=>{this.groups=[],this.info("Hub connection closed"),this.emitEvent("disconnected"),this.reconnect()}),this.hubConnection.onreconnected(()=>this.emitEvent("reconnected"))});n(this,"emitEvent",(e,...t)=>{if(this.internalEvents.has(e)){this.info(`Emitting event "${e}"`);const i=this.internalEvents.get(e);i&&i.forEach(s=>s(...t))}else this.info(`Failed to emit event "${e}". There were no listeners.`)});n(this,"skipSignal",(e,t)=>{this.info(`Skipped signal "${e}"`,t)});n(this,"enhanceListener",(e,t,i)=>s=>{const o=JSON.parse(s),c=i&&o.clientId&&o.clientId===this.clientId;return c||this.info(`Received signal "${e}"`,s),c?this.skipSignal(e,s):t(o)});n(this,"setClientId",e=>{this.clientId=e});n(this,"connect",async(e=!1)=>{try{this.info("Connecting..."),await this.hubConnection.start(),this.info("Connected"),this.emitEvent("connected")}catch(t){if(this.info("Failed to connect"),e)throw t}});n(this,"disconnect",async()=>{try{this.info("Disconnecting..."),await this.hubConnection.stop(),this.info("Disconnected"),this.emitEvent("disconnected")}catch{this.info("Failed to disconnect")}});n(this,"addEventListener",(e,t)=>{this.internalEvents.has(e)||this.internalEvents.set(e,[]);const i=this.internalEvents.get(e);return i&&i.push(t),()=>this.removeEventListener(e,t)});n(this,"removeEventListener",(e,t)=>{var i;if(this.internalEvents.has(e)){const s=this.internalEvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(s.splice(o,1),this.info(`Removed event listener for event "${e}"`)):this.info(`Failed to remove event listener for event "${e}". Specified listener was not found.`)}else this.info(`Failed to remove event listener for event "${e}". Event doesn't have any listeners.`)});n(this,"addSignalListener",(e,t,i=!0)=>{this.signalREvents.has(e)||this.signalREvents.set(e,[]);const s=this.signalREvents.get(e),o=this.enhanceListener(e,t,i);return s&&s.push(o),this.hubConnection.on(e,o),this.info(`Added signal listener for signal "${e}"`),()=>this.removeSignalListener(e,o)});n(this,"removeSignalListener",(e,t)=>{var i;if(this.signalREvents.has(e)){const s=this.signalREvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(this.hubConnection.off(e,t),s.splice(o,1),this.info(`Removed signal listener for signal "${e}"`)):this.info(`Failed to remove signal listener for signal "${e}". Specified listener was not found.`)}else this.info(`Failed to remove signal listener for signal "${e}". Signal doesn't have any listeners.`)});n(this,"joinGroup",async e=>{this.info(`Joining group "${e}"...`);const t=this.groups.push(e)-1;try{await this.hubConnection.invoke(a.SignalRMethodName.JoinGroup,e),this.info(`Joined group "${e}"`)}catch(i){this.info(`Failed to join group "${e}"`,i),t>=0&&this.groups.splice(t,1)}});n(this,"leaveGroup",async e=>{this.info(`Leaving group "${e}"...`);const t=this.groups.indexOf(e);t>=0&&this.groups.splice(t,1);try{await this.hubConnection.invoke(a.SignalRMethodName.LeaveGroup,e),this.info(`Left group "${e}"`)}catch(i){this.groups.indexOf(e)<0&&this.groups.push(e),this.info(`Failed to leave group "${e}"`,i)}});n(this,"leaveAllGroups",async()=>{this.info(`Leaving all (${this.groups.length}) groups...`);const e=[...this.groups].map(t=>this.leaveGroup(t));await Promise.all(e),this.info("Left all groups")});n(this,"getHubConnectionId",()=>this.hubConnection.connectionId);this.internalEvents=new Map,this.signalREvents=new Map,this.groups=[],e.enableLogging&&(this.logger=e.logger),this.hubConnection=new h.HubConnectionBuilder().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(h.LogLevel.None).build(),this.buildInitialListeners()}}module.exports=g;
1
+ "use strict";var f=Object.defineProperty;var d=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(d(r,typeof e!="symbol"?e+"":e,t),t);const h=require("@microsoft/signalr"),a=require("@ancon/wildcat-types"),l=require("../shared/wait.js"),u=require("../api/generateBackoffWithEqualJitter.js");require("../number/randomIntFromInterval.js");class g{constructor(e){n(this,"internalEvents");n(this,"signalREvents");n(this,"hubConnection");n(this,"clientId");n(this,"logger");n(this,"backoff",[]);n(this,"reconnectAttempt",0);n(this,"shouldReconnect",!0);n(this,"groups");n(this,"info",(e,t)=>{var i;(i=this.logger)==null||i.info(e,t)});n(this,"generateBackoff",()=>{this.backoff=u(50,500,5e3),this.info("Generated new backoff")});n(this,"reconnect",async()=>{if(this.shouldReconnect)try{this.info("Attempting to reconnect...",{attempt:this.reconnectAttempt+1}),await this.connect(!0),this.info("Reconnected"),this.reconnectAttempt=0}catch{if(this.backoff[this.reconnectAttempt]!=null){const t=this.backoff[this.reconnectAttempt];if(t!=null)await l(t);else throw new Error("Could not resolve ms from backoff")}else{this.reconnectAttempt>0&&this.info("Ran out of backoff intervals, restarting backoff..."),this.reconnectAttempt=0,this.generateBackoff();const t=this.backoff[this.reconnectAttempt];if(t!=null)await l(t);else throw new Error("Could not resolve ms from backoff")}this.reconnectAttempt+=1,await this.reconnect()}});n(this,"buildInitialListeners",()=>{this.hubConnection.onclose(()=>{this.groups=[],this.info("Hub connection closed"),this.emitEvent("disconnected"),this.reconnect()}),this.hubConnection.onreconnected(()=>this.emitEvent("reconnected"))});n(this,"emitEvent",(e,...t)=>{if(this.internalEvents.has(e)){this.info(`Emitting event "${e}"`);const i=this.internalEvents.get(e);i&&i.forEach(s=>s(...t))}else this.info(`Failed to emit event "${e}". There were no listeners.`)});n(this,"skipSignal",(e,t)=>{this.info(`Skipped signal "${e}"`,t)});n(this,"enhanceListener",(e,t,i)=>s=>{const o=JSON.parse(s),c=i&&o.clientId&&o.clientId===this.clientId;return c||this.info(`Received signal "${e}"`,s),c?this.skipSignal(e,s):t(o)});n(this,"setClientId",e=>{this.clientId=e});n(this,"connect",async(e=!1)=>{try{this.info("Connecting..."),await this.hubConnection.start(),this.info("Connected"),this.emitEvent("connected")}catch(t){if(this.info("Failed to connect"),e)throw t}});n(this,"disconnect",async()=>{try{this.shouldReconnect=!1,this.info("Disconnecting..."),await this.hubConnection.stop(),this.info("Disconnected"),this.emitEvent("disconnected")}catch{this.info("Failed to disconnect")}});n(this,"addEventListener",(e,t)=>{this.internalEvents.has(e)||this.internalEvents.set(e,[]);const i=this.internalEvents.get(e);return i&&i.push(t),()=>this.removeEventListener(e,t)});n(this,"removeEventListener",(e,t)=>{var i;if(this.internalEvents.has(e)){const s=this.internalEvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(s.splice(o,1),this.info(`Removed event listener for event "${e}"`)):this.info(`Failed to remove event listener for event "${e}". Specified listener was not found.`)}else this.info(`Failed to remove event listener for event "${e}". Event doesn't have any listeners.`)});n(this,"addSignalListener",(e,t,i=!0)=>{this.signalREvents.has(e)||this.signalREvents.set(e,[]);const s=this.signalREvents.get(e),o=this.enhanceListener(e,t,i);return s&&s.push(o),this.hubConnection.on(e,o),this.info(`Added signal listener for signal "${e}"`),()=>this.removeSignalListener(e,o)});n(this,"removeSignalListener",(e,t)=>{var i;if(this.signalREvents.has(e)){const s=this.signalREvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(this.hubConnection.off(e,t),s.splice(o,1),this.info(`Removed signal listener for signal "${e}"`)):this.info(`Failed to remove signal listener for signal "${e}". Specified listener was not found.`)}else this.info(`Failed to remove signal listener for signal "${e}". Signal doesn't have any listeners.`)});n(this,"joinGroup",async e=>{this.info(`Joining group "${e}"...`);const t=this.groups.push(e)-1;try{await this.hubConnection.invoke(a.SignalRMethodName.JoinGroup,e),this.info(`Joined group "${e}"`)}catch(i){this.info(`Failed to join group "${e}"`,i),t>=0&&this.groups.splice(t,1)}});n(this,"leaveGroup",async e=>{this.info(`Leaving group "${e}"...`);const t=this.groups.indexOf(e);t>=0&&this.groups.splice(t,1);try{await this.hubConnection.invoke(a.SignalRMethodName.LeaveGroup,e),this.info(`Left group "${e}"`)}catch(i){this.groups.indexOf(e)<0&&this.groups.push(e),this.info(`Failed to leave group "${e}"`,i)}});n(this,"leaveAllGroups",async()=>{this.info(`Leaving all (${this.groups.length}) groups...`);const e=[...this.groups].map(t=>this.leaveGroup(t));await Promise.all(e),this.info("Left all groups")});n(this,"getHubConnectionId",()=>this.hubConnection.connectionId);this.internalEvents=new Map,this.signalREvents=new Map,this.groups=[],e.enableLogging&&(this.logger=e.logger),this.hubConnection=new h.HubConnectionBuilder().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(h.LogLevel.None).build(),this.buildInitialListeners()}}module.exports=g;
@@ -1,10 +1,10 @@
1
1
  var f = Object.defineProperty;
2
2
  var l = (r, t, e) => t in r ? f(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var n = (r, t, e) => (l(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- import { HubConnectionBuilder as d, LogLevel as g } from "@microsoft/signalr";
4
+ import { HubConnectionBuilder as d, LogLevel as u } from "@microsoft/signalr";
5
5
  import { SignalRMethodName as h } from "@ancon/wildcat-types";
6
6
  import a from "../shared/wait.mjs";
7
- import u from "../api/generateBackoffWithEqualJitter.mjs";
7
+ import g from "../api/generateBackoffWithEqualJitter.mjs";
8
8
  import "../number/randomIntFromInterval.mjs";
9
9
  class L {
10
10
  constructor(t) {
@@ -15,36 +15,38 @@ class L {
15
15
  n(this, "logger");
16
16
  n(this, "backoff", []);
17
17
  n(this, "reconnectAttempt", 0);
18
+ n(this, "shouldReconnect", !0);
18
19
  n(this, "groups");
19
20
  n(this, "info", (t, e) => {
20
21
  var i;
21
22
  (i = this.logger) == null || i.info(t, e);
22
23
  });
23
24
  n(this, "generateBackoff", () => {
24
- this.backoff = u(50, 500, 5e3), this.info("Generated new backoff");
25
+ this.backoff = g(50, 500, 5e3), this.info("Generated new backoff");
25
26
  });
26
27
  n(this, "reconnect", async () => {
27
- try {
28
- this.info("Attempting to reconnect...", {
29
- attempt: this.reconnectAttempt + 1
30
- }), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
31
- } catch {
32
- if (this.backoff[this.reconnectAttempt] != null) {
33
- const e = this.backoff[this.reconnectAttempt];
34
- if (e != null)
35
- await a(e);
36
- else
37
- throw new Error("Could not resolve ms from backoff");
38
- } else {
39
- this.reconnectAttempt > 0 && this.info("Ran out of backoff intervals, restarting backoff..."), this.reconnectAttempt = 0, this.generateBackoff();
40
- const e = this.backoff[this.reconnectAttempt];
41
- if (e != null)
42
- await a(e);
43
- else
44
- throw new Error("Could not resolve ms from backoff");
28
+ if (this.shouldReconnect)
29
+ try {
30
+ this.info("Attempting to reconnect...", {
31
+ attempt: this.reconnectAttempt + 1
32
+ }), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
33
+ } catch {
34
+ if (this.backoff[this.reconnectAttempt] != null) {
35
+ const e = this.backoff[this.reconnectAttempt];
36
+ if (e != null)
37
+ await a(e);
38
+ else
39
+ throw new Error("Could not resolve ms from backoff");
40
+ } else {
41
+ this.reconnectAttempt > 0 && this.info("Ran out of backoff intervals, restarting backoff..."), this.reconnectAttempt = 0, this.generateBackoff();
42
+ const e = this.backoff[this.reconnectAttempt];
43
+ if (e != null)
44
+ await a(e);
45
+ else
46
+ throw new Error("Could not resolve ms from backoff");
47
+ }
48
+ this.reconnectAttempt += 1, await this.reconnect();
45
49
  }
46
- this.reconnectAttempt += 1, await this.reconnect();
47
- }
48
50
  });
49
51
  n(this, "buildInitialListeners", () => {
50
52
  this.hubConnection.onclose(() => {
@@ -84,7 +86,7 @@ class L {
84
86
  });
85
87
  n(this, "disconnect", async () => {
86
88
  try {
87
- this.info("Disconnecting..."), await this.hubConnection.stop(), this.info("Disconnected"), this.emitEvent("disconnected");
89
+ this.shouldReconnect = !1, this.info("Disconnecting..."), await this.hubConnection.stop(), this.info("Disconnected"), this.emitEvent("disconnected");
88
90
  } catch {
89
91
  this.info("Failed to disconnect");
90
92
  }
@@ -172,7 +174,7 @@ class L {
172
174
  await Promise.all(t), this.info("Left all groups");
173
175
  });
174
176
  n(this, "getHubConnectionId", () => this.hubConnection.connectionId);
175
- this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], t.enableLogging && (this.logger = t.logger), this.hubConnection = new d().withUrl(`${t.signalRApiUrl}/${t.hub}`).configureLogging(g.None).build(), this.buildInitialListeners();
177
+ this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], t.enableLogging && (this.logger = t.logger), this.hubConnection = new d().withUrl(`${t.signalRApiUrl}/${t.hub}`).configureLogging(u.None).build(), this.buildInitialListeners();
176
178
  }
177
179
  }
178
180
  export {
@@ -1 +1 @@
1
- "use strict";const n=require("react"),C=require("react-redux"),T=require("../noop-7ea3b37b.js"),B=a=>Object.freeze(Object.defineProperty({__proto__:null,default:a},Symbol.toStringTag,{value:"Module"}));function F(a,y,w,_){const{logger:j,enableLogging:q}=a;let{signalRApiUrl:I}=a;const{clientIdSelector:x,isSignalROnlineSelector:c}=y??{},{setIsSignalROnlineAction:l}=w??{},{useAppStore:D=C.useStore,useAppDispatch:G=C.useDispatch,useAppSelector:m=C.useSelector}=_??{},p=new Set;function M(u){const[f,P]=n.useState(I),[e,z]=n.useState(null),d=D(),b=G(),h=m(x??(()=>{})),[o,N]=n.useState(!1),[r,E]=n.useState(!1),v=n.useRef(o),S=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!1&&l&&b(l({isSignalROnline:!0})),r||E(!0)},[b,r,d]),O=S,k=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!0&&l&&b(l({isSignalROnline:!1})),r&&E(!1)},[b,r,d]),H=n.useCallback(async t=>{e&&e.groups.indexOf(t)<0&&await(e==null?void 0:e.joinGroup(t))},[e]),A=n.useCallback(async t=>{e&&e.groups.indexOf(t)>=0&&await(e==null?void 0:e.leaveGroup(t))},[e]),L=n.useCallback((t,s,i)=>e?e==null?void 0:e.addSignalListener(t,s,i):T.noop,[e]),U=n.useCallback((t,s)=>{e&&e.removeSignalListener(t,s)},[e]),g=n.useCallback(()=>e?e.getHubConnectionId():null,[e]);return n.useEffect(()=>{let t=!1;return Promise.resolve().then(()=>B(require("./SignalR.js"))).then(({default:s})=>{t||z(new s({signalRApiUrl:f,hub:u,logger:j,enableLogging:q}))}),()=>{t=!0}},[u,f]),n.useEffect(()=>{function t(s){P(s)}return p.add(t),()=>{p.delete(t)}},[]),n.useEffect(()=>{v.current=o},[o]),n.useEffect(()=>{const t=e==null?void 0:e.addEventListener("connected",S),s=e==null?void 0:e.addEventListener("reconnected",O),i=e==null?void 0:e.addEventListener("disconnected",k);return e&&!v.current&&N(!0),()=>{t==null||t(),s==null||s(),i==null||i()}},[e,S,k,O]),n.useEffect(()=>{e==null||e.setClientId(h||void 0)},[e,h]),n.useEffect(()=>{async function t(){await(e==null?void 0:e.connect())}o&&t()},[e,o]),n.useEffect(()=>()=>{e==null||e.leaveAllGroups().then(()=>{e==null||e.disconnect()})},[e]),n.useMemo(()=>({isHubConnected:r,join:H,leave:A,subscribe:L,unsubscribe:U,getHubConnectionId:g}),[r,H,A,L,U,g])}return{useSignalR:M,setUrl(u){I=u,p.forEach(f=>{f(u)})}}}module.exports=F;
1
+ "use strict";const n=require("react"),h=require("react-redux"),C=require("../noop-7ea3b37b.js"),B=a=>Object.freeze(Object.defineProperty({__proto__:null,default:a},Symbol.toStringTag,{value:"Module"}));function F(a,_,g,j){const{logger:q,enableLogging:x}=a;let{signalRApiUrl:I}=a;const{clientIdSelector:D,isSignalROnlineSelector:s}=_??{},{setIsSignalROnlineAction:l}=g??{},{useAppStore:G=h.useStore,useAppDispatch:m=h.useDispatch,useAppSelector:M=h.useSelector}=j??{},b=new Set;function P(o){const[f,z]=n.useState(I),[e,N]=n.useState(null),d=G(),p=m(),E=M(D??(()=>{})),[u,T]=n.useState(!1),[r,v]=n.useState(!1),O=n.useRef(u),S=n.useCallback(()=>{(s==null?void 0:s(d.getState()))===!1&&l&&p(l({isSignalROnline:!0})),r||v(!0)},[p,r,d]),k=S,H=n.useCallback(()=>{(s==null?void 0:s(d.getState()))===!0&&l&&p(l({isSignalROnline:!1})),r&&v(!1)},[p,r,d]),y=n.useCallback(async t=>{e&&e.groups.indexOf(t)<0&&await(e==null?void 0:e.joinGroup(t))},[e]),A=n.useCallback(async t=>{e&&e.groups.indexOf(t)>=0&&await(e==null?void 0:e.leaveGroup(t))},[e]),L=n.useCallback((t,c,i)=>e?e==null?void 0:e.addSignalListener(t,c,i):C.noop,[e]),U=n.useCallback((t,c)=>{e&&e.removeSignalListener(t,c)},[e]),w=n.useCallback(()=>e?e.getHubConnectionId():null,[e]);return n.useEffect(()=>{let t=!1;return Promise.resolve().then(()=>B(require("./SignalR.js"))).then(({default:c})=>{t||N(new c({signalRApiUrl:f,hub:o,logger:q,enableLogging:x}))}),()=>{t=!0}},[o,f]),n.useEffect(()=>{function t(c){z(c)}return b.add(t),()=>{b.delete(t)}},[]),n.useEffect(()=>{O.current=u},[u]),n.useEffect(()=>{const t=e==null?void 0:e.addEventListener("connected",S),c=e==null?void 0:e.addEventListener("reconnected",k),i=e==null?void 0:e.addEventListener("disconnected",H);return e&&!O.current&&T(!0),()=>{t==null||t(),c==null||c(),i==null||i()}},[e,S,H,k]),n.useEffect(()=>{e==null||e.setClientId(E||void 0)},[e,E]),n.useEffect(()=>{async function t(){await(e==null?void 0:e.connect())}u&&t()},[e,u]),n.useEffect(()=>()=>{e==null||e.leaveAllGroups().then(()=>{e==null||e.disconnect()}).catch(C.noop).finally(()=>{e==null||e.disconnect().catch(C.noop)})},[e]),n.useMemo(()=>({isHubConnected:r,join:y,leave:A,subscribe:L,unsubscribe:U,getHubConnectionId:w}),[r,y,A,L,U,w])}return{useSignalR:P,setUrl(o){I=o,b.forEach(f=>{f(o)})}}}module.exports=F;
@@ -1,52 +1,52 @@
1
- import { useState as S, useRef as N, useCallback as s, useEffect as r, useMemo as P } from "react";
2
- import { useStore as Q, useDispatch as T, useSelector as V } from "react-redux";
3
- import { n as W } from "../noop-378485d5.mjs";
4
- function $(h, x, y, D) {
5
- const { logger: G, enableLogging: j } = h;
6
- let { signalRApiUrl: v } = h;
7
- const { clientIdSelector: k, isSignalROnlineSelector: o } = x ?? {}, { setIsSignalROnlineAction: a } = y ?? {}, {
8
- useAppStore: M = Q,
9
- useAppDispatch: q = T,
10
- useAppSelector: z = V
11
- } = D ?? {}, b = /* @__PURE__ */ new Set();
12
- function B(i) {
13
- const [l, F] = S(v), [e, J] = S(null), f = M(), p = q(), H = z(k ?? (() => {
14
- })), [u, K] = S(!1), [c, A] = S(!1), L = N(u), I = s(() => {
15
- (o == null ? void 0 : o(f.getState())) === !1 && a && p(a({ isSignalROnline: !0 })), c || A(!0);
16
- }, [p, c, f]), U = I, m = s(() => {
17
- (o == null ? void 0 : o(f.getState())) === !0 && a && p(a({ isSignalROnline: !1 })), c && A(!1);
18
- }, [p, c, f]), C = s(
1
+ import { useState as S, useRef as P, useCallback as c, useEffect as r, useMemo as Q } from "react";
2
+ import { useStore as T, useDispatch as V, useSelector as W } from "react-redux";
3
+ import { n as I } from "../noop-378485d5.mjs";
4
+ function $(v, D, G, g) {
5
+ const { logger: j, enableLogging: k } = v;
6
+ let { signalRApiUrl: H } = v;
7
+ const { clientIdSelector: M, isSignalROnlineSelector: s } = D ?? {}, { setIsSignalROnlineAction: a } = G ?? {}, {
8
+ useAppStore: q = T,
9
+ useAppDispatch: z = V,
10
+ useAppSelector: B = W
11
+ } = g ?? {}, b = /* @__PURE__ */ new Set();
12
+ function F(i) {
13
+ const [l, J] = S(H), [e, K] = S(null), f = q(), p = z(), A = B(M ?? (() => {
14
+ })), [u, N] = S(!1), [o, L] = S(!1), U = P(u), h = c(() => {
15
+ (s == null ? void 0 : s(f.getState())) === !1 && a && p(a({ isSignalROnline: !0 })), o || L(!0);
16
+ }, [p, o, f]), m = h, C = c(() => {
17
+ (s == null ? void 0 : s(f.getState())) === !0 && a && p(a({ isSignalROnline: !1 })), o && L(!1);
18
+ }, [p, o, f]), O = c(
19
19
  async (t) => {
20
20
  e && e.groups.indexOf(t) < 0 && await (e == null ? void 0 : e.joinGroup(t));
21
21
  },
22
22
  [e]
23
- ), O = s(
23
+ ), w = c(
24
24
  async (t) => {
25
25
  e && e.groups.indexOf(t) >= 0 && await (e == null ? void 0 : e.leaveGroup(t));
26
26
  },
27
27
  [e]
28
- ), w = s(
28
+ ), E = c(
29
29
  (t, n, d) => e ? e == null ? void 0 : e.addSignalListener(
30
30
  t,
31
31
  n,
32
32
  d
33
- ) : W,
33
+ ) : I,
34
34
  [e]
35
- ), E = s(
35
+ ), y = c(
36
36
  (t, n) => {
37
37
  e && e.removeSignalListener(t, n);
38
38
  },
39
39
  [e]
40
- ), g = s(() => e ? e.getHubConnectionId() : null, [e]);
40
+ ), x = c(() => e ? e.getHubConnectionId() : null, [e]);
41
41
  return r(() => {
42
42
  let t = !1;
43
43
  return import("./SignalR.mjs").then(({ default: n }) => {
44
- t || J(
44
+ t || K(
45
45
  new n({
46
46
  signalRApiUrl: l,
47
47
  hub: i,
48
- logger: G,
49
- enableLogging: j
48
+ logger: j,
49
+ enableLogging: k
50
50
  })
51
51
  );
52
52
  }), () => {
@@ -54,35 +54,35 @@ function $(h, x, y, D) {
54
54
  };
55
55
  }, [i, l]), r(() => {
56
56
  function t(n) {
57
- F(n);
57
+ J(n);
58
58
  }
59
59
  return b.add(t), () => {
60
60
  b.delete(t);
61
61
  };
62
62
  }, []), r(() => {
63
- L.current = u;
63
+ U.current = u;
64
64
  }, [u]), r(() => {
65
65
  const t = e == null ? void 0 : e.addEventListener(
66
66
  "connected",
67
- I
67
+ h
68
68
  ), n = e == null ? void 0 : e.addEventListener(
69
69
  "reconnected",
70
- U
70
+ m
71
71
  ), d = e == null ? void 0 : e.addEventListener(
72
72
  "disconnected",
73
- m
73
+ C
74
74
  );
75
- return e && !L.current && K(!0), () => {
75
+ return e && !U.current && N(!0), () => {
76
76
  t == null || t(), n == null || n(), d == null || d();
77
77
  };
78
78
  }, [
79
79
  e,
80
- I,
81
- m,
82
- U
80
+ h,
81
+ C,
82
+ m
83
83
  ]), r(() => {
84
- e == null || e.setClientId(H || void 0);
85
- }, [e, H]), r(() => {
84
+ e == null || e.setClientId(A || void 0);
85
+ }, [e, A]), r(() => {
86
86
  async function t() {
87
87
  await (e == null ? void 0 : e.connect());
88
88
  }
@@ -91,25 +91,27 @@ function $(h, x, y, D) {
91
91
  () => () => {
92
92
  e == null || e.leaveAllGroups().then(() => {
93
93
  e == null || e.disconnect();
94
+ }).catch(I).finally(() => {
95
+ e == null || e.disconnect().catch(I);
94
96
  });
95
97
  },
96
98
  [e]
97
- ), P(
99
+ ), Q(
98
100
  () => ({
99
- isHubConnected: c,
100
- join: C,
101
- leave: O,
102
- subscribe: w,
103
- unsubscribe: E,
104
- getHubConnectionId: g
101
+ isHubConnected: o,
102
+ join: O,
103
+ leave: w,
104
+ subscribe: E,
105
+ unsubscribe: y,
106
+ getHubConnectionId: x
105
107
  }),
106
- [c, C, O, w, E, g]
108
+ [o, O, w, E, y, x]
107
109
  );
108
110
  }
109
111
  return {
110
- useSignalR: B,
112
+ useSignalR: F,
111
113
  setUrl(i) {
112
- v = i, b.forEach((l) => {
114
+ H = i, b.forEach((l) => {
113
115
  l(i);
114
116
  });
115
117
  }