Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix CBCS support in some platforms #63

Merged
merged 5 commits into from
May 7, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (audioScheme && !checkSupportedScheme(audioScheme, supportedScheme)) {
joeyparrish marked this conversation as resolved.
Show resolved Hide resolved
return notSupportedResult;
}
if (videoScheme && videoScheme != supportedScheme) {
if (videoScheme && !checkSupportedScheme(videoScheme, supportedScheme)) {
return notSupportedResult;
}
}
Expand Down Expand Up @@ -600,6 +598,35 @@ 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) {
// 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
Loading