Skip to content

Commit

Permalink
use displayMediaStarted boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
eronnen committed Oct 5, 2023
1 parent 6a37c39 commit 9c02ebd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/content/getusermedia/getdisplaymedia/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const preferredDisplaySurface = document.getElementById('displaySurface');
const startStopButton = document.getElementById('startButton');
const videoElement = document.querySelector('video');
let displayMediaStarted = false;

if (adapter.browserDetails.browser === 'chrome' &&
adapter.browserDetails.version >= 107) {
Expand All @@ -22,6 +23,7 @@ if (adapter.browserDetails.browser === 'chrome' &&
}

function handleSuccess(stream) {
displayMediaStarted = true;
startStopButton.textContent = 'Stop';
preferredDisplaySurface.disabled = true;
videoElement.srcObject = stream;
Expand Down Expand Up @@ -49,7 +51,7 @@ function errorMsg(msg, error) {


startStopButton.addEventListener('click', () => {
if (startStopButton.textContent === 'Start') {
if (!displayMediaStarted) {
const options = {audio: true, video: true};
const displaySurface = preferredDisplaySurface.options[preferredDisplaySurface.selectedIndex].value;
if (displaySurface !== 'default') {
Expand All @@ -64,6 +66,7 @@ startStopButton.addEventListener('click', () => {
videoElement.srcObject.getTracks().forEach(track => track.stop());
videoElement.srcObject = null;
startStopButton.textContent = 'Start';
displayMediaStarted = false;
}
});

Expand Down

0 comments on commit 9c02ebd

Please sign in to comment.