📄 useDisplayMedia¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 5 |
| 📦 Imports | 9 |
| ⚡ Async/Await Patterns | 4 |
| 🟢 Vue Composition API | 1 |
| 📐 Interfaces | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useDisplayMedia/index.ts
📦 Imports¶
| Name | Source |
|---|---|
MaybeRef |
vue |
ShallowRef |
vue |
ConfigurableNavigator |
../_configurable |
Supportable |
../types |
shallowRef |
vue |
watch |
vue |
defaultNavigator |
../_configurable |
useEventListener |
../useEventListener |
useSupported |
../useSupported |
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| await-expression | useDisplayMedia |
navigator!.mediaDevices.getDisplayMedia(constraint), _start() | none |
| async-function | _start |
navigator!.mediaDevices.getDisplayMedia(constraint) | none |
| async-function | _stop |
none | none |
| async-function | start |
_start() | none |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
watch |
watch | none | none |
Functions¶
useDisplayMedia(options: UseDisplayMediaOptions): UseDisplayMediaReturn¶
Reactive mediaDevices.getDisplayMedia streaming
Parameters:
optionsany: No description
See: https://vueuse.org/useDisplayMedia
Raw JSDoc
Calls:
shallowRef (from vue)useSupported (from ../useSupported)navigator!.mediaDevices.getDisplayMediastream.value?.getTracks().forEachuseEventListener (from ../useEventListener)t.stop_stop_startwatch (from vue)
Code
export function useDisplayMedia(options: UseDisplayMediaOptions = {}): UseDisplayMediaReturn {
const enabled = shallowRef(options.enabled ?? false)
const video = options.video
const audio = options.audio
const { navigator = defaultNavigator } = options
const isSupported = useSupported(() => navigator?.mediaDevices?.getDisplayMedia)
const constraint: MediaStreamConstraints = { audio, video }
const stream = shallowRef<MediaStream | undefined>()
async function _start() {
if (!isSupported.value || stream.value)
return
stream.value = await navigator!.mediaDevices.getDisplayMedia(constraint)
stream.value?.getTracks().forEach(t => useEventListener(t, 'ended', stop, { passive: true }))
return stream.value
}
async function _stop() {
stream.value?.getTracks().forEach(t => t.stop())
stream.value = undefined
}
function stop() {
_stop()
enabled.value = false
}
async function start() {
await _start()
if (stream.value)
enabled.value = true
return stream.value
}
watch(
enabled,
(v) => {
if (v)
_start()
else
_stop()
},
{ immediate: true },
)
return {
isSupported,
stream,
start,
stop,
enabled,
}
}
Internal helpers¶
Declared inside another function in this file.
_start(): Promise<any>¶
Returns: Promise<any>
Calls:
navigator!.mediaDevices.getDisplayMediastream.value?.getTracks().forEachuseEventListener (from ../useEventListener)
Code
_stop(): Promise<void>¶
Returns: Promise<void>
Calls:
stream.value?.getTracks().forEacht.stop
Code
stop(): void¶
Returns: void
Calls:
_stop
start(): Promise<any>¶
Returns: Promise<any>
Calls:
_start
Code
Interfaces¶
UseDisplayMediaOptions¶
Interface Code
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
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
enabled |
MaybeRef<boolean> |
✓ | not shown |
video |
boolean \| MediaTrackConstraints \| undefined |
✓ | not shown |
audio |
boolean \| MediaTrackConstraints \| undefined |
✓ | not shown |
UseDisplayMediaReturn¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
stream |
ShallowRef<MediaStream \| undefined> |
✗ | not shown |
start |
() => Promise<MediaStream \| undefined> |
✗ | not shown |
stop |
() => void |
✗ | not shown |
enabled |
ShallowRef<boolean> |
✗ | not shown |
Generated by Syntax Scribe