Skip to content

Commit

Permalink
Editorial: Wrap examples using 'await' in 'async' functions (for linter)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-be committed Oct 30, 2017
1 parent 8a803b5 commit ec61f09
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions getusermedia.html
Original file line number Diff line number Diff line change
Expand Up @@ -4276,50 +4276,56 @@ <h2>Methods</h2>
</pre>
<p>Here's an example of use of ideal:</p>
<pre class="example">
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.aspectRatio || !supports.facingMode) {
// Treat like an error.
}
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {min: 320, ideal: 1280, max: 1920},
height: {min: 240, ideal: 720, max: 1080},
frameRate: 30, // Shorthand for ideal.
facingMode: {
exact: 'environment'
// facingMode: "environment" would be optional.
}
async function useIdeal() {
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.aspectRatio || !supports.facingMode) {
// Treat like an error.
}
});
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {min: 320, ideal: 1280, max: 1920},
height: {min: 240, ideal: 720, max: 1080},
frameRate: 30, // Shorthand for ideal.
facingMode: {
exact: 'environment'
// facingMode: "environment" would be optional.
}
}
});
}
</pre>
<p>Here's an example of "I want 720p, but I can accept up to 1080p and
down to VGA.":</p>
<pre class="example">
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.width || !supports.height) {
// Treat like an error.
}
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {min: 640, ideal: 1280, max: 1920},
height: {min: 480, ideal: 720, max: 1080},
async function constrainVideo() {
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.width || !supports.height) {
// Treat like an error.
}
});
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {min: 640, ideal: 1280, max: 1920},
height: {min: 480, ideal: 720, max: 1080},
}
});
}
</pre>
<p>Here's an example of "I want a front-facing camera and it must be
VGA.":</p>
<pre class="example">
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.width || !supports.height || !supports.facingMode) {
// Treat like an error.
}
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: {exact: 'user'},
width: {exact: 640},
height: {exact: 480}
async function specifyCamera() {
const supports = navigator.mediaDevices.getSupportedConstraints();
if (!supports.width || !supports.height || !supports.facingMode) {
// Treat like an error.
}
});
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: {exact: 'user'},
width: {exact: 640},
height: {exact: 480}
}
});
}
</pre>
</section>
<section>
Expand Down

0 comments on commit ec61f09

Please sign in to comment.