Docs
React SDK

Microphone controls

Capture audio, mute sending and select an input device.

Import and access

React
import { useLocalParticipant, useLocalMedia } from '@relayrtc/react'
 
const local = useLocalParticipant()
const { microphone } = useLocalMedia()

Requirements

A connected room, audio:publish permission and microphone access.

Methods

MethodReturnsPurpose
enable(constraints?)Promise<MediaStreamTrack>Capture and publish microphone audio.
disable()Promise<void>Release capture and remove publication.
switchDevice(deviceId)Promise<MediaStreamTrack or null>Replace the active input device.
mute()voidPause outgoing audio while retaining capture.
unmute()voidResume outgoing audio.
subscribe(listener)() => voidObserve the microphone snapshot.

Audio constraints

With no argument, enable uses an empty constraint object and lets the browser choose capture settings.

SettingExampleMeaning
deviceId{ exact: selectedDeviceId }Select the input device.
echoCancellationtrueRequest acoustic echo cancellation.
noiseSuppressiontrueRequest background noise suppression.
autoGainControltrueRequest automatic input gain.
channelCount1Request a channel count.
sampleRate48000Request sample rate when supported.

Browser and hardware support determine the actual capture settings.

Example

React
await local?.microphone.enable({
  echoCancellation: true,
  noiseSuppression: true,
  autoGainControl: true,
})
 
local?.microphone.mute()
local?.microphone.unmute()
await local?.microphone.disable()

Snapshot

Microphone uses the same input snapshot fields, with source: 'microphone'.

Mute retains device access and is not a remote participant status message. If your UI shows remote microphone status, define a metadata field for that application state and update it along with the control.