From d10c709fabc199e3467a6ce2c2df0ef817582bbd Mon Sep 17 00:00:00 2001 From: Anton Lantukh Date: Mon, 25 Nov 2024 19:49:57 +0100 Subject: [PATCH] feat(project): add user_id support for DRM, Live and SSAI --- packages/common/src/constants.ts | 5 +++++ packages/common/src/utils/sources.ts | 31 +++++++++++----------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index 5f2b2617b..be062c573 100644 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -102,3 +102,8 @@ export const APP_CONFIG_ITEM_TYPE = { content_list: 'content_list', media: 'media', } as const; + +export const MANIFEST_TYPE = { + dash: 'application/dash+xml"', + hls: 'application/vnd.apple.mpegurl', +}; diff --git a/packages/common/src/utils/sources.ts b/packages/common/src/utils/sources.ts index 0b666b47d..3b1a7d3c8 100644 --- a/packages/common/src/utils/sources.ts +++ b/packages/common/src/utils/sources.ts @@ -1,14 +1,7 @@ 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}`); -}; +import { MANIFEST_TYPE } from '@jwp/ott-common/src/constants'; export const getSources = ({ item, @@ -29,22 +22,21 @@ export const getSources = ({ const userId = user?.id; const hasServerAds = !!adConfig && adDeliveryMethod === 'ssai'; + console.info(item, 'item'); + return sources.map((source: Source) => { const url = new URL(source.file); - const sourceUrl = url.href; + const isDRM = (url.searchParams.has('exp') && url.searchParams.has('sig')) || source.drm; - 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`; + // Use SSAI URL for configs with server side ads, DRM is not supported yet + if (hasServerAds && !isDRM) { + url.href = `${baseUrl}/v2/sites/${siteId}/media/${mediaid}/ssai.${MANIFEST_TYPE.dash === source.type ? 'mpd' : '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) { + } + + // Attach user_id for VOD and BCL SaaS Live Streams + if (userId) { url.searchParams.set('user_id', userId); } @@ -55,6 +47,7 @@ export const getSources = ({ } source.file = url.toString(); + return source; }); };