Skip to content

Commit

Permalink
feat(Demo): Allow storage of MSS-PlayReady in demo (#7801)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 24, 2024
1 parent bc41643 commit 8764169
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
38 changes: 35 additions & 3 deletions demo/common/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const ShakaDemoAssetInfo = class {
/** @type {!Map.<string, string>} */
this.licenseServers = new Map();
/** @type {!Map.<string, string>} */
this.offlineLicenseServers = new Map();
/** @type {!Map.<string, string>} */
this.licenseRequestHeaders = new Map();
/** @type {?shaka.extern.RequestFilter} */
this.requestFilter = null;
Expand Down Expand Up @@ -239,6 +241,16 @@ const ShakaDemoAssetInfo = class {
return this;
}

/**
* @param {string} keySystem
* @param {string} licenseServer
* @return {!ShakaDemoAssetInfo}
*/
addOfflineLicenseServer(keySystem, licenseServer) {
this.offlineLicenseServers.set(keySystem, licenseServer);
return this;
}

/**
* @param {string} uri
* @return {!ShakaDemoAssetInfo}
Expand Down Expand Up @@ -476,9 +488,11 @@ const ShakaDemoAssetInfo = class {

/**
* Gets the configuration object for the asset.
*
* @param {boolean=} forStorage
* @return {!shaka.extern.PlayerConfiguration}
*/
getConfiguration() {
getConfiguration(forStorage = false) {
const config = /** @type {shaka.extern.PlayerConfiguration} */(
{drm: {advanced: {}}, manifest: {dash: {}, hls: {}}});

Expand All @@ -488,9 +502,15 @@ const ShakaDemoAssetInfo = class {
}
}

if (this.licenseServers.size) {
let licenseServers = this.licenseServers;
// PR license servers may require a different URL for offline.
if (forStorage && this.offlineLicenseServers.size) {
licenseServers = this.offlineLicenseServers;
}

if (licenseServers.size) {
config.drm.servers = config.drm.servers || {};
this.licenseServers.forEach((value, key) => {
licenseServers.forEach((value, key) => {
config.drm.servers[key] = value;
});
}
Expand All @@ -501,6 +521,18 @@ const ShakaDemoAssetInfo = class {
config.drm.clearKeys[key] = value;
});
}

// Windows Edge only support persistent licenses with
// `com.microsoft.playready.recommendation` keySystem.
if (forStorage &&
navigator.userAgent.match(/Edge?\//) &&
navigator.platform &&
navigator.platform.toLowerCase().includes('win32')) {
config.drm.keySystemsMapping = {
'com.microsoft.playready': 'com.microsoft.playready.recommendation',
};
}

return config;
}

Expand Down
2 changes: 2 additions & 0 deletions demo/common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,9 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.MSS)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.addLicenseServer('com.microsoft.playready', 'https://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)')
.addOfflineLicenseServer('com.microsoft.playready', 'https://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:true,sl:150)')
.setMimeType('application/vnd.ms-sstr+xml'),
// }}}

Expand Down
3 changes: 2 additions & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,11 @@ shakaDemo.Main = class {
goog.asserts.assert(netEngine, 'There should be a net engine.');
asset.applyFilters(netEngine);

const assetConfig = asset.getConfiguration();
if (storage) {
const assetConfig = asset.getConfiguration(/* forStorage= */ true);
storage.configure(assetConfig);
} else {
const assetConfig = asset.getConfiguration();
// Remove all not-player-applied configurations, by resetting the
// configuration then re-applying the desired configuration.
this.player_.resetConfiguration();
Expand Down

0 comments on commit 8764169

Please sign in to comment.