简体   繁体   English

JS 如何在 Firefox 中分别检查对网络摄像头和麦克风的访问

[英]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中不支持cameramicrophone 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.

相关问题 如何在 FireFox 中检查访问麦克风的权限是否已被用户拒绝 - How to check if the permission to access microphone has been rejected by the user in FireFox 如何在JS中访问麦克风? - How to access to the microphone in JS? 如何检查Firefox是否使用asm.js代码? - How can I check if Firefox uses asm.js code? 如何访问Firefox扩展资源 - How can I access firefox extension resources Chrome 中的网络摄像头 js 错误:无法访问网络摄像头 - Webcam js Error in Chrome: Could not access webcam 为什么有2个不同的闪存权限对话框用于网络摄像头/麦克风访问 - Why are there 2 different flash permission dialogs for webcam / microphone access chrome 扩展可以访问 background.js 中的网络摄像头吗? - Can a chrome extension access a webcam in the background.js? iOS 12上的麦克风访问FIrefox和Chrome - Microphone access FIrefox and Chrome on iOS 12 当检测到静音(JS)时,如何提取前面的音频(来自麦克风)作为缓冲区? - How can I extract the preceding audio (from microphone) as a buffer when silence is detected (JS)? 如何使用 webcam.js 在移动设备中打开后置摄像头? - How can I open rear camera in mobile device using webcam.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM