From 510e680038e6dbfe8c1004ccc71c0bf9f2106f56 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:04:02 +0900 Subject: [PATCH] test --- getChallenge.js | 49 ++++++++++++++++++++++--------------------------- index.html | 4 +++- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/getChallenge.js b/getChallenge.js index 7a97fd8..a2b7350 100644 --- a/getChallenge.js +++ b/getChallenge.js @@ -1,16 +1,17 @@ -export default function() { - navigator.requestMediaKeySystemAccess('com.widevine.alpha', config).then(keySystemAccess => { - createMediaKeys(keySystemAccess); - }) -}; - -const b64 = { - decode: s => Uint8Array.from(atob(s), c => c.charCodeAt(0)), - encode: b => btoa(String.fromCharCode(...new Uint8Array(b))) +export default async function() { + let keySystemAccess; + try{ + keySystemAccess = await navigator.requestMediaKeySystemAccess('com.widevine.alpha', config) + } catch { + config[0]['sessionTypes'] = ['temporary'] + keySystemAccess = await navigator.requestMediaKeySystemAccess('com.widevine.alpha', config) + } + let challenge = await getChallenge(keySystemAccess); + return challenge }; // Tears of Steel Init data Widevine -let initData = b64.decode('AAAARHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACQIARIBMRoNd2lkZXZpbmVfdGVzdCIKMjAxNV90ZWFycyoCU0Q=') +let initData = Uint8Array.from(atob('AAAARHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACQIARIBMRoNd2lkZXZpbmVfdGVzdCIKMjAxNV90ZWFycyoCU0Q='), c => c.charCodeAt(0)) // Widevine CDM config MediaKeyAccess default let config = [{ @@ -24,22 +25,16 @@ let config = [{ }] }]; -async function createMediaKeys(keySystemAccess) { - try{ - let mediaKeys = await keySystemAccess.createMediaKeys(); - let challenge = await onCreate(mediaKeys); - console.log(b64.encode(challenge)) - } catch(err) { - console.error("Unable to create MediaKeys : " + err) - } -} - -// Initialization of the CDM session and generation of the request -function onCreate(mediaKeys) { - return new Promise(resolve => { - let keySession = mediaKeys.createSession(config[0]['sessionTypes']) - - keySession.addEventListener("message", () => resolve(event.message)); - keySession.generateRequest("cenc", initData) +async function getChallenge(keySystemAccess) { + return new Promise((resolve, reject) => { + try{ + keySystemAccess.createMediaKeys().then(mediaKeys => { + let keySession = mediaKeys.createSession(config[0]['sessionTypes']) + keySession.addEventListener("message", () => resolve(event.message)); + keySession.generateRequest("cenc", initData) + }) + } catch(err) { + reject("Unable to create MediaKeys : " + err) + } }) } diff --git a/index.html b/index.html index 2e75e96..41ace1c 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,9 @@