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] 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. *