Skip to content

Commit 2c7d63f

Browse files
committed
Merge branch 'main' into dl/audio_stuff
2 parents e5fbdf5 + 0f24b42 commit 2c7d63f

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.github/banner_dark.png

-375 Bytes
Loading

.github/banner_light.png

-170 Bytes
Loading

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ Apache License 2.0
416416
<br/><table>
417417
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
418418
<tbody>
419-
<tr><td>Realtime SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/components-swift">Swift Components</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS/visionOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <b>React Native</b> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
420-
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
421-
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
419+
<tr><td>LiveKit SDKs</td><td><a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS/visionOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <b>React Native</b> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (WebGL)</a></td></tr><tr></tr>
420+
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a> · <a href="https://github.com/pabloFuente/livekit-server-sdk-dotnet">.NET (community)</a></td></tr><tr></tr>
421+
<tr><td>UI Components</td><td><a href="https://github.com/livekit/components-js">React</a> · <a href="https://github.com/livekit/components-android">Android Compose</a> · <a href="https://github.com/livekit/components-swift">SwiftUI</a></td></tr><tr></tr>
422+
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agents-js">Node.js</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
422423
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">LiveKit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
423424
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/home/self-hosting/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
424425
</tbody>

android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import java.util.concurrent.Callable
1616

1717
object LiveKitReactNative {
1818

19+
20+
private var audioType: AudioType = AudioType.CommunicationAudioType()
21+
1922
@SuppressLint("StaticFieldLeak")
20-
private lateinit var adm: JavaAudioDeviceModule
23+
private var adm: JavaAudioDeviceModule? = null
2124

2225
val audioDeviceModule: JavaAudioDeviceModule
2326
get() {
24-
if (!::adm.isInitialized) {
25-
throw IllegalStateException("Audio device module is not initialized! Did you remember to call LiveKitReactNative.setup in your Application.onCreate?")
26-
}
27+
val adm = this.adm
28+
?: throw IllegalStateException("Audio device module is not initialized! Did you remember to call LiveKitReactNative.setup in your Application.onCreate?")
2729
return adm
2830
}
2931

@@ -63,11 +65,17 @@ object LiveKitReactNative {
6365
) {
6466
_audioRecordSamplesDispatcher = AudioRecordSamplesDispatcher()
6567

68+
this.audioType = audioType
6669
val options = WebRTCModuleOptions.getInstance()
6770
options.videoEncoderFactory = CustomVideoEncoderFactory(null, true, true)
6871
options.videoDecoderFactory = CustomVideoDecoderFactory()
6972
options.enableMediaProjectionService = true
7073

74+
setupAdm(context)
75+
options.audioDeviceModule = adm
76+
}
77+
78+
private fun setupAdm(context: Context) {
7179
val useHardwareAudioProcessing = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
7280

7381
adm = JavaAudioDeviceModule.builder(context)
@@ -76,7 +84,17 @@ object LiveKitReactNative {
7684
.setAudioAttributes(audioType.audioAttributes)
7785
.setSamplesReadyCallback(audioRecordSamplesDispatcher)
7886
.createAudioDeviceModule()
87+
}
88+
89+
internal fun invalidate(context: Context) {
90+
val options = WebRTCModuleOptions.getInstance()
91+
if (options.audioDeviceModule == adm) {
92+
options.audioDeviceModule = null
93+
}
94+
adm?.release()
95+
adm = null
7996

97+
setupAdm(context)
8098
options.audioDeviceModule = adm
8199

82100
// CustomAudioProcessingController can't be instantiated before WebRTC is loaded.

android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,8 @@ class LivekitReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
193193
fun removeListeners(count: Int?) {
194194
// Keep: Required for RN built in Event Emitter Calls.
195195
}
196+
197+
override fun invalidate() {
198+
LiveKitReactNative.invalidate(reactApplicationContext)
199+
}
196200
}

0 commit comments

Comments
 (0)