Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(project): OWA-56 add DRM check for CDN analytics #469

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions packages/common/src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import type { PlaylistItem, Source } from '../../types/playlist';

export const attachAnalyticsParams = (item: PlaylistItem) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to your change, but this function mutates the given item, should we create a new object instead?

export const attachAnalyticsParams = (item: PlaylistItem) => {
  const updatedSources = item.sources.map(source => {
    // logic
    return { ...source, file: url.toString() };
  });

  return { ...item, sources: updatedSources };
};

// @todo pass these as params instead of reading the stores
const { config } = useConfigStore.getState();
const { config, settings } = useConfigStore.getState();
const { user } = useAccountStore.getState();
const { profile } = useProfileStore.getState();

const vendorId = settings.vendorId;

const { sources, mediaid } = item;

const userId = user?.id;
Expand All @@ -17,22 +19,31 @@ export const attachAnalyticsParams = (item: PlaylistItem) => {

sources.map((source: Source) => {
const url = new URL(source.file);
const urlSearchParams = url.searchParams;

const mediaId = mediaid.toLowerCase();
const sourceUrl = url.href.toLowerCase();

// Attach user_id and profile_id only for VOD and BCL SaaS Live Streams
const isVOD = sourceUrl === `https://cdn.jwplayer.com/manifests/${mediaId}.m3u8`;
const isBCL = sourceUrl === `https://content.jwplatform.com/live/broadcast/${mediaId}.m3u8`;
const cdnUrlVOD = `https://cdn.jwplayer.com/manifests/${mediaId}.m3u8`;
const cdnUrlBCL = `https://content.jwplatform.com/live/broadcast/${mediaId}.m3u8`;
Comment on lines +27 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should remove the extension check? The sources could also contain MPEG-DASH or MP4 files that won't have the analytic parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Christiaan, that is a good catch. I was referring to Marco's previous notes while working on this task.
Even though it is still blocked by Media Core team I would suggest discussing this in our monthly sync.
CC: @dbudzins @AntonLantukh


// Attach user_id, profile_id and vendor_id only for VOD, BCL SaaS Live Streams and DRM
const isVOD = sourceUrl === cdnUrlVOD;
const isBCL = sourceUrl === cdnUrlBCL;
const isDRM = sourceUrl.startsWith(cdnUrlVOD) && urlSearchParams.has('exp') && urlSearchParams.has('sig');

if ((isVOD || isBCL) && userId) {
url.searchParams.set('user_id', userId);
if ((isVOD || isBCL || isDRM) && userId) {
urlSearchParams.set('user_id', userId);

if (isJwIntegration && profileId) {
url.searchParams.set('profile_id', profileId);
urlSearchParams.set('profile_id', profileId);
}
}

if (vendorId) {
urlSearchParams.set('vendor_id', vendorId);
}

source.file = url.toString();
});
};
1 change: 1 addition & 0 deletions packages/common/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type Settings = {
playerLicenseKey?: string;
additionalAllowedConfigSources?: string[];
UNSAFE_allowAnyConfigSource?: boolean;
vendorId?: string;
};
Loading