rns-nativecall 0.5.8 → 0.6.0

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,46 +10,46 @@ class AcceptCallActivity : Activity() {
10
10
  override fun onCreate(savedInstanceState: Bundle?) {
11
11
  super.onCreate(savedInstanceState)
12
12
 
13
- val extras = intent.extras
14
13
  val dataMap = mutableMapOf<String, String>()
15
-
14
+ val extras = intent.extras
15
+
16
+ // Extract every single extra passed in from NativeCallManager
16
17
  extras?.keySet()?.forEach { key ->
17
- extras.get(key)?.let { dataMap[key] = it.toString() }
18
+ val value = extras.get(key)
19
+ if (value != null) {
20
+ dataMap[key] = value.toString()
21
+ }
18
22
  }
19
23
 
20
24
  val uuid = dataMap["callUuid"]
21
25
 
22
26
  if (uuid != null) {
23
- // 1. IMMEDIATELY KILL THE GHOSTS
24
- // This stops the 18s timer in MessagingService
27
+ // Kill background processes
25
28
  CallMessagingService.stopBackupTimer(uuid)
26
-
27
- // This kills the Headless JS task so it stops running in background
28
29
  val stopHeadlessIntent = Intent(applicationContext, CallHeadlessTask::class.java)
29
30
  applicationContext.stopService(stopHeadlessIntent)
30
31
 
31
- // 2. STOP NATIVE RINGTONE & NOTIFICATION PILL
32
+ // Stop Ringtone & Notification
32
33
  NativeCallManager.stopRingtone()
33
34
  val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
34
35
  notificationManager.cancel(uuid.hashCode())
35
36
 
36
- // 3. PREPARE DATA FOR REACT NATIVE
37
+ // SYNC WITH JS
37
38
  CallModule.setPendingCallData(dataMap)
38
39
  CallModule.sendEventToJS("onCallAccepted", dataMap)
39
40
 
40
- // 4. LAUNCH MAIN APP
41
+ // OPEN THE APP
41
42
  val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
42
43
  launchIntent?.apply {
43
- // IMPORTANT: Use these flags to wake up the app from any state
44
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
44
+ // Pass ALL data forward to the main app
45
45
  putExtras(extras ?: Bundle())
46
46
  putExtra("navigatingToCall", true)
47
- putExtra("callUuid", uuid)
47
+
48
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
48
49
  }
49
50
  startActivity(launchIntent)
50
51
  }
51
52
 
52
- // Kill this trampoline activity immediately
53
53
  finish()
54
54
  }
55
55
  }
@@ -61,9 +61,7 @@ class CallMessagingService : FirebaseMessagingService() {
61
61
  if (isAppInForeground(context)) {
62
62
  CallModule.sendEventToJS("onCallReceived", data)
63
63
  } else {
64
- // 1. Trigger Notification UI immediately
65
- NativeCallManager.handleIncomingPush(context, data)
66
-
64
+
67
65
  // 2. Start Headless Task
68
66
  try {
69
67
  val headlessIntent = Intent(context, CallHeadlessTask::class.java).apply {
@@ -85,6 +83,9 @@ class CallMessagingService : FirebaseMessagingService() {
85
83
  if (!isAppInForeground(context)) {
86
84
  Log.d("CallMessagingService", "Backup timer triggered for: $uuid")
87
85
  NativeCallManager.handleIncomingPush(context, data)
86
+ // 1. Trigger Notification UI immediately
87
+ // NativeCallManager.handleIncomingPush(context, data)
88
+
88
89
  }
89
90
  pendingNotifications.remove(uuid)
90
91
  }
@@ -94,6 +94,32 @@ object NativeCallManager {
94
94
  .addAction(0, "Answer", answerPendingIntent)
95
95
  .addAction(0, "Decline", rejectPendingIntent)
96
96
 
97
+
98
+
99
+ val acceptIntent = Intent(context, AcceptCallActivity::class.java).apply {
100
+ // THIS IS THE CRITICAL PART:
101
+ // You must map the FCM data (Map<String, String>) into the Intent Extras
102
+ data.forEach { (key, value) ->
103
+ this.putExtra(key, value)
104
+ }
105
+ // Ensure we have a unique action so the system doesn't cache old data
106
+ action = "ACTION_ACCEPT_CALL_${System.currentTimeMillis()}"
107
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION)
108
+ }
109
+
110
+ val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
111
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE // MUST BE MUTABLE to carry data
112
+ } else {
113
+ PendingIntent.FLAG_UPDATE_CURRENT
114
+ }
115
+
116
+ val acceptPendingIntent = PendingIntent.getActivity(
117
+ context,
118
+ 1001,
119
+ acceptIntent,
120
+ pendingFlags
121
+ )
122
+
97
123
  notificationManager.notify(uuid.hashCode(), builder.build())
98
124
 
99
125
  // Start Ringtone
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
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",
@@ -46,10 +46,11 @@
46
46
  "withNativeCallVoip.js"
47
47
  ],
48
48
  "peerDependencies": {
49
- "react-native": "*",
50
- "expo": "*"
49
+ "expo": "*",
50
+ "react-native": "*"
51
51
  },
52
52
  "dependencies": {
53
- "@expo/config-plugins": "~10.1.1"
53
+ "@expo/config-plugins": "~10.1.1",
54
+ "rns-nativecall": "^0.5.9"
54
55
  }
55
56
  }
@@ -85,9 +85,10 @@ function withAndroidConfig(config) {
85
85
  $: {
86
86
  'android:name': 'com.rnsnativecall.AcceptCallActivity',
87
87
  'android:theme': '@android:style/Theme.Translucent.NoTitleBar',
88
- 'android:exported': 'false',
89
- 'android:showWhenLocked': 'true', // Changed to true for calling
90
- 'android:turnScreenOn': 'true' // Changed to true for calling
88
+ 'android:exported': 'true', // CHANGE TO TRUE
89
+ 'android:showWhenLocked': 'true',
90
+ 'android:turnScreenOn': 'true',
91
+ 'android:launchMode': 'singleInstance' // Add this to prevent multiple instances
91
92
  }
92
93
  });
93
94
  }