@ericchen1990/pano-view 3.1.2 → 3.1.3
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 +55 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +55 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2366,6 +2366,9 @@ function isMediaActivationEvent(event) {
|
|
|
2366
2366
|
return false;
|
|
2367
2367
|
}
|
|
2368
2368
|
}
|
|
2369
|
+
function isAutoplayPolicyError(error) {
|
|
2370
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === "NotAllowedError";
|
|
2371
|
+
}
|
|
2369
2372
|
|
|
2370
2373
|
// src/audio/howl.ts
|
|
2371
2374
|
import_howler.Howler.autoUnlock = true;
|
|
@@ -3897,7 +3900,7 @@ function hasPanoMediaActivationIntent(host) {
|
|
|
3897
3900
|
return host.intents.size > 0;
|
|
3898
3901
|
}
|
|
3899
3902
|
function needsMediaGesture() {
|
|
3900
|
-
if (typeof navigator !== "undefined" && navigator.userActivation?.
|
|
3903
|
+
if (typeof navigator !== "undefined" && navigator.userActivation?.isActive) {
|
|
3901
3904
|
return false;
|
|
3902
3905
|
}
|
|
3903
3906
|
if (import_howler2.Howler.ctx?.state === "running") {
|
|
@@ -7204,10 +7207,6 @@ var PanoViewer = (0, import_react26.forwardRef)(
|
|
|
7204
7207
|
if (!shouldActivateMedia) {
|
|
7205
7208
|
return;
|
|
7206
7209
|
}
|
|
7207
|
-
if (!needsMediaGesture()) {
|
|
7208
|
-
void activateMedia();
|
|
7209
|
-
return;
|
|
7210
|
-
}
|
|
7211
7210
|
let cancelled = false;
|
|
7212
7211
|
let activating = false;
|
|
7213
7212
|
const removeListeners = () => {
|
|
@@ -7215,32 +7214,69 @@ var PanoViewer = (0, import_react26.forwardRef)(
|
|
|
7215
7214
|
window.removeEventListener("pointerup", handleGesture, true);
|
|
7216
7215
|
window.removeEventListener("keydown", handleGesture, true);
|
|
7217
7216
|
};
|
|
7218
|
-
const
|
|
7219
|
-
if (
|
|
7217
|
+
const completeIfUnlocked = (requestedVideo, videoOk) => {
|
|
7218
|
+
if (cancelled || !isPanoAudioUnlocked()) {
|
|
7219
|
+
return;
|
|
7220
|
+
}
|
|
7221
|
+
if (requestedVideo && videoHost.controller && !videoOk) {
|
|
7222
|
+
return;
|
|
7223
|
+
}
|
|
7224
|
+
removeListeners();
|
|
7225
|
+
setMediaActivated(true);
|
|
7226
|
+
};
|
|
7227
|
+
const tryActivate = () => {
|
|
7228
|
+
if (activating || cancelled) {
|
|
7220
7229
|
return;
|
|
7221
7230
|
}
|
|
7222
7231
|
activating = true;
|
|
7232
|
+
let videoPlay;
|
|
7233
|
+
const controls2 = {
|
|
7234
|
+
resumeAudio: mediaActivationControls.resumeAudio,
|
|
7235
|
+
playVideo: (options) => {
|
|
7236
|
+
const result = mediaActivationControls.playVideo(options);
|
|
7237
|
+
videoPlay = result;
|
|
7238
|
+
return result;
|
|
7239
|
+
},
|
|
7240
|
+
playBackgroundAudio: mediaActivationControls.playBackgroundAudio
|
|
7241
|
+
};
|
|
7223
7242
|
try {
|
|
7224
|
-
const resume =
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7243
|
+
const resume = controls2.resumeAudio();
|
|
7244
|
+
mediaActivationOptions?.onActivate?.(controls2);
|
|
7245
|
+
const requestedVideo = videoPlay !== void 0;
|
|
7246
|
+
void Promise.all([resume, videoPlay ?? Promise.resolve(true)]).then(
|
|
7247
|
+
([, videoOk]) => {
|
|
7248
|
+
completeIfUnlocked(requestedVideo, videoOk);
|
|
7249
|
+
},
|
|
7250
|
+
() => {
|
|
7251
|
+
completeIfUnlocked(requestedVideo, false);
|
|
7228
7252
|
}
|
|
7229
|
-
|
|
7230
|
-
setMediaActivated(true);
|
|
7231
|
-
});
|
|
7253
|
+
);
|
|
7232
7254
|
} finally {
|
|
7233
7255
|
activating = false;
|
|
7234
7256
|
}
|
|
7235
7257
|
};
|
|
7258
|
+
const handleGesture = (event) => {
|
|
7259
|
+
if (!isMediaActivationEvent(event)) {
|
|
7260
|
+
return;
|
|
7261
|
+
}
|
|
7262
|
+
tryActivate();
|
|
7263
|
+
};
|
|
7236
7264
|
window.addEventListener("pointerdown", handleGesture, { capture: true });
|
|
7237
7265
|
window.addEventListener("pointerup", handleGesture, { capture: true });
|
|
7238
7266
|
window.addEventListener("keydown", handleGesture, { capture: true });
|
|
7267
|
+
if (!needsMediaGesture()) {
|
|
7268
|
+
tryActivate();
|
|
7269
|
+
}
|
|
7239
7270
|
return () => {
|
|
7240
7271
|
cancelled = true;
|
|
7241
7272
|
removeListeners();
|
|
7242
7273
|
};
|
|
7243
|
-
}, [
|
|
7274
|
+
}, [
|
|
7275
|
+
mediaActivationControls,
|
|
7276
|
+
mediaActivationOptions,
|
|
7277
|
+
shouldActivateMedia,
|
|
7278
|
+
videoHost
|
|
7279
|
+
]);
|
|
7244
7280
|
const fallbackViewRef = (0, import_react26.useRef)(DEFAULT_VIEW);
|
|
7245
7281
|
const normalizedMinFov = Math.max(1, Math.min(minFov, maxFov - 1));
|
|
7246
7282
|
const normalizedMaxFov = Math.min(
|
|
@@ -10531,8 +10567,10 @@ function PanoVideo({
|
|
|
10531
10567
|
try {
|
|
10532
10568
|
await video.play();
|
|
10533
10569
|
} catch (error) {
|
|
10534
|
-
|
|
10535
|
-
|
|
10570
|
+
if (isAutoplayPolicyError(error)) {
|
|
10571
|
+
blockedRef.current = true;
|
|
10572
|
+
onPlaybackStateChangeRef.current?.("blocked");
|
|
10573
|
+
}
|
|
10536
10574
|
onErrorRef.current?.({ source: "video", error });
|
|
10537
10575
|
emitSnapshot();
|
|
10538
10576
|
}
|