@evergis/react 3.1.93 → 3.1.94

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.js CHANGED
@@ -3937,6 +3937,15 @@ const ServerNotificationsContext = React.createContext({});
3937
3937
  const useServerNotifications = (url, initialized) => {
3938
3938
  const hubConnection = React.useRef(null);
3939
3939
  const [connection, setConnection] = React.useState(null);
3940
+ const subscribeNotifications = React.useCallback(() => {
3941
+ if (!connection || connection.state !== "Connected") {
3942
+ return;
3943
+ }
3944
+ connection
3945
+ .invoke("SubscribeNotifications", [])
3946
+ .then(() => console.info("Подписка `SubscribeNotifications` оформлена"))
3947
+ .catch(err => console.info("Ошибка подписки `SubscribeNotifications`:", err));
3948
+ }, [connection]);
3940
3949
  React.useEffect(() => {
3941
3950
  if (!initialized) {
3942
3951
  return;
@@ -3945,6 +3954,7 @@ const useServerNotifications = (url, initialized) => {
3945
3954
  .withUrl(`${url}?clientId=${api.generateId()}`, {
3946
3955
  withCredentials: true,
3947
3956
  })
3957
+ .withAutomaticReconnect({ nextRetryDelayInMilliseconds: () => 3000 })
3948
3958
  .configureLogging(signalr.LogLevel.Information)
3949
3959
  .build();
3950
3960
  hubConnection.current
@@ -3957,10 +3967,9 @@ const useServerNotifications = (url, initialized) => {
3957
3967
  if (!connection || connection.state !== "Connected") {
3958
3968
  return;
3959
3969
  }
3960
- connection
3961
- .invoke("SubscribeNotifications", [])
3962
- .then(() => console.info("Подписка `SubscribeNotifications` оформлена"))
3963
- .catch(err => console.info("Ошибка подписки `SubscribeNotifications`:", err));
3970
+ connection.onreconnecting(() => console.info("Переподключение к серверным нотификациям"));
3971
+ connection.onreconnected(subscribeNotifications);
3972
+ subscribeNotifications();
3964
3973
  }, [connection]);
3965
3974
  return connection;
3966
3975
  };