MCPcopy Create free account
hub / github.com/GoogleChrome/samples / onCreateSessionButtonClick

Function onCreateSessionButtonClick

media/key-session-closed-reason.js:3–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1let keySession;
2
3async function onCreateSessionButtonClick() {
4 const config = [
5 {
6 initDataTypes: ["webm"],
7 audioCapabilities: [{ contentType: 'audio/webm; codecs="opus"' }],
8 },
9 ];
10 const keySystemAccess = await navigator.requestMediaKeySystemAccess(
11 "org.w3.clearkey",
12 config
13 );
14 // Create media keys.
15 const mediaKeys = await keySystemAccess.createMediaKeys();
16 // Create a key session.
17 keySession = mediaKeys.createSession();
18 // Generate a fake license request.
19 await keySession.generateRequest("webm", new Uint8Array([1, 2, 3]));
20
21 log(`Media key session is created.`);
22
23 keySession.closed.then((reason) => {
24 // Reason is either undefined if not supported, "internal-error",
25 // "closed-by-application", "release-acknowledged",
26 // "hardware-context-reset", or "resource-evicted".
27 log(`Media key session was closed. Reason: "${reason}".`);
28 });
29}
30
31async function onCloseSessionButtonClick() {
32 // Will close media key session with "closed-by-application" reason.

Callers

nothing calls this directly

Calls 1

logFunction · 0.50

Tested by

no test coverage detected