Skip to content

Commit

Permalink
fix: Fix CBCS support in some platforms (#63)
Browse files Browse the repository at this point in the history
Fixes #62

Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
  • Loading branch information
avelad and joeyparrish committed May 7, 2024
1 parent 5316552 commit 3978d61
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -369,10 +367,10 @@ class McEncryptionSchemePolyfill {
configuration: requestedConfiguration,
};

if (audioScheme && audioScheme != supportedScheme) {
if (!checkSupportedScheme(audioScheme, supportedScheme)) {
return notSupportedResult;
}
if (videoScheme && videoScheme != supportedScheme) {
if (!checkSupportedScheme(videoScheme, supportedScheme)) {
return notSupportedResult;
}
}
Expand Down Expand Up @@ -600,6 +598,35 @@ function hasEncryptionScheme(mediaKeySystemAccess) {
return false;
}

/**
* @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.
*
Expand Down Expand Up @@ -642,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} */
(() => {
Expand Down

0 comments on commit 3978d61

Please sign in to comment.