Skip to content

Commit

Permalink
Merge pull request #3 from cbsinteractive/feature/cmcd-config-object
Browse files Browse the repository at this point in the history
feature/cmcd-config-object
  • Loading branch information
littlespex authored Nov 8, 2021
2 parents 640fe43 + 933cf1c commit 2f9b6b6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 54 deletions.
24 changes: 12 additions & 12 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ export class ChunkMetadata {
//
// @public (undocumented)
export type CMCDControllerConfig = {
cmcdEnabled: boolean;
cmcdSessionId?: string;
cmcdContentId?: string;
cmcdUseHeaders?: boolean;
sessionId?: string;
contentId?: string;
useHeaders?: boolean;
};

// Warning: (ae-missing-release-tag) "CuesInterface" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -972,14 +971,15 @@ export type HlsConfig = {
subtitleTrackController?: typeof SubtitleTrackController;
timelineController?: typeof TimelineController;
emeController?: typeof EMEController;
cmcd?: CMCDControllerConfig;
cmcdController?: typeof CMCDController;
abrController: typeof AbrController;
bufferController: typeof BufferController;
capLevelController: typeof CapLevelController;
fpsController: typeof FPSController;
progressive: boolean;
lowLatencyMode: boolean;
} & ABRControllerConfig & BufferControllerConfig & CapLevelControllerConfig & CMCDControllerConfig & EMEControllerConfig & FPSControllerConfig & FragmentLoaderConfig & LevelControllerConfig & MP4RemuxerConfig & PlaylistLoaderConfig & StreamControllerConfig & LatencyControllerConfig & TimelineControllerConfig & TSDemuxerConfig;
} & ABRControllerConfig & BufferControllerConfig & CapLevelControllerConfig & EMEControllerConfig & FPSControllerConfig & FragmentLoaderConfig & LevelControllerConfig & MP4RemuxerConfig & PlaylistLoaderConfig & StreamControllerConfig & LatencyControllerConfig & TimelineControllerConfig & TSDemuxerConfig;

// Warning: (ae-missing-release-tag) "HlsEventEmitter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down Expand Up @@ -2150,13 +2150,13 @@ export interface UserdataSample {

