useLocalMedia
The useLocalMedia hook exposes methods to fetch and produce streams of a local peer.
| Name | Description | Return Type | Params |
|---|---|---|---|
| fetchStream | Fetches a stream from the local peer | Promise<MediaStream> | mediaDeviceKind: "mic" | "cam" |
| produceStream | Produces a stream to the local peer | Promise<Producer<AppData>> | {stream: MediaStream; label: string; appData: AppData} |
| stopProducing | Stops producing a stream to the local peer | void | label: string |
const { fetchStream, produceStream, stopProducing } = useLocalMedia();
const fetchAudioStream = async () => {
const stream = await fetchStream({
mediaDeviceKind: 'mic'
});
return stream;
};
const produceAudioStream = async () => {
const stream = await fetchAudioStream();
await produceStream({
stream,
label: 'mic',
appData: {}
});
return stream;
};