Skip to content

Commit

Permalink
Fix background-blur.js (#852)
Browse files Browse the repository at this point in the history
* Simplify script
* Update constraint
* Fix bugs
  • Loading branch information
markafoltz authored Sep 27, 2024
1 parent 9e4b3b7 commit 4144077
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions image-capture/background-blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ navigator.mediaDevices.getUserMedia({ video: true })
})
.catch((error) => log("Argh!", `${error}`));

function buttonClick() {
async function buttonClick() {
const stream = document.querySelector("video").srcObject;
const [track] = stream.getVideoTracks();
const settings = track.getSettings();
const newState = !settings.backgroundBlur;
const constraints = {
advanced: [{ backgroundBlur: !settings.backgroundBlur }],
backgroundBlur: newState
};
track.applyConstraints(constraints)
.then(() => {
const settings = track.getSettings();
log(`Background blur is now ${settings.backgroundBlur ? "ON" : "OFF"}`);
})
.catch((error) => log("Argh!", `${error}`));
try {
await track.applyConstraints(constraints);
log(`Background blur constraint was set to ${newState ? "ON" : "OFF"}`);
} catch (error) {
log("Argh!", `${error}`);
}
}

function configurationChange(event) {
const settings = event.target.getSettings();
if ("backgroundBlur" in settings) {
log(`Background blur changed to ${settings.backgroundBlur ? "ON" : "OFF"}`);
log(`Background blur setting changed to ${settings.backgroundBlur ? "ON" : "OFF"}`);
}
}

0 comments on commit 4144077

Please sign in to comment.