blob: 3ff782b1bf392b1bd0915ca8362dccd0d0304922 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<!DOCTYPE html>
<html>
<head>
<title>Eme createMediaKeys helper page</title>
<script>
// This script waits for a message then attempts to requestMediaKeySystemAccess
// then createMediaKeys. On success posts 'successCreatingMediaKeys' to the
// source of the message, on failure posts 'failureCreatingMediaKeys' and a
// description of the failure to the source of the message.
async function createMediaKeys() {
const clearKeyOptions = [
{
initDataTypes: ["webm"],
videoCapabilities: [{ contentType: 'video/webm; codecs="vp9"' }],
},
];
let access = await navigator.requestMediaKeySystemAccess(
"org.w3.clearkey",
clearKeyOptions
);
return access.createMediaKeys();
}
function setupMessageListener() {
window.onmessage = async event => {
// We don't bother checking the message data since it should always be
// telling us to create media keys.
try {
let keys = await createMediaKeys();
if (!keys) {
event.source.postMessage("failureCreatingMediaKeys no keys", "*");
return;
}
event.source.postMessage("successCreatingMediaKeys", "*");
} catch (e) {
event.source.postMessage(`failureCreatingMediaKeys ${e}`, "*");
}
};
}
window.onload = setupMessageListener;
</script>
</head>
<body>
</body>
</html>
|