react-realtime-hooks 2.0.1 → 2.0.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/dist/index.cjs CHANGED
@@ -1232,10 +1232,12 @@ var useWebSocket = (options) => {
1232
1232
  controller.noteUserCloseRequested();
1233
1233
  reconnect.cancel();
1234
1234
  heartbeat.stop();
1235
+ const socket2 = socketRef.current;
1236
+ const hasInFlightSocket = socket2 !== null && (socket2.readyState === WebSocket.CONNECTING || socket2.readyState === WebSocket.OPEN);
1235
1237
  commitState((current) => ({
1236
1238
  ...current,
1237
1239
  lastChangedAt: Date.now(),
1238
- status: "closing"
1240
+ status: hasInFlightSocket ? "closing" : "closed"
1239
1241
  }));
1240
1242
  closeSocket({
1241
1243
  code,
@@ -1304,6 +1306,14 @@ var useWebSocket = (options) => {
1304
1306
  if (cancelled) {
1305
1307
  return;
1306
1308
  }
1309
+ if (controller.hasManualCloseRequested()) {
1310
+ commitState((current) => ({
1311
+ ...current,
1312
+ lastChangedAt: Date.now(),
1313
+ status: "closed"
1314
+ }));
1315
+ return;
1316
+ }
1307
1317
  const socket2 = new WebSocket(resolvedUrl, protocols);
1308
1318
  const socketEpoch = nextSocketEpochRef.current + 1;
1309
1319
  socketRef.current = socket2;
@@ -1724,6 +1734,14 @@ var useEventSource = (options) => {
1724
1734
  if (cancelled) {
1725
1735
  return;
1726
1736
  }
1737
+ if (manualCloseRef.current) {
1738
+ commitState((current) => ({
1739
+ ...current,
1740
+ lastChangedAt: Date.now(),
1741
+ status: "closed"
1742
+ }));
1743
+ return;
1744
+ }
1727
1745
  const source = new EventSource(resolvedUrl, {
1728
1746
  withCredentials: options.withCredentials ?? false
1729
1747
  });