@ericchen1990/pano-view 2.5.0 → 2.5.1

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
@@ -2330,6 +2330,20 @@ function subscribeBackgroundAudioHost(host, listener) {
2330
2330
  host.listeners.delete(listener);
2331
2331
  };
2332
2332
  }
2333
+ function subscribeBackgroundAudioStore(host, onStoreChange) {
2334
+ let unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
2335
+ });
2336
+ const unsubscribeHost = subscribeBackgroundAudioHost(host, () => {
2337
+ unsubscribeController();
2338
+ unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
2339
+ });
2340
+ onStoreChange();
2341
+ });
2342
+ return () => {
2343
+ unsubscribeController();
2344
+ unsubscribeHost();
2345
+ };
2346
+ }
2333
2347
 
2334
2348
  // src/cn.ts
2335
2349
  function cn(...values) {
@@ -5047,6 +5061,20 @@ function subscribePanoVideoHost(host, onStoreChange) {
5047
5061
  host.listeners.delete(onStoreChange);
5048
5062
  };
5049
5063
  }
5064
+ function subscribePanoVideoStore(host, onStoreChange) {
5065
+ let unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
5066
+ });
5067
+ const unsubscribeHost = subscribePanoVideoHost(host, () => {
5068
+ unsubscribeController();
5069
+ unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
5070
+ });
5071
+ onStoreChange();
5072
+ });
5073
+ return () => {
5074
+ unsubscribeController();
5075
+ unsubscribeHost();
5076
+ };
5077
+ }
5050
5078
  function getPanoVideoHostRevision(host) {
5051
5079
  return host.revision;
5052
5080
  }
