|
1 |
| -# Webcam-canvas |
| 1 | +# 📸 React Webcam Ultimate |
| 2 | + |
| 3 | +Ultimate tool for working with media stream and displaying it in your React application |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Install with [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/) |
| 8 | + |
| 9 | +```shell |
| 10 | +npm i react-webcam-ultimate |
| 11 | +# or |
| 12 | +yarn add react-webcam-ultimate |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +```jsx |
| 18 | +import React from 'react'; |
| 19 | +import ReactDOM from 'react-dom'; |
| 20 | +import { Webcam } from 'react-webcam-ultimate'; |
| 21 | + |
| 22 | +const App = () => ( |
| 23 | + <Webcam /> |
| 24 | +); |
| 25 | + |
| 26 | +const root = ReactDOM.createRoot(document.getElementById('root')); |
| 27 | +root.render(<App/>); |
| 28 | +``` |
| 29 | + |
| 30 | +### Get webcam snapshot |
| 31 | + |
| 32 | +```jsx |
| 33 | +import { Webcam } from 'react-webcam-ultimate'; |
| 34 | + |
| 35 | +const YourComponent = () => ( |
| 36 | + <Webcam mirrored> |
| 37 | + {({ getSnapshot }) => ( |
| 38 | + <button onClick={() => getSnapshot({ quality: 0.8 })}> |
| 39 | + Make photo |
| 40 | + </button> |
| 41 | + )} |
| 42 | + </Webcam> |
| 43 | +); |
| 44 | +``` |
| 45 | + |
| 46 | +## API |
| 47 | + |
| 48 | +You can pass any supported [properties](https://developer.mozilla.org/ru/docs/Web/HTML/Element/video) to the underlying video tag (eg `autoplay`, `className`, etc). However, for convenience, the component uses its own values for these properties, but you can reassign them without any problems: |
| 49 | +| **Prop** | **Type** | **Default** | |
| 50 | +| ------------------------- | -------- | ------------ | |
| 51 | +| muted | boolean | true | |
| 52 | +| autoPlay | boolean | true | |
| 53 | +| playsInline | boolean | true | |
| 54 | +| controls | boolean | false | |
| 55 | + |
| 56 | +The component also supports many properties for more specific work: |
| 57 | +| **Prop** | **Type** | **Default** | **Note** | |
| 58 | +| ------------------------- | -------- | ------------ | --------------------------------------------------------------------------------------- | |
| 59 | +| stream | boolean | | external media stream (turns off internal media stream handling logic) | |
| 60 | +| mirrored | boolean | false | show camera preview and get the screenshot mirrored | |
| 61 | +| mainCamera | boolean | false | should use a main camera (requires Navigator.mediaDevices.enumerateDevices) | |
| 62 | +| frontCamera | boolean | false | should use a front camera (MediaTrackConstraints['facingFront'] === 'user') | |
| 63 | +| applyConstraints | boolean | false | should new constraints be applied to the media stream | |
| 64 | +| cameraResolutionType | string | | video track resolution size - 'UHD' | 'QHD' | 'FHD' | 'HD' | |
| 65 | +| cameraResolutionMode | string | 'ideal' | video track resolution mode - 'min' | 'max' | 'ideal' | 'exact' | |
| 66 | +| audioConstraints | object | | audio track constraints - MediaStreamConstraints['audio'] | |
| 67 | +| videoConstraints | object | | video track constraints - MediaStreamConstraints['video'] | |
| 68 | +| requestTimeLimit | number | | limiting the media stream request by time | |
| 69 | +| onStreamRequest | function | | callback for when component requests a media stream | |
| 70 | +| onStreamStart | function | | callback for when component starts a media stream | |
| 71 | +| onStreamStop | function | | callback for when component stops a media stream | |
| 72 | +| onStreamError | function | | callback for when component can't receive a media stream | |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
0 commit comments