Shinigami Hooks
useLocalAudio

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
DescriptionReturn 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 NameTypeDescriptionRequired
producerProducerThe 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
DescriptionReturn 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
DescriptionReturn 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
DescriptionType
Your microphone's audio stream. null if not enabled yet.MediaStream | null
2. trackObject
DescriptionType
Your microphone's audio stream track. null if not enabled yet.MediaStreamTrack | null
3. enableAudioFunction
DescriptionReturn Type
Enable your microphone's audio stream and start producing it with other peers in the room.Promise<void>
4. disableAudioFunction
DescriptionReturn Type
Disable your microphone's audio stream and stop producing it with other peers in the room.Promise<void>
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2022 Graphene 01, Inc. All Rights Reserved.