@@ -6969,7 +6997,7 @@ var PanoViewer = (0, import_react24.forwardRef)(
6969
6997
  requestVRPermission: () => webVRHost.controller?.requestPermission() ?? Promise.resolve(false),
6970
6998
  // -- Video --
6971
6999
  getVideo: () => videoHost.controller,
6972
- subscribeVideo: (onStoreChange) => subscribePanoVideoHost(videoHost, onStoreChange),
7000
+ subscribeVideo: (onStoreChange) => subscribePanoVideoStore(videoHost, onStoreChange),
6973
7001
  playVideo: () => videoHost.controller?.play() ?? Promise.resolve(),
6974
7002
  pauseVideo: () => videoHost.controller?.pause(),
6975
7003
  toggleVideo: () => videoHost.controller?.togglePlay(),
@@ -6979,7 +7007,7 @@ var PanoViewer = (0, import_react24.forwardRef)(
6979
7007
  toggleVideoMuted: () => videoHost.controller?.toggleMuted(),
6980
7008
  // -- Background Audio --
6981
7009
  getBackgroundAudio: () => bgmHost.controller,
6982
- subscribeBackgroundAudio: (onStoreChange) => subscribeBackgroundAudioHost(bgmHost, onStoreChange),
7010
+ subscribeBackgroundAudio: (onStoreChange) => subscribeBackgroundAudioStore(bgmHost, onStoreChange),
6983
7011
  playBackgroundAudio: () => {
6984
7012
  bgmHost.controller?.play();
6985
7013
  return Promise.resolve();
@@ -7343,6 +7371,8 @@ function BackgroundAudio({
7343
7371
  const loopRef = (0, import_react25.useRef)(loop);
7344
7372
  const mutedRef = (0, import_react25.useRef)(muted);
7345
7373
  const volumeRef = (0, import_react25.useRef)(volume);
7374
+ const mutedPropRef = (0, import_react25.useRef)(muted);
7375
+ const volumePropRef = (0, import_react25.useRef)(volume);
7346
7376
  const fadeMsRef = (0, import_react25.useRef)(resolveFadeMs(fadeMs));
7347
7377
  const onPlaybackStateChangeRef = (0, import_react25.useRef)(onPlaybackStateChange);
7348
7378
  const onPlaybackErrorRef = (0, import_react25.useRef)(onPlaybackError);
@@ -7350,9 +7380,15 @@ function BackgroundAudio({
7350
7380
  const onErrorRef = (0, import_react25.useRef)(onError);
7351
7381
  playingRef.current = playing;
7352
7382
  loopRef.current = loop;
7353
- mutedRef.current = muted;
7354
- volumeRef.current = volume;
7355
7383
  fadeMsRef.current = resolveFadeMs(fadeMs);
7384
+ if (mutedPropRef.current !== muted) {
7385
+ mutedPropRef.current = muted;
7386
+ mutedRef.current = muted;
7387
+ }
7388
+ if (volumePropRef.current !== volume) {
7389
+ volumePropRef.current = volume;
7390
+ volumeRef.current = volume;
7391
+ }
7356
7392
  onPlaybackStateChangeRef.current = onPlaybackStateChange;
7357
7393
  onPlaybackErrorRef.current = onPlaybackError;
7358
7394
  onEndedRef.current = onEnded;
@@ -7406,20 +7442,17 @@ function BackgroundAudio({
7406
7442
  if (isControlledRef.current) {
7407
7443
  return;
7408
7444
  }
7409
- const howl = currentRef.current?.handle.howl;
7410
- if (howl) {
7411
- howl.volume(clampAudioVolume(vol));
7412
- }
7413
- notifySnapshot({ volume: clampAudioVolume(vol) });
7445
+ const next = clampAudioVolume(vol);
7446
+ volumeRef.current = next;
7447
+ currentRef.current?.handle.howl.volume(next);
7448
+ notifySnapshot({ volume: next });
7414
7449
  },
7415
7450
  setMuted: (m) => {
7416
7451
  if (isControlledRef.current) {
7417
7452
  return;
7418
7453
  }
7419
- const howl = currentRef.current?.handle.howl;
7420
- if (howl) {
7421
- howl.mute(m);
7422
- }
7454
+ mutedRef.current = m;
7455
+ currentRef.current?.handle.howl.mute(m);
7423
7456
  notifySnapshot({ muted: m });
7424
7457
  },
7425
7458
  toggleMuted: () => {
@@ -7427,10 +7460,8 @@ function BackgroundAudio({
7427
7460
  return;
7428
7461
  }
7429
7462
  const next = !snapshotRef.current.muted;
7430
- const howl = currentRef.current?.handle.howl;
7431
- if (howl) {
7432
- howl.mute(next);
7433
- }
7463
+ mutedRef.current = next;
7464
+ currentRef.current?.handle.howl.mute(next);
7434
7465
  notifySnapshot({ muted: next });
7435
7466
  }
7436
7467
  }),
@@ -7497,6 +7528,9 @@ function BackgroundAudio({
7497
7528
  shouldRetryPlay: () => currentRef.current?.key === trackKey && playingRef.current,
7498
7529
  onEnded: () => {
7499
7530
  notifySnapshot({ playing: false, ended: true });
7531
+ if (!isControlledRef.current) {
7532
+ setInternalPlaying(false);
7533
+ }
7500
7534
  onPlaybackStateChangeRef.current?.("ended");
7501
7535
  onEndedRef.current?.();
7502
7536
  },
@@ -7569,7 +7603,9 @@ function BackgroundAudio({
7569
7603
  }
7570
7604
  if (!playing) {
7571
7605
  fadingInRef.current = false;
7572
- howl.pause();
7606
+ if (howl.playing()) {
7607
+ howl.pause();
7608
+ }
7573
7609
  for (const slot of outgoingRef.current) {
7574
7610
  slot.handle.dispose();
7575
7611
  }
@@ -7584,11 +7620,14 @@ function BackgroundAudio({
7584
7620
  return;
7585
7621
  }
7586
7622
  slot.handle.howl.loop(loop);
7587
- slot.handle.howl.mute(muted);
7623
+ slot.handle.howl.mute(mutedRef.current);
7588
7624
  if (!fadingInRef.current) {
7589
- slot.handle.howl.volume(clampAudioVolume(volume));
7625
+ slot.handle.howl.volume(clampAudioVolume(volumeRef.current));
7590
7626
  }
7591
- notifySnapshot({ muted, volume: clampAudioVolume(volume) });
7627
+ notifySnapshot({
7628
+ muted: mutedRef.current,
7629
+ volume: clampAudioVolume(volumeRef.current)
7630
+ });
7592
7631
  }, [loop, muted, trackKey, volume]);
7593
7632
  (0, import_react25.useEffect)(() => {
7594
7633
  if (!pauseWhenHidden) {