Skip to content

Commit

Permalink
add applyconstraints button
Browse files Browse the repository at this point in the history
  • Loading branch information
Mounir Lamouri committed Nov 15, 2024
1 parent a86597e commit d49e763
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions getdisplaymedia/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC
<button id="startButton" disabled>Start</button>
<button id="stopButton" disabled>Stop</button>
<button id="replayButton" disabled>Replay</button>
<button id="applyConstraints" disabled>applyConstraints</button>
<fieldset id="options" style="display:none">
<legend>Advanced options</legend>
<select id="displaySurface">
Expand Down
18 changes: 18 additions & 0 deletions getdisplaymedia/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const preferredDisplaySurface = document.getElementById('displaySurface');
const startButton = document.getElementById('startButton');
const stopButton = document.getElementById('stopButton');
const replayButton = document.getElementById('replayButton');
const applyConstraints = document.getElementById('applyConstraints');

let recorder = null;
let recordChunks =[];
Expand Down Expand Up @@ -70,12 +71,15 @@ startButton.addEventListener('click', () => {
.then(handleSuccess, handleError).then(() => {
stopButton.disabled = false;
replayButton.disabled = true;
applyConstraints.disabled = false;
})
});

stopButton.addEventListener('click', () => {
startButton.disabled = false;
stopButton.disabled = true;
applyConstraints.disable = true;

video.srcObject.getTracks().forEach(track => track.stop());

recorder.addEventListener('stop', e => {
Expand All @@ -99,6 +103,20 @@ replayButton.addEventListener('click', () => {
recordChunks = [];
});

applyConstraints.addEventListener('click', () => {
console.log('apply constraints');
const stream = video.srcObject;

// Apply a random constraint on the stream, just for applying one.
stream.getVideoTracks()[0].applyConstraints({
width: { min: 640, ideal: 1280 },
height: { min: 480, ideal: 720 },
advanced: [{ width: 1920, height: 1280 }, { aspectRatio: 1.333 }],
}).then(() => {
console.log('constraints applied');
});
});

if ((navigator.mediaDevices && 'getDisplayMedia' in navigator.mediaDevices)) {
startButton.disabled = false;
} else {
Expand Down

0 comments on commit d49e763

Please sign in to comment.