Skip to content

Commit

Permalink
Add ability to stop recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mounir Lamouri committed Nov 13, 2024
1 parent afbb255 commit 3d5203d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions getdisplaymedia/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC

<video id="video" autoplay playsinline controls></video>
<button id="startButton" disabled>Start</button>
<button id="stopButton" disabled>Stop</button>
<fieldset id="options" style="display:none">
<legend>Advanced options</legend>
<select id="displaySurface">
Expand Down
11 changes: 10 additions & 1 deletion getdisplaymedia/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

const preferredDisplaySurface = document.getElementById('displaySurface');
const startButton = document.getElementById('startButton');
const stopButton = document.getElementById('stopButton');

if (adapter.browserDetails.browser === 'chrome' &&
adapter.browserDetails.version >= 107) {
Expand Down Expand Up @@ -55,7 +56,15 @@ startButton.addEventListener('click', () => {
options.video = {displaySurface};
}
navigator.mediaDevices.getDisplayMedia(options)
.then(handleSuccess, handleError);
.then(handleSuccess, handleError).then(() => {
stopButton.disabled = false;
})
});

stopButton.addEventListener('click', () => {
startButton.disabled = false;
stopButton.disabled = true;
video.srcObject.getTracks().forEach(track => track.stop());
});

if ((navigator.mediaDevices && 'getDisplayMedia' in navigator.mediaDevices)) {
Expand Down

0 comments on commit 3d5203d

Please sign in to comment.