Skip to content

Commit

Permalink
fix: Fix CBCS support in some platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 6, 2024
1 parent bf24834 commit 6cf08f7
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 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 (audioScheme && !checkSupportedScheme(audioScheme, supportedScheme)) {
return notSupportedResult;
}
if (videoScheme && videoScheme != supportedScheme) {
if (videoScheme && !checkSupportedScheme(videoScheme, supportedScheme)) {
return notSupportedResult;
}
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 6cf08f7

Please sign in to comment.