forked from webrtcHacks/jitsiLocalRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDisplayMedia.html
76 lines (67 loc) · 2.83 KB
/
getDisplayMedia.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Check getDisplayMedia</title>
</head>
<body>
<p>Pick which <em>displaySurface</em> constraint to apply to <em>getDisplayMedia</em></p>
<p>
<button id="display">Display</button>
<button id="application">Application</button>
<button id="window">Window</button>
<button id="browser">Browser</button>
</p>
<p>
<label for="frameRate">Frame rate</label>
<input id="frameRate" type="text" size="2"/>
</p>
<p>
<input type="checkbox" id="audioCapture" value="audioCapture" checked>
<label for="audioCapture">Audio</label>
</p>
<p><em><span id="mode"></span></em></p>
<h3>Result</h3>
<p id="result"></p>
<h3>Display Surface Video Track Details</h3>
<p id="displaySettings"></p>
<h3>Audio Capture Track Details</h3>
<p id="audioSettings"></p>
<script>
const result = document.getElementById('result');
const displaySettings = document.getElementById('displaySettings');
const audioSettings = document.getElementById('audioSettings');
const frameRate = document.getElementById('frameRate');
const audioCapture = document.getElementById('audioCapture');
const buttons = document.querySelectorAll('button');
buttons.forEach(button => button.addEventListener('click', async () => {
try {
let stream = await navigator.mediaDevices.getDisplayMedia({
video: {displaySurface: button.id, frameRate: frameRate.value > 0 ? frameRate.value : null},
audio: audioCapture.checked
});
//.then(s=>stream=s); // ToDo: add support for Safari
console.log(stream.getTracks());
let trackSettings = stream.getVideoTracks()[0].getSettings();
result.innerHTML = `You asked for <strong>${button.id}</strong> and got <strong>${trackSettings.displaySurface}</strong>`;
// Show all video and audio track settings - there should only be a single track on each max
let videoDetails = "";
stream.getVideoTracks().forEach((track, i) => {
videoDetails += `<strong>Track ${i}</strong>`;
videoDetails += JSON.stringify(track.getSettings(), null, '<br/>').replace(/["{},]/g, "");
});
displaySettings.innerHTML = videoDetails === "" ? "No video track captured" : videoDetails;
let audioDetails = "";
stream.getAudioTracks().forEach((track, i) => {
audioDetails += `<strong>Track ${i}</strong>`;
audioDetails += JSON.stringify(track.getSettings(), null, '<br/>').replace(/["{},]/g, "");
});
audioSettings.innerHTML = audioDetails === "" ? "No audio track captured" : audioDetails;
} catch (e) {
result.innerText = e;
console.error(e);
}
}));
</script>
</body>
</html>