我正在尝试通过Mobiles浏览器访问相机和麦克风。它没有允许任何弹出式访问权限。但是我们可以使用the laptop's browser
在Localhost上访问相同的功能。
我正在使用react js
。
我尝试的是
startCamera = () => {
if (!('mediaDevices' in navigator)) {
navigator.mediaDevices = {};
}
if (!('getUserMedia' in navigator.mediaDevices)) {
navigator.mediaDevices.getUserMedia = function (constraints) {
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented!'));
}
return new Promise(function (resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
navigator.mediaDevices.getUserMedia({
video: { facingMode: 'user' },
audio: true
}).then((stream) => {
console.log('recording started');
return this.startRecording(stream)
}).then(recordedChunks => {
let recordedBlob = new Blob(recordedChunks, { type: "video/webm" });
this.props.getVideoUploadLink(this.props.candidateScore[0].jdId, this.props.candidateScore[0].resumeId, recordedBlob);
this.setState({ downloadUrl: URL.createObjectURL(recordedBlob) });
})
.catch(console.log);
}
那么,我需要合并一些额外的东西来通过移动浏览器访问权限吗?谢谢
来自Chrome 48前进,如果协议不是HTTPS,则忽略了getusermedia的呼叫。除Localhost(仍然接受不安全的HTTP用于开发目的)外。
如果您要尝试从手机到笔记本电脑,则需要https。
一些像Create React应用这样的锅炉允许您使用https启动开发服务器:
https = true npm start