From 643073f8e89a29e4795321036d7df56d82808f32 Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Thu, 17 Oct 2024 10:48:05 +0200 Subject: [PATCH] Update --- .../video/android/core/socket/common/SocketActions.kt | 5 +++++ .../android/core/socket/common/StreamWebSocket.kt | 4 ++++ .../core/socket/common/parser2/MoshiVideoParser.kt | 4 +++- .../core/socket/coordinator/CoordinatorSocket.kt | 7 +++++++ .../socket/coordinator/CoordinatorSocketConnection.kt | 11 ++++++++++- .../video/android/core/socket/sfu/SfuSocket.kt | 6 ++++++ .../android/core/socket/sfu/SfuSocketConnection.kt | 2 ++ 7 files changed, 37 insertions(+), 2 deletions(-) diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/SocketActions.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/SocketActions.kt index f0313ed618..f4f2d374d6 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/SocketActions.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/SocketActions.kt @@ -24,6 +24,11 @@ interface SocketActions { */ public fun errors(): Flow + /** + * Send raw data to the socket. If you already have a parsed event that can be sent. + */ + fun sendData(data: String) + /** * Send event to the socket. */ diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/StreamWebSocket.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/StreamWebSocket.kt index 07536f8c59..fc73ea2a63 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/StreamWebSocket.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/StreamWebSocket.kt @@ -95,6 +95,10 @@ internal class StreamWebSocket>( } fun close(): Boolean = webSocket.close(CLOSE_SOCKET_CODE, CLOSE_SOCKET_REASON) fun listen(): Flow = eventFlow.asSharedFlow() + + fun sendRaw(data: String) { + webSocket.send(data) + } } diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/parser2/MoshiVideoParser.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/parser2/MoshiVideoParser.kt index d24aef857d..746e625d48 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/parser2/MoshiVideoParser.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/common/parser2/MoshiVideoParser.kt @@ -32,9 +32,11 @@ import org.openapitools.client.infrastructure.ByteArrayAdapter import org.openapitools.client.infrastructure.LocalDateAdapter import org.openapitools.client.infrastructure.LocalDateTimeAdapter import org.openapitools.client.infrastructure.OffsetDateTimeAdapter +import org.openapitools.client.infrastructure.Serializer import org.openapitools.client.infrastructure.URIAdapter import org.openapitools.client.infrastructure.UUIDAdapter import org.openapitools.client.models.VideoEventAdapter +import org.openapitools.client.models.WSAuthMessageRequest import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory @@ -47,7 +49,7 @@ internal class MoshiVideoParser : VideoParser { .add(UUIDAdapter()).add(ByteArrayAdapter()).add(URIAdapter()).add(BigDecimalAdapter()) .add(BigIntegerAdapter()) // JsonAdapter - .addAdapter(lenientAdapter(DateAdapter())) + .addAdapter(DateAdapter()) .add(lenientAdapter(VideoEventAdapter())).add( lenientAdapter( org.openapitools.client.models.AudioSettingsRequest.DefaultDevice.DefaultDeviceAdapter(), diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocket.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocket.kt index 9824c03acb..40c9eab152 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocket.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocket.kt @@ -307,6 +307,13 @@ internal open class CoordinatorSocket( */ internal fun sendEvent(event: VideoEvent): Boolean = streamWebSocket?.send(event) ?: false + /** + * Send raw data to the web socket connection. + */ + internal fun senRawData(data: String) { + streamWebSocket?.sendRaw(data) + } + internal fun isConnected(): Boolean = coordinatorSocketStateService.currentState is VideoSocketState.Connected /** diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt index 34b5a270ee..ea1745b118 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt @@ -17,6 +17,7 @@ package io.getstream.video.android.core.socket.coordinator import androidx.lifecycle.Lifecycle +import com.squareup.moshi.JsonAdapter import io.getstream.log.taggedLogger import io.getstream.video.android.core.errors.DisconnectCause import io.getstream.video.android.core.internal.network.NetworkStateProvider @@ -47,6 +48,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.launch import okhttp3.OkHttpClient +import org.openapitools.client.infrastructure.Serializer import org.openapitools.client.models.ConnectUserDetailsRequest import org.openapitools.client.models.ConnectedEvent import org.openapitools.client.models.VideoEvent @@ -140,8 +142,13 @@ public open class CoordinatorSocketConnection( custom = user.custom, ), ) + + val adapter: JsonAdapter = + Serializer.moshi.adapter(WSAuthMessageRequest::class.java) + val data = adapter.toJson(authRequest) logger.d { "[onConnected] Sending auth request: $authRequest" } - sendEvent(authRequest) + logger.d { "[onConnected#data] Data: $data" } + sendData(data) } } } @@ -203,6 +210,8 @@ public open class CoordinatorSocketConnection( override fun errors(): Flow = errors + override fun sendData(data: String) = internalSocket.senRawData(data) + override suspend fun sendEvent(event: VideoEvent): Boolean = internalSocket.sendEvent(event) override suspend fun connect(user: User) { diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocket.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocket.kt index d033ed4409..c8d28384d5 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocket.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocket.kt @@ -294,6 +294,12 @@ internal open class SfuSocket( */ internal fun sendEvent(event: SfuDataRequest): Boolean = streamWebSocket?.send(event) ?: false + + /** + * Send raw data to the web socket connection. + */ + internal fun sendRawData(data: String) = streamWebSocket?.sendRaw(data) ?: Unit + internal fun isConnected(): Boolean = sfuSocketStateService.currentState is SfuSocketState.Connected diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocketConnection.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocketConnection.kt index 17766eaa3d..f6cc978298 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocketConnection.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/sfu/SfuSocketConnection.kt @@ -182,6 +182,8 @@ class SfuSocketConnection( override fun errors(): MutableSharedFlow = errors + override fun sendData(data: String) = internalSocket.sendRawData(data) + override suspend fun sendEvent(event: SfuDataRequest): Boolean = internalSocket.sendEvent(event) override fun connectionId(): Flow = connectionId.mapNotNull {