Primitives / foldkit-primitives/device
mediaDevices
function · packages/primitives/src/device/media-devices.ts:71
function mediaDevices<const Name extends string>(config: {
readonly name: Name
readonly create?:
((navigator: Navigator) => MediaDevicesHandle | null) | undefined
}): Bundle.Bundle<
Name,
void,
{
readonly status: 'unknown' | 'ready' | 'denied'
readonly devices: readonly {
readonly deviceId: string
readonly groupId: string
readonly kind: 'audioinput' | 'audiooutput' | 'videoinput'
readonly label: string
}[]
readonly lastError: string | null
},
| { readonly _tag: 'Denied' }
| { readonly _tag: 'Failed'; readonly message: string }
| { readonly _tag: 'Scan' }
| { readonly _tag: 'DevicesChanged' }
| {
readonly _tag: 'Refreshed'
readonly devices: readonly {
readonly deviceId: string
readonly groupId: string
readonly kind: 'audioinput' | 'audiooutput' | 'videoinput'
readonly label: string
}[]
},
never,
never,
never,
void,
{},
{}
>Media devices as a bundle factory: the enumerated device list in the
Model, scanned on placement and re-scanned on every devicechange.
Denial lands as denied while keeping the last list (actionable UI over
stale data, like Geolocation's last fix); any other failure keeps the
list and notes the error. No media-devices API yields an empty stream
and a Failed scan instead of throwing.