@capgo/capacitor-stream-call 0.0.38 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,8 @@ import android.content.BroadcastReceiver
64
64
  import android.content.Intent
65
65
  import android.content.IntentFilter
66
66
  import io.getstream.android.video.generated.models.CallSessionParticipantLeftEvent
67
+ import io.getstream.video.android.core.RealtimeConnection
68
+ import io.getstream.video.android.core.events.ParticipantLeftEvent
67
69
 
68
70
  // I am not a religious pearson, but at this point, I am not sure even god himself would understand this code
69
71
  // It's a spaghetti-like, tangled, unreadable mess and frankly, I am deeply sorry for the code crimes commited in the Android impl
@@ -706,25 +708,39 @@ public class StreamCallPlugin : Plugin() {
706
708
  updateCallStatusAndNotify(event.callCid, "left")
707
709
  }
708
710
 
709
- is CallSessionParticipantLeftEvent -> {
711
+ is ParticipantLeftEvent, is CallSessionParticipantLeftEvent -> {
710
712
  val activeCall = streamVideoClient?.state?.activeCall?.value
711
- android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Received for call ${event.callCid}. User left: ${event.participant?.user?.id}. Active call: ${activeCall?.cid}")
712
713
 
713
- if (activeCall != null && activeCall.cid == event.callCid) {
714
- // Directly check remote participants after a left event for the active call
715
- val remoteParticipants = activeCall.state.remoteParticipants.value
716
- android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Active call ${activeCall.cid}, remote participants count: ${remoteParticipants.size}")
714
+ val callId = when (event) {
715
+ is ParticipantLeftEvent -> {
716
+ event.callCid
717
+ }
718
+ is CallSessionParticipantLeftEvent -> {
719
+ event.callCid
720
+ }
721
+
722
+ else -> {
723
+ throw RuntimeException("Unreachable code reached when getting callId")
724
+ }
725
+ }
717
726
 
718
- if (remoteParticipants.isEmpty()) {
719
- android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: All remote participants have left call ${activeCall.cid}. Ending call.")
720
- kotlinx.coroutines.GlobalScope.launch(Dispatchers.IO) {
721
- endCallRaw(activeCall)
727
+ android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Received for call $callId. Active call: ${activeCall?.cid}")
728
+
729
+
730
+ if (activeCall != null && activeCall.cid == callId) {
731
+ val connectionState = activeCall.state.connection.value
732
+ if (connectionState == RealtimeConnection.Disconnected) {
733
+ val total = activeCall.state.participantCounts.value?.total
734
+ android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Participant left, remaining: $total");
735
+ if (total != null && total <= 2) {
736
+ android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: All remote participants have left call ${activeCall.cid}. Ending call.")
737
+ kotlinx.coroutines.GlobalScope.launch(Dispatchers.IO) {
738
+ endCallRaw(activeCall)
739
+ }
722
740
  }
723
- } else {
724
- android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Remote participants still present in call ${activeCall.cid}. Count: ${remoteParticipants.size}")
725
741
  }
726
742
  } else {
727
- android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Conditions not met (activeCall null, or cid mismatch, or local user not joined). ActiveCall CID: ${activeCall?.cid}, Event CID: ${event.callCid}")
743
+ android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Conditions not met (activeCall null, or cid mismatch, or local user not joined). ActiveCall CID: ${activeCall?.cid}")
728
744
  }
729
745
  }
730
746
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-stream-call",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "Uses the https://getstream.io/ SDK to implement calling in Capacitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",