useAudio

useAudio

💡

produceAudio() method takes list of peerId as an optional argument, by default it will produce audio for all peers.

These are the fields which are returned from useAudio hook.

NameTypeDescription
fetchAudioStream(deviceId?: string)FunctionEnables audio stream from user’s device mic(lobby)
stopAudioStream()FunctionDisables audio stream from user’s device mic(lobby)
produceAudio(micStream: MediaStream, peerIds?: string[])FunctionStarts sharing user’s webcam audio stream with other peers in the room
stopProducingAudio()FunctionStops sharing user’s webcam audio stream with other peers in the room
enumerateDevices()FunctionReturns the list of audio devices
createMicConsumer(peerId: string)FunctionStarts consuming audio stream for given peerId
closeMicConsumer(peerId: string)FunctionStops consuming audio stream for given peerId
isLoadingbooleanloading state
isProducingbooleanstate whether the audio is producing or not
streamMediaStreamaudio stream
errorstringgives the error message

Sample Code

 
import { useAudio } from '@huddle01/react/hooks';
 
const App = () => {
  const { fetchAudioStream, stopAudioStream, isProducing, stream, error} = useAudio();
 
  return (
    <div>
      
     {/* Mic */} 
      <button disabled={!fetchAudioStream.isCallable} onClick={fetchAudioStream}>
        FETCH_AUDIO_STREAM
      </button>
 
    </div>
  );
};
 
 
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.