mage-react-cam
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -0,5 +1,29 @@ | ||
type CustomMediaTrackCapabilitiesProps = MediaTrackCapabilities & { | ||
torch: any; | ||
}; | ||
interface CustomVideoTrackProps { | ||
getCapabilities: () => CustomMediaTrackCapabilitiesProps; | ||
getConstraints: () => CustomMediaTrackCapabilitiesProps; | ||
applyConstraints: (data: { | ||
advanced: { | ||
torch: any; | ||
}[]; | ||
}) => Promise<void>; | ||
} | ||
type GetTrackProps = { | ||
stop: () => void; | ||
}; | ||
export interface MediaSrcObjectProps { | ||
getVideoTracks: () => CustomVideoTrackProps[]; | ||
getTracks: () => GetTrackProps[]; | ||
removeTrack: (data: GetTrackProps) => void; | ||
} | ||
export type CustomMediaVideoProps = HTMLVideoElement & { | ||
srcObject: MediaSrcObjectProps; | ||
}; | ||
export type TReactCamRef = { | ||
snapshot: () => void; | ||
snapshot: () => string | undefined; | ||
zoomIn: () => void; | ||
zoomOut: () => void; | ||
video?: CustomMediaVideoProps; | ||
}; | ||
@@ -11,4 +35,5 @@ interface MageReactCamProps { | ||
height?: number; | ||
facingMode?: "environment" | "user"; | ||
} | ||
declare const MageReactCam: import("react").ForwardRefExoticComponent<MageReactCamProps & import("react").RefAttributes<TReactCamRef>>; | ||
export default MageReactCam; |
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react'; | ||
const MageReactCam = forwardRef(({ onUserMediaError, videoConstraints, width, height }, ref) => { | ||
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react"; | ||
const MageReactCam = forwardRef(({ onUserMediaError, videoConstraints, width, height, facingMode, }, ref) => { | ||
const internalRef = useRef(null); | ||
@@ -8,8 +8,8 @@ const snapshot = () => { | ||
const video = internalRef.current; | ||
const tempCanvas = document.createElement('canvas'); | ||
const tempContext = tempCanvas.getContext('2d'); | ||
const tempCanvas = document.createElement("canvas"); | ||
const tempContext = tempCanvas.getContext("2d"); | ||
tempCanvas.width = video.videoWidth; | ||
tempCanvas.height = video.videoHeight; | ||
tempContext?.drawImage(video, 0, 0, tempCanvas.width, tempCanvas.height); | ||
const dataURL = tempCanvas.toDataURL('image/jpeg'); | ||
const dataURL = tempCanvas.toDataURL("image/jpeg"); | ||
return dataURL; | ||
@@ -37,3 +37,3 @@ } | ||
video: { | ||
facingMode: 'environment', | ||
facingMode: facingMode || "environment", | ||
width: { ideal: width || 500 }, | ||
@@ -78,3 +78,3 @@ height: { ideal: height || 500 }, | ||
}); | ||
MageReactCam.displayName = 'MageReactCam'; | ||
MageReactCam.displayName = "MageReactCam"; | ||
export default MageReactCam; |
{ | ||
"name": "mage-react-cam", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A React component for capturing camera input", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
7609
117