From ee2285dfd36d39ce484fe4152066c229acda8fea Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Thu, 30 May 2024 16:03:56 +0200 Subject: [PATCH 1/2] [PBE-3921] call accept triggered on one device pulls the other into the call (#1101) --- .../video/android/core/StreamVideoImpl.kt | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoImpl.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoImpl.kt index 8af46092f6..cc31db7c04 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoImpl.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoImpl.kt @@ -78,6 +78,7 @@ import okhttp3.Response import org.openapitools.client.models.AcceptCallResponse import org.openapitools.client.models.BlockUserRequest import org.openapitools.client.models.BlockUserResponse +import org.openapitools.client.models.CallAcceptedEvent import org.openapitools.client.models.CallRequest import org.openapitools.client.models.CallSettingsRequest import org.openapitools.client.models.ConnectedEvent @@ -141,8 +142,7 @@ internal class StreamVideoImpl internal constructor( internal val sounds: Sounds, internal val crashOnMissingPermission: Boolean = true, internal val permissionCheck: StreamPermissionCheck = DefaultStreamPermissionCheck(), -) : StreamVideo, - NotificationHandler by streamNotificationManager { +) : StreamVideo, NotificationHandler by streamNotificationManager { private var locationJob: Deferred>? = null @@ -304,9 +304,7 @@ internal class StreamVideoImpl internal constructor( } override suspend fun connectIfNotAlreadyConnected() { - if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected && - connectionModule.coordinatorSocket.connectionState.value != SocketState.Connecting - ) { + if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected && connectionModule.coordinatorSocket.connectionState.value != SocketState.Connecting) { connectionModule.coordinatorSocket.connect() } } @@ -314,32 +312,29 @@ internal class StreamVideoImpl internal constructor( /** * Observes the app lifecycle and attempts to reconnect/release the socket connection. */ - private val lifecycleObserver = - StreamLifecycleObserver( - lifecycle, - object : LifecycleHandler { - override fun started() { - scope.launch { - // We should only connect if we were previously connected - if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected) { - connectionModule.coordinatorSocket.connect() - } + private val lifecycleObserver = StreamLifecycleObserver( + lifecycle, + object : LifecycleHandler { + override fun started() { + scope.launch { + // We should only connect if we were previously connected + if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected) { + connectionModule.coordinatorSocket.connect() } } + } - override fun stopped() { - // We should only disconnect if we were previously connected - // Also don't disconnect the socket if we are in an active call - if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected && - state.activeCall.value == null - ) { - connectionModule.coordinatorSocket.disconnect( - PersistentSocket.DisconnectReason.ByRequest, - ) - } + override fun stopped() { + // We should only disconnect if we were previously connected + // Also don't disconnect the socket if we are in an active call + if (connectionModule.coordinatorSocket.connectionState.value != SocketState.NotConnected && state.activeCall.value == null) { + connectionModule.coordinatorSocket.disconnect( + PersistentSocket.DisconnectReason.ByRequest, + ) } - }, - ) + } + }, + ) init { @@ -522,6 +517,21 @@ internal class StreamVideoImpl internal constructor( } if (selectedCid.isNotEmpty()) { + // Special handling for accepted events + if (event is CallAcceptedEvent) { + // Skip accepted events not meant for the current outgoing call. + val currentRingingCall = state.ringingCall.value + val state = currentRingingCall?.state?.ringingState?.value + if (currentRingingCall != null && + (state is RingingState.Outgoing || state == RingingState.Idle) && + currentRingingCall.cid != event.callCid + ) { + // Skip this event + return + } + } + + // Update calls as usual calls[selectedCid]?.let { it.state.handleEvent(event) it.session?.handleEvent(event) @@ -938,12 +948,11 @@ internal class StreamVideoImpl internal constructor( sessionId: String?, ): Result { return wrapAPICall { - val result = - if (sessionId == null) { - connectionModule.api.listRecordingsTypeId0(type, id) - } else { - connectionModule.api.listRecordingsTypeIdSession1(type, id, sessionId) - } + val result = if (sessionId == null) { + connectionModule.api.listRecordingsTypeId0(type, id) + } else { + connectionModule.api.listRecordingsTypeIdSession1(type, id, sessionId) + } result } } @@ -1000,10 +1009,7 @@ internal class StreamVideoImpl internal constructor( suspend fun _selectLocation(): Result { return wrapAPICall { val url = "https://hint.stream-io-video.com/" - val request: Request = Request.Builder() - .url(url) - .method("HEAD", null) - .build() + val request: Request = Request.Builder().url(url).method("HEAD", null).build() val call = connectionModule.okHttpClient.newCall(request) val response = suspendCancellableCoroutine { continuation -> call.enqueue(object : Callback { From 4457d5f7e60622c15709a4b25c8085bdf7057553 Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Thu, 30 May 2024 16:38:31 +0200 Subject: [PATCH 2/2] Prepare release 1.0.4 (#1102) --- .../main/kotlin/io/getstream/video/android/Configuration.kt | 4 ++-- docusaurus/docs/Android/02-tutorials/01-video-calling.mdx | 2 +- docusaurus/docs/Android/02-tutorials/02-audio-room.mdx | 2 +- docusaurus/docs/Android/02-tutorials/03-livestream.mdx | 2 +- docusaurus/docs/Android/06-advanced/07-chat-with-video.mdx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/io/getstream/video/android/Configuration.kt b/buildSrc/src/main/kotlin/io/getstream/video/android/Configuration.kt index cbde4c33a1..a8ded3fb58 100644 --- a/buildSrc/src/main/kotlin/io/getstream/video/android/Configuration.kt +++ b/buildSrc/src/main/kotlin/io/getstream/video/android/Configuration.kt @@ -6,9 +6,9 @@ object Configuration { const val minSdk = 24 const val majorVersion = 1 const val minorVersion = 0 - const val patchVersion = 3 + const val patchVersion = 4 const val versionName = "$majorVersion.$minorVersion.$patchVersion" - const val versionCode = 26 + const val versionCode = 27 const val snapshotVersionName = "$majorVersion.$minorVersion.${patchVersion + 1}-SNAPSHOT" const val artifactGroup = "io.getstream" const val streamVideoCallGooglePlayVersion = "1.1.2" diff --git a/docusaurus/docs/Android/02-tutorials/01-video-calling.mdx b/docusaurus/docs/Android/02-tutorials/01-video-calling.mdx index a0496958cf..af64743197 100644 --- a/docusaurus/docs/Android/02-tutorials/01-video-calling.mdx +++ b/docusaurus/docs/Android/02-tutorials/01-video-calling.mdx @@ -31,7 +31,7 @@ If you're new to android, note that there are 2 `build.gradle` files, you want t ```kotlin dependencies { // Stream Video Compose SDK - implementation("io.getstream:stream-video-android-ui-compose:1.0.3") + implementation("io.getstream:stream-video-android-ui-compose:1.0.4") // Optionally add Jetpack Compose if Android studio didn't automatically include them implementation(platform("androidx.compose:compose-bom:2023.08.00")) diff --git a/docusaurus/docs/Android/02-tutorials/02-audio-room.mdx b/docusaurus/docs/Android/02-tutorials/02-audio-room.mdx index a12a39b62b..9a83f08e39 100644 --- a/docusaurus/docs/Android/02-tutorials/02-audio-room.mdx +++ b/docusaurus/docs/Android/02-tutorials/02-audio-room.mdx @@ -35,7 +35,7 @@ If you're new to android, note that there are 2 `build.gradle` files, you want t ```groovy dependencies { // Stream Video Compose SDK - implementation("io.getstream:stream-video-android-ui-compose:1.0.3") + implementation("io.getstream:stream-video-android-ui-compose:1.0.4") // Jetpack Compose (optional/ android studio typically adds them when you create a new project) implementation(platform("androidx.compose:compose-bom:2023.08.00")) diff --git a/docusaurus/docs/Android/02-tutorials/03-livestream.mdx b/docusaurus/docs/Android/02-tutorials/03-livestream.mdx index 285840bf54..b410a4b3fd 100644 --- a/docusaurus/docs/Android/02-tutorials/03-livestream.mdx +++ b/docusaurus/docs/Android/02-tutorials/03-livestream.mdx @@ -35,7 +35,7 @@ If you're new to android, note that there are 2 `build.gradle` files, you want t ```kotlin dependencies { // Stream Video Compose SDK - implementation("io.getstream:stream-video-android-ui-compose:1.0.3") + implementation("io.getstream:stream-video-android-ui-compose:1.0.4") // Jetpack Compose (optional/ android studio typically adds them when you create a new project) implementation(platform("androidx.compose:compose-bom:2023.08.00")) diff --git a/docusaurus/docs/Android/06-advanced/07-chat-with-video.mdx b/docusaurus/docs/Android/06-advanced/07-chat-with-video.mdx index 8064130856..bc22beecaa 100644 --- a/docusaurus/docs/Android/06-advanced/07-chat-with-video.mdx +++ b/docusaurus/docs/Android/06-advanced/07-chat-with-video.mdx @@ -31,7 +31,7 @@ Let the project sync. It should have all the dependencies required for you to fi ```groovy dependencies { // Stream Video Compose SDK - implementation("io.getstream:stream-video-android-ui-compose:1.0.3") + implementation("io.getstream:stream-video-android-ui-compose:1.0.4") // Stream Chat implementation(libs.stream.chat.compose)