@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.mjs CHANGED
@@ -2274,6 +2274,20 @@ function subscribeBackgroundAudioHost(host, listener) {
2274
2274
  host.listeners.delete(listener);
2275
2275
  };
2276
2276
  }
2277
+ function subscribeBackgroundAudioStore(host, onStoreChange) {
2278
+ let unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
2279
+ });
2280
+ const unsubscribeHost = subscribeBackgroundAudioHost(host, () => {
2281
+ unsubscribeController();
2282
+ unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
2283
+ });
2284
+ onStoreChange();
2285
+ });
2286
+ return () => {
2287
+ unsubscribeController();
2288
+ unsubscribeHost();
2289
+ };
2290
+ }
2277
2291
 
2278
2292
  // src/cn.ts
2279
2293
  function cn(...values) {
@@ -5022,6 +5036,20 @@ function subscribePanoVideoHost(host, onStoreChange) {
5022
5036
  host.listeners.delete(onStoreChange);
5023
5037
  };
5024
5038
  }
5039
+ function subscribePanoVideoStore(host, onStoreChange) {
5040
+ let unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
5041
+ });
5042
+ const unsubscribeHost = subscribePanoVideoHost(host, () => {
5043
+ unsubscribeController();
5044
+ unsubscribeController = host.controller?.subscribe(onStoreChange) ?? (() => {
5045
+ });
5046
+ onStoreChange();
5047
+ });
5048
+ return () => {
5049
+ unsubscribeController();
5050
+ unsubscribeHost();
5051
+ };
5052
+ }
5025
5053
  function getPanoVideoHostRevision(host) {
5026
5054
  return host.revision;
5027
5055
  }
