stream-chat-react 12.0.0-rc.5 → 12.0.0-rc.6

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.
@@ -29,6 +29,9 @@ export const AudioRecordingInProgress = () => {
29
29
  if (!recorder?.mediaRecorder)
30
30
  return;
31
31
  const { mediaRecorder } = recorder;
32
+ if (mediaRecorder.state === 'recording') {
33
+ startCounter();
34
+ }
32
35
  mediaRecorder.addEventListener('start', startCounter);
33
36
  mediaRecorder.addEventListener('resume', startCounter);
34
37
  mediaRecorder.addEventListener('stop', stopCounter);
@@ -4,23 +4,24 @@ export const useTimeElapsed = ({ startOnMount } = {}) => {
4
4
  const [secondsElapsed, setSecondsElapsed] = useState(0);
5
5
  const updateInterval = useRef();
6
6
  const startCounter = useCallback(() => {
7
+ if (updateInterval.current)
8
+ return;
7
9
  updateInterval.current = setInterval(() => {
8
10
  setSecondsElapsed((prev) => prev + 1);
9
11
  }, 1000);
10
12
  }, []);
11
13
  const stopCounter = useCallback(() => {
12
14
  clearInterval(updateInterval.current);
15
+ updateInterval.current = undefined;
13
16
  }, []);
14
17
  useEffect(() => {
15
18
  if (!startOnMount)
16
19
  return;
17
- updateInterval.current = setInterval(() => {
18
- setSecondsElapsed((prev) => prev + 1);
19
- }, 1000);
20
+ startCounter();
20
21
  return () => {
21
22
  stopCounter();
22
23
  };
23
- }, [startOnMount, stopCounter]);
24
+ }, [startCounter, startOnMount, stopCounter]);
24
25
  return {
25
26
  secondsElapsed,
26
27
  startCounter,
package/dist/index.cjs.js CHANGED
@@ -43464,23 +43464,24 @@ var useTimeElapsed = ({ startOnMount } = {}) => {
43464
43464
  const [secondsElapsed, setSecondsElapsed] = (0, import_react81.useState)(0);
43465
43465
  const updateInterval = (0, import_react81.useRef)();
43466
43466
  const startCounter = (0, import_react81.useCallback)(() => {
43467
+ if (updateInterval.current)
43468
+ return;
43467
43469
  updateInterval.current = setInterval(() => {
43468
43470
  setSecondsElapsed((prev) => prev + 1);
43469
43471
  }, 1e3);
43470
43472
  }, []);
43471
43473
  const stopCounter = (0, import_react81.useCallback)(() => {
43472
43474
  clearInterval(updateInterval.current);
43475
+ updateInterval.current = void 0;
43473
43476
  }, []);
43474
43477
  (0, import_react81.useEffect)(() => {
43475
43478
  if (!startOnMount)
43476
43479
  return;
43477
- updateInterval.current = setInterval(() => {
43478
- setSecondsElapsed((prev) => prev + 1);
43479
- }, 1e3);
43480
+ startCounter();
43480
43481
  return () => {
43481
43482
  stopCounter();
43482
43483
  };
43483
- }, [startOnMount, stopCounter]);
43484
+ }, [startCounter, startOnMount, stopCounter]);
43484
43485
  return {
43485
43486
  secondsElapsed,
43486
43487
  startCounter,
@@ -43524,6 +43525,9 @@ var AudioRecordingInProgress = () => {
43524
43525
  if (!recorder?.mediaRecorder)
43525
43526
  return;
43526
43527
  const { mediaRecorder } = recorder;
43528
+ if (mediaRecorder.state === "recording") {
43529
+ startCounter();
43530
+ }
43527
43531
  mediaRecorder.addEventListener("start", startCounter);
43528
43532
  mediaRecorder.addEventListener("resume", startCounter);
43529
43533
  mediaRecorder.addEventListener("stop", stopCounter);