rns-nativecall 0.4.7 → 0.4.8

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.
@@ -1,9 +1,12 @@
1
+ package com.rnsnativecall
2
+
1
3
  import android.app.NotificationChannel
2
4
  import android.app.NotificationManager
3
5
  import android.app.PendingIntent
4
6
  import android.content.Context
5
- import android.content.Intent
7
+ import android.content.Intent // CRITICAL IMPORT
6
8
  import android.os.Build
9
+ import android.os.Bundle // CRITICAL IMPORT
7
10
  import androidx.core.app.NotificationCompat
8
11
  import android.media.Ringtone
9
12
  import android.media.RingtoneManager
@@ -23,14 +26,13 @@ object NativeCallManager {
23
26
  val name = data["name"] ?: "Someone"
24
27
  val callType = data["callType"] ?: "audio"
25
28
 
26
- // Use FLAG_IMMUTABLE for security unless you need to modify the intent in the system
27
29
  val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
28
30
  PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
29
31
  } else {
30
32
  PendingIntent.FLAG_UPDATE_CURRENT
31
33
  }
32
34
 
33
- // 1. Full Screen Intent (Opens the UI when phone is locked or heads-up is clicked)
35
+ // 1. Full Screen / UI Intent
34
36
  val intentToActivity = Intent(context, AcceptCallActivity::class.java).apply {
35
37
  action = "ACTION_SHOW_UI_$uuid"
36
38
  data.forEach { (key, value) -> putExtra(key, value) }
@@ -40,7 +42,7 @@ object NativeCallManager {
40
42
  context, uuid.hashCode(), intentToActivity, pendingFlags
41
43
  )
42
44
 
43
- // 2. Reject Intent (Broadcast)
45
+ // 2. Reject Intent
44
46
  val rejectIntent = Intent(context, CallActionReceiver::class.java).apply {
45
47
  action = "ACTION_REJECT_$uuid"
46
48
  putExtra("EXTRA_CALL_UUID", uuid)
@@ -50,9 +52,9 @@ object NativeCallManager {
50
52
  context, uuid.hashCode() + 1, rejectIntent, pendingFlags
51
53
  )
52
54
 
53
- // 3. Answer Intent (Broadcast - Process the logic before opening UI)
55
+ // 3. Answer Intent (Using your CallActionReceiver)
54
56
  val answerIntent = Intent(context, CallActionReceiver::class.java).apply {
55
- action = "ACTION_ANSWER_$uuid"
57
+ action = "ACTION_ACCEPT_$uuid" // Changed to match your Receiver logic
56
58
  putExtra("EXTRA_CALL_UUID", uuid)
57
59
  data.forEach { (key, value) -> putExtra(key, value) }
58
60
  }
@@ -62,35 +64,28 @@ object NativeCallManager {
62
64
 
63
65
  val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
64
66
 
65
- // Create Channel for Android O+
66
67
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
67
- val channel = NotificationChannel(
68
- CALL_CHANNEL_ID,
69
- "Incoming Call",
70
- NotificationManager.IMPORTANCE_HIGH
71
- ).apply {
68
+ val channel = NotificationChannel(CALL_CHANNEL_ID, "Incoming Call", NotificationManager.IMPORTANCE_HIGH).apply {
72
69
  setBypassDnd(true)
73
70
  lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
74
- enableVibration(true)
75
- setSound(null, null) // Sound is handled manually via RingtoneManager
71
+ enableVibration(true)
72
+ setSound(null, null)
76
73
  }
77
74
  notificationManager.createNotificationChannel(channel)
78
75
  }
79
76
 
80
- // 4. Build the "Person" (Required for CallStyle)
81
77
  val caller = Person.Builder()
82
78
  .setName(name)
83
79
  .setImportant(true)
84
80
  .build()
85
81
 
86
- // 5. Create the Notification with CallStyle
87
82
  val builder = NotificationCompat.Builder(context, CALL_CHANNEL_ID)
88
- .setSmallIcon(context.applicationInfo.icon) // Ensure this is a silhouette icon
83
+ .setSmallIcon(context.applicationInfo.icon)
89
84
  .setContentTitle("Incoming $callType call")
90
85
  .setContentText(name)
91
86
  .setPriority(NotificationCompat.PRIORITY_MAX)
92
87
  .setCategory(NotificationCompat.CATEGORY_CALL)
93
- .setOngoing(true)
88
+ .setOngoing(true)
94
89
  .setAutoCancel(false)
95
90
  .setFullScreenIntent(fullScreenPendingIntent, true)
96
91
  .setColor(Color.parseColor("#28a745"))
@@ -102,26 +97,21 @@ object NativeCallManager {
102
97
  answerPendingIntent
103
98
  )
104
99
  )
105
-
100
+
106
101
  notificationManager.notify(uuid.hashCode(), builder.build())
107
102
 
108
- // Start Ringtone
109
103
  try {
110
104
  val ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
111
105
  ringtone = RingtoneManager.getRingtone(context, ringtoneUri)
112
106
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ringtone?.isLooping = true
113
107
  ringtone?.play()
114
- } catch (e: Exception) {
115
- e.printStackTrace()
116
- }
108
+ } catch (e: Exception) { e.printStackTrace() }
117
109
  }
