mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-15 16:06:41 +03:00
1c47e1e09b
Closes #137 Change-Id: I092a6152d8c9c2f3809f3ef27e237c06ff0a6490
58 lines
1.9 KiB
Plaintext
58 lines
1.9 KiB
Plaintext
/**
|
|
* @param {string} schemeIdUri The ContentProtection's scheme ID URI.
|
|
* @param {!Element} contentProtection The ContentProtection element.
|
|
* @return {Array.<shaka.player.DrmInfo.Config>} An array of Config
|
|
* objects or null if the element is not understood by this application.
|
|
*/
|
|
function interpretContentProtection(schemeIdUri, contentProtection) {
|
|
if (schemeIdUri != App.APP_SPECIFIC_SCHEME_ID_URI) {
|
|
console.warn('Unrecognized scheme: ' + schemeIdUri);
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param {!shaka.player.DrmInfo.LicenseRequestInfo} requestInfo
|
|
*/
|
|
var preProcessor = function(requestInfo) {
|
|
// Encode the license request message as base64.
|
|
var message = window.btoa(
|
|
String.fromCharCode.apply(null, new Uint8Array(requestInfo.body)));
|
|
|
|
// Encode the payload as JSON.
|
|
var obj = {
|
|
'app_data': App.clientData, // Provide some arbitrary data.
|
|
'message', message
|
|
};
|
|
requestInfo.body = JSON.stringify(obj);
|
|
requestInfo.headers['Content-Type'] = 'application/json';
|
|
};
|
|
|
|
/**
|
|
* @param {!Uint8Array} serverResponse
|
|
* @return {!Uint8Array}
|
|
*/
|
|
var postProcessor = function(serverResponse) {
|
|
// serverResponse is a Uint8Array, so decode it into an object.
|
|
var json = String.fromCharCode.apply(null, serverResponse);
|
|
var obj = JSON.parse(json);
|
|
|
|
// Update our arbitrary data.
|
|
App.clientData = obj['app_data'];
|
|
|
|
// obj['license'] is base64, so decode it into a string and then encode it
|
|
// into a Uint8Array.
|
|
var licenseString = window.atob(obj['license']);
|
|
var license = new Uint8Array(licenseString.split('').map(
|
|
function(ch) { return ch.charCodeAt(0); }));
|
|
return license;
|
|
};
|
|
|
|
return [{
|
|
'keySystem': 'com.widevine.alpha',
|
|
'licenseServerUrl': App.APP_SPECIFIC_LICENSE_SERVER_URL,
|
|
'licensePreProcessor': preProcessor,
|
|
'licensePostProcessor': postProcessor
|
|
}];
|
|
}
|
|
|