Skip to content

useDisplayMedia ​

Category
Export Size
476 B
Last Changed
6 minutes ago
Related

Reactive mediaDevices.getDisplayMedia streaming.

Demo ​

Usage ​

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

const { stream, start } = useDisplayMedia()

// start streaming

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

watchEffect(() => {
  // preview on a video element
  video.srcObject = stream.value
})

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: Ref<MediaStream | undefined, MediaStream | undefined>
  start: () => Promise<MediaStream | undefined>
  stop: () => void
  enabled: Ref<boolean, MaybeRef<boolean>>
}
export type UseDisplayMediaReturn = ReturnType<typeof useDisplayMedia>

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
Anthony Fu
Robert Rosman
Jelf
wheat
Abderrahim SOUBAI-ELIDRISI

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.10.0 on 5/27/2024
a3c6f - fix: stop stream when screen is not shared anymore (#3976)

Released under the MIT License.