Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxRefire committed Aug 5, 2024
1 parent a7564b8 commit 510e680
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
49 changes: 22 additions & 27 deletions getChallenge.js
Original file line number Diff line number Diff line change
@@ -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 = [{
Expand All @@ -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)
}
})
}
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<script type="module">
import getChallenge from './getChallenge.js'
window.onload = () => {
getChallenge()
let b64encode = b => btoa(String.fromCharCode(...new Uint8Array(b)))
let challenge = getChallenge()
console.log(challenge)
}
</script>
</head>
Expand Down

0 comments on commit 510e680

Please sign in to comment.