Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record: add gDM recording support. #1690

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/getusermedia/record/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
margin: 0 3px 10px 0;
padding-left: 2px;
padding-right: 2px;
width: 99px;
width: 120px;
}

button:last-of-type {
Expand Down
3 changes: 2 additions & 1 deletion src/content/getusermedia/record/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC
<video id="recorded" playsinline loop></video>

<div>
<button id="start">Start camera</button>
<button id="start-gum">Start camera</button>
<button id="start-gdm">Start screenshare</button>
<button id="record" disabled>Start Recording</button>
<button id="play" disabled>Play</button>
<button id="download" disabled>Download</button>
Expand Down
28 changes: 19 additions & 9 deletions src/content/getusermedia/record/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function stopRecording() {

function handleSuccess(stream) {
recordButton.disabled = false;
console.log('getUserMedia() got stream:', stream);
console.log('Got stream:', stream);
window.stream = stream;

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

async function init(constraints) {
async function init(constraints, isGetDisplayMedia) {
try {
const stream = await navigator.mediaDevices.getUserMedia(constraints);
const stream = isGetDisplayMedia ?
await navigator.mediaDevices.getDisplayMedia(constraints) :
await navigator.mediaDevices.getUserMedia(constraints);
handleSuccess(stream);
} catch (e) {
console.error('navigator.getUserMedia error:', e);
errorMsgElement.innerHTML = `navigator.getUserMedia error:${e.toString()}`;
console.error('Source open error:', e);
errorMsgElement.innerHTML = `Source error: ${e.toString()}`;
}
}

document.querySelector('button#start').addEventListener('click', async () => {
document.querySelector('button#start').disabled = true;
async function onStart(isGetDisplayMedia) {
document.querySelector('button#start-gum').disabled = true;
document.querySelector('button#start-gdm').disabled = true;
const hasEchoCancellation = document.querySelector('#echoCancellation').checked;
const constraints = {
audio: {
echoCancellation: {exact: hasEchoCancellation}
echoCancellation: hasEchoCancellation
},
video: {
width: 1280, height: 720
}
};
console.log('Using media constraints:', constraints);
await init(constraints);
await init(constraints, isGetDisplayMedia);
}

document.querySelector('button#start-gum').addEventListener('click', async () => {
await onStart(false);
});
document.querySelector('button#start-gdm').addEventListener('click', async () => {
await onStart(true);
});
Loading