rns-nativecall 0.3.5 → 0.3.6

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.
@@ -6,15 +6,15 @@ import com.facebook.react.bridge.Arguments
6
6
  import com.facebook.react.jstasks.HeadlessJsTaskConfig
7
7
 
8
8
  class CallHeadlessTask : HeadlessJsTaskService() {
9
- override fun getTaskConfig(intent: Intent): HeadlessJsTaskConfig? {
10
- val extras = intent.extras
9
+ // Note: The '?' after Intent and the return type are specific in Kotlin
10
+ override fun getTaskConfig(intent: Intent?): HeadlessJsTaskConfig? {
11
+ val extras = intent?.extras
11
12
  return if (extras != null) {
12
- // INCREASE timeout to 30000 (30s) so it covers your 18s delay
13
13
  HeadlessJsTaskConfig(
14
14
  "ColdStartCallTask",
15
15
  Arguments.fromBundle(extras),
16
16
  30000,
17
- true // Allow in foreground
17
+ true
18
18
  )
19
19
  } else {
20
20
  null
@@ -14,80 +14,67 @@ import com.facebook.react.HeadlessJsTaskService
14
14
 
15
15
  class CallMessagingService : FirebaseMessagingService() {
16
16
 
17
- // This companion object allows the Cancel logic to find the active timer
18
17
  companion object {
19
18
  private val handler = Handler(Looper.getMainLooper())
20
19
  private val pendingNotifications = mutableMapOf<String, Runnable>()
20
+ // This is the standard ID used for the incoming call notification pill
21
+ private const val CALL_NOTIFICATION_ID = 123
21
22
  }
22
23
 
23
24
  override fun onMessageReceived(remoteMessage: RemoteMessage) {
24
25
  val data = remoteMessage.data
25
26
  val context = applicationContext
26
27
 
27
- // Extract variables for logic
28
28
  val uuid = data["callUuid"] ?: return
29
29
  val type = data["type"] ?: ""
30
30
 
31
- // CASE 1: CALLER HUNG UP / CANCELLED
32
31
  if (type == "CANCEL") {
33
- // 1. Remove the pending 18s timer for this specific call
34
32
  pendingNotifications[uuid]?.let {
35
33
  handler.removeCallbacks(it)
36
34
  pendingNotifications.remove(uuid)
37
35
  }
38
36
 
39
- // 2. Stop the ringtone/Pill if it had already started showing
37
+ // 1. Stop the ringtone
40
38
  NativeCallManager.stopRingtone()
41
- CallHandler.destroyNativeCallUI(uuid) // Ensure native UI is killed
42
39
 
43
- // 3. Show standard "Missed Call" notification
40
+ // 2. DISMISS THE PILL (Direct Native Way)
41
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
42
+ notificationManager.cancel(CALL_NOTIFICATION_ID)
43
+
44
+ // 3. Show Missed Call
44
45
  showMissedCallNotification(context, data, uuid)
45
46
  return
46
47
  }
47
48
 
48
- // CASE 2: NEW INCOMING CALL
49
49
  if (isAppInForeground(context)) {
50
- // App is visible: Send event to active JS bridge immediately
51
50
  CallModule.sendEventToJS("onCallReceived", data)
52
51
  } else {
53
- // 1. Wake the actual App process by launching the Intent
54
- val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
55
- launchIntent?.apply {
56
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
57
- // This is key: it tells the app to boot the JS but stay minimized
58
- putExtra("background_wake", true)
59
- }
60
- context.startActivity(launchIntent)
61
-
62
- // You SHOULD see "Android Bundled..." now because the Activity is starting
63
-
64
- val showNotificationRunnable = Runnable {
65
- if (!isAppInForeground(context)) {
66
- NativeCallManager.handleIncomingPush(context, data)
67
- }
68
- }
69
- handler.postDelayed(showNotificationRunnable, 18000)
70
- }
71
- }
52
+ val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
53
+ launchIntent?.apply {
54
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
55
+ putExtra("background_wake", true)
56
+ }
57
+ context.startActivity(launchIntent)
58
+
59
+ val showNotificationRunnable = Runnable {
60
+ if (!isAppInForeground(context)) {
61
+ NativeCallManager.handleIncomingPush(context, data)
62
+ }
63
+ pendingNotifications.remove(uuid)
64
+ }
72
65
 
73
- private fun startHeadlessTask(context: Context, data: Map<String, String>) {
74
- val serviceIntent = Intent(context, CallHeadlessTask::class.java)
75
- val bundle = Bundle()
76
- data.forEach { (key, value) -> bundle.putString(key, value) }
77
- serviceIntent.putExtras(bundle)
78
-
79
- context.startService(serviceIntent)
80
- HeadlessJsTaskService.acquireWakeLockNow(context)
66
+ pendingNotifications[uuid] = showNotificationRunnable
67
+ handler.postDelayed(showNotificationRunnable, 18000)
68
+ }
81
69
  }
82
70
 
83
71
  private fun showMissedCallNotification(context: Context, data: Map<String, String>, uuid: String) {
84
72
  val name = data["name"] ?: "Unknown"
85
73
  val callType = data["callType"] ?: "video"
86
- val channelId = "missed_calls" // Ensure this channel is created in your MainApplication or CallManager
74
+ val channelId = "missed_calls"
87
75
 
88
76
  val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
89
77
 
90
- // Use ic_launcher as fallback if ic_missed_call isn't found
91
78
  var iconResId = context.resources.getIdentifier("ic_missed_call", "drawable", context.packageName)
92
79
  if (iconResId == 0) iconResId = android.R.drawable.sym_call_missed
93
80
 
@@ -97,7 +84,7 @@ class CallMessagingService : FirebaseMessagingService() {
97
84
  .setContentText("You missed a call from $name")
98
85
  .setPriority(NotificationCompat.PRIORITY_HIGH)
99
86
  .setAutoCancel(true)
100
- .setCategory(NotificationCompat.CATEGORY_MISS)
87
+ .setCategory(NotificationCompat.CATEGORY_MISSED_CALL)
101
88
 
102
89
  notificationManager.notify(uuid.hashCode(), builder.build())
103
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "RNS nativecall component with native Android/iOS for handling native call ui, when app is not open or open.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",