Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New mute/unmute prop for video preview #404

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The props here are specific to this component but one can pass any prop to the u
| mirrored | boolean | false | show camera preview and get the screenshot mirrored |
| minScreenshotHeight | number | | min height of screenshot |
| minScreenshotWidth | number | | min width of screenshot |
| mutePreview | boolean | true | mute/unmute video preview |
| onUserMedia | function | noop | callback for when component receives a media stream |
| onUserMediaError | function | noop | callback for when component can't receive a media stream with MediaStreamError param |
| screenshotFormat | string | 'image/webp' | format of screenshot |
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/react-webcam.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ it('renders correctly', () => {
expect(tree.toJSON()).toMatchSnapshot();
});

it('sets <video/> muted to false when props.audio is true', () => {
it('sets <video/> muted to false when props.mutePreview is false', () => {
const tree = renderer
.create(
<Webcam
Expand All @@ -46,6 +46,7 @@ it('sets <video/> muted to false when props.audio is true', () => {
imageSmoothing={false}
minScreenshotHeight={1000}
minScreenshotWidth={1000}
mutePreview={false}
onUserMedia={() => {}}
onUserMediaError={() => {}}
screenshotFormat="image/png"
Expand Down
4 changes: 3 additions & 1 deletion src/react-webcam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type WebcamProps = Omit<React.HTMLProps<HTMLVideoElement>, "ref"> & {
mirrored: boolean;
minScreenshotHeight?: number;
minScreenshotWidth?: number;
mutePreview?: boolean;
onUserMedia: (stream: MediaStream) => void;
onUserMediaError: (error: string | DOMException) => void;
screenshotFormat: "image/webp" | "image/png" | "image/jpeg";
Expand Down Expand Up @@ -391,6 +392,7 @@ export default class Webcam extends React.Component<WebcamProps, WebcamState> {
screenshotQuality,
minScreenshotWidth,
minScreenshotHeight,
mutePreview = true,
audioConstraints,
videoConstraints,
imageSmoothing,
Expand All @@ -412,7 +414,7 @@ export default class Webcam extends React.Component<WebcamProps, WebcamState> {
autoPlay
disablePictureInPicture={disablePictureInPicture}
src={state.src}
muted={!audio}
muted={mutePreview}
playsInline
ref={ref => {
this.video = ref;
Expand Down