rns-nativecall 0.6.3 → 0.6.4

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.
@@ -13,70 +13,43 @@ class AcceptCallActivity : Activity() {
13
13
  override fun onCreate(savedInstanceState: Bundle?) {
14
14
  super.onCreate(savedInstanceState)
15
15
 
16
- // Wake + lock flags
17
16
  window.addFlags(
18
17
  WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
19
18
  WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
20
- WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
21
- WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
19
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
22
20
  )
23
21
 
24
- // Optionally dismiss keyguard
25
22
  val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
26
23
  keyguardManager.requestDismissKeyguard(this, null)
27
24
 
28
25
  processCallIntent(intent)
29
26
  }
30
27
 
31
- override fun onNewIntent(intent: Intent) {
32
- super.onNewIntent(intent)
33
- setIntent(intent)
34
- processCallIntent(intent)
35
- }
36
-
37
28
  private fun processCallIntent(intent: Intent) {
38
29
  NativeCallManager.stopRingtone()
39
30
 
40
31
  val extras = intent.extras
41
32
  val uuid = extras?.getString("callUuid")
42
- val name = extras?.getString("name") ?: "Someone"
43
- val callType = extras?.getString("callType") ?: "audio"
44
33
 
45
34
  val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
46
35
  uuid?.let { notificationManager.cancel(it.hashCode()) }
47
36
 
48
- val dataMap = mutableMapOf<String, String>()
49
- extras?.keySet()?.forEach { key ->
50
- extras.get(key)?.let { dataMap[key] = it.toString() }
51
- }
52
-
53
- if (CallModule.isReady()) {
54
- CallModule.sendEventToJS("onCallAccepted", dataMap)
55
- openMainApp(extras)
56
- finish()
57
- } else {
58
- CallModule.setPendingCallData("onCallAccepted_pending", dataMap)
59
- if (uuid != null) {
60
- NativeCallManager.connecting(this, uuid, name, callType)
61
- }
62
- // Register callback to auto‑open app once RN is ready
63
- CallModule.registerOnReadyCallback {
64
- runOnUiThread {
65
- openMainApp(extras)
66
- finish()
67
- }
68
- }
69
- }
37
+ // WE STOP SENDING THE JS EVENT HERE.
38
+ // Instead, we pass the intent to MainActivity with a specific ACTION.
39
+ openMainApp(extras)
40
+ finish()
70
41
  }
71
42
 
72
- // ✅ Now a proper member function
73
43
  private fun openMainApp(extras: Bundle?) {
44
+ // We look for the MainActivity class specifically
74
45
  val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
75
46
  launchIntent?.apply {
47
+ // ✅ CRITICAL: Identify this as a deliberate "Answer" click
48
+ action = "com.rnsnativecall.ACTION_ANSWER"
49
+
76
50
  addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
77
51
  putExtras(extras ?: Bundle())
78
- putExtra("navigatingToCall", true)
79
52
  startActivity(this)
80
53
  }
81
54
  }
82
- }
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "High-performance React Native module for handling native VoIP call UI on Android and iOS.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -4,34 +4,58 @@ const { withAndroidManifest, withInfoPlist, withPlugins, withMainActivity } = re
4
4
  function withMainActivityDataFix(config) {
5
5
  return withMainActivity(config, (config) => {
6
6
  let contents = config.modResults.contents;
7
+
8
+ // Ensure imports exist
7
9
  if (!contents.includes('import android.content.Intent')) {
8
10
  contents = contents.replace(/package .*/, (match) => `${match}\n\nimport android.content.Intent`);
9
11
  }
10
12
  if (!contents.includes('import android.os.Bundle')) {
11
13
  contents = contents.replace(/package .*/, (match) => `${match}\n\nimport android.os.Bundle`);
12
14
  }
15
+
13
16
  const onNewIntentCode = `
14
17
  override fun onNewIntent(intent: Intent) {
15
18
  super.onNewIntent(intent)
16
19
  setIntent(intent)
20
+
21
+ // Only fire JS event if the user actually pressed "Answer"
22
+ val isAnswerAction = intent.action == "com.rnsnativecall.ACTION_ANSWER"
23
+
17
24
  val dataMap = mutableMapOf<String, String>()
18
25
  intent.extras?.keySet()?.forEach { key ->
19
26
  dataMap[key] = intent.extras?.get(key)?.toString() ?: ""
20
27
  }
21
- if (dataMap.isNotEmpty()) {
28
+
29
+ if (dataMap.isNotEmpty() && isAnswerAction) {
22
30
  com.rnsnativecall.CallModule.setPendingCallData(dataMap)
23
31
  com.rnsnativecall.CallModule.sendEventToJS("onCallAccepted", dataMap)
24
32
  }
25
33
  }
26
34
  `;
35
+
27
36
  const onCreateCode = `
28
37
  override fun onCreate(savedInstanceState: Bundle?) {
29
38
  super.onCreate(savedInstanceState)
30
- if (intent.getBooleanExtra("background_wake", false)) {
39
+
40
+ val isAnswerAction = intent.action == "com.rnsnativecall.ACTION_ANSWER"
41
+
42
+ // Logic for Cold Start (App was dead, user answered)
43
+ if (isAnswerAction) {
44
+ val dataMap = mutableMapOf<String, String>()
45
+ intent.extras?.keySet()?.forEach { key ->
46
+ dataMap[key] = intent.extras?.get(key)?.toString() ?: ""
47
+ }
48
+ com.rnsnativecall.CallModule.setPendingCallData(dataMap)
49
+ }
50
+
51
+ // Move to back if it's a background wake (FCM) and NOT an answer click
52
+ if (intent.getBooleanExtra("background_wake", false) && !isAnswerAction) {
31
53
  moveTaskToBack(true)
32
54
  }
33
55
  }
34
56
  `;
57
+
58
+ // Inject codes
35
59
  if (!contents.includes('override fun onNewIntent')) {
36
60
  const lastBraceIndex = contents.lastIndexOf('}');
37
61
  contents = contents.slice(0, lastBraceIndex) + onNewIntentCode + contents.slice(lastBraceIndex);
@@ -40,6 +64,7 @@ function withMainActivityDataFix(config) {
40
64
  const lastBraceIndex = contents.lastIndexOf('}');
41
65
  contents = contents.slice(0, lastBraceIndex) + onCreateCode + contents.slice(lastBraceIndex);
42
66
  }
67
+
43
68
  config.modResults.contents = contents;
44
69
  return config;
45
70
  });