@waveform-playlist/browser 15.3.2 → 15.3.4

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
@@ -1657,6 +1657,12 @@ function createPeaksWorker() {
1657
1657
  generate() {
1658
1658
  return Promise.reject(new Error("Worker creation failed"));
1659
1659
  },
1660
+ // Reports NOT terminated: CSP blocking is permanent for the page, so
1661
+ // recreating on every call would just re-attempt (and re-warn about)
1662
+ // Worker construction each time.
1663
+ isTerminated() {
1664
+ return false;
1665
+ },
1660
1666
  terminate() {
1661
1667
  }
1662
1668
  };
@@ -1689,6 +1695,9 @@ function createPeaksWorker() {
1689
1695
  pending.clear();
1690
1696
  };
1691
1697
  return {
1698
+ isTerminated() {
1699
+ return terminated;
1700
+ },
1692
1701
  generate(params) {
1693
1702
  if (terminated) return Promise.reject(new Error("Worker terminated"));
1694
1703
  const messageId = String(++idCounter);
@@ -1731,7 +1740,7 @@ function useWaveformDataCache(tracks, baseScale) {
1731
1740
  const subscribersByBufferRef = (0, import_react16.useRef)(/* @__PURE__ */ new WeakMap());
1732
1741
  const pendingCountRef = (0, import_react16.useRef)(0);
1733
1742
  const getWorker = (0, import_react16.useCallback)(() => {
1734
- if (!workerRef.current) {
1743
+ if (!workerRef.current || workerRef.current.isTerminated()) {
1735
1744
  workerRef.current = createPeaksWorker();
1736
1745
  }
1737
1746
  return workerRef.current;
@@ -1959,6 +1968,7 @@ var WaveformPlaylistProvider = ({
1959
1968
  const playbackStartTimeRef = (0, import_react17.useRef)(0);
1960
1969
  const audioStartPositionRef = (0, import_react17.useRef)(0);
1961
1970
  const playbackEndTimeRef = (0, import_react17.useRef)(null);
1971
+ const suppressEngineStopMirrorRef = (0, import_react17.useRef)(false);
1962
1972
  const scrollContainerRef = (0, import_react17.useRef)(null);
1963
1973
  const isAutomaticScrollRef = (0, import_react17.useRef)(false);
1964
1974
  const frameCallbacksRef = (0, import_react17.useRef)(/* @__PURE__ */ new Map());
@@ -2167,7 +2177,9 @@ var WaveformPlaylistProvider = ({
2167
2177
  const wasPlaying = isPlayingRef.current;
2168
2178
  const resumePosition = currentTimeRef.current;
2169
2179
  if (engineRef.current && wasPlaying) {
2180
+ suppressEngineStopMirrorRef.current = true;
2170
2181
  engineRef.current.stop();
2182
+ suppressEngineStopMirrorRef.current = false;
2171
2183
  stopAnimationFrameLoop();
2172
2184
  pendingResumeRef.current = { position: resumePosition };
2173
2185
  }
@@ -2267,6 +2279,14 @@ var WaveformPlaylistProvider = ({
2267
2279
  }
2268
2280
  }
2269
2281
  });
2282
+ engine.on("stop", () => {
2283
+ if (suppressEngineStopMirrorRef.current) return;
2284
+ setIsPlaying(false);
2285
+ stopAnimationFrameLoop();
2286
+ const stoppedAt = engine.getCurrentTime();
2287
+ setCurrentTimeRefs(stoppedAt);
2288
+ setCurrentTime(stoppedAt);
2289
+ });
2270
2290
  engine.setTracks(tracksWithState);
2271
2291
  suppressTracksMirroring = false;
2272
2292
  lastTracksVersionRef.current = engine.getState().tracksVersion;
@@ -2564,7 +2584,9 @@ var WaveformPlaylistProvider = ({
2564
2584
  if (isPlaying && animationFrameRef.current && engineRef.current) {
2565
2585
  if (continuousPlay) {
2566
2586
  const currentPos = currentTimeRef.current;
2587
+ suppressEngineStopMirrorRef.current = true;
2567
2588
  engineRef.current.stop();
2589
+ suppressEngineStopMirrorRef.current = false;
2568
2590
  stopAnimationLoop();
2569
2591
  const timeNow = getAudioContextTime();
2570
2592
  playbackStartTimeRef.current = timeNow;
@@ -2619,7 +2641,9 @@ var WaveformPlaylistProvider = ({
2619
2641
  const actualStartTime = startTime != null ? startTime : currentTimeRef.current;
2620
2642
  playStartPositionRef.current = actualStartTime;
2621
2643
  setCurrentTimeRefs(actualStartTime);
2644
+ suppressEngineStopMirrorRef.current = true;
2622
2645
  engineRef.current.stop();
2646
+ suppressEngineStopMirrorRef.current = false;
2623
2647
  engineRef.current.seek(actualStartTime);
2624
2648
  stopAnimationLoop();
2625
2649
  const startTimeNow = getAudioContextTime();
@@ -2734,7 +2758,9 @@ var WaveformPlaylistProvider = ({
2734
2758
  setCurrentTimeRefs(start);
2735
2759
  setCurrentTime(start);
2736
2760
  if (isPlaying && engineRef.current) {
2761
+ suppressEngineStopMirrorRef.current = true;
2737
2762
  engineRef.current.stop();
2763
+ suppressEngineStopMirrorRef.current = false;
2738
2764
  engineRef.current.seek(start);
2739
2765
  engineRef.current.play(start);
2740
2766
  }