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