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
21
21
import org.webrtc.AudioTrackSink
22
22
import org.webrtc.audio.JavaAudioDeviceModule
23
23
import java.nio.ByteBuffer
24
+ import java.util.Collections
24
25
25
26
/* *
26
27
* Dispatches recorded audio samples from the local microphone.
27
28
*/
28
29
class AudioRecordSamplesDispatcher : JavaAudioDeviceModule .SamplesReadyCallback {
29
30
30
- private val sinks = mutableSetOf<AudioTrackSink >()
31
+ private val sinks = Collections .synchronizedSet( mutableSetOf<AudioTrackSink >() )
31
32
32
33
@Synchronized
33
34
fun registerSink (sink : AudioTrackSink ) {
Original file line number Diff line number Diff line change @@ -5,13 +5,14 @@ import com.livekit.reactnative.LiveKitReactNative
5
5
import com.oney.WebRTCModule.WebRTCModule
6
6
import org.webrtc.AudioTrack
7
7
import org.webrtc.AudioTrackSink
8
+ import java.util.Collections
8
9
import java.util.UUID
9
10
10
11
private const val LOCAL_PC_ID = - 1
11
12
12
13
class AudioSinkManager (val reactContext : ReactContext ) {
13
14
14
- private val sinks = mutableMapOf<String , AudioTrackSink >()
15
+ private val sinks = Collections .synchronizedMap( mutableMapOf<String , AudioTrackSink >() )
15
16
16
17
/* *
17
18
* Registers a sink to this manager.
@@ -35,7 +36,12 @@ class AudioSinkManager(val reactContext: ReactContext) {
35
36
* Unregisters a sink from this manager. Does not detach the sink from tracks.
36
37
*/
37
38
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
+ }
39
45
}
40
46
41
47
fun getSink (reactTag : String ) = sinks[reactTag]
You can’t perform that action at this time.
0 commit comments