-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): add ssai ads for vod (#583)
* feat(project): add ssai ads for vod, refactor sources function
- Loading branch information
1 parent
6e4d263
commit d3a4750
Showing
8 changed files
with
85 additions
and
51 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { PlaylistItem, Source } from '@jwp/ott-common/types/playlist'; | ||
import type { Config } from '@jwp/ott-common/types/config'; | ||
import type { Customer } from '@jwp/ott-common/types/account'; | ||
|
||
const isVODManifestType = (sourceUrl: string, baseUrl: string, mediaId: string, extensions: ('m3u8' | 'mpd')[]) => { | ||
return extensions.some((ext) => sourceUrl === `${baseUrl}/manifests/${mediaId}.${ext}`); | ||
}; | ||
|
||
const isBCLManifestType = (sourceUrl: string, baseUrl: string, mediaId: string, extensions: ('m3u8' | 'mpd')[]) => { | ||
return extensions.some((ext) => sourceUrl === `${baseUrl}/live/broadcast/${mediaId}.${ext}`); | ||
}; | ||
|
||
export const getSources = ({ item, baseUrl, config, user }: { item: PlaylistItem; baseUrl: string; config: Config; user: Customer | null }) => { | ||
const { sources, mediaid } = item; | ||
const { adConfig, siteId, adDeliveryMethod } = config; | ||
|
||
const userId = user?.id; | ||
const hasServerAds = !!adConfig && adDeliveryMethod === 'ssai'; | ||
|
||
return sources.map((source: Source) => { | ||
const url = new URL(source.file); | ||
|
||
const sourceUrl = url.href; | ||
|
||
const isBCLManifest = isBCLManifestType(sourceUrl, baseUrl, mediaid, ['m3u8', 'mpd']); | ||
const isVODManifest = isVODManifestType(sourceUrl, baseUrl, mediaid, ['m3u8', 'mpd']); | ||
const isDRM = url.searchParams.has('exp') && url.searchParams.has('sig'); | ||
|
||
// Use SSAI URL for configs with server side ads, DRM is not supported | ||
if (isVODManifest && hasServerAds && !isDRM) { | ||
// Only HLS is supported now | ||
url.href = `${baseUrl}/v2/sites/${siteId}/media/${mediaid}/ssai.m3u8`; | ||
url.searchParams.set('ad_config_id', adConfig); | ||
// Attach user_id only for VOD and BCL SaaS Live Streams (doesn't work with SSAI items) | ||
} else if ((isVODManifest || isBCLManifest) && userId) { | ||
url.searchParams.set('user_id', userId); | ||
} | ||
|
||
source.file = url.toString(); | ||
|
||
return source; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMemo } from 'react'; | ||
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore'; | ||
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore'; | ||
import type { PlaylistItem, Source } from '@jwp/ott-common/types/playlist'; | ||
import { getSources } from '@jwp/ott-common/src/utils/sources'; | ||
|
||
/** Modify manifest URLs to handle server ads and analytics params */ | ||
export const useMediaSources = ({ item, baseUrl }: { item: PlaylistItem; baseUrl: string }): Source[] => { | ||
const config = useConfigStore((s) => s.config); | ||
const user = useAccountStore((s) => s.user); | ||
|
||
return useMemo(() => getSources({ item, baseUrl, config, user }), [item, baseUrl, config, user]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters