-
Notifications
You must be signed in to change notification settings - Fork 56
Improve ringing state transition to Active when WS is not connected #1617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rahul-lohra
wants to merge
5
commits into
develop
Choose a base branch
from
bugfix/rahullohra/join-and-ring-issues
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
35db03b
fix: Correctly update from RingingState.Outgoing is to RingingState.A…
rahul-lohra 697050d
Merge branch 'develop' into bugfix/rahullohra/join-and-ring-issues
rahul-lohra c620f4d
chore: refactor
rahul-lohra ebcdf79
chore: atomically update ringingStateUpdatesStopped
rahul-lohra dfb6f30
Merge remote-tracking branch 'origin/bugfix/rahullohra/join-and-ring-…
rahul-lohra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ package io.getstream.video.android.core | |
|
|
||
| import android.app.Notification | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import androidx.compose.runtime.Stable | ||
| import androidx.core.app.NotificationManagerCompat | ||
| import io.getstream.android.video.generated.models.BlockedUserEvent | ||
|
|
@@ -160,6 +159,7 @@ import java.util.Locale | |
| import java.util.SortedMap | ||
| import java.util.UUID | ||
| import java.util.concurrent.ConcurrentHashMap | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
| import java.util.concurrent.atomic.AtomicReference | ||
| import kotlin.time.Duration | ||
| import kotlin.time.DurationUnit | ||
|
|
@@ -1023,7 +1023,7 @@ public class CallState( | |
| is JoinCallResponseEvent -> { | ||
| // time to update call state based on the join response | ||
| updateFromJoinResponse(event) | ||
| if (!ringingStateUpdatesStopped) { | ||
| if (!ringingStateUpdatesStopped.get()) { | ||
| updateRingingState() | ||
| } else { | ||
| _ringingState.value = RingingState.Outgoing(acceptedByCallee = true) | ||
|
|
@@ -1239,6 +1239,7 @@ public class CallState( | |
| } | ||
|
|
||
| private fun updateRingingState(rejectReason: RejectReason? = null) { | ||
| val ringingStateLogger by taggedLogger("RingingState") | ||
| if (ringingState.value == RingingState.RejectedByAll) { | ||
| return | ||
| } | ||
|
|
@@ -1256,8 +1257,9 @@ public class CallState( | |
| val userIsParticipant = | ||
| _session.value?.participants?.find { it.user.id == client.userId } != null | ||
| val outgoingMembersCount = _members.value.filter { it.value.user.id != client.userId }.size | ||
| val createdBySelf = createdBy?.id == client.userId | ||
|
|
||
| Log.d("RingingState", "Current: ${_ringingState.value}, call_id: ${call.cid}") | ||
| ringingStateLogger.d { "Current: ${_ringingState.value}, call_id: ${call.cid}" } | ||
|
|
||
| val ringingStateLogs = arrayListOf( | ||
| ("acceptedByMe: $isAcceptedByMe"), | ||
|
|
@@ -1268,19 +1270,19 @@ public class CallState( | |
| ("userIsParticipant: $userIsParticipant"), | ||
| ).joinToString("") { it + "\n" } | ||
|
|
||
| Log.d( | ||
| "RingingState", | ||
| "call_id: ${call.cid}, Flags: $ringingStateLogs", | ||
| ) | ||
| ringingStateLogger.d { "call_id: ${call.cid}, Flags: $ringingStateLogs" } | ||
|
|
||
| // no members - call is empty, we can join | ||
| val state: RingingState = if (hasActiveCall && !ringingStateUpdatesStopped) { | ||
| val state: RingingState = if (hasActiveCall && !ringingStateUpdatesStopped.get()) { | ||
| cancelTimeout() | ||
| RingingState.Active | ||
| } else if (isRejectedByMe) { | ||
| call.leave("updateRingingState-rejected-self") | ||
| cancelTimeout() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| RingingState.RejectedByAll | ||
| } else if (hasActiveCall && createdBySelf && acceptedBy.isNotEmpty() && !isAcceptedByMe) { // for joinAndRing | ||
| cancelTimeout() | ||
| RingingState.Active | ||
| } else if ((rejectedBy.isNotEmpty() && rejectedBy.size >= outgoingMembersCount) || | ||
| (rejectedBy.contains(createdBy?.id) && hasRingingCall) | ||
| ) { | ||
|
|
@@ -1303,7 +1305,7 @@ public class CallState( | |
| } | ||
| } else if (hasRingingCall && createdBy?.id == client.userId) { | ||
| // The call is created by us | ||
| logger.d { "acceptedBy: $acceptedBy, userIsParticipant: $userIsParticipant" } | ||
| ringingStateLogger.d { "acceptedBy: $acceptedBy, userIsParticipant: $userIsParticipant" } | ||
| if (acceptedBy.isEmpty()) { | ||
| // no one accepted the call | ||
| RingingState.Outgoing(acceptedByCallee = false) | ||
|
|
@@ -1312,8 +1314,9 @@ public class CallState( | |
| RingingState.Outgoing(acceptedByCallee = true) | ||
| } else { | ||
| // call is accepted and we are already in the call | ||
| ringingStateUpdatesStopped = false | ||
| ringingStateUpdatesStopped.set(false) | ||
| cancelTimeout() | ||
| logger.d { "RingingState.Active source 3" } | ||
| RingingState.Active | ||
| } | ||
| } else { | ||
|
|
@@ -1325,7 +1328,7 @@ public class CallState( | |
| } | ||
|
|
||
| if (_ringingState.value != state) { | ||
| logger.d { "Updating ringing state ${_ringingState.value} -> $state" } | ||
| ringingStateLogger.d { "Updating ringing state ${_ringingState.value} -> $state" } | ||
|
|
||
| // handle the auto-cancel for outgoing ringing calls | ||
| if (state is RingingState.Outgoing && !state.acceptedByCallee) { | ||
|
|
@@ -1338,7 +1341,7 @@ public class CallState( | |
|
|
||
| // stop the call ringing timer if it's running | ||
| } | ||
| Log.d("RingingState", "Update: $state") | ||
| ringingStateLogger.d { "Update: $state" } | ||
|
|
||
| _ringingState.value = state | ||
| } | ||
|
|
@@ -1394,7 +1397,7 @@ public class CallState( | |
|
|
||
| // double check that we are still in Outgoing call state and call is not active | ||
| if (_ringingState.value is RingingState.Outgoing || _ringingState.value is RingingState.Incoming && client.state.activeCall.value == null) { | ||
| ringingStateUpdatesStopped = false | ||
| ringingStateUpdatesStopped.set(false) | ||
| call.reject(reason = RejectReason.Custom(alias = REJECT_REASON_TIMEOUT)) | ||
| call.leave("start-ringing-timeout") | ||
| } | ||
|
|
@@ -1643,10 +1646,10 @@ public class CallState( | |
| _broadcasting.value = true | ||
| } | ||
|
|
||
| private var ringingStateUpdatesStopped = false | ||
| private var ringingStateUpdatesStopped = AtomicBoolean(false) | ||
|
|
||
| internal fun toggleRingingStateUpdates(stopped: Boolean) { | ||
| ringingStateUpdatesStopped = stopped | ||
| ringingStateUpdatesStopped.set(stopped) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ringingStateLoggeris created insideupdateRingingState()via delegate — this allocates a new logger on every call. This method fires frequently during call state changes. Should be a class-level property like the existinglogger.