From 6cf08f79ecedb707d7e1b9e04876f7f83520dc82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Mon, 6 May 2024 13:01:59 +0200 Subject: [PATCH 1/4] fix: Fix CBCS support in some platforms --- index.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 3a26cf9..88a3719 100644 --- a/index.js +++ b/index.js @@ -202,10 +202,8 @@ class EmeEncryptionSchemePolyfill { } 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); }); } } @@ -369,10 +367,10 @@ class McEncryptionSchemePolyfill { configuration: requestedConfiguration, }; - if (audioScheme && audioScheme != supportedScheme) { + if (audioScheme && !checkSupportedScheme(audioScheme, supportedScheme)) { return notSupportedResult; } - if (videoScheme && videoScheme != supportedScheme) { + if (videoScheme && !checkSupportedScheme(videoScheme, supportedScheme)) { return notSupportedResult; } } @@ -600,6 +598,30 @@ function hasEncryptionScheme(mediaKeySystemAccess) { return false; } +/** + * @param {?string} 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 && scheme != supportedScheme) { + if (scheme == 'cbcs') { + // Firefox supports CBCS since version 100, but does not yet implement + // encryptionScheme support. + if (parseInt(navigator.userAgent.split('Firefox/').pop(), 10) >= 100) { + return true; + } + // All Chromecast supports CBCS. + if (navigator.userAgent.includes('CrKey')) { + return true; + } + } + return false; + } + return true; +} + /** * The original requestMediaKeySystemAccess, before we patched it. * From d77fca417b7a82654cf104868c0cdf21cc97c500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Tue, 7 May 2024 06:35:48 +0200 Subject: [PATCH 2/4] Update implementation --- index.js | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index aa4695b..a11b1b6 100644 --- a/index.js +++ b/index.js @@ -605,21 +605,26 @@ function hasEncryptionScheme(mediaKeySystemAccess) { * @return {boolean} True if the scheme is compatible. */ function checkSupportedScheme(scheme, supportedScheme) { - if (scheme && scheme != supportedScheme) { - if (scheme == 'cbcs') { - // Firefox supports CBCS since version 100, but does not yet implement - // encryptionScheme support. - if (parseInt(navigator.userAgent.split('Firefox/').pop(), 10) >= 100) { - return true; - } - // All Chromecast supports CBCS. - if (navigator.userAgent.includes('CrKey')) { - return true; - } + 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; } - return true; + + return false; } /** @@ -664,6 +669,18 @@ class EncryptionSchemePolyfills { } } +/** + * @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. /** @suppress {undefinedVars} */ (() => { From e2565c382fed69df52892bd60304a0a7193ebf1d Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 7 May 2024 09:04:35 -0700 Subject: [PATCH 3/4] Drop null check --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a11b1b6..d2382ba 100644 --- a/index.js +++ b/index.js @@ -367,10 +367,10 @@ class McEncryptionSchemePolyfill { configuration: requestedConfiguration, }; - if (audioScheme && !checkSupportedScheme(audioScheme, supportedScheme)) { + if (!checkSupportedScheme(audioScheme, supportedScheme)) { return notSupportedResult; } - if (videoScheme && !checkSupportedScheme(videoScheme, supportedScheme)) { + if (!checkSupportedScheme(videoScheme, supportedScheme)) { return notSupportedResult; } } From 58ddea5f51672a32138f81c3519c3545fece7f73 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 7 May 2024 09:12:30 -0700 Subject: [PATCH 4/4] Tweak input type --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d2382ba..f2c4d6b 100644 --- a/index.js +++ b/index.js @@ -599,7 +599,7 @@ function hasEncryptionScheme(mediaKeySystemAccess) { } /** - * @param {?string} scheme Encryption scheme to check + * @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.