Leave an active call when Telecom puts it to inactive or hold#1622
Leave an active call when Telecom puts it to inactive or hold#1622rahul-lohra wants to merge 1 commit intodevelopfrom
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
WalkthroughThe change adds telecom hold state observation to Changes
Sequence DiagramsequenceDiagram
participant Caller as Caller
participant CS as CallState
participant JTR as JetpackTelecomRepository
participant TC as TelecomCall
participant Coroutine as Coroutine (Default)
Caller->>CS: Set jetpackTelecomRepository
activate CS
CS->>CS: Custom setter invoked
CS->>CS: Call observeTelecomHold(repo)
activate CS
CS->>Coroutine: Launch coroutine
deactivate CS
activate Coroutine
Coroutine->>JTR: Observe currentCall flow
activate JTR
JTR->>TC: Emit TelecomCall state
deactivate JTR
activate TC
TC-->>Coroutine: Is on-hold?
deactivate TC
alt On-hold detected
Coroutine->>CS: Check ringing state
alt Is ringing
Coroutine->>CS: Reject call
else Not ringing
Coroutine->>CS: Leave call
end
end
deactivate Coroutine
deactivate CS
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt`:
- Around line 728-732: The setter for jetpackTelecomRepository only starts
observation when a non-null value is assigned but never cancels
telecomHoldObserverJob when the repository is cleared, causing a coroutine leak;
update the setter for jetpackTelecomRepository so that when value is null it
cancels and nulls telecomHoldObserverJob (and any related observers) and when
non-null calls observeTelecomHold(value), ensuring observeTelecomHold and the
telecomHoldObserverJob lifecycle are symmetrical and safe to call multiple
times.
- Around line 1764-1789: The telecom hold handler is firing for every
re-emission of the same Registered call because repo.currentCall is collected
directly; change the collector to only react to changes in the isOnHold flag
(rising edge) by applying a distinctUntilChanged on the isOnHold value before
handling. Specifically, update the logic around telecomHoldObserverJob that
collects repo.currentCall/TelecomCall.Registered so it maps to the isOnHold
state (or filters Registered then maps) and uses distinctUntilChanged() to only
enter the block when isOnHold transitions true, then perform the existing
ringingState checks and call.reject/call.leave; keep references to
TelecomCall.Registered, ringingState, call.reject, and call.leave when locating
the code to modify.
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt
Show resolved
Hide resolved
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt
Show resolved
Hide resolved
SDK Size Comparison 📏
|
3284e0b to
3dbce6e
Compare
3dbce6e to
2d0b36e
Compare
|


Goal
Ensure active call is correctly left when Android Telecom transitions the SDK state to HOLD , preventing inconsistent call and UI states.
Implementation
We observe Android Telecom state changes via
JetpackTelecomRepository.currentCalland react when the registered Telecom call is placed on hold.When isOnHold becomes true, we reconcile the SDK call state with Telecom by taking explicit action based on the current RingingState:
• Active → Leave the call
• Other states → No action
The observer job is cancelled and restarted to avoid multiple collectors and ensure only one active Telecom state observer at a time.
🎨 UI Changes
None
Add relevant videos
Testing
Summary by CodeRabbit