118
110
 
119
111
  fun stopRingtone() {
120
112
  try {
121
113
  ringtone?.let {
122
- if (it.isPlaying) {
123
- it.stop()
124
- }
114
+ if (it.isPlaying) it.stop()
125
115
  }
126
116
  ringtone = null
127
117
  } catch (e: Exception) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
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",
@@ -9,7 +9,8 @@ function withMainActivityDataFix(config) {
9
9
  'import android.view.WindowManager',
10
10
  'import android.os.Build',
11
11
  'import android.os.Bundle',
12
- 'import android.content.Intent'
12
+ 'import android.content.Intent',
13
+ 'import android.content.Context' // Added: Required for KEYGUARD_SERVICE
13
14
  ];
14
15
 
15
16
  imports.forEach(imp => {
@@ -18,14 +19,6 @@ function withMainActivityDataFix(config) {
18
19
  }
19
20
  });
20
21
 
21
- imports.forEach(imp => {
22
- if (!contents.includes(imp)) {
23
- contents = contents.replace(/package .*/, (match) => `${match}\n${imp}`);
24
- }
25
- });
26
-
27
- // FIXED: Corrected Kotlin bitwise OR syntax and logic check
28
- // We check for "navigatingToCall" so this only runs when Answer is tapped
29
22
  const wakeLogic = `super.onCreate(savedInstanceState)
30
23
  if (intent?.getBooleanExtra("navigatingToCall", false) == true) {
31
24
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
@@ -35,13 +28,10 @@ function withMainActivityDataFix(config) {
35
28
  window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
36
29
  }
37
30
 
38
- // Remove Keyguard so we jump straight to app (optional but recommended)
39
31
  val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as? android.app.KeyguardManager
40
32
  keyguardManager?.requestDismissKeyguard(this, null)
41
33
  }`;
42
34
 
43
-
44
-
45
35
  if (!contents.includes('setShowWhenLocked')) {
46
36
  contents = contents.replace(/super\.onCreate\(.*\)/, wakeLogic);
47
37
  }
@@ -67,7 +57,7 @@ function withAndroidConfig(config) {
67
57
  const androidManifest = config.modResults.manifest;
68
58
  const mainApplication = androidManifest.application[0];
69
59
 
70
- // 2. Permissions
60
+ // Permissions
71
61
  const permissions = [
72
62
  'android.permission.USE_FULL_SCREEN_INTENT',
73
63
  'android.permission.VIBRATE',
@@ -88,7 +78,7 @@ function withAndroidConfig(config) {
88
78
  }
89
79
  });
90
80
 
91
- // 3. Activity/Service/Receiver registration (Cleaned up duplicates)
81
+ // Activity Registration: AcceptCallActivity
92
82
  mainApplication.activity = mainApplication.activity || [];
93
83
  if (!mainApplication.activity.some(a => a.$['android:name'] === 'com.rnsnativecall.AcceptCallActivity')) {
94
84
  mainApplication.activity.push({
@@ -96,8 +86,19 @@ function withAndroidConfig(config) {
96
86
  'android:name': 'com.rnsnativecall.AcceptCallActivity',
97
87
  'android:theme': '@android:style/Theme.Translucent.NoTitleBar',
98
88
  'android:exported': 'false',
99
- 'android:showWhenLocked': 'false',
100
- 'android:turnScreenOn': 'false'
89
+ 'android:showWhenLocked': 'true', // Changed to true for calling
90
+ 'android:turnScreenOn': 'true' // Changed to true for calling
91
+ }
92
+ });
93
+ }
94
+
95
+ // Receiver Registration: CallActionReceiver
96
+ mainApplication.receiver = mainApplication.receiver || [];
97
+ if (!mainApplication.receiver.some(r => r.$['android:name'] === 'com.rnsnativecall.CallActionReceiver')) {
98
+ mainApplication.receiver.push({
99
+ $: {
100
+ 'android:name': 'com.rnsnativecall.CallActionReceiver',
101
+ 'android:exported': 'false'
101
102
  }
102
103
  });
103
104
  }
@@ -112,7 +113,7 @@ function withAndroidConfig(config) {
112
113
  });
113
114
  }
114
115
 
115
- // Headless Task Service (Fixed for Android 14)
116
+ // Headless Task Service (Android 14)
116
117
  const headlessName = 'com.rnsnativecall.CallHeadlessTask';
117
118
  const headlessIndex = mainApplication.service.findIndex(s => s.$['android:name'] === headlessName);
118
119
  const headlessEntry = {