Skip to content

[WIP] Add configurable audio device ID for WebRTC on Android #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jonathanphilippou
Copy link

Overview

This PR adds the ability to configure the audio device ID used by WebRTC on Android. Currently, the WebRTC implementation on React Native only reports a single hardcoded "audio-1" device regardless of what physical microphone is connected, making it difficult to work with multiple audio inputs or integrate with other audio libraries like Expo AV.

Changes

  • Added a configurable defaultAudioDeviceId field to WebRTCModuleOptions
  • Modified GetUserMediaImpl to use this configurable ID throughout the audio device lifecycle
  • Added support for overriding the default via audio constraints in getUserMedia
  • Added new JavaScript APIs to get and set the default audio device ID
  • Updated all related code to use the configurable device ID instead of hardcoded "audio-1"

JavaScript API

// Set the default audio device ID
setDefaultAudioDeviceId('expo-av-audio');

// Get the current default audio device ID
const deviceId = await getDefaultAudioDeviceId();

Use Cases

This PR helps solve several issues:

  1. Integration with other audio libraries: Allows setting the audio device ID to match what Expo AV or other libraries use
  2. External microphone support: Makes it easier to handle external microphones that may not be detected correctly with the default ID
  3. Cross-platform consistency: Better audio device handling across platforms

Testing

I've tested this with both built-in and external microphones on Android. The configurable ID effectively allows WebRTC to use the same microphone as other audio APIs by setting the appropriate device ID.

Related Issues

This addresses the common issue where WebRTC and other audio APIs (like Expo AV) can't use the same microphone device on Android.

@jonathanphilippou jonathanphilippou changed the title Add configurable audio device ID for WebRTC on Android [WIP] Add configurable audio device ID for WebRTC on Android Apr 24, 2025
global.RTCRtpTransceiver = RTCRtpTransceiver
global.RTCRtpReceiver = RTCRtpReceiver
global.RTCRtpSender = RTCRtpSender
global.RTCErrorEvent = RTCErrorEvent
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll undo all of the reformatting changes from my editor. sorry about that 😅

Log.d(TAG, "==========================================");
Log.d(TAG, "JONATHAN'S FORK: USING CUSTOM AUDIO DEVICE CODE");
Log.d(TAG, "==========================================");

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will delete this kind of thing after i know what i have works

@@ -64,6 +71,9 @@
public class WebRTCModule extends ReactContextBaseJavaModule {
static final String TAG = WebRTCModule.class.getCanonicalName();

// Define fork version constant - increment this when making changes to the fork
public static final String FORK_VERSION = "fork-version-0";

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will delete this when i know my code works. sorry about that

@davidliu
Copy link

  1. I don't see how this actually affects any of the audio routing. As far as I can tell, the code just saves an audioDeviceId, but doesn't actually use it for anything.
  2. If you'd like to make this change, open a PR on the upstream repo instead. This repo is for LiveKit specific changes that aren't applicable more broadly.

@davidliu davidliu closed this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants