rns-nativecall 0.6.7 → 0.6.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.
@@ -3,11 +3,16 @@ package com.rnsnativecall
3
3
  import android.app.*
4
4
  import android.content.Context
5
5
  import android.content.Intent
6
+ import android.content.pm.ServiceInfo
6
7
  import android.os.Build
8
+ import android.os.Bundle
7
9
  import android.os.IBinder
8
10
  import androidx.core.app.NotificationCompat
9
11
  import com.facebook.react.HeadlessJsTaskService
10
12
 
13
+ import android.os.Handler // Added
14
+ import android.os.Looper // Added
15
+
11
16
  class CallForegroundService : Service() {
12
17
 
13
18
  companion object {
@@ -26,22 +31,37 @@ class CallForegroundService : Service() {
26
31
 
27
32
  createNotificationChannel()
28
33
 
29
- // Create a notification that shows "Connecting..."
30
34
  val notification = NotificationCompat.Builder(this, CHANNEL_ID)
31
35
  .setContentTitle(name)
32
36
  .setContentText("Connecting...")
33
37
  .setSmallIcon(applicationInfo.icon)
34
38
  .setCategory(NotificationCompat.CATEGORY_CALL)
35
- .setPriority(NotificationCompat.PRIORITY_LOW) // Keep it subtle until UI pops
39
+ .setPriority(NotificationCompat.PRIORITY_HIGH)
36
40
  .setOngoing(true)
37
41
  .build()
38
42
 
39
- // Start Foreground immediately to satisfy OS requirements
40
- startForeground(NOTIFICATION_ID, notification)
43
+ // --- ANDROID 14 FIX START ---
44
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
45
+ startForeground(
46
+ NOTIFICATION_ID,
47
+ notification,
48
+ ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
49
+ )
50
+ } else {
51
+ startForeground(NOTIFICATION_ID, notification)
52
+ }
53
+ // --- ANDROID 14 FIX END ---
41
54
 
42
- // Launch the Headless Task while under the protection of this service
55
+ // Launch the Headless Task
43
56
  val headlessIntent = Intent(this, CallHeadlessTask::class.java).apply {
44
- data?.let { putExtras(it) }
57
+ // Safe bundle copy
58
+ val bundle = Bundle()
59
+ data?.let { b ->
60
+ for (key in b.keySet()) {
61
+ bundle.putString(key, b.get(key)?.toString())
62
+ }
63
+ }
64
+ putExtras(bundle)
45
65
  }
46
66
 
47
67
  try {
@@ -51,20 +71,34 @@ class CallForegroundService : Service() {
51
71
  e.printStackTrace()
52
72
  }
53
73
 
74
+
75
+ // Automatically stop this service if JS doesn't stop it within 30 seconds
76
+ Handler(Looper.getMainLooper()).postDelayed({
77
+ try {
78
+ stopSelf()
79
+ } catch (e: Exception) {
80
+ // Service might already be stopped
81
+ }
82
+ }, 30000)
54
83
  return START_NOT_STICKY
55
84
  }
56
85
 
57
86
  private fun createNotificationChannel() {
58
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
59
- val channel = NotificationChannel(
60
- CHANNEL_ID,
61
- "Call Service",
62
- NotificationManager.IMPORTANCE_LOW
63
- )
64
- val manager = getSystemService(NotificationManager::class.java)
65
- manager.createNotificationChannel(channel)
87
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
88
+ val channel = NotificationChannel(
89
+ CHANNEL_ID,
90
+ "Call Service",
91
+ NotificationManager.IMPORTANCE_HIGH
92
+ ).apply {
93
+ description = "Handles incoming call connection state"
94
+ // Optional: makes the "Connecting" notification silent
95
+ // so it doesn't double-beep with the actual ringtone
96
+ setSound(null, null)
66
97
  }
98
+ val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
99
+ manager.createNotificationChannel(channel)
67
100
  }
101
+ }
68
102
 
69
103
  override fun onBind(intent: Intent?): IBinder? = null
70
104
  }
@@ -49,6 +49,9 @@ if (!CallState.setCurrent(uuid)) {
49
49
  return
50
50
  }
51
51
 
52
+
53
+
54
+
52
55
  if (isAppInForeground(context)) {
53
56
  // Foreground → send event directly
54
57
  CallModule.sendEventToJS("onCallReceived", data)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
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",