refactor: consolidate remote cdm initialization into a helper function
This commit is contained in:
parent
9e071365e3
commit
f8712d7726
243
src/inject.js
243
src/inject.js
@ -537,12 +537,11 @@ function postDRMTypeAndPssh(type, pssh) {
|
|||||||
window.postMessage({ type: "__PSSH_DATA__", data: pssh }, "*");
|
window.postMessage({ type: "__PSSH_DATA__", data: pssh }, "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureRemoteCDM(type, deviceInfo, pssh) {
|
function createAndOpenRemoteCDM(type, deviceInfo, pssh) {
|
||||||
if (!remoteCDM) {
|
let cdm;
|
||||||
if (type === "Widevine") {
|
if (type === "Widevine") {
|
||||||
const { device_type, system_id, security_level, host, secret, device_name } =
|
const { device_type, system_id, security_level, host, secret, device_name } = deviceInfo;
|
||||||
deviceInfo;
|
cdm = new remoteWidevineCDM(
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
device_type,
|
||||||
system_id,
|
system_id,
|
||||||
security_level,
|
security_level,
|
||||||
@ -550,14 +549,20 @@ function ensureRemoteCDM(type, deviceInfo, pssh) {
|
|||||||
secret,
|
secret,
|
||||||
device_name
|
device_name
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
cdm.openSession();
|
||||||
remoteCDM.getChallenge(pssh);
|
cdm.getChallenge(pssh);
|
||||||
} else if (type === "PlayReady") {
|
} else if (type === "PlayReady") {
|
||||||
const { security_level, host, secret, device_name } = deviceInfo;
|
const { security_level, host, secret, device_name } = deviceInfo;
|
||||||
remoteCDM = new remotePlayReadyCDM(security_level, host, secret, device_name);
|
cdm = new remotePlayReadyCDM(security_level, host, secret, device_name);
|
||||||
remoteCDM.openSession();
|
cdm.openSession();
|
||||||
remoteCDM.getChallenge(pssh);
|
cdm.getChallenge(pssh);
|
||||||
}
|
}
|
||||||
|
return cdm;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureRemoteCDM(type, deviceInfo, pssh) {
|
||||||
|
if (!remoteCDM) {
|
||||||
|
remoteCDM = createAndOpenRemoteCDM(type, deviceInfo, pssh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,17 +594,11 @@ MediaKeySession.prototype.generateRequest = function (initDataType, initData) {
|
|||||||
interceptType !== "DISABLED" &&
|
interceptType !== "DISABLED" &&
|
||||||
!serviceCertFound
|
!serviceCertFound
|
||||||
) {
|
) {
|
||||||
const { device_type, system_id, security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
widevineDeviceInfo;
|
"Widevine",
|
||||||
remoteCDM = new remoteWidevineCDM(
|
widevineDeviceInfo,
|
||||||
device_type,
|
foundWidevinePssh
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!injectionSuccess &&
|
!injectionSuccess &&
|
||||||
@ -751,36 +750,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (base64Body.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
if (base64Body.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (base64Body.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
if (base64Body.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
@ -816,36 +797,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (base64EncodedBody.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
if (base64EncodedBody.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (base64EncodedBody.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
if (base64EncodedBody.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
@ -881,36 +844,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: resource }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.WIDEVINE)) {
|
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.PLAYREADY)) {
|
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
@ -967,36 +912,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (base64Body.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
if (base64Body.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (base64Body.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
if (base64Body.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
@ -1032,36 +959,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (base64EncodedBody.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
if (base64EncodedBody.startsWith(DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (base64EncodedBody.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
if (base64EncodedBody.startsWith(DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
@ -1097,36 +1006,18 @@ MediaKeySession.prototype.update = function (response) {
|
|||||||
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
|
||||||
if (!remoteCDM) {
|
if (!remoteCDM) {
|
||||||
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.WIDEVINE)) {
|
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.WIDEVINE)) {
|
||||||
const {
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
device_type,
|
"Widevine",
|
||||||
system_id,
|
widevineDeviceInfo,
|
||||||
security_level,
|
foundWidevinePssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name,
|
|
||||||
} = widevineDeviceInfo;
|
|
||||||
remoteCDM = new remoteWidevineCDM(
|
|
||||||
device_type,
|
|
||||||
system_id,
|
|
||||||
security_level,
|
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundWidevinePssh);
|
|
||||||
}
|
}
|
||||||
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.PLAYREADY)) {
|
if (jsonContainsValue(jsonBody, DRM_SIGNATURES.PLAYREADY)) {
|
||||||
const { security_level, host, secret, device_name } =
|
remoteCDM = createAndOpenRemoteCDM(
|
||||||
playreadyDeviceInfo;
|
"PlayReady",
|
||||||
remoteCDM = new remotePlayReadyCDM(
|
playreadyDeviceInfo,
|
||||||
security_level,
|
foundPlayreadyPssh
|
||||||
host,
|
|
||||||
secret,
|
|
||||||
device_name
|
|
||||||
);
|
);
|
||||||
remoteCDM.openSession();
|
|
||||||
remoteCDM.getChallenge(foundPlayreadyPssh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remoteCDM && remoteCDM.challenge === null) {
|
if (remoteCDM && remoteCDM.challenge === null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user