Skip to content

Commit

Permalink
Mark stability to the Call, CallState, and ParticipantSate (#995)
Browse files Browse the repository at this point in the history
* Mark stability to the Call, CallState, and ParticipantSate

* Add stable marker to the connection states
  • Loading branch information
skydoves authored Jan 25, 2024
1 parent f9535bd commit 9be46df
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.video.android.core
import android.content.Intent
import android.graphics.Bitmap
import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.Stable
import io.getstream.log.taggedLogger
import io.getstream.result.Error
import io.getstream.result.Result
Expand Down Expand Up @@ -104,14 +105,15 @@ const val sfuReconnectTimeoutMillis = 30_000
* val result = call.join()
*
*/
@Stable
public class Call(
internal val client: StreamVideo,
val type: String,
val id: String,
val user: User,
) {
private var statsGatheringJob: Job? = null
internal var location: String? = null
private var location: String? = null

private var subscriptions = mutableSetOf<EventSubscription>()

Expand Down Expand Up @@ -520,12 +522,18 @@ public class Call(
logger.i { "Switching SFU from ${session?.sfuUrl} to ${cred.server.url}" }
val iceServers = cred.iceServers.map { it.toIceServer() }

session?.switchSfu(cred.server.edgeName, cred.server.url, cred.token, iceServers, failedToSwitch = {
logger.e {
"[switchSfu] Failed to connect to new SFU during migration. Reverting to full reconnect"
}
state._connection.value = RealtimeConnection.Reconnecting
})
session?.switchSfu(
cred.server.edgeName,
cred.server.url,
cred.token,
iceServers,
failedToSwitch = {
logger.e {
"[switchSfu] Failed to connect to new SFU during migration. Reverting to full reconnect"
}
state._connection.value = RealtimeConnection.Reconnecting
},
)
} else {
logger.e {
"[switchSfu] Failed to get a join response during " +
Expand Down Expand Up @@ -864,13 +872,14 @@ public class Call(
private fun updateMediaManagerFromSettings(callSettings: CallSettingsResponse) {
// Speaker
if (speaker.status.value is DeviceStatus.NotSelected) {
val enableSpeaker = if (callSettings.video.cameraDefaultOn || camera.status.value is DeviceStatus.Enabled) {
// if camera is enabled then enable speaker. Eventually this should
// be a new audio.defaultDevice setting returned from backend
true
} else {
callSettings.audio.defaultDevice == AudioSettings.DefaultDevice.Speaker
}
val enableSpeaker =
if (callSettings.video.cameraDefaultOn || camera.status.value is DeviceStatus.Enabled) {
// if camera is enabled then enable speaker. Eventually this should
// be a new audio.defaultDevice setting returned from backend
true
} else {
callSettings.audio.defaultDevice == AudioSettings.DefaultDevice.Speaker
}
speaker.setEnabled(enableSpeaker)
}

Expand Down Expand Up @@ -1010,9 +1019,10 @@ public class Call(
}
}

fun isPinnedParticipant(sessionId: String): Boolean = state.pinnedParticipants.value.containsKey(
sessionId,
)
fun isPinnedParticipant(sessionId: String): Boolean =
state.pinnedParticipants.value.containsKey(
sessionId,
)

fun isServerPin(sessionId: String): Boolean = state._serverPins.value.containsKey(sessionId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.getstream.video.android.core

import androidx.compose.runtime.Stable
import io.getstream.log.taggedLogger
import io.getstream.video.android.core.call.RtcSession
import io.getstream.video.android.core.events.AudioLevelChangedEvent
Expand Down Expand Up @@ -125,6 +126,7 @@ import java.util.UUID
import kotlin.time.DurationUnit
import kotlin.time.toDuration

@Stable
public sealed interface RealtimeConnection {
/**
* We start out in the PreJoin state. This is before call.join is called
Expand Down Expand Up @@ -173,6 +175,7 @@ public sealed interface RealtimeConnection {
*
*
*/
@Stable
public class CallState(
private val client: StreamVideo,
private val call: Call,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.getstream.video.android.core

import android.content.Context
import androidx.compose.runtime.Stable
import androidx.core.content.ContextCompat
import io.getstream.video.android.core.notifications.internal.service.CallService
import io.getstream.video.android.model.StreamCallId
Expand All @@ -28,6 +29,7 @@ import org.openapitools.client.models.CallRingEvent
import org.openapitools.client.models.ConnectedEvent
import org.openapitools.client.models.VideoEvent

@Stable
public sealed interface ConnectionState {
public data object PreConnect : ConnectionState
public data object Loading : ConnectionState
Expand All @@ -37,6 +39,7 @@ public sealed interface ConnectionState {
public class Failed(error: Error) : ConnectionState
}

@Stable
public sealed interface RingingState {
public data object Idle : RingingState
public data class Incoming(val acceptedByMe: Boolean = false) : RingingState
Expand All @@ -46,6 +49,7 @@ public sealed interface RingingState {
public data object TimeoutNoAnswer : RingingState
}

@Stable
class ClientState(client: StreamVideo) {
/**
* Current user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import stream.video.sfu.models.TrackType
* * A list of participants is shared when you join a call the SFU send you the participant joined event.
*
*/
@Stable
public data class ParticipantState(
/** The SFU returns a session id for each participant. This session id is unique */
var sessionId: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.getstream.video.android.core

import android.content.Context
import android.os.Build
import androidx.compose.runtime.Stable
import io.getstream.android.push.PushDevice
import io.getstream.log.StreamLog
import io.getstream.result.Result
Expand All @@ -36,6 +37,7 @@ import org.openapitools.client.models.VideoEvent
/**
* The main interface to control the Video calls. [StreamVideoImpl] implements this interface.
*/
@Stable
public interface StreamVideo : NotificationHandler {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package io.getstream.video.android.model

import androidx.compose.runtime.Stable
import androidx.compose.runtime.Immutable
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -65,7 +65,7 @@ public object OffsetDateTimeSerializer : KSerializer<OffsetDateTime> {
)
}

@Stable
@Immutable
@Serializable
public data class User(
/** ID is required, the rest is optional */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RingTest : IntegrationTestBase() {
}

@Test
@Ignore
fun `Outgoing call is automatically cancelled`() = runTest {
client.state._ringingCall.value = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,21 @@ public final class io/getstream/video/android/compose/ui/components/call/pinning
public static final field $stable I
public fun <init> (Landroidx/compose/ui/graphics/vector/ImageVector;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V
public synthetic fun <init> (Landroidx/compose/ui/graphics/vector/ImageVector;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Landroidx/compose/ui/graphics/vector/ImageVector;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Z
public final fun component4 ()Lkotlin/jvm/functions/Function2;
public final fun component5 ()Lkotlin/jvm/functions/Function3;
public final fun copy (Landroidx/compose/ui/graphics/vector/ImageVector;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lio/getstream/video/android/compose/ui/components/call/pinning/ParticipantAction;
public static synthetic fun copy$default (Lio/getstream/video/android/compose/ui/components/call/pinning/ParticipantAction;Landroidx/compose/ui/graphics/vector/ImageVector;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lio/getstream/video/android/compose/ui/components/call/pinning/ParticipantAction;
public fun equals (Ljava/lang/Object;)Z
public final fun getAction ()Lkotlin/jvm/functions/Function3;
public final fun getCondition ()Lkotlin/jvm/functions/Function2;
public final fun getFirstToggleAction ()Z
public final fun getIcon ()Landroidx/compose/ui/graphics/vector/ImageVector;
public final fun getLabel ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/video/android/compose/ui/components/call/renderer/ComposableSingletons$FloatingParticipantVideoKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.outlined.MoreHoriz
import androidx.compose.material.icons.outlined.PushPin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -86,7 +87,8 @@ import org.openapitools.client.models.OwnCapability
* @param condition the condition if the action is to be shown or not.
* @param action the action (i.e. callable)
*/
public class ParticipantAction(
@Immutable
public data class ParticipantAction(
public val icon: ImageVector,
public val label: String,
public val firstToggleAction: Boolean = true,
Expand Down Expand Up @@ -235,7 +237,8 @@ internal fun BoxScope.ParticipantActionsDialog(
) {
actions.forEach {
if (it.condition.invoke(call, participant)) {
val circleColor = if (it.firstToggleAction) VideoTheme.colors.textHighEmphasis else VideoTheme.colors.primaryAccent
val circleColor =
if (it.firstToggleAction) VideoTheme.colors.textHighEmphasis else VideoTheme.colors.primaryAccent
val strokeWidth = if (it.firstToggleAction) 2.dp else 4.dp
Column {
CircleIcon(
Expand All @@ -249,7 +252,9 @@ internal fun BoxScope.ParticipantActionsDialog(
}
Spacer(modifier = Modifier.height(8.dp))
Text(
modifier = Modifier.align(CenterHorizontally).width(80.dp),
modifier = Modifier
.align(CenterHorizontally)
.width(80.dp),
textAlign = TextAlign.Center,
text = it.label,
color = VideoTheme.colors.textHighEmphasis,
Expand Down

0 comments on commit 9be46df

Please sign in to comment.