forked from tpd94/CDRM-Extension
extract DRM PSSH detection and storage into a separate function
This commit is contained in:
parent
81f44b2f0e
commit
a40a6abaf7
@ -556,23 +556,32 @@ function ensureRemoteCDM(type, deviceInfo, pssh) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function detectAndStorePssh(initData) {
|
||||||
|
const detections = [
|
||||||
|
{
|
||||||
|
type: "PlayReady",
|
||||||
|
getter: getPlayReadyPssh,
|
||||||
|
store: (pssh) => (foundPlayreadyPssh = pssh),
|
||||||
|
},
|
||||||
|
{ type: "Widevine", getter: getWidevinePssh, store: (pssh) => (foundWidevinePssh = pssh) },
|
||||||
|
];
|
||||||
|
|
||||||
|
detections.forEach(({ type, getter, store }) => {
|
||||||
|
const pssh = getter(initData);
|
||||||
|
if (pssh) {
|
||||||
|
logWithPrefix(`[DRM Detected] ${type}`);
|
||||||
|
store(pssh);
|
||||||
|
logWithPrefix(`[${type} PSSH found] ${pssh}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Challenge generator interceptor
|
// Challenge generator interceptor
|
||||||
const originalGenerateRequest = MediaKeySession.prototype.generateRequest;
|
const originalGenerateRequest = MediaKeySession.prototype.generateRequest;
|
||||||
MediaKeySession.prototype.generateRequest = function (initDataType, initData) {
|
MediaKeySession.prototype.generateRequest = function (initDataType, initData) {
|
||||||
const session = this;
|
const session = this;
|
||||||
let playReadyPssh = getPlayReadyPssh(initData);
|
detectAndStorePssh(initData);
|
||||||
if (playReadyPssh) {
|
|
||||||
logWithPrefix("[DRM Detected] PlayReady");
|
|
||||||
foundPlayreadyPssh = playReadyPssh;
|
|
||||||
logWithPrefix("[PlayReady PSSH found] " + playReadyPssh);
|
|
||||||
}
|
|
||||||
let wideVinePssh = getWidevinePssh(initData);
|
|
||||||
if (wideVinePssh) {
|
|
||||||
// Widevine code
|
|
||||||
logWithPrefix("[DRM Detected] Widevine");
|
|
||||||
foundWidevinePssh = wideVinePssh;
|
|
||||||
logWithPrefix("[Widevine PSSH found] " + wideVinePssh);
|
|
||||||
}
|
|
||||||
// Challenge message interceptor
|
// Challenge message interceptor
|
||||||
if (!remoteListenerMounted) {
|
if (!remoteListenerMounted) {
|
||||||
remoteListenerMounted = true;
|
remoteListenerMounted = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user