Skip to content

Improve video analytics by correctly sending ice state#1724

Open
rahul-lohra wants to merge 5 commits into
developfrom
fix/rahullohra/video-analytics-ice-state
Open

Improve video analytics by correctly sending ice state#1724
rahul-lohra wants to merge 5 commits into
developfrom
fix/rahullohra/video-analytics-ice-state

Conversation

@rahul-lohra

@rahul-lohra rahul-lohra commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Goal

Closes AND-1241
Correctly map raw ice state to VideoAnalyticsIceState

Implementation

Introduce a new VideoAnalyticsIceState which will be mapped from Raw ICE state

internal enum class VideoAnalyticsIceState(val text: String) {
    CONNECTED("CONNECTED"), FAILED("FAILED"), NOT_CONNECTED("NOT_CONNECTED")
}

🎨 UI Changes

None

Testing

Run 1-1 calls/group calls. Verify the local logs or kibana

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of connection state reporting during calls.
    • Enhanced fallback handling for missing connection state information.
  • Improvements

    • Refined grace period logic for connection state transitions to increase analytics reliability.

@rahul-lohra rahul-lohra self-assigned this Jun 17, 2026
@rahul-lohra rahul-lohra added the pr:improvement Enhances an existing feature or code label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 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 Jun 17, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-video-android-core 12.27 MB 12.27 MB 0.00 MB 🟢
stream-video-android-ui-xml 5.68 MB 5.68 MB 0.00 MB 🟢
stream-video-android-ui-compose 6.28 MB 6.28 MB 0.00 MB 🟢

@rahul-lohra rahul-lohra changed the title Improve video analytics by correctly sending ice state [AND-1241] Improve video analytics by correctly sending ice state Jun 17, 2026
@rahul-lohra rahul-lohra changed the title [AND-1241] Improve video analytics by correctly sending ice state Improve video analytics by correctly sending ice state Jun 17, 2026
@rahul-lohra rahul-lohra marked this pull request as ready for review June 17, 2026 11:34
@rahul-lohra rahul-lohra requested a review from a team as a code owner June 17, 2026 11:34
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Introduces a VideoAnalyticsIceState enum (CONNECTED, FAILED, NOT_CONNECTED) to replace raw nullable WebRTC PeerConnection.IceConnectionState? across the analytics pipeline. PeerConnectionAnalytics is refactored into a unified observeConnection coroutine with a configurable grace-period wait for ICE CONNECTED. All dependent method signatures in ClientEventReporter, ClientEventFactory, and CallAnalytics are updated, and tests are expanded accordingly.

Changes

VideoAnalyticsIceState Analytics Refactor

Layer / File(s) Summary
VideoAnalyticsIceState enum, mapping, and PeerConnectionSnapshot
...analytics/call/observer/PeerConnectionAnalytics.kt
Defines VideoAnalyticsIceState enum (CONNECTED, FAILED, NOT_CONNECTED), PeerConnectionSnapshot data class, and PeerConnection.IceConnectionState?.toVideoAnalyticsIceState() extension function.
Unified observeConnection with ICE grace-period
...analytics/call/observer/PeerConnectionAnalytics.kt
Replaces duplicated publisher/subscriber coroutine logic with a single observeConnection that filters allowed peer-connection states, waits up to ICE_CONNECTED_GRACE_MILLIS for ICE to reach CONNECTED/COMPLETED, deduplicates snapshots via distinctUntilChanged, and updates onPeerConnectionStateChanged to accept VideoAnalyticsIceState.
Updated reporting pipeline signatures
...analytics/reporting/ClientEventReporter.kt, ...reporting/ClientEventFactory.kt, ...analytics/call/CallAnalytics.kt
Propagates VideoAnalyticsIceState through all handler method signatures in ClientEventReporter; updates ClientEventFactory.buildRequest to accept VideoAnalyticsIceState? and serialize via .text; updates CallAnalytics.onCallLeave to derive ICE states via toVideoAnalyticsIceState() with a NOT_CONNECTED fallback.
Updated and expanded analytics tests
...analytics/call/observer/PeerConnectionAnalyticsTest.kt, ...analytics/reporting/ClientEventReporterTest.kt, ...analytics/call/CallAnalyticsTest.kt
Updates all tests to use VideoAnalyticsIceState expectations; adds grace-period tests (ICE never connects, ICE connects within window, ICE already connected at observation time); adds toVideoAnalyticsIceState() mapping assertions for all WebRTC values including null; replaces removed "null ICE ignored" test with "CONNECTED completes even when ICE is NOT_CONNECTED".

