[英]JS how can I separately check access to webcam and microphone in Firefox
I need to know if there is a way to check access to a microphone or to a webcam for Firefox not using navigator.mediaDevices.getUserMedia
.我需要知道是否有办法在不使用
navigator.mediaDevices.getUserMedia
的情况下检查对 Firefox 的麦克风或网络摄像头的访问。 For example, this code navigator.permissions.query({name : 'camera'})
works very well for Chrome, but Firefox doesn't support camera
and microphone
in permission.query
.例如,这段代码
navigator.permissions.query({name : 'camera'})
在 Chrome 上工作得很好,但 Firefox 在permission.query
中不支持camera
和microphone
。 The reason why I do not want to use navigator.mediaDevices.getUserMedia
is that the permission modal for the camera and microphone will be shown separately if I make it like this navigator.mediaDevices.getUserMedia({video: true})
for webcam and navigator.mediaDevices.getUserMedia({audio: true})
for microphone.我不想使用
navigator.mediaDevices.getUserMedia
是,如果我像这样navigator.mediaDevices.getUserMedia({video: true})
for webcam and navigator.mediaDevices.getUserMedia({audio: true})
将单独显示相机和麦克风的权限模式navigator.mediaDevices.getUserMedia({audio: true})
用于麦克风。 Thanks.谢谢。
For anyone looking for an answer, this isn't perfect but it does separate the permissions.对于任何寻找答案的人来说,这并不完美,但它确实将权限分开。 If you want the audio permission to still fire when you deny permission to video, then take the getUserMedia function out of the promise chain.
如果您希望在拒绝视频权限时仍然激活音频权限,请从承诺链中取出 getUserMedia 函数。
Also, this is in coffeescript.另外,这是在coffeescript中。
cameraAttributes = {}
navigator.mediaDevices.getUserMedia {video: true}
.then ->
navigator.mediaDevices.enumerateDevices()
.then (devices) =>
videoDevices = devices.filter (test) -> test.kind is 'videoinput'
cameraAttributes =
videoDevices: videoDevices
cameraAttributes
.then ->
navigator.mediaDevices.getUserMedia {audio: true}
.then (devices) =>
audioDevices = devices.filter (test) -> test.kind is 'audioinput'
Object.assign cameraAttributes, audioDevices
cameraAttributes
.catch (error) =>
if error instanceof DOMException
console.log "Audio - #{error}"
else
console.error error
cameraAttributes
.catch (error) =>
if error instanceof DOMException
console.log "Video - #{error}"
else
console.error error
cameraAttributes =
videoDevices: []
audioDevices: []
cameraAttributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.