Skip to content

useDisplayMedia

Category
Export Size
496 B
Last Changed
last month
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
})

Type Declarations

Show Type Declarations
typescript
export interface UseDisplayMediaOptions extends ConfigurableNavigator {
  /**
   * If the stream is enabled
   * @default false
   */
  enabled?: MaybeRef<boolean>
  /**
   * If the stream video media constraints
   */
  video?: boolean | MediaTrackConstraints | undefined
  /**
   * If the stream audio media constraints
   */
  audio?: boolean | MediaTrackConstraints | undefined
}
/**
 * Reactive `mediaDevices.getDisplayMedia` streaming
 *
 * @see https://vueuse.org/useDisplayMedia
 * @param options
 */
export declare function useDisplayMedia(options?: UseDisplayMediaOptions): {
  isSupported: ComputedRef<boolean>
  stream: ShallowRef<MediaStream | undefined, MediaStream | undefined>
  start: () => Promise<MediaStream | undefined>
  stop: () => void
  enabled:
    | Ref<boolean, boolean>
    | ShallowRef<boolean, boolean>
    | WritableComputedRef<boolean, boolean>
    | ShallowRef<true, true>
    | ShallowRef<false, false>
}
export type UseDisplayMediaReturn = ReturnType<typeof useDisplayMedia>

Source

SourceDemoDocs

Contributors

Anthony Fu
丶远方
IlyaL
Anthony Fu
Fernando Fernández
Robert Rosman
Jelf
wheat
Abderrahim SOUBAI-ELIDRISI

Changelog

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
c6c6e - feat: use useEventListener where it was not being used (#4479)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
a3c6f - fix: stop stream when screen is not shared anymore (#3976)

Released under the MIT License.