useLocalAudio
The useLocalAudio hook exposes primitives to interact with your own audio stream - coming from your microphone device.
const {
stream,
track,
enableAudio,
disableAudio,
} = useLocalAudio({
onProduceStart(producer) {},
onProduceClose() {},
onProduceError() {},
});
Props
The useLocalAudio hook accepts an object with the following fields as props.
1. onProduceStartOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when you start producing your microphone's audio stream i.e sharing it with other peers in the room. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
producer | Producer | The mediasoup producer object. | Yes |
Example Usage
const localAudio = useLocalAudio({ onProduceStart: (producer) => {
console.log("Started producing your audio stream!");
console.log(producer);
// your code here
}});
2. onProduceCloseOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when you stop producing your microphone's audio stream. | void |
Example Usage
const localAudio = useLocalAudio({ onProduceClose: () => {
console.log("Stopped producing your audio stream!");
// your code here
}});
3. onProduceErrorOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when there was an error encountered while producing your microphone's audio stream. | void |
Example Usage
const localAudio = useLocalAudio({ onProduceError: () => {
console.log("There was an error in producing your audio stream!");
// your code here
}});
Returns
The useLocalAudio hook returns an object with the following fields.
1. streamObject
Description | Type |
---|---|
Your microphone's audio stream. null if not enabled yet. | MediaStream | null |
2. trackObject
Description | Type |
---|---|
Your microphone's audio stream track. null if not enabled yet. | MediaStreamTrack | null |
3. enableAudioFunction
Description | Return Type |
---|---|
Enable your microphone's audio stream and start producing it with other peers in the room. | Promise<void> |
4. disableAudioFunction
Description | Return Type |
---|---|
Disable your microphone's audio stream and stop producing it with other peers in the room. | Promise<void> |