Skip to content

Commit 3e2f3ba

Browse files
committed
Fix/improve example
1 parent 31a998b commit 3e2f3ba

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,25 @@ For example, using **jsDelivr**:
9191
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vitallens.browser.js"></script>
9292

9393
<!-- Use with core API -->
94-
<script>
95-
// vitallens.js is exposed as a global, for example as window.VitalLens.
96-
const vl = new VitalLens({ method: 'vitallens', apiKey: 'YOUR_API_KEY' });
97-
// Suppose myMediaStream and myVideoElement are defined:
98-
vl.addVideoStream(myMediaStream, myVideoElement);
99-
vl.addEventListener('vitals', (data) => console.log(data));
100-
vl.startVideoStream();
94+
<video id="my-video" autoplay muted playsinline></video>
95+
<script type="module">
96+
import { VitalLens } from 'https://cdn.jsdelivr.net/npm/vitallens';
97+
98+
(async () => {
99+
try {
100+
const videoElement = document.getElementById('my-video');
101+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
102+
videoElement.srcObject = stream;
103+
104+
const vl = new VitalLens({ method: 'vitallens', apiKey: 'YOUR_API_KEY' });
105+
106+
await vl.setVideoStream(stream, videoElement); // Use await here
107+
vl.addEventListener('vitals', (data) => console.log(data));
108+
vl.startVideoStream();
109+
} catch (err) {
110+
console.error("Failed to start VitalLens:", err);
111+
}
112+
})();
101113
</script>
102114

103115
<!-- Or use our widget -->

0 commit comments

Comments
 (0)