Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@guardian/ab-core": "8.0.0",
"@guardian/ab-testing-config": "workspace:ab-testing-config",
"@guardian/braze-components": "22.2.0",
"@guardian/bridget": "8.7.0",
"@guardian/bridget": "8.8.0-2026-03-05",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pre-release version - we will need to update this before merge

"@guardian/browserslist-config": "6.1.0",
"@guardian/cdk": "62.3.5",
"@guardian/commercial-core": "29.0.0",
Expand Down
68 changes: 44 additions & 24 deletions dotcom-rendering/src/components/SelfHostedVideo.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
submitComponentEvent,
} from '../client/ophan/ophan';
import type { ArticleFormat } from '../lib/articleFormat';
import { getVideoClient } from '../lib/bridgetApi';
import { getZIndex } from '../lib/getZIndex';
import { generateImageURL } from '../lib/image';
import { useIsInView } from '../lib/useIsInView';
Expand All @@ -32,7 +33,7 @@ import type {
SubtitleSize,
} from './SelfHostedVideoPlayer';
import { SelfHostedVideoPlayer } from './SelfHostedVideoPlayer';
import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters';
import { ophanTrackerApps, ophanTrackerWeb } from './YoutubeAtom/eventEmitters';

const VISIBILITY_THRESHOLD = 0.5;

Expand Down Expand Up @@ -266,6 +267,30 @@ type Props = {
role?: RoleType;
};

const doesUserPermitAutoplayOnWeb = (): boolean => {
/**
* The user indicates a preference for reduced motion: https://web.dev/articles/prefers-reduced-motion
*/
const userPrefersReducedMotion = window.matchMedia(
'(prefers-reduced-motion: reduce)',
).matches;

/**
* The user can set this on their Accessibility Settings page.
* Explicitly `false` when the user has said they don't want autoplay video.
*/
const autoplayPreference = storage.local.get(
'gu.prefs.accessibility.autoplay-video',
);

return !userPrefersReducedMotion && autoplayPreference !== false;
};

const doesUserPermitAutoplayOnApps = async (): Promise<boolean> => {
const videoClient = getVideoClient();
return videoClient.isAutoplayEnabled();
};

export const SelfHostedVideo = ({
sources,
atomId,
Expand Down Expand Up @@ -397,25 +422,6 @@ export const SelfHostedVideo = ({
/>
);

const doesUserPermitAutoplay = (): boolean => {
/**
* The user indicates a preference for reduced motion: https://web.dev/articles/prefers-reduced-motion
*/
const userPrefersReducedMotion = window.matchMedia(
'(prefers-reduced-motion: reduce)',
).matches;

/**
* The user can set this on their Accessibility Settings page.
* Explicitly `false` when the user has said they don't want autoplay video.
*/
const autoplayPreference = storage.local.get(
'gu.prefs.accessibility.autoplay-video',
);

return !userPrefersReducedMotion && autoplayPreference !== false;
};

/**
* Setup.
*
Expand All @@ -424,7 +430,11 @@ export const SelfHostedVideo = ({
* 3. Creates event listeners to control playback when there are multiple videos.
*/
useEffect(() => {
setIsAutoplayAllowed(doesUserPermitAutoplay());
if (renderingTarget === 'Apps') {
void doesUserPermitAutoplayOnApps().then(setIsAutoplayAllowed);
} else {
setIsAutoplayAllowed(doesUserPermitAutoplayOnWeb());
}

/**
* Initialise Ophan attention tracking
Expand Down Expand Up @@ -464,7 +474,13 @@ export const SelfHostedVideo = ({
*/
const handleRestoreFromCache = (event: PageTransitionEvent) => {
if (event.persisted) {
setIsAutoplayAllowed(doesUserPermitAutoplay());
if (renderingTarget === 'Apps') {
void doesUserPermitAutoplayOnApps().then(
setIsAutoplayAllowed,
);
} else {
setIsAutoplayAllowed(doesUserPermitAutoplayOnWeb());
}
setHasPageBecomeActive(true);
} else {
setHasPageBecomeActive(false);
Expand Down Expand Up @@ -513,7 +529,7 @@ export const SelfHostedVideo = ({
handlePageBecomesVisible();
});
};
}, [uniqueId, atomId]);
}, [uniqueId, atomId, renderingTarget]);

/**
* Track the first time the video comes into view.
Expand Down Expand Up @@ -601,7 +617,11 @@ export const SelfHostedVideo = ({
const handlePlaying = () => {
if (hasTrackedPlay) return;

ophanTrackerWeb(atomId, 'loop')('play');
if (renderingTarget === 'Apps') {
ophanTrackerApps(atomId)('play');
} else {
ophanTrackerWeb(atomId, 'loop')('play');
}
setHasTrackedPlay(true);
};

Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading