eme-encryption-scheme-polyfill
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -0,1 +1,8 @@ | ||
## 2.0.3 (2021-04-19) | ||
Bugfixes: | ||
- Fix MCap polyfill for browsers that support MCap but not the | ||
encryption-related parts of the MCap API. | ||
## 2.0.2 (2021-02-05) | ||
@@ -2,0 +9,0 @@ |
@@ -8,2 +8,2 @@ /*! | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).EncryptionSchemePolyfills=e()}}(function(){var e={exports:{}};function i(e,i,t){return t?i?i(e):e:(e&&e.then||(e=Promise.resolve(e)),i?e.then(i):e)}var t=function(){function e(){}return e.install=function(){e.originalRMKSA_||navigator.requestMediaKeySystemAccess&&MediaKeySystemAccess.prototype.getConfiguration&&(e.originalRMKSA_=navigator.requestMediaKeySystemAccess,navigator.requestMediaKeySystemAccess=e.probeRMKSA_)},e.probeRMKSA_=function(t,n){try{var o=this;return i(e.originalRMKSA_.call(o,t,n),function(i){return a(i)?(navigator.requestMediaKeySystemAccess=e.originalRMKSA_,i):(navigator.requestMediaKeySystemAccess=e.polyfillRMKSA_,e.polyfillRMKSA_.call(o,t,n))})}catch(r){return Promise.reject(r)}},e.polyfillRMKSA_=function(t,n){try{var a=r(t),s=[],c=n,l=Array.isArray(c),f=0;for(c=l?c:c[Symbol.iterator]();;){var u;if(l){if(f>=c.length)break;u=c[f++]}else{if((f=c.next()).done)break;u=f.value}var y=u,d=e.filterCapabilities_(y.videoCapabilities,a),p=e.filterCapabilities_(y.audioCapabilities,a);if(y.videoCapabilities&&y.videoCapabilities.length&&!d.length);else if(y.audioCapabilities&&y.audioCapabilities.length&&!p.length);else{var g=Object.assign({},y);g.videoCapabilities=d,g.audioCapabilities=p,s.push(g)}}if(!s.length){var m=new Error("Unsupported keySystem or supportedConfigurations.");throw m.name="NotSupportedError",m.code=DOMException.NOT_SUPPORTED_ERR,m}return i(e.originalRMKSA_.call(this,t,s),function(e){return new o(e,a)})}catch(h){return Promise.reject(h)}},e.filterCapabilities_=function(e,i){return e?e.filter(function(e){return!e.encryptionScheme||e.encryptionScheme==i}):e},e}(),n=function(){function e(){}return e.install=function(){e.originalDecodingInfo_||navigator.mediaCapabilities&&(e.originalDecodingInfo_=navigator.mediaCapabilities.decodingInfo,navigator.mediaCapabilities.decodingInfo=e.probeDecodingInfo_)},e.probeDecodingInfo_=function(t){try{var n=this;return i(e.originalDecodingInfo_.call(n,t),function(i){return t.keySystemConfiguration&&i.keySystemAccess?a(i.keySystemAccess)?(navigator.mediaCapabilities.decodingInfo=e.originalDecodingInfo_,i):(navigator.mediaCapabilities.decodingInfo=e.polyfillDecodingInfo_,e.polyfillDecodingInfo_.call(n,t)):i})}catch(o){return Promise.reject(o)}},e.polyfillDecodingInfo_=function(t){try{var n=null;if(t.keySystemConfiguration){var a=t.keySystemConfiguration,s=a.keySystem,c=a.audio&&a.audio.encryptionScheme,l=a.video&&a.video.encryptionScheme;n=r(s);var f={powerEfficient:!1,smooth:!1,supported:!1,keySystemAccess:null,configuration:t};if(c&&c!=n)return f;if(l&&l!=n)return f}return i(e.originalDecodingInfo_.call(this,t),function(e){return e.keySystemAccess&&(e.keySystemAccess=new o(e.keySystemAccess,n)),e})}catch(u){return Promise.reject(u)}},e}(),o=function(){function e(e,i){this.mksa_=e,this.scheme_=i,this.keySystem=e.keySystem}var i=e.prototype;return i.getConfiguration=function(){var e=this.mksa_.getConfiguration();if(e.videoCapabilities){var i=e.videoCapabilities,t=Array.isArray(i),n=0;for(i=t?i:i[Symbol.iterator]();;){var o;if(t){if(n>=i.length)break;o=i[n++]}else{if((n=i.next()).done)break;o=n.value}o.encryptionScheme=this.scheme_}}if(e.audioCapabilities){var r=e.audioCapabilities,a=Array.isArray(r),s=0;for(r=a?r:r[Symbol.iterator]();;){var c;if(a){if(s>=r.length)break;c=r[s++]}else{if((s=r.next()).done)break;c=s.value}c.encryptionScheme=this.scheme_}}return e},i.createMediaKeys=function(){return this.mksa_.createMediaKeys()},e}();function r(e){return e.startsWith("com.widevine")?"cenc":e.startsWith("com.microsoft")?"cenc":e.startsWith("com.adobe")?"cenc":e.startsWith("org.w3")?"cenc":e.startsWith("com.apple")?"cbcs-1-9":(console.warn("EmeEncryptionSchemePolyfill: Unknown key system:",e,"Please contribute!"),null)}function a(e){var i=e.getConfiguration(),t=i.videoCapabilities&&i.videoCapabilities[0],n=i.audioCapabilities&&i.audioCapabilities[0],o=t||n;return!(!o||void 0===o.encryptionScheme)}t.originalRMKSA_,n.originalDecodingInfo_;var s=function(){function e(){}return e.install=function(){t.install(),n.install()},e}();return e.exports&&(e.exports=s),e=e.exports}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).EncryptionSchemePolyfills=e()}}(function(){var e={exports:{}};function i(e,i,t){return t?i?i(e):e:(e&&e.then||(e=Promise.resolve(e)),i?e.then(i):e)}var t=function(){function e(){}return e.install=function(){e.originalRMKSA_||navigator.requestMediaKeySystemAccess&&MediaKeySystemAccess.prototype.getConfiguration&&(e.originalRMKSA_=navigator.requestMediaKeySystemAccess,navigator.requestMediaKeySystemAccess=e.probeRMKSA_)},e.probeRMKSA_=function(t,n){try{var o=this;return i(e.originalRMKSA_.call(o,t,n),function(i){return s(i)?(navigator.requestMediaKeySystemAccess=e.originalRMKSA_,i):(navigator.requestMediaKeySystemAccess=e.polyfillRMKSA_,e.polyfillRMKSA_.call(o,t,n))})}catch(r){return Promise.reject(r)}},e.polyfillRMKSA_=function(t,n){try{var o=a(t),s=[],c=n,l=Array.isArray(c),f=0;for(c=l?c:c[Symbol.iterator]();;){var u;if(l){if(f>=c.length)break;u=c[f++]}else{if((f=c.next()).done)break;u=f.value}var y=u,d=e.filterCapabilities_(y.videoCapabilities,o),p=e.filterCapabilities_(y.audioCapabilities,o);if(y.videoCapabilities&&y.videoCapabilities.length&&!d.length);else if(y.audioCapabilities&&y.audioCapabilities.length&&!p.length);else{var g=Object.assign({},y);g.videoCapabilities=d,g.audioCapabilities=p,s.push(g)}}if(!s.length){var m=new Error("Unsupported keySystem or supportedConfigurations.");throw m.name="NotSupportedError",m.code=DOMException.NOT_SUPPORTED_ERR,m}return i(e.originalRMKSA_.call(this,t,s),function(e){return new r(e,o)})}catch(v){return Promise.reject(v)}},e.filterCapabilities_=function(e,i){return e?e.filter(function(e){return!e.encryptionScheme||e.encryptionScheme==i}):e},e}();function n(){}var o=function(){function e(){}return e.install=function(){e.originalDecodingInfo_||navigator.mediaCapabilities&&(e.originalDecodingInfo_=navigator.mediaCapabilities.decodingInfo,navigator.mediaCapabilities.decodingInfo=e.probeDecodingInfo_)},e.probeDecodingInfo_=function(t){try{var n=this;return i(e.originalDecodingInfo_.call(n,t),function(i){if(!t.keySystemConfiguration)return i;var o=i.keySystemAccess;return o&&s(o)?(navigator.mediaCapabilities.decodingInfo=e.originalDecodingInfo_,i):(navigator.mediaCapabilities.decodingInfo=e.polyfillDecodingInfo_,e.polyfillDecodingInfo_.call(n,t))})}catch(o){return Promise.reject(o)}},e.polyfillDecodingInfo_=function(t){try{var o=null;if(t.keySystemConfiguration){var s=t.keySystemConfiguration,c=s.keySystem,l=s.audio&&s.audio.encryptionScheme,f=s.video&&s.video.encryptionScheme;o=a(c);var u={powerEfficient:!1,smooth:!1,supported:!1,keySystemAccess:null,configuration:t};if(l&&l!=o)return u;if(f&&f!=o)return u}return i(e.originalDecodingInfo_.call(this,t),function(a){return s=function(){return a},(c=function(){if(!a.keySystemAccess)return function(o){var r=function(){if(t.keySystemConfiguration){var n=e.convertToMediaKeySystemConfig_(t);return i(navigator.requestMediaKeySystemAccess(t.keySystemConfiguration.keySystem,[n]),function(e){a.keySystemAccess=e})}}();if(r&&r.then)return r.then(n)}();a.keySystemAccess=new r(a.keySystemAccess,o)}())&&c.then?c.then(s):s();var s,c})}catch(y){return Promise.reject(y)}},e.convertToMediaKeySystemConfig_=function(e){var i=e.keySystemConfiguration,t=[],n=[];if(i.audio){var o={robustness:i.audio.robustness||"",contentType:e.audio.contentType};t.push(o)}if(i.video){var r={robustness:i.video.robustness||"",contentType:e.video.contentType};n.push(r)}var a={initDataTypes:i.initDataType?[i.initDataType]:[],distinctiveIdentifier:i.distinctiveIdentifier,persistentState:i.persistentState,sessionTypes:i.sessionTypes};return t.length&&(a.audioCapabilities=t),n.length&&(a.videoCapabilities=n),a},e}(),r=function(){function e(e,i){this.mksa_=e,this.scheme_=i,this.keySystem=e.keySystem}var i=e.prototype;return i.getConfiguration=function(){var e=this.mksa_.getConfiguration();if(e.videoCapabilities){var i=e.videoCapabilities,t=Array.isArray(i),n=0;for(i=t?i:i[Symbol.iterator]();;){var o;if(t){if(n>=i.length)break;o=i[n++]}else{if((n=i.next()).done)break;o=n.value}o.encryptionScheme=this.scheme_}}if(e.audioCapabilities){var r=e.audioCapabilities,a=Array.isArray(r),s=0;for(r=a?r:r[Symbol.iterator]();;){var c;if(a){if(s>=r.length)break;c=r[s++]}else{if((s=r.next()).done)break;c=s.value}c.encryptionScheme=this.scheme_}}return e},i.createMediaKeys=function(){return this.mksa_.createMediaKeys()},e}();function a(e){return e.startsWith("com.widevine")?"cenc":e.startsWith("com.microsoft")?"cenc":e.startsWith("com.adobe")?"cenc":e.startsWith("org.w3")?"cenc":e.startsWith("com.apple")?"cbcs-1-9":(console.warn("EmeEncryptionSchemePolyfill: Unknown key system:",e,"Please contribute!"),null)}function s(e){var i=e.getConfiguration(),t=i.videoCapabilities&&i.videoCapabilities[0],n=i.audioCapabilities&&i.audioCapabilities[0],o=t||n;return!(!o||void 0===o.encryptionScheme)}t.originalRMKSA_,o.originalDecodingInfo_;var c=function(){function e(){}return e.install=function(){t.install(),o.install()},e}();return e.exports&&(e.exports=c),e=e.exports}); |
68
index.js
@@ -283,4 +283,3 @@ /*! | ||
if (!requestedConfiguration.keySystemConfiguration || | ||
!capabilities.keySystemAccess) { | ||
if (!requestedConfiguration.keySystemConfiguration) { | ||
// This was not a query regarding encrypted content. The results are | ||
@@ -294,3 +293,3 @@ // valid, but won't tell us anything about native support for | ||
if (hasEncryptionScheme(mediaKeySystemAccess)) { | ||
if (mediaKeySystemAccess && hasEncryptionScheme(mediaKeySystemAccess)) { | ||
// The browser supports the encryptionScheme field! | ||
@@ -307,5 +306,5 @@ // No need for a patch. Revert back to the original implementation. | ||
// If we land here, the browser does _not_ support the encryptionScheme | ||
// field. So we install another patch to check the encryptionScheme field | ||
// in future calls. | ||
// If we land here, the browser does _not_ support the mediaKeySystemAccess | ||
// field or the encryptionScheme field. So we install another patch to | ||
// check the mediaKeySystemAccess or encryptionScheme field in future calls. | ||
console.debug('McEncryptionSchemePolyfill: ' + | ||
@@ -384,2 +383,10 @@ 'No native encryptionScheme support found. '+ | ||
capabilities.keySystemAccess, supportedScheme); | ||
} else if (requestedConfiguration.keySystemConfiguration) { | ||
const mediaKeySystemConfig = | ||
McEncryptionSchemePolyfill.convertToMediaKeySystemConfig_( | ||
requestedConfiguration); | ||
capabilities.keySystemAccess = | ||
await navigator.requestMediaKeySystemAccess( | ||
requestedConfiguration.keySystemConfiguration.keySystem, | ||
[mediaKeySystemConfig]); | ||
} | ||
@@ -389,2 +396,51 @@ | ||
} | ||
/** | ||
* Convert the MediaDecodingConfiguration object to a | ||
* MediaKeySystemConfiguration object. | ||
* @param {!MediaDecodingConfiguration} decodingConfig | ||
* @return {!MediaKeySystemConfiguration} | ||
*/ | ||
static convertToMediaKeySystemConfig_(decodingConfig) { | ||
const mediaCapKeySystemConfig = decodingConfig.keySystemConfiguration; | ||
const audioCapabilities = []; | ||
const videoCapabilities = []; | ||
if (mediaCapKeySystemConfig.audio) { | ||
const capability = { | ||
robustness: mediaCapKeySystemConfig.audio.robustness || '', | ||
contentType: decodingConfig.audio.contentType, | ||
}; | ||
audioCapabilities.push(capability); | ||
} | ||
if (mediaCapKeySystemConfig.video) { | ||
const capability = { | ||
robustness: mediaCapKeySystemConfig.video.robustness || '', | ||
contentType: decodingConfig.video.contentType, | ||
}; | ||
videoCapabilities.push(capability); | ||
} | ||
const initDataTypes = mediaCapKeySystemConfig.initDataType ? | ||
[mediaCapKeySystemConfig.initDataType] : []; | ||
/** @type {!MediaKeySystemConfiguration} */ | ||
const mediaKeySystemConfig = { | ||
initDataTypes: initDataTypes, | ||
distinctiveIdentifier: mediaCapKeySystemConfig.distinctiveIdentifier, | ||
persistentState: mediaCapKeySystemConfig.persistentState, | ||
sessionTypes: mediaCapKeySystemConfig.sessionTypes, | ||
}; | ||
// Only add the audio video capablities if they have valid data. | ||
// Otherwise the query will fail. | ||
if (audioCapabilities.length) { | ||
mediaKeySystemConfig.audioCapabilities = audioCapabilities; | ||
} | ||
if (videoCapabilities.length) { | ||
mediaKeySystemConfig.videoCapabilities = videoCapabilities; | ||
} | ||
return mediaKeySystemConfig; | ||
} | ||
} | ||
@@ -391,0 +447,0 @@ |
{ | ||
"name": "eme-encryption-scheme-polyfill", | ||
"description": "A polyfill for the encryptionScheme field in EME", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43609
549