Skip to content

useDevicesList

Category
Export Size
1.09 kB
Last Changed
15 minutes ago
Related

响应式 enumerateDevices 列出可用的输入/输出设备。

Demo

相机 (0)
麦克风 (0)
扬声器 (0)

用法

js
import { useDevicesList } from '@vueuse/core'

const {
  devices,
  videoInputs: cameras,
  audioInputs: microphones,
  audioOutputs: speakers,
} = useDevicesList()

组件

vue
<template>
  <UseDevicesList v-slot="{ videoInputs, audioInputs, audioOutputs }">
    摄像头:{{ videoInputs }}
    麦克风:{{ audioInputs }}
    扬声器:{{ audioOutputs }}
  </UseDevicesList>
</template>

类型声明

typescript
export interface UseDevicesListOptions extends ConfigurableNavigator {
  onUpdated?: (devices: MediaDeviceInfo[]) => void
  /**
   * 如果权限未授予,则立即请求权限,否则标签和设备 ID 可能为空
   *
   * @default false
   */
  requestPermissions?: boolean
  /**
   * 请求媒体权限类型
   *
   * @default { audio: true, video: true }
   */
  constraints?: MediaStreamConstraints
}
export interface UseDevicesListReturn {
  /**
   * 所有设备
   */
  devices: Ref<MediaDeviceInfo[]>
  videoInputs: ComputedRef<MediaDeviceInfo[]>
  audioInputs: ComputedRef<MediaDeviceInfo[]>
  audioOutputs: ComputedRef<MediaDeviceInfo[]>
  permissionGranted: Ref<boolean>
  ensurePermissions: () => Promise<boolean>
  isSupported: Ref<boolean>
}
/**
 * 响应式 `enumerateDevices` 列出可用的输入/输出设备
 *
 * @see https://vueuse.org/useDevicesList
 * @param options
 */
export declare function useDevicesList(
  options?: UseDevicesListOptions,
): UseDevicesListReturn

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
wheat
Espen Solli Grande
Anthony Fu
Félix Zapata
vaakian X
vaakian X
Jelf
Andras Serfozo
Alex Kozack

变更日志

v11.2.0 on 10/30/2024
bf0f2 - fix: handle NotAllowedError on reject/close (#4246)
v10.0.0-beta.2 on 3/28/2023
0823d - fix: show devices for Firefox (#2798)
v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.