Skip to content

useDisplayMedia

Category
Export Size
476 B
Last Changed
15 minutes ago
Related

响应式 mediaDevices.getDisplayMedia 流。

Demo

用法

ts
import { useDisplayMedia } from '@vueuse/core'

const { stream, start } = useDisplayMedia()

// 开始流式传输

start()
ts
const video = document.getElementById('video')

watchEffect(() => {
  // 在视频元素上预览
  video.srcObject = stream.value
})

类型声明

typescript
export interface UseDisplayMediaOptions extends ConfigurableNavigator {
  /**
   * 流是否已启用
   * @default false
   */
  enabled?: MaybeRef<boolean>
  /**
   * 流的视频媒体约束条件
   */
  video?: boolean | MediaTrackConstraints | undefined
  /**
   * 流的音频媒体约束条件
   */
  audio?: boolean | MediaTrackConstraints | undefined
}
/**
 * 响应式 `mediaDevices.getDisplayMedia` 获取屏幕共享流
 *
 * @see https://vueuse.org/useDisplayMedia
 * @param options
 */
export declare function useDisplayMedia(options?: UseDisplayMediaOptions): {
  isSupported: ComputedRef<boolean>
  stream: Ref<MediaStream | undefined, MediaStream | undefined>
  start: () => Promise<MediaStream | undefined>
  stop: () => void
  enabled: Ref<boolean, MaybeRef<boolean>>
}
export type UseDisplayMediaReturn = ReturnType<typeof useDisplayMedia>

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
Robert Rosman
Jelf
wheat
Abderrahim SOUBAI-ELIDRISI

变更日志

v10.10.0 on 5/27/2024
a3c6f - fix: stop stream when screen is not shared anymore (#3976)

Released under the MIT License.