Skip to content

Commit

Permalink
feat(demo): Make it possible to add custom ad assets with no manifest…
Browse files Browse the repository at this point in the history
… uri.

IMA DAI manifests are requested through the Google Ad Manager.
This change makes it possible to add a custom asset without providing a
manifest if IMA id fields were filled.

Closes shaka-project#3136

Change-Id: I4e0f42648a682583f2d1ca17c5dda108637af550
  • Loading branch information
ismena committed Mar 3, 2021
1 parent f6f2817 commit 40aa213
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
34 changes: 33 additions & 1 deletion demo/custom.js
Expand Up @@ -46,6 +46,9 @@ shakaDemo.Custom = class {
/** @private {!Set.<!ShakaDemoAssetInfo>} */
this.assets_ = this.loadAssetInfos_();

/** @private {!HTMLInputElement} */
this.manifestField_;

/** @private {!Array.<!shakaDemo.AssetCard>} */
this.assetCards_ = [];
this.savedList_ = document.createElement('div');
Expand Down Expand Up @@ -238,6 +241,7 @@ shakaDemo.Custom = class {
return headersDiv;
}


/**
* @param {!ShakaDemoAssetInfo} assetInProgress
* @param {!Array.<!HTMLInputElement>} inputsToCheck
Expand Down Expand Up @@ -270,9 +274,14 @@ shakaDemo.Custom = class {
if (assetInProgress.imaContentSrcId) {
input.value = assetInProgress.imaContentSrcId;
}

this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const contentSrcIdOnChange = (input) => {
assetInProgress.imaContentSrcId = input.value;
this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const contentSrcIdName = shakaDemoMain.getLocalizedString(
shakaDemo.MessageIds.IMA_CONTENT_SRC_ID);
Expand All @@ -284,9 +293,14 @@ shakaDemo.Custom = class {
if (assetInProgress.imaVideoId) {
input.value = assetInProgress.imaVideoId;
}

this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const videoIdOnChange = (input) => {
assetInProgress.imaVideoId = input.value;
this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const videoIdName = shakaDemoMain.getLocalizedString(
shakaDemo.MessageIds.IMA_VIDEO_ID);
Expand All @@ -298,9 +312,14 @@ shakaDemo.Custom = class {
if (assetInProgress.imaAssetKey) {
input.value = assetInProgress.imaAssetKey;
}

this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const assetKeyChange = (input) => {
assetInProgress.imaAssetKey = input.value;
this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const assetKeyName = shakaDemoMain.getLocalizedString(
shakaDemo.MessageIds.IMA_ASSET_KEY);
Expand Down Expand Up @@ -431,8 +450,9 @@ shakaDemo.Custom = class {
container.appendChild(error);

// Add a regex that will detect empty strings.
input.required = true;
input.required = this.checkManifestRequired_(assetInProgress);
input.pattern = '^(?!([\r\n\t\f\v ]+)$).*$';
this.manifestField_ = input;
};
const manifestOnChange = (input) => {
assetInProgress.manifestUri = input.value;
Expand Down Expand Up @@ -511,6 +531,18 @@ shakaDemo.Custom = class {
return mainDiv;
}

/**
* @param {!ShakaDemoAssetInfo} assetInProgress
* @private
*/
checkManifestRequired_(assetInProgress) {
// The manifest field is required unless we're getting the manifest
// from the Google Ad Manager using IMA ids.
const isDaiAdManifest = (assetInProgress.imaContentSrcId &&
assetInProgress.imaVideoId) || assetInProgress.imaAssetKey != null;
return !isDaiAdManifest;
}

/**
* @param {!ShakaDemoAssetInfo} assetInProgress
* @param {!Array.<!HTMLInputElement>} inputsToCheck
Expand Down
2 changes: 1 addition & 1 deletion demo/locales/en.json
Expand Up @@ -115,7 +115,7 @@
"DEMO_MANIFEST_SEARCH": "Manifest",
"DEMO_MANIFEST_SECTION_HEADER": "Manifest",
"DEMO_MANIFEST_URL": "Manifest URL",
"DEMO_MANIFEST_URL_ERROR": "Must have a manifest URL.",
"DEMO_MANIFEST_URL_ERROR": "Must have a manifest URL, or IMA DAI id fields",
"DEMO_MAX_ATTEMPTS": "Max Attempts",
"DEMO_MAX_BANDWIDTH": "Max Bandwidth",
"DEMO_MAX_FRAMERATE": "Max Framerate",
Expand Down
4 changes: 2 additions & 2 deletions demo/locales/source.json
Expand Up @@ -464,8 +464,8 @@
"message": "Manifest URL"
},
"DEMO_MANIFEST_URL_ERROR": {
"description": "An error that is displayed if the user does not provide a manifest URL for a custom asset.",
"message": "Must have a manifest URL."
"description": "An error that is displayed if the user does not provide a manifest URL for a custom asset or identification fields in the Google Ad Manager system.",
"message": "Must have a manifest URL, or IMA DAI id fields."
},
"DEMO_MAX_ATTEMPTS": {
"description": "The name of a configuration value.",
Expand Down

0 comments on commit 40aa213

Please sign in to comment.