File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
android/src/main/java/com/livekit/reactnative/audio/processing Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,14 @@ import android.os.SystemClock
2121import org.webrtc.AudioTrackSink
2222import org.webrtc.audio.JavaAudioDeviceModule
2323import java.nio.ByteBuffer
24+ import java.util.Collections
2425
2526/* *
2627 * Dispatches recorded audio samples from the local microphone.
2728 */
2829class AudioRecordSamplesDispatcher : JavaAudioDeviceModule .SamplesReadyCallback {
2930
30- private val sinks = mutableSetOf<AudioTrackSink >()
31+ private val sinks = Collections .synchronizedSet( mutableSetOf<AudioTrackSink >() )
3132
3233 @Synchronized
3334 fun registerSink (sink : AudioTrackSink ) {
Original file line number Diff line number Diff line change @@ -5,13 +5,14 @@ import com.livekit.reactnative.LiveKitReactNative
55import com.oney.WebRTCModule.WebRTCModule
66import org.webrtc.AudioTrack
77import org.webrtc.AudioTrackSink
8+ import java.util.Collections
89import java.util.UUID
910
1011private const val LOCAL_PC_ID = - 1
1112
1213class AudioSinkManager (val reactContext : ReactContext ) {
1314
14- private val sinks = mutableMapOf<String , AudioTrackSink >()
15+ private val sinks = Collections .synchronizedMap( mutableMapOf<String , AudioTrackSink >() )
1516
1617 /* *
1718 * Registers a sink to this manager.
@@ -35,7 +36,12 @@ class AudioSinkManager(val reactContext: ReactContext) {
3536 * Unregisters a sink from this manager. Does not detach the sink from tracks.
3637 */
3738 fun unregisterSink (sink : AudioTrackSink ) {
38- sinks.filterNot { entry -> entry.value == sink }
39+ synchronized(sinks) {
40+ val keysToRemove = sinks.filterValues { it == sink }.keys
41+ for (key in keysToRemove) {
42+ sinks.remove(key)
43+ }
44+ }
3945 }
4046
4147 fun getSink (reactTag : String ) = sinks[reactTag]
You can’t perform that action at this time.
0 commit comments