mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-28 07:51:31 +00:00
fetch ads provider for all homepage videos (but still only show ads for unauth users)
This commit is contained in:
parent
807e520b0e
commit
f2d83cbf9d
2 changed files with 7 additions and 5 deletions
|
@ -122,7 +122,7 @@ function VideoViewer(props: Props) {
|
||||||
const embedded = useContext(EmbedContext);
|
const embedded = useContext(EmbedContext);
|
||||||
const approvedVideo = Boolean(channelClaimId) && adApprovedChannelIds.includes(channelClaimId);
|
const approvedVideo = Boolean(channelClaimId) && adApprovedChannelIds.includes(channelClaimId);
|
||||||
const adsEnabled = ENABLE_PREROLL_ADS && !authenticated && !embedded && approvedVideo;
|
const adsEnabled = ENABLE_PREROLL_ADS && !authenticated && !embedded && approvedVideo;
|
||||||
const [adUrl, setAdUrl, isFetchingAd] = useGetAds(adsEnabled);
|
const [adUrl, setAdUrl, isFetchingAd] = useGetAds(approvedVideo, adsEnabled);
|
||||||
/* isLoading was designed to show loading screen on first play press, rather than completely black screen, but
|
/* isLoading was designed to show loading screen on first play press, rather than completely black screen, but
|
||||||
breaks because some browsers (e.g. Firefox) block autoplay but leave the player.play Promise pending */
|
breaks because some browsers (e.g. Firefox) block autoplay but leave the player.play Promise pending */
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
|
@ -9,12 +9,14 @@ const PRE_ROLL_ADS_PROVIDER = 'https://tag.targeting.unrulymedia.com/rmp/216276/
|
||||||
const ADS_CAP_LEVEL = 1 * 60 * 1000;
|
const ADS_CAP_LEVEL = 1 * 60 * 1000;
|
||||||
const vastClient = new VASTClient(0, ADS_CAP_LEVEL);
|
const vastClient = new VASTClient(0, ADS_CAP_LEVEL);
|
||||||
|
|
||||||
export function useGetAds(adsEnabled: boolean): [?string, (?string) => void, boolean] {
|
export function useGetAds(approvedVideo: boolean, adsEnabled: boolean): [?string, (?string) => void, boolean] {
|
||||||
const [isFetching, setIsFetching] = React.useState(true);
|
const [isFetching, setIsFetching] = React.useState(true);
|
||||||
const [adUrl, setAdUrl] = React.useState();
|
const [adUrl, setAdUrl] = React.useState();
|
||||||
|
|
||||||
|
// Fetch ads for all approved videos, even if we won't show ads to the user
|
||||||
|
// Unruly needs more fetches before they will start returning ads ¯\_(ツ)_/¯
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!adsEnabled) {
|
if (!approvedVideo) {
|
||||||
setIsFetching(false);
|
setIsFetching(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +39,7 @@ export function useGetAds(adsEnabled: boolean): [?string, (?string) => void, boo
|
||||||
// Dummy video file
|
// Dummy video file
|
||||||
// const adUrl = 'https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4';
|
// const adUrl = 'https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4';
|
||||||
|
|
||||||
if (adUrl) {
|
if (adsEnabled && adUrl) {
|
||||||
setAdUrl(adUrl);
|
setAdUrl(adUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +49,7 @@ export function useGetAds(adsEnabled: boolean): [?string, (?string) => void, boo
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setIsFetching(false);
|
setIsFetching(false);
|
||||||
});
|
});
|
||||||
}, [adsEnabled]);
|
}, [approvedVideo, adsEnabled]);
|
||||||
|
|
||||||
return [adUrl, setAdUrl, isFetching];
|
return [adUrl, setAdUrl, isFetching];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue