From 82a1073e73b27d31a01f2fd65c760506d3b1ea7d Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Tue, 19 Mar 2024 10:44:09 +0100 Subject: [PATCH] Fix concurrent modification exception (#1038) * Fix concurrent modification exception * Spotless --- .../main/kotlin/io/getstream/video/android/core/Call.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt index 861bd42bbf..d7cc089e4d 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt @@ -87,6 +87,7 @@ import org.webrtc.VideoSink import org.webrtc.audio.JavaAudioDeviceModule.AudioSamples import stream.video.sfu.models.TrackType import stream.video.sfu.models.VideoDimension +import java.util.Collections import kotlin.coroutines.resume /** @@ -113,7 +114,7 @@ public class Call( val user: User, ) { private var location: String? = null - private var subscriptions = mutableSetOf() + private var subscriptions = Collections.synchronizedSet(mutableSetOf()) internal val clientImpl = client as StreamVideoImpl @@ -822,7 +823,7 @@ public class Call( public fun subscribeFor( vararg eventTypes: Class, listener: VideoEventListener, - ): EventSubscription { + ): EventSubscription = synchronized(subscriptions) { val filter = { event: VideoEvent -> eventTypes.any { type -> type.isInstance(event) } } @@ -833,7 +834,7 @@ public class Call( public fun subscribe( listener: VideoEventListener, - ): EventSubscription { + ): EventSubscription = synchronized(subscriptions) { val sub = EventSubscription(listener) subscriptions.add(sub) return sub @@ -877,7 +878,7 @@ public class Call( return clientImpl.updateMembers(type, id, request) } - fun fireEvent(event: VideoEvent) { + fun fireEvent(event: VideoEvent) = synchronized(subscriptions) { subscriptions.forEach { sub -> if (!sub.isDisposed) { // subs without filters should always fire