Skip to content

Commit c23f961

Browse files
authored
Merge pull request #1690 from handellm/add_gdm_record_support
Record: add gDM recording support.
2 parents 86ba3f1 + 9086df2 commit c23f961

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/content/getusermedia/record/css/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
margin: 0 3px 10px 0;
1010
padding-left: 2px;
1111
padding-right: 2px;
12-
width: 99px;
12+
width: 120px;
1313
}
1414

1515
button:last-of-type {

src/content/getusermedia/record/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC
4444
<video id="recorded" playsinline loop></video>
4545

4646
<div>
47-
<button id="start">Start camera</button>
47+
<button id="start-gum">Start camera</button>
48+
<button id="start-gdm">Start screenshare</button>
4849
<button id="record" disabled>Start Recording</button>
4950
<button id="play" disabled>Play</button>
5051
<button id="download" disabled>Download</button>

src/content/getusermedia/record/js/main.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function stopRecording() {
144144

145145
function handleSuccess(stream) {
146146
recordButton.disabled = false;
147-
console.log('getUserMedia() got stream:', stream);
147+
console.log('Got stream:', stream);
148148
window.stream = stream;
149149

150150
const gumVideo = document.querySelector('video#gum');
@@ -159,27 +159,37 @@ function handleSuccess(stream) {
159159
codecPreferences.disabled = false;
160160
}
161161

162-
async function init(constraints) {
162+
async function init(constraints, isGetDisplayMedia) {
163163
try {
164-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
164+
const stream = isGetDisplayMedia ?
165+
await navigator.mediaDevices.getDisplayMedia(constraints) :
166+
await navigator.mediaDevices.getUserMedia(constraints);
165167
handleSuccess(stream);
166168
} catch (e) {
167-
console.error('navigator.getUserMedia error:', e);
168-
errorMsgElement.innerHTML = `navigator.getUserMedia error:${e.toString()}`;
169+
console.error('Source open error:', e);
170+
errorMsgElement.innerHTML = `Source error: ${e.toString()}`;
169171
}
170172
}
171173

172-
document.querySelector('button#start').addEventListener('click', async () => {
173-
document.querySelector('button#start').disabled = true;
174+
async function onStart(isGetDisplayMedia) {
175+
document.querySelector('button#start-gum').disabled = true;
176+
document.querySelector('button#start-gdm').disabled = true;
174177
const hasEchoCancellation = document.querySelector('#echoCancellation').checked;
175178
const constraints = {
176179
audio: {
177-
echoCancellation: {exact: hasEchoCancellation}
180+
echoCancellation: hasEchoCancellation
178181
},
179182
video: {
180183
width: 1280, height: 720
181184
}
182185
};
183186
console.log('Using media constraints:', constraints);
184-
await init(constraints);
187+
await init(constraints, isGetDisplayMedia);
188+
}
189+
190+
document.querySelector('button#start-gum').addEventListener('click', async () => {
191+
await onStart(false);
192+
});
193+
document.querySelector('button#start-gdm').addEventListener('click', async () => {
194+
await onStart(true);
185195
});

0 commit comments

Comments
 (0)