Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar-apostolov committed Oct 17, 2024
1 parent 3f907cd commit 643073f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ interface SocketActions<EventIn, EventOut, Error, State, Token> {
*/
public fun errors(): Flow<Error>

/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ internal class StreamWebSocket<V, T: GenericParser<V>>(
}
fun close(): Boolean = webSocket.close(CLOSE_SOCKET_CODE, CLOSE_SOCKET_REASON)
fun listen(): Flow<StreamWebSocketEvent> = eventFlow.asSharedFlow()

fun sendRaw(data: String) {
webSocket.send(data)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,8 +142,13 @@ public open class CoordinatorSocketConnection(
custom = user.custom,
),
)

val adapter: JsonAdapter<WSAuthMessageRequest> =
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)
}
}
}
Expand Down Expand Up @@ -203,6 +210,8 @@ public open class CoordinatorSocketConnection(

override fun errors(): Flow<StreamWebSocketEvent.Error> = 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class SfuSocketConnection(

override fun errors(): MutableSharedFlow<StreamWebSocketEvent.Error> = errors

override fun sendData(data: String) = internalSocket.sendRawData(data)

override suspend fun sendEvent(event: SfuDataRequest): Boolean = internalSocket.sendEvent(event)

override fun connectionId(): Flow<String> = connectionId.mapNotNull {
Expand Down

0 comments on commit 643073f

Please sign in to comment.