Skip to content

Join livestreams over HLS when the backend grants HLS playback - #1908

Merged
aleksandar-apostolov merged 21 commits into
developfrom
pratimmallick/vid-1543-hls-join-sdk
Nov 27, 2026
Merged

aleksandar-apostolov merged 21 commits into
developfrom
pratimmallick/vid-1543-hls-join-sdk

Conversation

@PratimMallick

@PratimMallick PratimMallick commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Goal

Refs VID-1543. This lets the backend move livestream viewers to HLS. If the app has registered an HLS player factory, the SDK declares HLS support on the first join. When the response carries an HLS playback grant, the call joins without an SFU connection. The SDK then creates one player for the call and exposes the grant through call.state.playbackType. Backend: GetStream/chat#19517.

Core has no Media3 dependency. The ExoPlayer implementation and the Compose renderer are in a separate opt-in artifact (#1909), so apps that don't use HLS don't pay its size cost.

Implementation

  • Models: playback_capabilities and prefer on JoinCallRequest, playback on JoinCallResponse, and a new PlaybackResponse. These were added by hand to match the backend spec, not regenerated. They are placed last so no existing componentN moves.
  • New public HlsPlayer and HlsPlayerFactory interfaces in core.call.hls. They are registered through the new trailing StreamVideoBuilder(hlsPlayerFactory = ...) parameter, which defaults to null.
  • The first join sends playback_capabilities: ["hls"] only when a factory is registered. Without one, nothing changes and the join always gets SFU credentials. Rejoin and migrate never send it. There is no mid-call switch in v1.
  • prefer is not sent. The backend decides the tier through delivery.hls_percentage.
  • On an HLS grant, CallJoinCoordinator holds an EmptyRtcSession (from Add EmptyRtcSession, an RtcSession without an SFU connection #1903) in CallSessionManager.playbackSession, never as the active session. It skips the SFU connect, session monitoring and media setup. It creates the call's player through the factory, then moves the connection to Joined and then Connected. The join fails, with nothing installed, if the grant has an unknown type or a blank URL, if no factory is registered, or if the factory throws.
  • One player per call: Call.hlsPlayer (@InternalStreamVideoApi) is set on the HLS join. Leave and cleanup() clear it and call release(). Renderers only attach and detach the video, so rotation and recomposition don't rebuild the player.
  • Joining over HLS plays nothing by itself: playback, including audio, starts when the app shows HlsVideoRenderer from stream-video-android-hls. After that, playback continues while no renderer is shown or the app is in the background, the same as a WebRTC call, until the call is left.
  • The join coordinator reads the registered factory at join time, not when a Call is built.
  • New public PlaybackType (WebRtc / Hls(playlistUrl)) and CallState.playbackType. PlaybackType, HlsPlayer, CallState.playbackType and Call.hlsPlayer are @ExperimentalStreamVideoApi.
  • During HLS, participant counts keep coming from coordinator events.
  • CallReconnector.reconnect() returns early during HLS playback, since there is no SFU connection to recover.
  • The grant's playlist URL must be an absolute https URL.
  • While joined over HLS, the call is left when state.endedAt is set, so a missed call.ended event doesn't leave the viewer connected.
  • Leave and cleanup() take the player atomically, so it is released once.
  • The leave guard is reset at the start of the join, before its first suspension.
  • v1 limits, documented in KDoc: there is no mid-call switch. If the host stops the HLS broadcast, or the viewer is granted publish, the viewer stays on HLS and has to leave and rejoin.
  • API dump: new types, the playbackType getter, and a new StreamVideoBuilder constructor overload are added. The JoinCallRequest / JoinCallResponse constructor and copy signatures change because of the new trailing parameters, the same as earlier hand-added fields.

Testing

New unit tests:

  • CallJoinCoordinatorTest covers these cases:
    • The first join declares HLS only when a factory is registered.
    • An HLS grant joins without an SFU connection and installs the player.
    • A grant without a factory fails the join.
    • A factory that throws fails the join, cleans up the session, and installs nothing.
    • Joining again during HLS returns the playback session.
    • An unplayable grant fails the join.
  • CallApiClientTest: playbackCapabilities is forwarded only when the caller passes it.
  • CallReconnectorTest: reconnect is skipped during HLS playback.
  • CallLifecycleManagerTest: leaving after HLS releases the player and the playback session, resets the type, and sends no SFU leave event.
  • PlaybackSerializationTest: request JSON, parsing an HLS grant, and unknown values mapping to Unknown.
  • PlaybackSerializationTest: a full HLS join response with empty SFU credentials parses.
  • CallJoinCoordinatorTest: the call is left when endedAt is set during HLS, a non-https playlist URL fails the join, a leave during the join preamble prevents the HLS install, and a WebRTC join that fails after leave started stays Disconnected.

./gradlew spotlessCheck apiCheck :stream-video-android-core:testDebugUnitTest :demo-app:compileDevelopmentDebugKotlin passes.

Manual check to run with #1909's demo app, which registers the factory:

  1. Use a call type with delivery.hls_percentage > 0 and a running HLS broadcast.
  2. Join as a viewer with no publish capabilities.
  3. Expect call.state.playbackType to be Hls(url) and the connection to be Connected, with no SFU connection.

Made with Cursor

PratimMallick and others added 6 commits November 2, 2026 13:59
…nection

RtcSession becomes open and gains an internal initializeRtc flag. When the
flag is false, the session never creates the SFU connection or any peer
connection and leaves the shared peer connection factory untouched.
EmptyRtcSession uses it and turns every public member into a no-op.

cleanup() no longer assumes the SFU connection module exists.

Prepares for joining a call without WebRTC media (VID-1543). No behaviour
change for existing sessions.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@PratimMallick PratimMallick added the pr:new-feature Adds new functionality label Nov 3, 2026
@PratimMallick

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The join API adds HLS capability and playback response fields. The call coordinator routes valid HLS responses to playback sessions and keeps WebRTC joins on their existing media initialization path. Call state exposes the playback type, and lifecycle and reconnect handling account for playback sessions. Tests cover serialization, request forwarding, playback joins, cleanup, and reconnect behavior.

Suggested reviewers: aleksandar-apostolov

Merge Risk: Moderate · up to f07c8

If a viewer leaves while an HLS join is still pending, the call can end up marked active and connected after the leave. This is a narrow race, but it should be fixed before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Join livestreams over HLS when the backend grants HLS playback" matches the main change. The PR adds HLS playback joins: the coordinator skips the SFU connection when the backend returns an…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template. It has Goal, Implementation, Testing, and Checklist content. The Goal section links VID-1543 and explains the HLS playback grant flow. The Implementati…
Full details: Title check

Explanation

The title "Join livestreams over HLS when the backend grants HLS playback" matches the main change. The PR adds HLS playback joins: the coordinator skips the SFU connection when the backend returns an HLS grant, and it exposes the playlist URL through CallState.playbackType. The title is specific, concise, and names the primary behavior.

Full details: Description check

Explanation

The description follows the repository template. It has Goal, Implementation, Testing, and Checklist content. The Goal section links VID-1543 and explains the HLS playback grant flow. The Implementation section lists the model changes, the new HlsPlayer and HlsPlayerFactory interfaces, the first-join capability rule, the join coordinator behavior, the player lifecycle, the PlaybackType and CallState.playbackType additions, and the reconnect and participant-count behavior. The Testing section lists the new unit tests, the Gradle command that passes, and a manual check procedure. The Checklist is present but not ticked. The description does not state whether tests and docs were updated in the checklist sense. It also does not mention the CLA status, which the template lists for external contributors only. These gaps are minor and do not block the check.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the join request’s flow
An HLS playlist begins to glow
The session rests where broadcasts stream
WebRTC waits outside the scene
Then off hops the rabbit, pleased with the scheme

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e7a3db74-9879-4ba4-b324-2e963468d14b
Commits

Reviewing files that changed from the base of the PR and between e42ea3a and f07c821.

Files ignored due to path filters: 4

  • stream-video-android-core/src/main/kotlin/io/getstream/android/video/generated/infrastructure/Serializer.kt is excluded by !**/generated/**
  • stream-video-android-core/src/main/kotlin/io/getstream/android/video/generated/models/JoinCallRequest.kt is excluded by !**/generated/**
  • stream-video-android-core/src/main/kotlin/io/getstream/android/video/generated/models/JoinCallResponse.kt is excluded by !**/generated/**
  • stream-video-android-core/src/main/kotlin/io/getstream/android/video/generated/models/PlaybackResponse.kt is excluded by !**/generated/**
Files selected for processing: 17

  • stream-video-android-core/api/stream-video-android-core.api
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/components/CallApiClient.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/components/CallJoinCoordinator.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/components/CallLifecycleManager.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/components/CallReconnector.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/components/CallSessionManager.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/model/PlaybackType.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/call/components/CallApiClientTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/call/components/CallJoinCoordinatorTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/call/components/CallLifecycleManagerTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/call/components/CallReconnectorTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/e2ee/CallE2EETest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/model/PlaybackSerializationTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/rtc/JoinRecoverableFailureTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-video-android-core 12.38 MB 12.38 MB 0.00 MB 🟢
stream-video-android-ui-xml 5.65 MB 5.66 MB 0.02 MB 🟢
stream-video-android-ui-compose 6.19 MB 6.19 MB 0.00 MB 🟢

@PratimMallick
PratimMallick marked this pull request as ready for review November 9, 2026 11:40
@PratimMallick
PratimMallick requested a review from a team as a code owner November 9, 2026 11:40
@aleksandar-apostolov

Copy link
Copy Markdown
Collaborator

The description still says rendering is PR 3, but 5a27e0f adds the Media3 player and HlsVideoRenderer here. Could that commit go back to its own PR on top, so this one stays core-only?

@PratimMallick

Copy link
Copy Markdown
Contributor Author

Moved the renderer out: this PR is back to the three core commits, and 5a27e0f plus the fixes for your two renderer comments are in #1909, stacked on this one.

Base automatically changed from pratimmallick/vid-1543-empty-rtc-session to develop November 18, 2026 10:20
Media3 adds about 2 MB, and few apps need HLS, so the player moves to a
separate artifact. Core keeps the contract: HlsPlayer and HlsPlayerFactory,
registered through StreamVideoBuilder.hlsPlayerFactory.

The first join only declares HLS support when a factory is registered, so
an app without one is never served HLS. An HLS join creates the call's
player next to the playback session; leave releases it. A player that
cannot be created fails the join and installs nothing.
@sonarqubecloud

Copy link
Copy Markdown

@aleksandar-apostolov
aleksandar-apostolov added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
@aleksandar-apostolov
aleksandar-apostolov added this pull request to the merge queue Nov 27, 2026
Merged via the queue into develop with commit ef42815 Nov 27, 2026
23 checks passed
@aleksandar-apostolov
aleksandar-apostolov deleted the pratimmallick/vid-1543-hls-join-sdk branch November 27, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:new-feature Adds new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants