Skip to content

Commit

Permalink
feat(project): ads integration
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLantukh committed Oct 2, 2023
1 parent f27283e commit 044c40f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,19 @@ const Player: React.FC<Props> = ({

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,
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useMediaAds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
92 changes: 87 additions & 5 deletions src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ export const getAdSchedule = async (id: string | undefined | null): Promise<AdSc

export const getMediaAdSchedule = async (id: string, urls: AdTagUrls, fallbackAdSchedule: string | undefined | null): Promise<AdSchedule | undefined> => {
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,
});
Expand All @@ -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',
};

0 comments on commit 044c40f

Please sign in to comment.