@qusaieilouti99/call-manager 0.1.73 → 0.1.75

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.
@@ -10,10 +10,16 @@ import android.util.Log
10
10
  import android.view.WindowManager
11
11
  import android.widget.Button
12
12
  import android.widget.TextView
13
+ import android.content.BroadcastReceiver
14
+ import android.content.Context
15
+ import android.content.IntentFilter
13
16
 
14
17
  class CallActivity : Activity() {
15
18
 
16
- private enum class FinishReason { ANSWER, DECLINE, TIMEOUT, MANUAL_DISMISS }
19
+ private enum class FinishReason {
20
+ ANSWER, DECLINE, TIMEOUT, MANUAL_DISMISS, EXTERNAL_END
21
+ }
22
+
17
23
  private var finishReason: FinishReason? = null
18
24
  private var callId: String = ""
19
25
  private var callType: String = "Audio"
@@ -26,6 +32,18 @@ class CallActivity : Activity() {
26
32
  finishCallActivity()
27
33
  }
28
34
 
35
+ // NEW: Broadcast receiver to listen for close events
36
+ private val closeReceiver = object : BroadcastReceiver() {
37
+ override fun onReceive(context: Context?, intent: Intent?) {
38
+ val receivedCallId = intent?.getStringExtra("callId")
39
+ if (receivedCallId == callId) {
40
+ Log.d(TAG, "Received close broadcast for $callId")
41
+ finishReason = FinishReason.EXTERNAL_END
42
+ finishCallActivity()
43
+ }
44
+ }
45
+ }
46
+
29
47
  override fun onCreate(savedInstanceState: Bundle?) {
30
48
  super.onCreate(savedInstanceState)
31
49
  Log.d(TAG, "CallActivity onCreate")
@@ -62,8 +80,6 @@ class CallActivity : Activity() {
62
80
  answerBtn.setOnClickListener {
63
81
  Log.d(TAG, "CallActivity: Answer button clicked for callId: $callId")
64
82
  finishReason = FinishReason.ANSWER
65
-
66
- // FIXED: Use single source of truth - this will handle all cleanup
67
83
  CallEngine.answerCall(callId)
68
84
  finishCallActivity()
69
85
  }
@@ -75,6 +91,14 @@ class CallActivity : Activity() {
75
91
  finishCallActivity()
76
92
  }
77
93
 
94
+ // NEW: Register broadcast receiver
95
+ val filter = IntentFilter("com.qusaieilouti99.callmanager.CLOSE_CALL_ACTIVITY")
96
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
97
+ registerReceiver(closeReceiver, filter, Context.RECEIVER_NOT_EXPORTED)
98
+ } else {
99
+ registerReceiver(closeReceiver, filter)
100
+ }
101
+
78
102
  timeoutHandler.postDelayed(timeoutRunnable, 60_000)
79
103
  }
80
104
 
@@ -83,6 +107,13 @@ class CallActivity : Activity() {
83
107
  Log.d(TAG, "CallActivity onDestroy for callId: $callId. Reason: $finishReason")
84
108
  timeoutHandler.removeCallbacks(timeoutRunnable)
85
109
 
110
+ // NEW: Unregister broadcast receiver
111
+ try {
112
+ unregisterReceiver(closeReceiver)
113
+ } catch (e: Exception) {
114
+ Log.w(TAG, "Receiver already unregistered: ${e.message}")
115
+ }
116
+
86
117
  // FIXED: Ensure cleanup happens regardless of how activity ends
87
118
  CallEngine.stopRingtone()
88
119
  CallEngine.cancelIncomingCallUI()
@@ -602,6 +602,17 @@ object CallEngine {
602
602
  currentCallId = activeCalls.filter { it.value.state != CallState.ENDED }.keys.firstOrNull()
603
603
  }
604
604
 
605
+ // NEW: Send broadcast to close CallActivity
606
+ val context = requireContext()
607
+ val closeActivityIntent = Intent("com.qusaieilouti99.callmanager.CLOSE_CALL_ACTIVITY")
608
+ closeActivityIntent.putExtra("callId", callId)
609
+ try {
610
+ context.sendBroadcast(closeActivityIntent)
611
+ Log.d(TAG, "Sent close broadcast for CallActivity: $callId")
612
+ } catch (e: Exception) {
613
+ Log.w(TAG, "Failed to send close broadcast: ${e.message}")
614
+ }
615
+
605
616
  val connection = telecomConnections[callId]
606
617
  if (connection != null) {
607
618
  connection.setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
@@ -950,9 +961,7 @@ object CallEngine {
950
961
 
951
962
  notificationManager.notify(NOTIF_ID, notification)
952
963
 
953
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
954
- playRingtone()
955
- }
964
+ playRingtone()
956
965
 
957
966
  setInitialAudioRoute(callType)
958
967
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.73",
3
+ "version": "0.1.75",
4
4
  "description": "Call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",