Skip to content

useDisplayMedia

Category
Export Size
883 B
Last Changed
last month
Related

Reactive mediaDevices.getDisplayMedia streaming.

Demo

Usage

vue
<script setup lang="ts">
import { 
useDisplayMedia
} from '@vueuse/core'
import {
useTemplateRef
} from 'vue'
const {
stream
,
start
} =
useDisplayMedia
()
// start streaming
start
()
const
videoRef
=
useTemplateRef
('video')
watchEffect
(() => {
// preview on a video element
videoRef
.value.srcObject =
stream
.
value
}) </script> <template> <
video
ref
="
video
" />
</template>

Type Declarations

ts
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
} export interface UseDisplayMediaReturn extends Supportable {
stream
:
ShallowRef
<MediaStream | undefined>
start
: () =>
Promise
<MediaStream | undefined>
stop
: () => void
enabled
:
ShallowRef
<boolean>
} /** * Reactive `mediaDevices.getDisplayMedia` streaming * * @see https://vueuse.org/useDisplayMedia * @param options */ export declare function
useDisplayMedia
(
options
?: UseDisplayMediaOptions,
): UseDisplayMediaReturn

Source

SourceDemoDocs

Contributors

Anthony Fu
IlyaL
Anthony Fu
Vida Xie
SerKo
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.