Skip to content

Code refactor for Video Analytics #1727

Open
rahul-lohra wants to merge 2 commits into
developfrom
improvement/rahullohra/coordinator-analytics
Open

Code refactor for Video Analytics #1727
rahul-lohra wants to merge 2 commits into
developfrom
improvement/rahullohra/coordinator-analytics

Conversation

@rahul-lohra

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

Copy link
Copy Markdown
Contributor

Goal

Closes AND-1243
Code refactor of Video analytics

Implementation

Code refactor around CoordinatorAnalyticsStateHolder

🎨 UI Changes

None

Testing

Regular 1-1 calls

Summary by CodeRabbit

  • Refactor
    • Reorganized internal analytics architecture for improved maintainability and consistency across SDK components.

@rahul-lohra rahul-lohra self-assigned this Jun 18, 2026
@rahul-lohra rahul-lohra added the pr:internal Internal or infra-only changes label Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 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.

@rahul-lohra rahul-lohra changed the title [AND-1243] Code refactor for Video Analytics Code refactor for Video Analytics Jun 18, 2026
@rahul-lohra rahul-lohra marked this pull request as ready for review June 18, 2026 08:09
@rahul-lohra rahul-lohra requested a review from a team as a code owner June 18, 2026 08:09
@github-actions

github-actions Bot commented Jun 18, 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 🟢

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3bbfaee8-7b8d-4b8b-b1c5-ae73ff14b85d

📥 Commits

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

📒 Files selected for processing (11)
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/ClientState.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/analytics/AnalyticsModule.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/call/observer/SfuAnalytics.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/coordinator/CoordinatorAnalytics.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/analytics/coordinator/CoordinatorAnalyticsStateHolder.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/StreamVideoClientTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/analytics/coordinator/CoordinatorAnalyticsTest.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/analytics/reporting/ClientEventReporterTest.kt

Walkthrough

Introduces CoordinatorAnalyticsStateHolder, a StateFlow-backed container for coordinator connection IDs. CoordinatorAnalytics writes a UUID to it on initial WebSocket connection. ClientEventReporter and ClientEventFactory are refactored to read from this holder instead of using internal mutable state. A new AnalyticsModule composition root centralizes construction of these components, and StreamVideoClient adopts it in place of scattered analytics initialization.

Changes

Analytics module refactor

Layer / File(s) Summary
CoordinatorAnalyticsStateHolder and CoordinatorAnalytics update
analytics/coordinator/CoordinatorAnalyticsStateHolder.kt, analytics/coordinator/CoordinatorAnalytics.kt
New CoordinatorAnalyticsStateHolder exposes a StateFlow<String> for coordinator connection ID; CoordinatorAnalytics accepts it as a constructor dependency and writes a UUID to it on INITIAL_CONNECTION.
ClientEventReporter and ClientEventFactory updated to read state holder
analytics/reporting/ClientEventReporter.kt, analytics/reporting/ClientEventFactory.kt
ClientEventFactory replaces the getCoordinatorId lambda parameter with CoordinatorAnalyticsStateHolder and reads coordinatorConnectId.value in buildRequest; ClientEventReporter threads the same holder through its constructor and getDefault factory, removing its internal mutable coordinator connect-ID field.
AnalyticsModule composition root and wiring
analytics/AnalyticsModule.kt, core/StreamVideoClient.kt, core/ClientState.kt, analytics/call/observer/SfuAnalytics.kt
AnalyticsModule creates a shared CoordinatorAnalyticsStateHolder and assembles ClientEventReporter and CoordinatorAnalytics from it; StreamVideoClient replaces scattered analytics construction with a single analytics: AnalyticsModule property; ClientState and SfuAnalytics update their references accordingly.
Test wiring updates
test/.../StreamVideoClientTest.kt, test/.../CoordinatorAnalyticsTest.kt, test/.../ClientEventReporterTest.kt
Test helpers pass analytics = mockk(relaxed = true) or CoordinatorAnalyticsStateHolder() to match updated production constructor signatures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • GetStream/stream-video-android#1716: Refactors the same ClientEventReporter/CoordinatorAnalytics lifecycle wiring in StreamVideoClient and ClientState, directly touching the same classes and observer start/end patterns modified in this PR.

Suggested reviewers

  • PratimMallick
  • aleksandar-apostolov

🐇 A state flow born to carry the key,
A UUID written for all calls to see,
One module to bind them, analytics neat,
No scattered reporters — just one clean feat!
Hop hop hooray for tidy code today! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and missing most required template sections including detailed implementation details, testing methodology, and contributor/reviewer checklists. Complete the PR description with detailed implementation explanation, concrete testing steps, signed CLA confirmation, and updated checklists per the repository template.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Code refactor for Video Analytics' is vague and doesn't specify the key structural change (introducing AnalyticsModule and CoordinatorAnalyticsStateHolder) that organizes analytics initialization. Consider a more specific title like 'Refactor analytics initialization through AnalyticsModule' to clearly convey the main architectural change.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

✏️ 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 improvement/rahullohra/coordinator-analytics

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.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Labels

pr:internal Internal or infra-only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant