-
Notifications
You must be signed in to change notification settings - Fork 30
[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
Changes from 4 commits
b7b62a1
98c1e6d
2fd120d
3bef58c
0a6ba92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
package com.oney.WebRTCModule; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.media.AudioDeviceInfo; | ||
import android.media.AudioManager; | ||
import android.os.Build; | ||
import android.util.Log; | ||
import android.util.Pair; | ||
import android.util.SparseArray; | ||
|
@@ -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"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
PeerConnectionFactory mFactory; | ||
VideoEncoderFactory mVideoEncoderFactory; | ||
VideoDecoderFactory mVideoDecoderFactory; | ||
|
@@ -1544,4 +1554,44 @@ public void addListener(String eventName) { | |
public void removeListeners(Integer count) { | ||
// Keep: Required for RN built in Event Emitter Calls. | ||
} | ||
|
||
/** | ||
* Set the default audio device ID to use when no specific device is requested. | ||
* This allows applications to control which audio device is used by default. | ||
* | ||
* @param deviceId The device ID to use as default (e.g., "audio-1", "expo-av-audio", etc.) | ||
*/ | ||
@ReactMethod | ||
public void setDefaultAudioDeviceId(String deviceId) { | ||
if (deviceId != null && !deviceId.isEmpty()) { | ||
Log.d(TAG, "Setting default audio device ID to: " + deviceId); | ||
WebRTCModuleOptions.getInstance().defaultAudioDeviceId = deviceId; | ||
|
||
// Update current instance | ||
if (getUserMediaImpl != null) { | ||
getUserMediaImpl.setAudioDeviceId(deviceId); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the current default audio device ID. | ||
* | ||
* @param promise Promise to resolve with the current default audio device ID | ||
*/ | ||
@ReactMethod | ||
public void getDefaultAudioDeviceId(Promise promise) { | ||
String deviceId = WebRTCModuleOptions.getInstance().defaultAudioDeviceId; | ||
promise.resolve(deviceId); | ||
} | ||
|
||
/** | ||
* Get the version of this custom fork | ||
* | ||
* @param promise Promise to resolve with the fork version | ||
*/ | ||
@ReactMethod | ||
public void getForkVersion(Promise promise) { | ||
promise.resolve(FORK_VERSION); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NativeModules } from 'react-native' | ||
const { WebRTCModule } = NativeModules | ||
|
||
/** | ||
* Set the default audio device ID to use when no specific device is requested. | ||
* This allows applications to control which audio device is used by default. | ||
* | ||
* @param deviceId - The device ID to use as default (e.g., "audio-1", "expo-av-audio", etc.) | ||
*/ | ||
export function setDefaultAudioDeviceId(deviceId: string): void { | ||
if (typeof deviceId !== 'string' || !deviceId.trim()) { | ||
throw new TypeError('deviceId must be a non-empty string') | ||
Check failure on line 12 in src/AudioDeviceModule.ts
|
||
} | ||
|
||
WebRTCModule.setDefaultAudioDeviceId(deviceId) | ||
Check failure on line 15 in src/AudioDeviceModule.ts
|
||
} | ||
|
||
/** | ||
* Get the current default audio device ID. | ||
* | ||
* @returns A promise that resolves to the current default audio device ID | ||
*/ | ||
export function getDefaultAudioDeviceId(): Promise<string> { | ||
return WebRTCModule.getDefaultAudioDeviceId() | ||
Check failure on line 24 in src/AudioDeviceModule.ts
|
||
} |
There was a problem hiding this comment.
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