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