BarcodeScanner
Name | Type | Default Value | Description |
---|---|---|---|
options | ScanOptions | DEFAULT_OPTIONS | / |
onCapture | (barcodes: DetectedBarcode[]) => any | / | 当检测到指定类型的码时触发 |
trackConstraints | MediaTrackConstraints | DEFAULT_CONSTRAINTS | 基于MediaTrackConstraints (opens in a new tab)标准 |
useCamera
Name | Type | Default Value | Description |
---|---|---|---|
ref | RefObject<HTMLVideoElement> | Required* | HTMLVideoElement实例 |
trackConstraints | MediaTrackConstraints | DEFAULT_CONSTRAINTS | 基于MediaTrackConstraints (opens in a new tab)标准 |
DEFAULT_CONSTRAINTS
{
width: { min: 640, ideal: 1280 },
height: { min: 480, ideal: 720 },
facingMode: {
ideal: 'environment'
},
advanced: [
{ width: 1920, height: 1280 },
{ aspectRatio: 1.333 }
]
}
useScanning
Name | Type | Default Value | Description |
---|---|---|---|
ref | RefObject<HTMLVideoElement> | Required* | HTMLVideoElement实例 |
options | ScanOptions | DEFAULT_OPTIONS | delay: 扫描间隔 formats: 扫描的条码格式, 支持格式 |
DEFAULT_OPTIONS
{
delay: 1000,
formats: ['qr_code']
}
useTorch
Name | Type | Default Value | Description |
---|---|---|---|
open | Boolean | false | 是否默认启用闪光灯 |
useStreamState
管理通过useCamera
获取到的stream
function useStreamState (): [MediaStream | undefined, (newState: MediaStream) => void]
Types
ScanOptions
interface ScanOptions {
delay?: number
formats?: string[]
}