@@ -6953,7 +6981,7 @@ var PanoViewer = forwardRef2(
6953
6981
  requestVRPermission: () => webVRHost.controller?.requestPermission() ?? Promise.resolve(false),
6954
6982
  // -- Video --
6955
6983
  getVideo: () => videoHost.controller,
6956
- subscribeVideo: (onStoreChange) => subscribePanoVideoHost(videoHost, onStoreChange),
6984
+ subscribeVideo: (onStoreChange) => subscribePanoVideoStore(videoHost, onStoreChange),
6957
6985
  playVideo: () => videoHost.controller?.play() ?? Promise.resolve(),
6958
6986
  pauseVideo: () => videoHost.controller?.pause(),
6959
6987
  toggleVideo: () => videoHost.controller?.togglePlay(),
@@ -6963,7 +6991,7 @@ var PanoViewer = forwardRef2(
6963
6991
  toggleVideoMuted: () => videoHost.controller?.toggleMuted(),
6964
6992
  // -- Background Audio --
6965
6993
  getBackgroundAudio: () => bgmHost.controller,
6966
- subscribeBackgroundAudio: (onStoreChange) => subscribeBackgroundAudioHost(bgmHost, onStoreChange),
6994
+ subscribeBackgroundAudio: (onStoreChange) => subscribeBackgroundAudioStore(bgmHost, onStoreChange),
6967
6995
  playBackgroundAudio: () => {
6968
6996
  bgmHost.controller?.play();
6969
6997
  return Promise.resolve();
@@ -7327,6 +7355,8 @@ function BackgroundAudio({
7327
7355
  const loopRef = useRef13(loop);
7328
7356
  const mutedRef = useRef13(muted);
7329
7357
  const volumeRef = useRef13(volume);
7358
+ const mutedPropRef = useRef13(muted);
7359
+ const volumePropRef = useRef13(volume);
7330
7360
  const fadeMsRef = useRef13(resolveFadeMs(fadeMs));
7331
7361
  const onPlaybackStateChangeRef = useRef13(onPlaybackStateChange);
7332
7362
  const onPlaybackErrorRef = useRef13(onPlaybackError);
@@ -7334,9 +7364,15 @@ function BackgroundAudio({
7334
7364
  const onErrorRef = useRef13(onError);
7335
7365
  playingRef.current = playing;
7336
7366
  loopRef.current = loop;
7337
- mutedRef.current = muted;
7338
- volumeRef.current = volume;
7339
7367
  fadeMsRef.current = resolveFadeMs(fadeMs);
7368
+ if (mutedPropRef.current !== muted) {
7369
+ mutedPropRef.current = muted;
7370
+ mutedRef.current = muted;
7371
+ }
7372
+ if (volumePropRef.current !== volume) {
7373
+ volumePropRef.current = volume;
7374
+ volumeRef.current = volume;
7375
+ }
7340
7376
  onPlaybackStateChangeRef.current = onPlaybackStateChange;
7341
7377
  onPlaybackErrorRef.current = onPlaybackError;
7342
7378
  onEndedRef.current = onEnded;
@@ -7390,20 +7426,17 @@ function BackgroundAudio({
7390
7426
  if (isControlledRef.current) {
7391
7427
  return;
7392
7428
  }
7393
- const howl = currentRef.current?.handle.howl;
7394
- if (howl) {
7395
- howl.volume(clampAudioVolume(vol));
7396
- }
7397
- notifySnapshot({ volume: clampAudioVolume(vol) });
7429
+ const next = clampAudioVolume(vol);
7430
+ volumeRef.current = next;
7431
+ currentRef.current?.handle.howl.volume(next);
7432
+ notifySnapshot({ volume: next });
7398
7433
  },
7399
7434
  setMuted: (m) => {
7400
7435
  if (isControlledRef.current) {
7401
7436
  return;
7402
7437
  }
7403
- const howl = currentRef.current?.handle.howl;
7404
- if (howl) {
7405
- howl.mute(m);
7406
- }
7438
+ mutedRef.current = m;
7439
+ currentRef.current?.handle.howl.mute(m);
7407
7440
  notifySnapshot({ muted: m });
7408
7441
  },
7409
7442
  toggleMuted: () => {
@@ -7411,10 +7444,8 @@ function BackgroundAudio({
7411
7444
  return;
7412
7445
  }
7413
7446
  const next = !snapshotRef.current.muted;
7414
- const howl = currentRef.current?.handle.howl;
7415
- if (howl) {
7416
- howl.mute(next);
7417
- }
7447
+ mutedRef.current = next;
7448
+ currentRef.current?.handle.howl.mute(next);
7418
7449
  notifySnapshot({ muted: next });
7419
7450
  }
7420
7451
  }),
@@ -7481,6 +7512,9 @@ function BackgroundAudio({
7481
7512
  shouldRetryPlay: () => currentRef.current?.key === trackKey && playingRef.current,
7482
7513
  onEnded: () => {
7483
7514
  notifySnapshot({ playing: false, ended: true });
7515
+ if (!isControlledRef.current) {
7516
+ setInternalPlaying(false);
7517
+ }
7484
7518
  onPlaybackStateChangeRef.current?.("ended");
7485
7519
  onEndedRef.current?.();
7486
7520
  },
@@ -7553,7 +7587,9 @@ function BackgroundAudio({
7553
7587
  }
7554
7588
  if (!playing) {
7555
7589
  fadingInRef.current = false;
7556
- howl.pause();
7590
+ if (howl.playing()) {
7591
+ howl.pause();
7592
+ }
7557
7593
  for (const slot of outgoingRef.current) {
7558
7594
  slot.handle.dispose();
7559
7595
  }
@@ -7568,11 +7604,14 @@ function BackgroundAudio({
7568
7604
  return;
7569
7605
  }
7570
7606
  slot.handle.howl.loop(loop);
7571
- slot.handle.howl.mute(muted);
7607
+ slot.handle.howl.mute(mutedRef.current);
7572
7608
  if (!fadingInRef.current) {
7573
- slot.handle.howl.volume(clampAudioVolume(volume));
7609
+ slot.handle.howl.volume(clampAudioVolume(volumeRef.current));
7574
7610
  }
7575
- notifySnapshot({ muted, volume: clampAudioVolume(volume) });
7611
+ notifySnapshot({
7612
+ muted: mutedRef.current,
7613
+ volume: clampAudioVolume(volumeRef.current)
7614
+ });
7576
7615
  }, [loop, muted, trackKey, volume]);
7577
7616
  useEffect13(() => {
7578
7617
  if (!pauseWhenHidden) {