@qusaieilouti99/call-manager 0.1.11 → 0.1.13

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.
@@ -25,11 +25,13 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
25
25
 
26
26
  // Register JS event handler
27
27
  override fun setEventHandler(callback: Callback) {
28
+ Log.d(TAG, "setEventHandler called, registering JS callback")
28
29
  eventHandler = callback
29
30
  }
30
31
 
31
32
  // Helper to emit events to JS
32
33
  fun emitEvent(event: String, callData: String) {
34
+ Log.d(TAG, "emitEvent: event=$event, callData=$callData")
33
35
  eventHandler?.invoke(event, callData)
34
36
  }
35
37
 
@@ -42,23 +44,28 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
42
44
 
43
45
  // 2. End call
44
46
  override fun endCall(callId: String) {
47
+ Log.d(TAG, "endCall called with callId=$callId")
45
48
  val context = reactApplicationContext
46
49
  val intent = Intent(context, CallForegroundService::class.java)
47
- context.stopService(intent)
50
+ val stopped = context.stopService(intent)
51
+ Log.d(TAG, "CallForegroundService stopped: $stopped")
48
52
  }
49
53
 
50
54
  // 3. Answer call
51
55
  override fun answerCall(callId: String) {
56
+ Log.d(TAG, "answerCall called with callId=$callId")
52
57
  bringAppToForeground()
53
58
  }
54
59
 
55
60
  // 4. Silence ringtone
56
61
  override fun silenceRingtone() {
62
+ Log.d(TAG, "silenceRingtone called")
57
63
  // TODO: Implement ringtone silencing logic if you play a custom ringtone
58
64
  }
59
65
 
60
66
  // 5. Reject current and answer new
61
67
  override fun rejectCurrentAndAnswerNew(callId: String, callData: String) {
68
+ Log.d(TAG, "rejectCurrentAndAnswerNew called with callId=$callId, callData=$callData")
62
69
  endCall(currentCallId ?: "")
63
70
  CallNativeHelper.reportIncomingCall(reactApplicationContext, callId, callData)
64
71
  }
@@ -70,10 +77,14 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
70
77
  val packageName = context.packageName
71
78
  val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
72
79
  val tasks = activityManager.appTasks
80
+ Log.d(TAG, "bringAppToForeground called. tasks.isNullOrEmpty()=${tasks.isNullOrEmpty()}")
73
81
  if (tasks.isNullOrEmpty()) {
74
82
  val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
75
83
  launchIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
76
84
  context.startActivity(launchIntent)
85
+ Log.d(TAG, "App brought to foreground via launchIntent")
86
+ } else {
87
+ Log.d(TAG, "App already in foreground or has tasks")
77
88
  }
78
89
  }
79
90
  }
@@ -3,19 +3,21 @@ package com.qusaieilouti99.callmanager
3
3
  import android.content.BroadcastReceiver
4
4
  import android.content.Context
5
5
  import android.content.Intent
6
+ import android.util.Log
6
7
 
7
8
  class CallNotificationActionReceiver : BroadcastReceiver() {
8
9
  override fun onReceive(context: Context, intent: Intent) {
9
10
  val callId = intent.getStringExtra("callId") ?: return
10
- val module = (context.applicationContext as? com.facebook.react.ReactApplication)
11
- ?.reactNativeHost
12
- ?.reactInstanceManager
13
- ?.currentReactContext
14
- ?.getNativeModule(CallManagerModule::class.java)
11
+ val action = intent.action
15
12
 
16
- when (intent.action) {
13
+ val app = context.applicationContext as? com.facebook.react.ReactApplication
14
+ val reactInstanceManager = app?.reactNativeHost?.reactInstanceManager
15
+ val reactContext = reactInstanceManager?.currentReactContext
16
+ val module = reactContext?.getNativeModule(CallManagerModule::class.java)
17
+
18
+ when (action) {
17
19
  "com.qusaieilouti99.callmanager.ANSWER_CALL" -> {
18
- module?.answerCall(callId)
20
+ bringAppToForeground(context)
19
21
  }
20
22
  "com.qusaieilouti99.callmanager.DECLINE_CALL" -> {
21
23
  module?.endCall(callId)
@@ -24,4 +26,13 @@ class CallNotificationActionReceiver : BroadcastReceiver() {
24
26
  // Cancel notification and stop ringtone
25
27
  CallNotificationHelper(context).cancelIncomingCallNotification()
26
28
  }
29
+
30
+ private fun bringAppToForeground(context: Context) {
31
+ val packageName = context.packageName
32
+ val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
33
+ launchIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
34
+ launchIntent?.putExtra("incomingCall", true)
35
+ context.startActivity(launchIntent)
36
+ Log.d("CallNotificationActionReceiver", "Bringing app to foreground for incoming call")
37
+ }
27
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",