@capgo/capacitor-stream-call 0.0.80 → 0.0.82

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.
@@ -69,6 +69,7 @@ import io.getstream.video.android.core.GEO
69
69
  import io.getstream.video.android.core.RealtimeConnection
70
70
  import io.getstream.video.android.core.StreamVideo
71
71
  import io.getstream.video.android.core.StreamVideoBuilder
72
+ import io.getstream.video.android.core.EventSubscription
72
73
  import io.getstream.video.android.core.events.ParticipantLeftEvent
73
74
  import io.getstream.video.android.core.internal.InternalStreamVideoApi
74
75
  import io.getstream.video.android.core.notifications.NotificationConfig
@@ -81,6 +82,7 @@ import io.getstream.video.android.model.streamCallId
81
82
  import kotlinx.coroutines.CoroutineScope
82
83
  import kotlinx.coroutines.DelicateCoroutinesApi
83
84
  import kotlinx.coroutines.Dispatchers
85
+ import kotlinx.coroutines.Job
84
86
  import kotlinx.coroutines.launch
85
87
  import kotlinx.coroutines.tasks.await
86
88
  import androidx.core.net.toUri
@@ -102,6 +104,10 @@ public class StreamCallPlugin : Plugin() {
102
104
  private var savedActivityPaused = false
103
105
  private var savedCallsToEndOnResume = mutableListOf<Call>()
104
106
  private val callStates: MutableMap<String, LocalCallState> = mutableMapOf()
107
+ private var eventSubscription: EventSubscription? = null
108
+ private var activeCallStateJob: Job? = null
109
+ private var cameraStatusJob: Job? = null
110
+ private var microphoneStatusJob: Job? = null
105
111
 
106
112
  // Store current call info
107
113
  private var currentCallId: String = ""
@@ -500,6 +506,10 @@ public class StreamCallPlugin : Plugin() {
500
506
  try {
501
507
  // Clear stored credentials
502
508
  SecureUserRepository.getInstance(context).removeCurrentUser()
509
+ eventSubscription?.dispose()
510
+ activeCallStateJob?.cancel()
511
+ cameraStatusJob?.cancel()
512
+ microphoneStatusJob?.cancel()
503
513
 
504
514
  // Properly cleanup the client
505
515
  kotlinx.coroutines.GlobalScope.launch {
@@ -511,7 +521,6 @@ public class StreamCallPlugin : Plugin() {
511
521
 
512
522
  streamVideoClient = null
513
523
  state = State.NOT_INITIALIZED
514
- eventHandlersRegistered = false
515
524
 
516
525
  val ret = JSObject()
517
526
  ret.put("success", true)
@@ -552,10 +561,7 @@ public class StreamCallPlugin : Plugin() {
552
561
  android.util.Log.v("StreamCallPlugin", "Plugin's streamVideoClient is null, reusing singleton and registering event handlers")
553
562
  streamVideoClient = StreamVideo.instance()
554
563
  // Register event handlers since streamVideoClient was null
555
- if (!eventHandlersRegistered) {
556
- registerEventHandlers()
557
- eventHandlersRegistered = true
558
- }
564
+ registerEventHandlers()
559
565
  } else {
560
566
  android.util.Log.v("StreamCallPlugin", "Plugin already has streamVideoClient, skipping event handler registration")
561
567
  }
@@ -646,10 +652,8 @@ public class StreamCallPlugin : Plugin() {
646
652
  this.state = State.INITIALIZED
647
653
  return
648
654
  }
649
- if (!eventHandlersRegistered) {
650
- registerEventHandlers()
651
- eventHandlersRegistered = true
652
- }
655
+
656
+ registerEventHandlers()
653
657
 
654
658
  android.util.Log.v("StreamCallPlugin", "Initialization finished")
655
659
  initializationTime = System.currentTimeMillis()
@@ -704,9 +708,13 @@ public class StreamCallPlugin : Plugin() {
704
708
 
705
709
  @OptIn(DelicateCoroutinesApi::class)
706
710
  private fun registerEventHandlers() {
711
+ eventSubscription?.dispose()
712
+ activeCallStateJob?.cancel()
713
+ cameraStatusJob?.cancel()
714
+ microphoneStatusJob?.cancel()
707
715
  // Subscribe to call events
708
716
  streamVideoClient?.let { client ->
709
- client.subscribe { event: VideoEvent ->
717
+ eventSubscription = client.subscribe { event: VideoEvent ->
710
718
  android.util.Log.v("StreamCallPlugin", "Received an event ${event.getEventType()} $event")
711
719
  when (event) {
712
720
  is CallRingEvent -> {
@@ -907,7 +915,7 @@ public class StreamCallPlugin : Plugin() {
907
915
  if (connectionState != RealtimeConnection.Disconnected) {
908
916
  val total = activeCall.state.participantCounts.value?.total
909
917
  android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: Participant left, remaining: $total");
910
- if (total != null && total < 2) {
918
+ if (total != null && total <= 1) {
911
919
  android.util.Log.d("StreamCallPlugin", "CallSessionParticipantLeftEvent: All remote participants have left call ${activeCall.cid}. Ending call.")
912
920
  kotlinx.coroutines.GlobalScope.launch(Dispatchers.IO) {
913
921
  endCallRaw(activeCall)
@@ -930,7 +938,7 @@ public class StreamCallPlugin : Plugin() {
930
938
 
931
939
  // Add call state subscription using collect
932
940
  // used so that it follows the same patterns as iOS
933
- kotlinx.coroutines.GlobalScope.launch {
941
+ activeCallStateJob = kotlinx.coroutines.GlobalScope.launch {
934
942
  client.state.activeCall.collect { call ->
935
943
  android.util.Log.d("StreamCallPlugin", "Call State Update:")
936
944
  android.util.Log.d("StreamCallPlugin", "- Call is null: ${call == null}")
@@ -946,8 +954,11 @@ public class StreamCallPlugin : Plugin() {
946
954
  // Make sure activity is visible on lock screen
947
955
  changeActivityAsVisibleOnLockScreen(this@StreamCallPlugin.activity, true)
948
956
 
957
+ cameraStatusJob?.cancel()
958
+ microphoneStatusJob?.cancel()
959
+
949
960
  // Listen to camera status changes
950
- kotlinx.coroutines.GlobalScope.launch {
961
+ cameraStatusJob = kotlinx.coroutines.GlobalScope.launch {
951
962
  call.camera.isEnabled.collect { isEnabled ->
952
963
  android.util.Log.d("StreamCallPlugin", "Camera status changed for call ${call.id}: enabled=$isEnabled")
953
964
  updateCallStatusAndNotify(call.cid, if (isEnabled) "camera_enabled" else "camera_disabled")
@@ -955,13 +966,15 @@ public class StreamCallPlugin : Plugin() {
955
966
  }
956
967
 
957
968
  // Listen to microphone status changes
958
- kotlinx.coroutines.GlobalScope.launch {
969
+ microphoneStatusJob = kotlinx.coroutines.GlobalScope.launch {
959
970
  call.microphone.isEnabled.collect { isEnabled ->
960
971
  android.util.Log.d("StreamCallPlugin", "Microphone status changed for call ${call.id}: enabled=$isEnabled")
961
972
  updateCallStatusAndNotify(call.cid, if (isEnabled) "microphone_enabled" else "microphone_disabled")
962
973
  }
963
974
  }
964
975
  } ?: run {
976
+ cameraStatusJob?.cancel()
977
+ microphoneStatusJob?.cancel()
965
978
  // Notify that call has ended using our helper
966
979
  updateCallStatusAndNotify("", "left")
967
980
  changeActivityAsVisibleOnLockScreen(this@StreamCallPlugin.activity, false)
@@ -1778,12 +1791,12 @@ public class StreamCallPlugin : Plugin() {
1778
1791
  android.util.Log.d("StreamCallPlugin", "Call $callId - Creator: $createdBy, CurrentUser: $currentUserId, IsCreator: $isCreator, TotalParticipants: $totalParticipants, ShouldEnd: $shouldEndCall")
1779
1792
 
1780
1793
  if (shouldEndCall) {
1781
- // End the call for everyone if I'm the creator or only 2 people
1794
+ // End the call for everyone if I'm the creator or only 1 person
1782
1795
  android.util.Log.d("StreamCallPlugin", "Ending call $callId for all participants (creator: $isCreator, participants: $totalParticipants)")
1783
1796
  call.end()
1784
1797
  } else {
1785
- // Just leave the call if there are more than 2 people and I'm not the creator
1786
- android.util.Log.d("StreamCallPlugin", "Leaving call $callId (not creator, >2 participants)")
1798
+ // Just leave the call if there are more than 1 person and I'm not the creator
1799
+ android.util.Log.d("StreamCallPlugin", "Leaving call $callId (not creator, >1 participants)")
1787
1800
  call.leave()
1788
1801
  }
1789
1802
 
@@ -2428,7 +2441,6 @@ public class StreamCallPlugin : Plugin() {
2428
2441
  }
2429
2442
  }
2430
2443
  private var holder: StreamCallPlugin? = null
2431
- private var eventHandlersRegistered = false
2432
2444
 
2433
2445
  // Constants for SharedPreferences
2434
2446
  private const val API_KEY_PREFS_NAME = "stream_video_api_key_prefs"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-stream-call",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
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",