From 044c40f33874f8c35b7394c7c71c3d715bab78f1 Mon Sep 17 00:00:00 2001 From: Anton Lantukh Date: Mon, 2 Oct 2023 11:32:36 +0200 Subject: [PATCH] feat(project): ads integration --- src/components/Player/Player.tsx | 12 ++++- src/hooks/useMediaAds.ts | 3 ++ src/services/api.service.ts | 92 ++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 6 deletions(-) diff --git a/src/components/Player/Player.tsx b/src/components/Player/Player.tsx index 0b85c7f29..905f21224 100644 --- a/src/components/Player/Player.tsx +++ b/src/components/Player/Player.tsx @@ -162,9 +162,19 @@ const Player: React.FC = ({ playerRef.current = window.jwplayer(playerElementRef.current) as JWPlayer; + const data = { + ...adScheduleData, + schedule: adScheduleData.schedule.map((el) => ({ ...el, offset: el.offset / 1000 })), + client: 'googima', + vpaidmode: 'insecure', + rules: { startOnSeek: 'pre', timeBetweenAds: 0 }, + }; + + console.log(data, 'data'); + // Player options are untyped const playerOptions: { [key: string]: unknown } = { - advertising: adScheduleData, + advertising: data, aspectratio: false, controls: true, displaytitle: false, diff --git a/src/hooks/useMediaAds.ts b/src/hooks/useMediaAds.ts index d9a078349..115719e6e 100644 --- a/src/hooks/useMediaAds.ts +++ b/src/hooks/useMediaAds.ts @@ -18,6 +18,9 @@ export const useMediaAds = (adScheduleId: string | null | undefined, mediaId: st { enabled: Boolean(mediaId) }, ); + console.log(perMediaAds, 'perMediaAds'); + console.log(adSchedule, 'adSchedule'); + return { isLoading: isAdScheduleLoading || isPerMediaAdSchedule, data: perMediaAds || adSchedule, diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 6705ff0d6..c5252ebf0 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -251,10 +251,10 @@ export const getAdSchedule = async (id: string | undefined | null): Promise => { const { preRollUrl, midRollUrl, postRollUrl } = urls; - const pathname = `/v2/advertising/media/${id}/schedule.json`; - const url = addQueryParams(`${import.meta.env.APP_API_BASE_URL}${pathname}`, { + const pathname = `/v1/advertising/media/${id}/schedule.json`; + const url = addQueryParams(`https://timing-delivery.jwplayer.com${pathname}`, { preroll_url: preRollUrl, - midroll_url: midRollUrl, + midroll_url: midRollUrl || 'https://playertest.longtailvideo.com/vast-30s-ad.xml', postroll_url: postRollUrl, fallback_ad_schedule: fallbackAdSchedule, }); @@ -266,7 +266,89 @@ export const getMediaAdSchedule = async (id: string, urls: AdTagUrls, fallbackAd return; } - const data = (await getDataOrThrow(response)) as { timings: AdSchedule }; + const data = (await getDataOrThrow(response)) as AdSchedule; + + return data; +}; - return data.timings; +const advertising = { + rules: { + startOnSeek: 'pre', + timeBetweenAds: 0, + }, + client: 'googima', + schedule: [ + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 9, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 21, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 41, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 65, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 88, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 103, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 127, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 154, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 181, + }, + { + tag: [ + 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=', + ], + type: 'linear', + offset: 212, + }, + ], + adscheduleid: 'p7C1mlvt', + vpaidmode: 'insecure', };