我为银行和其他机构提供认证服务。身份验证服务是通过应用程序或WEB页面分两步提供的,首先是使用前置摄像头的最终用户面部识别,其次是使用后置摄像头的护照、驾驶执照或身份证扫描图片。
问题在于网页身份验证: start.ondato.com/start
使用web rtc引擎调用摄像头的代码片段:
Please find snippet:
export default class {
state = {
requiredAudio: false,
cameraConstraints: [
{ audio: false, video: { width: { exact: 1920 }, height: { exact: 1080 } } },
{ audio: false, video: { width: { exact: 1280 }, height: { exact: 720 } } },
{ audio: false, video: { width: { exact: 640 }, height: { exact: 360 } } },
{ audio: false, video: true }
],
facingMode: { exact: 'environment' }
}
async startCamera() {
let error
for (const cameraSettings of this.state.cameraConstraints) {
console.log(cameraSettings)
cameraSettings.video.facingMode = this.state.facingMode
cameraSettings.audio = this.state.requiredAudio
const result = await this.getUserMediaInit(cameraSettings)
if (result) {
if (result.tracks) return { tracks: result.tracks }
else if (result.error) error = result.error
}
}
return { error }
}
async getUserMediaInit(cameraSettings) {
try {
const stream = await navigator.mediaDevices.getUserMedia(cameraSettings)
if (!stream) return
const tracks = await this.getUserMediaSuccess(stream)
if (tracks) return { tracks }
} catch (error) {
if (error === errorTypes.cameraStreamInactive ||
error && (error.name === 'AbortError' || error.name === 'NotReadableError')) {
return { error: { type: errorTypes.cameraStreamInactive } }
}
}
}
getUserMediaSuccess(stream) {
return new Promise((resolve, reject) => {
const video = document.getElementById(this.state.videoId)
const videoTrack = stream.getVideoTracks()[0]
const audioTrack = stream.getAudioTracks()[0]
video.srcObject = stream
video.onloadeddata = () => {
if (!stream.active) {
videoTrack.stop()
if (audioTrack) audioTrack.stop()
return reject(errorTypes.cameraStreamInactive)
}
const aspectRatio = video.videoHeight / video.videoWidth
if (aspectRatio < 1 && this.state.isAndroidPortrait) {
videoTrack.stop()
if (audioTrack) audioTrack.stop()
return reject()
}
this.cameraLoaded(video)
this.state.tracks = {
videoTrack,
audioTrack
}
resolve(this.state.tracks)
}
})
}
}
有一个页面是需要做人脸识别步骤的,这个是前置摄像头,完全没有问题,采集完人脸图片后,会要求你去第二步换护照,驾照或者身份证使用后置摄像头扫描。而此时问题就出现了,比如对于身份证读取可以启用Tele-Photo lens,在P40Pro,P30Pro,或者P20Pro上的BW摄像头,Web Page使用Web RTC引擎,Web进程,Web前端请求摄像头,每次收到单独提交的cameraID,因此无法选择运行哪个后置摄像头。
由于设备中的列表是随机的,我无法选择如何选择和运行所需的相机进行文档扫描。
摄像机是如何分类的,如何通过浏览器检测和区分它们?