Skip to content

useDisplayMedia

Category
Export Size
926 B
Last Changed
5 months ago
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

Show 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
} /** * 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
SerKo
Fernando Fernández
Robert Rosman
Jelf
wheat
Abderrahim SOUBAI-ELIDRISI

Changelog

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

Released under the MIT License.

AI-Driven Development
You. But 10x faster
The structured masterclass to help you leverage AI and build with an edge
Join Early