// Warnings were encountered during analysis:
//
// src/config.ts:164:3 - (ae-forgotten-export) The symbol "ILogger" needs to be exported by the entry point hls.d.ts
// src/config.ts:173:3 - (ae-forgotten-export) The symbol "AudioStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:174:3 - (ae-forgotten-export) The symbol "AudioTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:176:3 - (ae-forgotten-export) The symbol "SubtitleStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:177:3 - (ae-forgotten-export) The symbol "SubtitleTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:178:3 - (ae-forgotten-export) The symbol "TimelineController" needs to be exported by the entry point hls.d.ts
// src/config.ts:180:3 - (ae-forgotten-export) The symbol "EMEController" needs to be exported by the entry point hls.d.ts
// src/config.ts:163:3 - (ae-forgotten-export) The symbol "ILogger" needs to be exported by the entry point hls.d.ts
// src/config.ts:172:3 - (ae-forgotten-export) The symbol "AudioStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:173:3 - (ae-forgotten-export) The symbol "AudioTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:175:3 - (ae-forgotten-export) The symbol "SubtitleStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:176:3 - (ae-forgotten-export) The symbol "SubtitleTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:177:3 - (ae-forgotten-export) The symbol "TimelineController" needs to be exported by the entry point hls.d.ts
// src/config.ts:179:3 - (ae-forgotten-export) The symbol "EMEController" needs to be exported by the entry point hls.d.ts
// src/config.ts:182:3 - (ae-forgotten-export) The symbol "CMCDController" needs to be exported by the entry point hls.d.ts
// src/config.ts:184:3 - (ae-forgotten-export) The symbol "AbrController" needs to be exported by the entry point hls.d.ts
// src/config.ts:185:3 - (ae-forgotten-export) The symbol "BufferController" needs to be exported by the entry point hls.d.ts
Expand Down
30 changes: 8 additions & 22 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@
- [`licenseResponseCallback`](#licenseResponseCallback)
- [`drmSystemOptions`](#drmSystemOptions)
- [`requestMediaKeySystemAccessFunc`](#requestMediaKeySystemAccessFunc)
- [`cmcdEnabled`](#cmcdEnabled)
- [`cmcdSessionId`](#cmcdSessionId)
- [`cmcdContentId`](#cmcdContentId)
- [`cmcdUseHeaders`](#cmcdUseHeaders)
- [`cmcd`](#cmcd)
- [Video Binding/Unbinding API](#video-bindingunbinding-api)
- [`hls.attachMedia(videoElement)`](#hlsattachmediavideoelement)
- [`hls.detachMedia()`](#hlsdetachmedia)
Expand Down Expand Up @@ -395,10 +392,7 @@ var config = {
licenseXhrSetup: undefined,
drmSystemOptions: {},
requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess,
cmcdEnabled: false,
cmcdSessionId: undefined,
cmcdContentId: undefined,
cmcdUseHeaders: false,
cmcd: undefined,
};

var hls = new Hls(config);
Expand Down Expand Up @@ -1200,22 +1194,14 @@ With the default argument, `''` will be specified for each option (_i.e. no spec

Allows for the customization of `window.navigator.requestMediaKeySystemAccess`.

### `cmcdEnabled`
### `cmcd`

Enabled the passing of [Common Media Client Data (CMCD)](https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf)
on all media requests (manifests, playlists, a/v segments, timed text).
When the `cmcd` object is defined, [Common Media Client Data (CMCD)](https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf)
data will be passed on all media requests (manifests, playlists, a/v segments, timed text). It's configuration values are:

### `cmcdSession`

The CMCD session id. One will be automatically generated if none is provided.

### `cmcdContent`

The CMCD content id.

### `cmcdUseHeaders`

Send CMCD data in request headers instead of as query args.
- `sessionId`: The CMCD session id. One will be automatically generated if none is provided.
- `contentId`: The CMCD content id.
- `useHeaders`: Send CMCD data in request headers instead of as query args. Defaults to `false`.

## Video Binding/Unbinding API

Expand Down
14 changes: 5 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ export type CapLevelControllerConfig = {
};

export type CMCDControllerConfig = {
cmcdEnabled: boolean;
cmcdSessionId?: string;
cmcdContentId?: string;
cmcdUseHeaders?: boolean;
sessionId?: string;
contentId?: string;
useHeaders?: boolean;
};

export type DRMSystemOptions = {
Expand Down Expand Up @@ -179,6 +178,7 @@ export type HlsConfig = {
// EME
emeController?: typeof EMEController;
// CMCD
cmcd?: CMCDControllerConfig;
cmcdController?: typeof CMCDController;

abrController: typeof AbrController;
Expand All @@ -190,7 +190,6 @@ export type HlsConfig = {
} & ABRControllerConfig &
BufferControllerConfig &
CapLevelControllerConfig &
CMCDControllerConfig &
EMEControllerConfig &
FPSControllerConfig &
FragmentLoaderConfig &
Expand Down Expand Up @@ -280,10 +279,7 @@ export const hlsDefaultConfig: HlsConfig = {
testBandwidth: true,
progressive: false,
lowLatencyMode: true,
cmcdEnabled: false,
cmcdSessionId: undefined,
cmcdContentId: undefined,
cmcdUseHeaders: false,
cmcd: undefined,

// Dynamic Modules
...timelineConfig(),
Expand Down
13 changes: 9 additions & 4 deletions src/controller/cmcd-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default class CMCDController implements ComponentAPI {
private config: HlsConfig;
private media?: HTMLMediaElement;
private sid?: string;
private cid?: string;
private useHeaders: boolean = false;
private initialized: boolean = false;
private starved: boolean = false;
private buffering: boolean = true;
Expand All @@ -43,12 +45,15 @@ export default class CMCDController implements ComponentAPI {
constructor(hls: Hls) {
this.hls = hls;
const config = (this.config = hls.config);
const { cmcd } = config;

if (config.cmcdEnabled === true) {
if (cmcd != null) {
config.pLoader = this.createPlaylistLoader();
config.fLoader = this.createFragmentLoader();

this.sid = config.cmcdSessionId || CMCDController.uuid();
this.sid = cmcd.sessionId || CMCDController.uuid();
this.cid = cmcd.contentId;
this.useHeaders = cmcd.useHeaders === true;
this.registerListeners();
}
}
Expand Down Expand Up @@ -129,7 +134,7 @@ export default class CMCDController implements ComponentAPI {
v: CMCDVersion,
sf: CMCDStreamingFormat.HLS,
sid: this.sid,
cid: this.config.cmcdContentId,
cid: this.cid,
pr: this.media?.playbackRate,
mtp: this.hls.bandwidthEstimate / 1000,
};
Expand Down Expand Up @@ -159,7 +164,7 @@ export default class CMCDController implements ComponentAPI {

// TODO: Implement rtp, nrr, nor, dl

if (this.config.cmcdUseHeaders) {
if (this.useHeaders) {
const headers = CMCDController.toHeaders(data);
if (!Object.keys(headers).length) {
return;
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/controller/cmcd-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const data = {
'com.test-token': Symbol('s'),
};

const setupEach = function (config?: CMCDControllerConfig) {
cmcdController = new CMCDController(new HlsMock(config));
const setupEach = function (cmcd?: CMCDControllerConfig) {
cmcdController = new CMCDController(new HlsMock({ cmcd }));
};

describe('CMCDController', function () {
Expand Down Expand Up @@ -95,14 +95,13 @@ describe('CMCDController', function () {
it('does not modify requests when disabled', function () {
setupEach();

expect(cmcdController.hls.config.pLoader).to.equal(undefined);
expect(cmcdController.hls.config.fLoader).to.equal(undefined);
const { config } = cmcdController.hls;
expect(config.pLoader).to.equal(undefined);
expect(config.fLoader).to.equal(undefined);
});

it('generates a session id if not provided', function () {
setupEach({
cmcdEnabled: true,
});
setupEach({});

const c = Object.assign({ frag: {} }, context);

Expand Down

0 comments on commit 2f9b6b6

Please sign in to comment.