eme-encryption-scheme-polyfill
Advanced tools
Comparing version 2.1.1 to 2.1.2
# Changelog | ||
## [2.1.2](https://github.com/shaka-project/eme-encryption-scheme-polyfill/compare/v2.1.1...v2.1.2) (2024-05-07) | ||
### Bug Fixes | ||
* Fix CBCS support in some platforms ([#63](https://github.com/shaka-project/eme-encryption-scheme-polyfill/issues/63)) ([3978d61](https://github.com/shaka-project/eme-encryption-scheme-polyfill/commit/3978d619eb03534d89651a0cb11be8a9afad3387)), closes [#62](https://github.com/shaka-project/eme-encryption-scheme-polyfill/issues/62) | ||
* Use cbcs as default scheme for Safari ([#64](https://github.com/shaka-project/eme-encryption-scheme-polyfill/issues/64)) ([5316552](https://github.com/shaka-project/eme-encryption-scheme-polyfill/commit/53165526cd0297a987c7802bb2d7b190b7eb0c71)) | ||
## [2.1.1](https://github.com/shaka-project/eme-encryption-scheme-polyfill/compare/v2.1.0...v2.1.1) (2022-08-10) | ||
@@ -5,0 +13,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 t(e,t,i){return i?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}function i(e,t){var i=e();return i&&i.then?i.then(t):t(i)}function n(){}function r(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=function(e,t){if(e){if("string"==typeof e)return o(e,void 0);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?o(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==i.return||i.return()}finally{if(c)throw a}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,i){return t&&s(e.prototype,t),i&&s(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}var u=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){e.originalRMKSA_||navigator.requestMediaKeySystemAccess&&MediaKeySystemAccess.prototype.getConfiguration&&(e.originalRMKSA_=navigator.requestMediaKeySystemAccess,navigator.requestMediaKeySystemAccess=e.probeRMKSA_)}},{key:"probeRMKSA_",value:function(i,n){try{var r=this;return t(e.originalRMKSA_.call(r,i,n),(function(t){return d(t)?(navigator.requestMediaKeySystemAccess=e.originalRMKSA_,t):(navigator.requestMediaKeySystemAccess=e.polyfillRMKSA_,e.polyfillRMKSA_.call(r,i,n))}))}catch(o){return Promise.reject(o)}}},{key:"polyfillRMKSA_",value:function(i,n){try{var o,a=y(i),s=[],c=r(n);try{for(c.s();!(o=c.n()).done;){var u=o.value,l=e.filterCapabilities_(u.videoCapabilities,a),d=e.filterCapabilities_(u.audioCapabilities,a);if(u.videoCapabilities&&u.videoCapabilities.length&&!l.length);else if(u.audioCapabilities&&u.audioCapabilities.length&&!d.length);else{var p=Object.assign({},u);p.videoCapabilities=l,p.audioCapabilities=d,s.push(p)}}}catch(m){c.e(m)}finally{c.f()}if(!s.length){var v=new Error("Unsupported keySystem or supportedConfigurations.");throw v.name="NotSupportedError",v.code=DOMException.NOT_SUPPORTED_ERR,v}return t(e.originalRMKSA_.call(this,i,s),(function(e){return new f(e,a)}))}catch(g){return Promise.reject(g)}}},{key:"filterCapabilities_",value:function(e,t){return e?e.filter((function(e){return!e.encryptionScheme||e.encryptionScheme==t})):e}}]),e}(),l=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){e.originalDecodingInfo_||navigator.mediaCapabilities&&(e.originalDecodingInfo_=navigator.mediaCapabilities.decodingInfo,navigator.mediaCapabilities.decodingInfo=e.probeDecodingInfo_)}},{key:"probeDecodingInfo_",value:function(n){try{var r=this;return t(e.originalDecodingInfo_.call(r,n),(function(o){var a=!1;if(!n.keySystemConfiguration)return o;var s=o.keySystemAccess;return s&&d(s)?(navigator.mediaCapabilities.decodingInfo=e.originalDecodingInfo_,o):(navigator.mediaCapabilities.decodingInfo=e.polyfillDecodingInfo_,i((function(){if(!s)return t(e.getMediaKeySystemAccess_(n),(function(e){return o.keySystemAccess=e,a=!0,o}))}),(function(t){return a?t:e.polyfillDecodingInfo_.call(r,n)})))}))}catch(o){return Promise.reject(o)}}},{key:"polyfillDecodingInfo_",value:function(r){try{var o=null;if(r.keySystemConfiguration){var a=r.keySystemConfiguration,s=a.keySystem,c=a.audio&&a.audio.encryptionScheme,u=a.video&&a.video.encryptionScheme;o=y(s);var l={powerEfficient:!1,smooth:!1,supported:!1,keySystemAccess:null,configuration:r};if(c&&c!=o)return t(l);if(u&&u!=o)return t(l)}return t(e.originalDecodingInfo_.call(this,r),(function(a){return i((function(){if(!a.keySystemAccess)return function(i){var o=function(){if(r.keySystemConfiguration)return t(e.getMediaKeySystemAccess_(r),(function(e){a.keySystemAccess=e}))}();if(o&&o.then)return o.then(n)}();a.keySystemAccess=new f(a.keySystemAccess,o)}),(function(){return a}))}))}catch(d){return Promise.reject(d)}}},{key:"getMediaKeySystemAccess_",value:function(i){try{var n=e.convertToMediaKeySystemConfig_(i);return t(navigator.requestMediaKeySystemAccess(i.keySystemConfiguration.keySystem,[n]))}catch(r){return Promise.reject(r)}}},{key:"convertToMediaKeySystemConfig_",value:function(e){var t=e.keySystemConfiguration,i=[],n=[];if(t.audio){var r={robustness:t.audio.robustness||"",contentType:e.audio.contentType};i.push(r)}if(t.video){var o={robustness:t.video.robustness||"",contentType:e.video.contentType};n.push(o)}var a={initDataTypes:t.initDataType?[t.initDataType]:[],distinctiveIdentifier:t.distinctiveIdentifier,persistentState:t.persistentState,sessionTypes:t.sessionTypes};return i.length&&(a.audioCapabilities=i),n.length&&(a.videoCapabilities=n),a}}]),e}(),f=function(){function e(t,i){a(this,e),this.mksa_=t,this.scheme_=i,this.keySystem=t.keySystem}return c(e,[{key:"getConfiguration",value:function(){var e=this.mksa_.getConfiguration();if(e.videoCapabilities){var t,i=r(e.videoCapabilities);try{for(i.s();!(t=i.n()).done;)t.value.encryptionScheme=this.scheme_}catch(a){i.e(a)}finally{i.f()}}if(e.audioCapabilities){var n,o=r(e.audioCapabilities);try{for(o.s();!(n=o.n()).done;)n.value.encryptionScheme=this.scheme_}catch(a){o.e(a)}finally{o.f()}}return e}},{key:"createMediaKeys",value:function(){return this.mksa_.createMediaKeys()}}]),e}();function y(e){return e.startsWith("com.widevine")||e.startsWith("com.microsoft")||e.startsWith("com.chromecast")||e.startsWith("com.adobe")||e.startsWith("org.w3")?"cenc":e.startsWith("com.apple")?"cbcs-1-9":(console.warn("EmeEncryptionSchemePolyfill: Unknown key system:",e,"Please contribute!"),null)}function d(e){var t=e.getConfiguration(),i=t.videoCapabilities&&t.videoCapabilities[0],n=t.audioCapabilities&&t.audioCapabilities[0],r=i||n;return!(!r||void 0===r.encryptionScheme)}u.originalRMKSA_,l.originalDecodingInfo_;var p=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){u.install(),l.install()}}]),e}();return e.exports&&(e.exports=p),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 t(e,t,i){return i?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}function i(e,t){var i=e();return i&&i.then?i.then(t):t(i)}function n(){}function r(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=function(e,t){if(e){if("string"==typeof e)return o(e,void 0);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?o(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==i.return||i.return()}finally{if(c)throw a}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,i){return t&&s(e.prototype,t),i&&s(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}var u=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){e.originalRMKSA_||navigator.requestMediaKeySystemAccess&&MediaKeySystemAccess.prototype.getConfiguration&&(e.originalRMKSA_=navigator.requestMediaKeySystemAccess,navigator.requestMediaKeySystemAccess=e.probeRMKSA_)}},{key:"probeRMKSA_",value:function(i,n){try{var r=this;return t(e.originalRMKSA_.call(r,i,n),(function(t){return d(t)?(navigator.requestMediaKeySystemAccess=e.originalRMKSA_,t):(navigator.requestMediaKeySystemAccess=e.polyfillRMKSA_,e.polyfillRMKSA_.call(r,i,n))}))}catch(o){return Promise.reject(o)}}},{key:"polyfillRMKSA_",value:function(i,n){try{var o,a=y(i),s=[],c=r(n);try{for(c.s();!(o=c.n()).done;){var u=o.value,l=e.filterCapabilities_(u.videoCapabilities,a),d=e.filterCapabilities_(u.audioCapabilities,a);if(u.videoCapabilities&&u.videoCapabilities.length&&!l.length);else if(u.audioCapabilities&&u.audioCapabilities.length&&!d.length);else{var p=Object.assign({},u);p.videoCapabilities=l,p.audioCapabilities=d,s.push(p)}}}catch(m){c.e(m)}finally{c.f()}if(!s.length){var v=new Error("Unsupported keySystem or supportedConfigurations.");throw v.name="NotSupportedError",v.code=DOMException.NOT_SUPPORTED_ERR,v}return t(e.originalRMKSA_.call(this,i,s),(function(e){return new f(e,a)}))}catch(g){return Promise.reject(g)}}},{key:"filterCapabilities_",value:function(e,t){return e?e.filter((function(e){return p(e.encryptionScheme,t)})):e}}]),e}(),l=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){e.originalDecodingInfo_||navigator.mediaCapabilities&&(e.originalDecodingInfo_=navigator.mediaCapabilities.decodingInfo,navigator.mediaCapabilities.decodingInfo=e.probeDecodingInfo_)}},{key:"probeDecodingInfo_",value:function(n){try{var r=this;return t(e.originalDecodingInfo_.call(r,n),(function(o){var a=!1;if(!n.keySystemConfiguration)return o;var s=o.keySystemAccess;return s&&d(s)?(navigator.mediaCapabilities.decodingInfo=e.originalDecodingInfo_,o):(navigator.mediaCapabilities.decodingInfo=e.polyfillDecodingInfo_,i((function(){if(!s)return t(e.getMediaKeySystemAccess_(n),(function(e){return o.keySystemAccess=e,a=!0,o}))}),(function(t){return a?t:e.polyfillDecodingInfo_.call(r,n)})))}))}catch(o){return Promise.reject(o)}}},{key:"polyfillDecodingInfo_",value:function(r){try{var o=null;if(r.keySystemConfiguration){var a=r.keySystemConfiguration,s=a.keySystem,c=a.audio&&a.audio.encryptionScheme,u=a.video&&a.video.encryptionScheme;o=y(s);var l={powerEfficient:!1,smooth:!1,supported:!1,keySystemAccess:null,configuration:r};if(!p(c,o))return t(l);if(!p(u,o))return t(l)}return t(e.originalDecodingInfo_.call(this,r),(function(a){return i((function(){if(!a.keySystemAccess)return function(i){var o=function(){if(r.keySystemConfiguration)return t(e.getMediaKeySystemAccess_(r),(function(e){a.keySystemAccess=e}))}();if(o&&o.then)return o.then(n)}();a.keySystemAccess=new f(a.keySystemAccess,o)}),(function(){return a}))}))}catch(d){return Promise.reject(d)}}},{key:"getMediaKeySystemAccess_",value:function(i){try{var n=e.convertToMediaKeySystemConfig_(i);return t(navigator.requestMediaKeySystemAccess(i.keySystemConfiguration.keySystem,[n]))}catch(r){return Promise.reject(r)}}},{key:"convertToMediaKeySystemConfig_",value:function(e){var t=e.keySystemConfiguration,i=[],n=[];if(t.audio){var r={robustness:t.audio.robustness||"",contentType:e.audio.contentType};i.push(r)}if(t.video){var o={robustness:t.video.robustness||"",contentType:e.video.contentType};n.push(o)}var a={initDataTypes:t.initDataType?[t.initDataType]:[],distinctiveIdentifier:t.distinctiveIdentifier,persistentState:t.persistentState,sessionTypes:t.sessionTypes};return i.length&&(a.audioCapabilities=i),n.length&&(a.videoCapabilities=n),a}}]),e}(),f=function(){function e(t,i){a(this,e),this.mksa_=t,this.scheme_=i,this.keySystem=t.keySystem}return c(e,[{key:"getConfiguration",value:function(){var e=this.mksa_.getConfiguration();if(e.videoCapabilities){var t,i=r(e.videoCapabilities);try{for(i.s();!(t=i.n()).done;)t.value.encryptionScheme=this.scheme_}catch(a){i.e(a)}finally{i.f()}}if(e.audioCapabilities){var n,o=r(e.audioCapabilities);try{for(o.s();!(n=o.n()).done;)n.value.encryptionScheme=this.scheme_}catch(a){o.e(a)}finally{o.f()}}return e}},{key:"createMediaKeys",value:function(){return this.mksa_.createMediaKeys()}}]),e}();function y(e){return e.startsWith("com.widevine")||e.startsWith("com.microsoft")||e.startsWith("com.chromecast")||e.startsWith("com.adobe")||e.startsWith("org.w3")?"cenc":e.startsWith("com.apple")?"cbcs":(console.warn("EmeEncryptionSchemePolyfill: Unknown key system:",e,"Please contribute!"),null)}function d(e){var t=e.getConfiguration(),i=t.videoCapabilities&&t.videoCapabilities[0],n=t.audioCapabilities&&t.audioCapabilities[0],r=i||n;return!(!r||void 0===r.encryptionScheme)}function p(e,t){return!e||e==t||!("cbcs"!=e&&"cbcs-1-9"!=e||!v.isRecentFirefox&&!v.isChromecast)}u.originalRMKSA_,l.originalDecodingInfo_;var v=function(){function e(){a(this,e)}return c(e,null,[{key:"install",value:function(){u.install(),l.install()}}]),e}();return v.isChromecast=navigator.userAgent.includes("CrKey"),v.isRecentFirefox=parseInt(navigator.userAgent.split("Firefox/").pop(),10)>=100,e.exports&&(e.exports=v),e=e.exports})); |
53
index.js
@@ -205,6 +205,4 @@ /*! | ||
return capabilities.filter((capability) => { | ||
// No specific scheme always works. In addition, accept the specific | ||
// scheme we guessed for this UA. | ||
return !capability['encryptionScheme'] || | ||
capability['encryptionScheme'] == supportedScheme; | ||
return checkSupportedScheme( | ||
capability['encryptionScheme'], supportedScheme); | ||
}); | ||
@@ -373,6 +371,6 @@ } | ||
if (audioScheme && audioScheme != supportedScheme) { | ||
if (!checkSupportedScheme(audioScheme, supportedScheme)) { | ||
return notSupportedResult; | ||
} | ||
if (videoScheme && videoScheme != supportedScheme) { | ||
if (!checkSupportedScheme(videoScheme, supportedScheme)) { | ||
return notSupportedResult; | ||
@@ -566,3 +564,3 @@ } | ||
} else if (keySystem.startsWith('com.apple')) { | ||
return 'cbcs-1-9'; | ||
return 'cbcs'; | ||
} | ||
@@ -607,2 +605,31 @@ | ||
/** | ||
* @param {(string|undefined)} scheme Encryption scheme to check | ||
* @param {?string} supportedScheme A guess at the encryption scheme this | ||
* supports. | ||
* @return {boolean} True if the scheme is compatible. | ||
*/ | ||
function checkSupportedScheme(scheme, supportedScheme) { | ||
if (!scheme) { | ||
// Not encrypted = always supported | ||
return true; | ||
} | ||
if (scheme == supportedScheme) { | ||
// The assumed-supported legacy scheme for this platform. | ||
return true; | ||
} | ||
if (scheme == 'cbcs' || scheme == 'cbcs-1-9') { | ||
if (EncryptionSchemePolyfills.isRecentFirefox || | ||
EncryptionSchemePolyfills.isChromecast) { | ||
// Firefox >= 100 supports CBCS, but doesn't support queries yet. | ||
// Older Chromecast devices are assumed to support CBCS as well. | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* The original requestMediaKeySystemAccess, before we patched it. | ||
@@ -649,2 +676,14 @@ * | ||
/** | ||
* @const {boolean} | ||
*/ | ||
EncryptionSchemePolyfills.isChromecast = | ||
navigator.userAgent.includes('CrKey'); | ||
/** | ||
* @const {boolean} | ||
*/ | ||
EncryptionSchemePolyfills.isRecentFirefox = | ||
parseInt(navigator.userAgent.split('Firefox/').pop(), 10) >= 100; | ||
// Support for CommonJS and AMD module formats. | ||
@@ -651,0 +690,0 @@ /** @suppress {undefinedVars} */ |
{ | ||
"name": "eme-encryption-scheme-polyfill", | ||
"description": "A polyfill for the encryptionScheme field in EME", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"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
50601
624