Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 181 additions & 9 deletions stream-video-android-core/api/stream-video-android-core.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ object Serializer {
.add(io.getstream.android.video.generated.models.IngressAudioEncodingOptionsRequest.Channels.ChannelsAdapter())
.add(io.getstream.android.video.generated.models.IngressSourceRequest.Fps.FpsAdapter())
.add(io.getstream.android.video.generated.models.IngressVideoLayerRequest.Codec.CodecAdapter())
.add(io.getstream.android.video.generated.models.JoinCallRequest.Prefer.PreferAdapter())
.add(io.getstream.android.video.generated.models.LayoutSettingsRequest.Name.NameAdapter())
.add(io.getstream.android.video.generated.models.NoiseCancellationSettings.Mode.ModeAdapter())
.add(io.getstream.android.video.generated.models.OwnCapability.OwnCapabilityAdapter())
.add(io.getstream.android.video.generated.models.PlaybackResponse.Reason.ReasonAdapter())
.add(io.getstream.android.video.generated.models.PlaybackResponse.Type.TypeAdapter())
.add(io.getstream.android.video.generated.models.RTMPBroadcastRequest.Quality.QualityAdapter())
.add(io.getstream.android.video.generated.models.RTMPSettingsRequest.Quality.QualityAdapter())
.add(io.getstream.android.video.generated.models.RawRecordingSettingsRequest.Mode.ModeAdapter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,43 @@ data class JoinCallRequest (
val migratingFromList: kotlin.collections.List<kotlin.String>? = emptyList(),

@Json(name = "data")
val data: io.getstream.android.video.generated.models.CallRequest? = null
val data: io.getstream.android.video.generated.models.CallRequest? = null,

@Json(name = "prefer")
val prefer: Prefer? = null,

@Json(name = "playback_capabilities")
val playbackCapabilities: kotlin.collections.List<kotlin.String>? = emptyList()
)
{

/**
* Prefer Enum
*/
sealed class Prefer(val value: kotlin.String) {
override fun toString(): String = value

companion object {
fun fromString(s: kotlin.String): Prefer = when (s) {
"hls" -> Hls
else -> Unknown(s)
}
}
object Hls : Prefer("hls")
data class Unknown(val unknownValue: kotlin.String) : Prefer(unknownValue)


class PreferAdapter : JsonAdapter<Prefer>() {
@FromJson
override fun fromJson(reader: JsonReader): Prefer? {
val s = reader.nextString() ?: return null
return Prefer.fromString(s)
}

@ToJson
override fun toJson(writer: JsonWriter, value: Prefer?) {
writer.value(value?.value)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ data class JoinCallResponse (
val statsOptions: io.getstream.android.video.generated.models.StatsOptions,

@Json(name = "membership")
val membership: io.getstream.android.video.generated.models.MemberResponse? = null
val membership: io.getstream.android.video.generated.models.MemberResponse? = null,

@Json(name = "playback")
val playback: io.getstream.android.video.generated.models.PlaybackResponse? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)

package io.getstream.android.video.generated.models

import kotlin.collections.List
import kotlin.collections.Map
import kotlin.collections.*
import kotlin.io.*
import com.squareup.moshi.FromJson
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.ToJson

/**
* How the client should play the call when it is not given SFU credentials
*/

@JsonClass(generateAdapter = true)
data class PlaybackResponse (
@Json(name = "playlist_url")
val playlistUrl: kotlin.String,

@Json(name = "reason")
val reason: Reason,

@Json(name = "type")
val type: Type
)
{

/**
* Reason Enum
*/
sealed class Reason(val value: kotlin.String) {
override fun toString(): String = value

companion object {
fun fromString(s: kotlin.String): Reason = when (s) {
"hint" -> Hint
"percentage" -> Percentage
else -> Unknown(s)
}
}
object Hint : Reason("hint")
object Percentage : Reason("percentage")
data class Unknown(val unknownValue: kotlin.String) : Reason(unknownValue)


class ReasonAdapter : JsonAdapter<Reason>() {
@FromJson
override fun fromJson(reader: JsonReader): Reason? {
val s = reader.nextString() ?: return null
return Reason.fromString(s)
}

@ToJson
override fun toJson(writer: JsonWriter, value: Reason?) {
writer.value(value?.value)
}
}
}
/**
* Type Enum
*/
sealed class Type(val value: kotlin.String) {
override fun toString(): String = value

companion object {
fun fromString(s: kotlin.String): Type = when (s) {
"hls" -> Hls
else -> Unknown(s)
}
}
object Hls : Type("hls")
data class Unknown(val unknownValue: kotlin.String) : Type(unknownValue)


class TypeAdapter : JsonAdapter<Type>() {
@FromJson
override fun fromJson(reader: JsonReader): Type? {
val s = reader.nextString() ?: return null
return Type.fromString(s)
}

@ToJson
override fun toJson(writer: JsonWriter, value: Type?) {
writer.value(value?.value)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import io.getstream.log.taggedLogger
import io.getstream.result.Result
import io.getstream.video.android.core.analytics.call.CallAnalytics
import io.getstream.video.android.core.analytics.call.observer.model.JoinAnalyticsModel
import io.getstream.video.android.core.call.EmptyRtcSession
import io.getstream.video.android.core.call.RtcSession
import io.getstream.video.android.core.call.audio.InputAudioFilter
import io.getstream.video.android.core.call.components.CallApiClient
Expand All @@ -73,6 +74,7 @@ import io.getstream.video.android.core.call.components.NoiseCancellationPolicy
import io.getstream.video.android.core.call.components.RtcSessionFactory
import io.getstream.video.android.core.call.components.SessionMonitor
import io.getstream.video.android.core.call.connection.StreamPeerConnectionFactory
import io.getstream.video.android.core.call.hls.HlsPlayer
import io.getstream.video.android.core.call.scope.ScopeProvider
import io.getstream.video.android.core.call.scope.ScopeProviderImpl
import io.getstream.video.android.core.call.video.VideoFilter
Expand Down Expand Up @@ -169,6 +171,14 @@ public class Call(
// is also internal, so it cannot appear in a public signature at all.
internal val session: StateFlow<RtcSession?> get() = sessionManager.session

/**
* Plays the call's HLS broadcast. Set while [CallState.playbackType] is
* [io.getstream.video.android.core.model.PlaybackType.Hls], null otherwise. Read by the HLS
* renderer in `stream-video-android-hls`.
*/
@InternalStreamVideoApi
public val hlsPlayer: StateFlow<HlsPlayer?> get() = sessionManager.hlsPlayer

var sessionId: String
get() = sessionManager.sessionId
set(value) {
Expand Down Expand Up @@ -207,6 +217,19 @@ public class Call(
)
}

/** Creates the [EmptyRtcSession] that the first join returns for HLS playback. */
private val playbackSessionFactory: () -> RtcSession = {
EmptyRtcSession(
client = clientImpl,
call = this,
sessionManager = sessionManager,
sessionId = sessionManager.sessionId,
apiKey = clientImpl.apiKey,
lifecycle = clientImpl.coordinatorConnectionModule.lifecycle,
sfuAnalytics = callAnalytics.sfuAnalytics,
)
}

/**
* The call's registration in the client-level ringing / active / telecom registries. Every
* operation needs this instance, which the extracted components deliberately don't hold.
Expand Down Expand Up @@ -537,7 +560,16 @@ public class Call(
clientImpl.permissionCheck
.checkAndroidPermissionsGroup(clientImpl.context, this@Call).first
},
createPlaybackSession = playbackSessionFactory,
consumeJoinSource = { consumeJoinSource() },
hlsPlayerFactory = {
clientImpl.hlsPlayerFactory?.let { factory ->
{
playlistUrl ->
factory.create(clientImpl.context, playlistUrl)
}
}
},
)

internal var reconnectDeadlineMillis: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import io.getstream.video.android.core.internal.InternalStreamVideoApi
import io.getstream.video.android.core.model.Ingress
import io.getstream.video.android.core.model.NetworkQuality
import io.getstream.video.android.core.model.PlaybackType
import io.getstream.video.android.core.model.RTMP
import io.getstream.video.android.core.model.Reaction
import io.getstream.video.android.core.model.RejectReason
Expand Down Expand Up @@ -282,6 +283,18 @@
it is RealtimeConnection.Reconnecting
}

internal val _playbackType = MutableStateFlow<PlaybackType>(PlaybackType.WebRtc)

Check warning on line 286 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Don't expose mutable flow types.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AaGiFCirUU2tmnUmt1AJ&open=AaGiFCirUU2tmnUmt1AJ&pullRequest=1908

/**
* How this client receives the call's media. The backend decides on join: a viewer can be
* served the call's HLS broadcast instead of joining the SFU, in which case this is
* [PlaybackType.Hls] and participants carry no video or audio tracks. Back to
* [PlaybackType.WebRtc] after leaving.
*
* Beta: HLS delivery is enabled per call type by Stream and may change.
*/
public val playbackType: StateFlow<PlaybackType> = _playbackType

private val internalParticipants = ConcurrentHashMap<SessionId, ParticipantState>()
private val _participants = MutableStateFlow<Map<String, ParticipantState>>(emptyMap())

Expand Down Expand Up @@ -1643,9 +1656,10 @@
// participant counts. Coordinator session snapshots (counts_updated, participant_joined/left,
// and any event carrying a CallSessionResponse) carry a smaller, stale view at scale and
// must NOT clobber the SFU value — that produces wild fluctuations in livestreams.
// An HLS viewer has no SFU, so the coordinator stays its only source.
if (sfuHealthCheckEvent != null) {
_participantCounts.value = sfuHealthCheckEvent.participantCount
} else if (session != null && !isInCall()) {
} else if (session != null && (!isInCall() || _playbackType.value is PlaybackType.Hls)) {
val byRoleCount = session.participantsCountByRole.values.sum()
val nonAnonymous = maxOf(byRoleCount, session.participants.size)
_participantCounts.value = ParticipantCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.getstream.log.AndroidStreamLogger
import io.getstream.log.StreamLog
import io.getstream.log.streamLog
import io.getstream.video.android.core.call.CallType
import io.getstream.video.android.core.call.hls.HlsPlayerFactory
import io.getstream.video.android.core.internal.InternalStreamVideoApi
import io.getstream.video.android.core.internal.module.CoordinatorConnectionModule
import io.getstream.video.android.core.logging.LoggingLevel
Expand Down Expand Up @@ -112,6 +113,10 @@ import java.net.ConnectException
* @property rejectCallWhenBusy Automatically rejects incoming calls when the user is already in another call.
* When enabled, the SDK suppresses incoming call notifications.
* CallRingEvent will not be propagated if there is an active or ongoing ringing call.
* @property hlsPlayerFactory Enables HLS playback for viewers. When set, a join tells the backend
* that this client can play HLS, and a call served that way plays through the player it
* builds. Null by default: every call joins over WebRTC. The `stream-video-android-hls`
* artifact provides `ExoHlsPlayerFactory`. Beta.
*
* @see build
* @see ClientState.connection
Expand Down Expand Up @@ -170,6 +175,7 @@ public class StreamVideoBuilder @JvmOverloads constructor(
private val connectOnInit: Boolean = true,
private val rejectCallWhenBusy: Boolean = false,
private val ringStatePolling: RingStatePollingConfig? = RingStatePollingConfig(),
private val hlsPlayerFactory: HlsPlayerFactory? = null,
) {
private val context: Context = context.applicationContext
private val scope = UserScope(ClientScope())
Expand Down Expand Up @@ -330,6 +336,7 @@ public class StreamVideoBuilder @JvmOverloads constructor(
},
tokenRepository = tokenRepository,
rejectCallWhenBusy = rejectCallWhenBusy,
hlsPlayerFactory = hlsPlayerFactory,
)

if (user.type == UserType.Guest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import io.getstream.result.Result.Success
import io.getstream.video.android.core.analytics.AnalyticsModule
import io.getstream.video.android.core.audio.AudioExecutionContext
import io.getstream.video.android.core.call.CallBusyHandler
import io.getstream.video.android.core.call.hls.HlsPlayerFactory
import io.getstream.video.android.core.errors.VideoErrorCode
import io.getstream.video.android.core.events.VideoEventListener
import io.getstream.video.android.core.filter.Filters
Expand Down Expand Up @@ -201,6 +202,7 @@ internal class StreamVideoClient internal constructor(
internal val enableStereoForSubscriber: Boolean = true,
internal val telecomConfig: TelecomConfig? = null,
internal val rejectCallWhenBusy: Boolean = false,
internal val hlsPlayerFactory: HlsPlayerFactory? = null,
internal val analytics: AnalyticsModule = AnalyticsModule.getDefault(
coordinatorConnectionModule.api,
scope,
Expand Down Expand Up @@ -865,6 +867,7 @@ internal class StreamVideoClient internal constructor(
migratingFromList: List<String>? = null,
hintHighScaleLivestreamPublisher: Boolean? = null,
e2ee: Boolean? = null,
playbackCapabilities: List<String>? = null,
): Result<JoinCallResponse> {
val joinCallRequest = JoinCallRequest(
create = create,
Expand All @@ -882,6 +885,7 @@ internal class StreamVideoClient internal constructor(
migratingFrom = migratingFrom,
migratingFromList = migratingFromList,
hintHighScaleLivestreamPublisher = hintHighScaleLivestreamPublisher,
playbackCapabilities = playbackCapabilities,
)

val result = apiCall {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ internal class CallApiClient(
/**
* Executes the coordinator join request. Shared by the join flow and the reconnect flow
* (rejoin / migrate), which is why it lives here rather than in either of them.
*
* Only the first join passes [playbackCapabilities]. Rejoin and migrate recover an SFU
* session, so they must always get SFU credentials back.
*/
suspend fun joinRequest(
create: CreateCallOptions? = null,
Expand All @@ -101,6 +104,7 @@ internal class CallApiClient(
hintHighScaleLivestreamPublisher: Boolean? = null,
joinAnalyticsModel: JoinAnalyticsModel,
e2ee: Boolean? = null,
playbackCapabilities: List<String>? = null,
): Result<JoinCallResponse> {
val migratingFromList =
migratingFromList ?: sessionManager.failedSfuIdsSnapshot().takeIf { it.isNotEmpty() }
Expand Down Expand Up @@ -129,6 +133,7 @@ internal class CallApiClient(
migratingFromList = migratingFromList,
hintHighScaleLivestreamPublisher = hintHighScaleLivestreamPublisher,
e2ee = requestE2ee,
playbackCapabilities = playbackCapabilities,
)
result.onSuccess {
callAnalytics.joinAnalytics.onJoinRequestSuccess(
Expand Down
Loading
Loading