diff --git a/src/components/videoBackground/VideoBackground.js b/src/components/videoBackground/VideoBackground.js
index 8f2a14f..2592970 100644
--- a/src/components/videoBackground/VideoBackground.js
+++ b/src/components/videoBackground/VideoBackground.js
@@ -4,7 +4,6 @@ import CustomLink from "../CustomLink/CustomLink"
import PropTypes from "prop-types"
import { GatsbyImage, getImage } from "gatsby-plugin-image"
-// ✅ CAMBIO: detectar versión de iOS
function getIOSVersion() {
if (typeof window === "undefined" || typeof navigator === "undefined") return null
const userAgent = navigator.userAgent
@@ -25,6 +24,39 @@ function isIOSPriorTo(version) {
if (currentVersion.major > majorVersion) return false
return currentVersion.minor < minorVersion
}
+function getQS(name) {
+ if (typeof window === "undefined") return null
+ return new URLSearchParams(window.location.search).get(name)
+}
+
+
+function resolvePoster(poster, image) {
+ const posterLocal =
+ poster?.localFile ||
+ poster?.data?.attributes?.localFile ||
+ null
+ const sharp = posterLocal ? getImage(posterLocal) : null
+
+ const rawUrl =
+ poster?.url ||
+ poster?.data?.attributes?.url ||
+ poster?.formats?.large?.url ||
+ poster?.formats?.medium?.url ||
+ poster?.formats?.small?.url ||
+ poster?.formats?.thumbnail?.url ||
+ null
+
+ const toAbs = u =>
+ !u ? null : (u.startsWith("http")
+ ? u
+ : `https://strapi-s3-bitlogic.s3.sa-east-1.amazonaws.com${u}`)
+
+ const url = toAbs(rawUrl)
+
+ const imageSharp = image?.localFile ? getImage(image.localFile) : null
+
+ return { sharp: sharp || imageSharp, url }
+}
function getVideoContent(
video,
@@ -36,29 +68,14 @@ function getVideoContent(
image,
posterData
) {
- const posterUrl = posterData?.url?.startsWith("http")
- ? getImage(posterData.url)
- : getImage(`https://strapi-s3-bitlogic.s3.sa-east-1.amazonaws.com${posterData?.url}`)
- const posterSharp = posterData?.localFile && getImage(posterData.localFile)
+ const { sharp: pSharp, url: pUrl } = resolvePoster(posterData, image)
+ const posterUrl = pUrl || pSharp?.images?.fallback?.src
const url = videoUrl?.replace("watch?v=", "embed/")
let code = url?.substring(url.lastIndexOf("/") + 1) || ""
const codeIndex = code.indexOf("?")
if (codeIndex !== -1) code = code.substring(0, codeIndex)
- const isOldIOS = isIOSPriorTo("17.4")
- if (isOldIOS && posterSharp) {
- return (
-
- )
- }
-
if (video?.url) {
return (
@@ -141,6 +158,12 @@ const VideoBackground = ({ data }) => {
poster,
} = data
+ const forced = getQS("forceOldIOS") === "1"
+ const initialIsOldIOS =
+ forced ||
+ (typeof navigator !== "undefined" && /iPhone/.test(navigator.userAgent) && isIOSPriorTo("17.4"))
+ const [isOldIOS] = useState(initialIsOldIOS)
+
const [isVideoPause, setIsVideoPause] = useState(false)
const [isIntersecting, setIsIntersecting] = useState(false)
const videoRef = useRef(null)
@@ -157,10 +180,12 @@ const VideoBackground = ({ data }) => {
pausePlay()
}
}
-
useEffect(() => {
+ if (isOldIOS) return
+
const elem = videoRef.current
if (!elem) return
+
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
@@ -172,11 +197,83 @@ const VideoBackground = ({ data }) => {
)
observer.observe(elem)
return () => observer.disconnect()
- }, [])
+ }, [isOldIOS])
useEffect(() => {
localStorage.setItem("videoPaused", isVideoPause)
}, [isVideoPause])
+ if (isOldIOS) {
+ const { sharp: posterSharp, url: posterFromUrl } = resolvePoster(poster, image)
+
+ return (
+
+
+
+ {posterSharp ? (
+
+ ) : posterFromUrl ? (
+
+ ) : (
+
+ (sin poster disponible)
+
+ )}
+
+ {description && (
+
+
{description}
+ {button && (
+
+ )}
+
+ )}
+
+
+
+ )
+ }
const videoContent = getVideoContent(
video,
@@ -200,7 +297,7 @@ const VideoBackground = ({ data }) => {
}}
>
-
+
{videoContent}
{description && (
@@ -223,31 +320,38 @@ const VideoBackground = ({ data }) => {
VideoBackground.propTypes = {
data: PropTypes.shape({
video: PropTypes.shape({
- url: PropTypes.string.isRequired,
- mime: PropTypes.string.isRequired,
+ url: PropTypes.string,
+ mime: PropTypes.string,
}),
videoUrl: PropTypes.string,
description: PropTypes.string,
- backgroundImage: PropTypes.shape({ url: PropTypes.string.isRequired }),
+ backgroundImage: PropTypes.shape({ url: PropTypes.string }),
image: PropTypes.shape({
alternativeText: PropTypes.string,
localFile: PropTypes.object,
}),
poster: PropTypes.shape({
- url: PropTypes.string.isRequired,
+ url: PropTypes.string,
alternativeText: PropTypes.string,
localFile: PropTypes.shape({
- childImageSharp: PropTypes.object.isRequired,
+ childImageSharp: PropTypes.object,
+ }),
+ formats: PropTypes.object,
+ data: PropTypes.shape({
+ attributes: PropTypes.shape({
+ url: PropTypes.string,
+ localFile: PropTypes.object,
+ }),
}),
}),
button: PropTypes.shape({
- content: PropTypes.string.isRequired,
+ content: PropTypes.string,
url: PropTypes.string,
landing_page: PropTypes.shape({
- slug: PropTypes.string.isRequired,
+ slug: PropTypes.string,
}),
}),
}),
}
-export default VideoBackground
+export default VideoBackground
\ No newline at end of file