Skip to content

Commit 366bc8b

Browse files
Add: CodeSandboxes 116. & 117.
1 parent 2ebc005 commit 366bc8b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,16 +4209,22 @@ The WebRTC (Web Real-Time Communication) API enables peer-to-peer communication
42094209
<script>
42104210
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
42114211
.then(function(stream) {
4212-
var videoElement = document.createElement('video');
4212+
const videoElement = document.createElement('video');
42134213
videoElement.srcObject = stream;
42144214
document.body.appendChild(videoElement);
42154215
})
42164216
.catch(function(error) {
4217-
console.log('getUserMedia error:', error);
4217+
alert('getUserMedia error:', error);
42184218
});
42194219
</script>
42204220
```
42214221

4222+
[![Edit 116-WebRTC API](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/116-webrtc-api-8kfdt8)
4223+
4224+
- [^116]CodeSandbox: WebRTC API.
4225+
4226+
[^116]:[CodeSandbox: WebRTC API.](https://8kfdt8.csb.app/), last access: October 7, 2024.
4227+
42224228
- The code above demonstrates how to use the WebRTC API to access the user's audio and video devices and display a live video stream in the browser.
42234229
- The `getUserMedia()` method is called on the `mediaDevices` object to request access to the user's microphone and camera.
42244230
- If the user grants permission, a media stream is obtained, which can then be attached to a `<video>` element's `srcObject` property to display the live video feed.
@@ -4231,10 +4237,17 @@ The Media Capture and Streams API enables web applications to capture audio, vid
42314237
<input type="file" accept="image/*" capture="camera">
42324238
```
42334239

4240+
[![Edit 117-Media Capture and Streams API](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/117-media-capture-and-streams-api-4s97wh)
4241+
4242+
- [^117]CodeSandbox: Media Capture and Streams API.
4243+
4244+
[^117]:[CodeSandbox: Media Capture and Streams API.](https://4s97wh.csb.app/), last access: October 7, 2024.
4245+
42344246
- The code above demonstrates how to use the Media Capture API to enable image capture from the device's camera.
42354247
- The `<input>` element has the `type` attribute set to `file` to create a file input control.
42364248
- The `accept` attribute specifies the file types that can be selected, in this case, only image files are allowed (`image/*`).
42374249
- The `capture` attribute instructs the browser to open the device's camera when the input is clicked, allowing the user to capture a photo directly from the camera.
4250+
- If your device is a desktop computer, you'll likely get a typical file picker. Please use a mobile device for this example.
42384251

42394252
#### Offline Applications and Service Workers
42404253

0 commit comments

Comments
 (0)