Sequence Diagram(s)

sequenceDiagram
  participant PeerConnectionAnalytics
  participant observeConnection
  participant IceStateFlow
  participant ClientEventReporter
  participant ClientEventFactory

  PeerConnectionAnalytics->>observeConnection: emit PeerConnectionState (CONNECTING/CONNECTED/FAILED)
  observeConnection->>observeConnection: filter allowed states, deduplicate via distinctUntilChanged
  alt PeerConnectionState == CONNECTED
    observeConnection->>IceStateFlow: withTimeoutOrNull(ICE_CONNECTED_GRACE_MILLIS) first(CONNECTED/COMPLETED)
    IceStateFlow-->>observeConnection: ICE CONNECTED within grace → VideoAnalyticsIceState.CONNECTED
    IceStateFlow-->>observeConnection: grace elapsed → VideoAnalyticsIceState (current)
  else CONNECTING or FAILED
    observeConnection->>observeConnection: toVideoAnalyticsIceState() immediately
  end
  observeConnection->>ClientEventReporter: onPeerConnectionStateChanged(VideoAnalyticsIceState, PeerConnectionState)
  ClientEventReporter->>ClientEventFactory: buildRequest(iceState: VideoAnalyticsIceState?)
  ClientEventFactory-->>ClientEventReporter: ClientEvent with iceState.text
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • GetStream/stream-video-android#1716: Introduced the original PeerConnectionAnalytics, ClientEventReporter, ClientEventFactory, and CallAnalytics abort/leave reporting plumbing that this PR directly refactors.

Suggested labels

pr:bug, released

Suggested reviewers

  • PratimMallick
  • aleksandar-apostolov

Poem

🐇 Hopping through ICE states old and new,
I swapped the nullable WebRTC stew.
A grace window waits for CONNECTED to bloom,
Or NOT_CONNECTED fills the reporting room.
The enum is tidy, the tests are bright—
This bunny's analytics feel just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: improving video analytics by correctly sending ICE state, which is the primary focus of all modifications.
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 Pull request description covers all required sections: Goal (references issue AND-1241), Implementation (introduces VideoAnalyticsIceState enum with clear structure), UI Changes (explicitly states None), and Testing (describes validation approach).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rahullohra/video-analytics-ice-state

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/reporting/ClientEventReporter.kt`:
- Around line 291-294: The unconditional Log.d call with tag "Noob" in the
onPeerConnectionStateChanged method will produce noisy logs on every peer
connection state transition in production. Either remove this debug log
statement entirely or wrap it in a conditional check using
StreamVideoImpl.developmentMode to ensure the verbose logging only occurs during
development, following the coding guideline that requires monitoring logging
verbosity and relying on developmentMode for guardrails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0f06c4ff-7006-4f6a-af60-fdd08b2ad968

📥 Commits

Reviewing files that changed from the base of the PR and between c5bcc10 and ca4ca85.

📒 Files selected for processing (7)
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/call/CallAnalytics.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/call/observer/PeerConnectionAnalytics.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/reporting/ClientEventFactory.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/reporting/ClientEventReporter.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/analytics/call/CallAnalyticsTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/analytics/call/observer/PeerConnectionAnalyticsTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/analytics/reporting/ClientEventReporterTest.kt

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:improvement Enhances an existing feature or code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants