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

Change errorMessages in props to optional #64

Open
wants to merge 1 commit 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
17 changes: 10 additions & 7 deletions src/components/Camera/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ import {
} from './types';
import { Container, Wrapper, Canvas, Cam, ErrorMsg } from './styles';

const defaultErrorMessages = {
noCameraAccessible: 'No camera device accessible. Please connect your camera or try a different browser.',
permissionDenied: 'Permission denied. Please refresh and give camera permission.',
switchCamera:
'It is not possible to switch camera to different one because there is only one video device accessible.',
canvas: 'Canvas is not supported.',
};

export const Camera = React.forwardRef<unknown, CameraProps>(
(
{
facingMode = 'user',
aspectRatio = 'cover',
numberOfCamerasCallback = () => null,
videoSourceDeviceId = undefined,
errorMessages = {
noCameraAccessible: 'No camera device accessible. Please connect your camera or try a different browser.',
permissionDenied: 'Permission denied. Please refresh and give camera permission.',
switchCamera:
'It is not possible to switch camera to different one because there is only one video device accessible.',
canvas: 'Canvas is not supported.',
},
errorMessages: propsErrorMessages = defaultErrorMessages,
videoReadyCallback = () => null,
},
ref,
Expand All @@ -40,6 +42,7 @@ export const Camera = React.forwardRef<unknown, CameraProps>(
const [torchSupported, setTorchSupported] = useState<boolean>(false);
const [torch, setTorch] = useState<boolean>(false);
const mounted = useRef(false);
const errorMessages = { ...defaultErrorMessages, ...propsErrorMessages };

useEffect(() => {
mounted.current = true;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Camera/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface CameraProps {
aspectRatio?: AspectRatio;
numberOfCamerasCallback?(numberOfCameras: number): void;
videoSourceDeviceId?: string | undefined;
errorMessages: {
errorMessages?: {
noCameraAccessible?: string;
permissionDenied?: string;
switchCamera?: string;
Expand Down