コンテンツにスキップ

useDevicesList

カテゴリ
エクスポートサイズ
1.09 KB
最終更新日
先週
関連

リアクティブな enumerateDevices は、利用可能な入力/出力デバイスをリスト表示します。

デモ

カメラ (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 }">
    Cameras: {{ videoInputs }}
    Microphones: {{ audioInputs }}
    Speakers: {{ audioOutputs }}
  </UseDevicesList>
</template>

型宣言

型宣言を表示
typescript
export interface UseDevicesListOptions extends ConfigurableNavigator {
  onUpdated?: (devices: MediaDeviceInfo[]) => void
  /**
   * Request for permissions immediately if it's not granted,
   * otherwise label and deviceIds could be empty
   *
   * @default false
   */
  requestPermissions?: boolean
  /**
   * Request for types of media permissions
   *
   * @default { audio: true, video: true }
   */
  constraints?: MediaStreamConstraints
}
export interface UseDevicesListReturn {
  /**
   * All devices
   */
  devices: Ref<MediaDeviceInfo[]>
  videoInputs: ComputedRef<MediaDeviceInfo[]>
  audioInputs: ComputedRef<MediaDeviceInfo[]>
  audioOutputs: ComputedRef<MediaDeviceInfo[]>
  permissionGranted: Ref<boolean>
  ensurePermissions: () => Promise<boolean>
  isSupported: Ref<boolean>
}
/**
 * Reactive `enumerateDevices` listing available input/output devices
 *
 * @see https://vueuse.dokyumento.jp/useDevicesList
 * @param options
 */
export declare function useDevicesList(
  options?: UseDevicesListOptions,
): UseDevicesListReturn

ソース

ソースデモドキュメント

コントリビューター

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

変更履歴

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2 サポートの削除、バンドルの最適化、クリーンアップ (#4349)
v11.2.0 2024/10/30
bf0f2 - fix: reject/close での NotAllowedError を処理 (#4246)
v10.0.0-beta.2 2023/3/28
0823d - fix: Firefox でデバイスを表示 (#2798)
v9.11.0 2023/1/17
d5321 - fix(components): defineComponent を pure としてマーク (#2623)

MITライセンスでリリースされています。