Skip to content

Commit

Permalink
Expose background blur setting
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Jan 11, 2023
1 parent ba7d7d4 commit eb50588
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions image-capture/background-blur.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ <h3>Background</h3>
{% include output_helper.html %}

{% include js_snippet.html filename='background-blur.js' %}

<script>
log = ChromeSamples.log;
</script>
17 changes: 16 additions & 1 deletion image-capture/background-blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ navigator.mediaDevices.getUserMedia({ video: true })

const [track] = mediaStream.getVideoTracks();
const capabilities = track.getCapabilities();
const settings = track.getSettings();

if ("backgroundBlur" in settings) {
log(`Background blur is ${settings.backgroundBlur ? "ON" : "OFF"}`);
}

// Check whether toggling background blur is supported or not.
if (capabilities.backgroundBlur?.length !== 2) {
Expand All @@ -12,6 +17,9 @@ navigator.mediaDevices.getUserMedia({ video: true })
);
}

// Listen to background blur changes.
track.onconfigurationchange = onconfigurationchange;

const toggleButton = document.querySelector("button");
toggleButton.onclick = () => {
const backgroundBlur = track.getSettings().backgroundBlur;
Expand All @@ -21,4 +29,11 @@ navigator.mediaDevices.getUserMedia({ video: true })
};
toggleButton.disabled = false;
})
.catch((error) => ChromeSamples.log("Argh!", `${error}`));
.catch((error) => log("Argh!", `${error}`));

function onconfigurationchange(event) {
const settings = event.target.getSettings();
if ("backgroundBlur" in settings) {
log(`Background blur is now ${settings.backgroundBlur ? "ON" : "OFF"}`);
}
}

0 comments on commit eb50588

Please sign in to comment.