rns-nativecall 0.7.0 → 0.7.2
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.
|
@@ -24,17 +24,21 @@ class CallMessagingService : FirebaseMessagingService() {
|
|
|
24
24
|
|
|
25
25
|
val uuid = data["callUuid"] ?: return
|
|
26
26
|
val type = data["type"] ?: ""
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
if (type == "CANCEL") {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
NativeCallManager.stopRingtone()
|
|
30
|
+
// Pass context here to persist the cancellation
|
|
31
|
+
CallState.markCanceled(uuid, context)
|
|
32
|
+
|
|
33
|
+
if (CallState.getCurrent() == uuid) {
|
|
34
|
+
CallState.clear(uuid, context)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Dismiss the "Connecting..." or "Incoming Call" UI
|
|
38
|
+
NativeCallManager.dismissIncomingCall(context, uuid)
|
|
39
|
+
showMissedCallNotification(context, data, uuid)
|
|
40
|
+
return
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
// Inside onMessageReceived
|
|
40
44
|
if (!CallState.setCurrent(uuid)) {
|
|
@@ -50,6 +50,7 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
50
50
|
promise.reject("CALL_ERROR", e.message)
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Combined Validity Check:
|
|
@@ -57,13 +58,14 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
57
58
|
*/
|
|
58
59
|
@ReactMethod
|
|
59
60
|
fun checkCallValidity(uuid: String, promise: Promise) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
// Pass context so it can check the persistent disk storage
|
|
62
|
+
val isValid = CallState.shouldProceed(uuid, reactApplicationContext)
|
|
63
|
+
val isCanceled = CallState.isCanceled(uuid, reactApplicationContext)
|
|
64
|
+
|
|
65
|
+
val map = Arguments.createMap().apply {
|
|
66
|
+
putBoolean("isValid", isValid)
|
|
67
|
+
putBoolean("isCanceled", isCanceled)
|
|
68
|
+
}
|
|
67
69
|
promise.resolve(map)
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
package com.rnsnativecall
|
|
2
2
|
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
|
|
3
6
|
object CallState {
|
|
4
7
|
@Volatile private var currentUuid: String? = null
|
|
5
8
|
@Volatile private var canceledUuids = mutableSetOf<String>()
|
|
6
9
|
|
|
10
|
+
// Helper to access persistent storage
|
|
11
|
+
private fun getPrefs(context: Context): SharedPreferences {
|
|
12
|
+
return context.getSharedPreferences("RNS_CALL_STATE_INTERNAL", Context.MODE_PRIVATE)
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
@Synchronized
|
|
8
16
|
fun isBusy(): Boolean = currentUuid != null
|
|
9
17
|
|
|
@@ -19,36 +27,56 @@ object CallState {
|
|
|
19
27
|
fun getCurrent(): String? = currentUuid
|
|
20
28
|
|
|
21
29
|
@Synchronized
|
|
22
|
-
fun markCanceled(uuid: String) {
|
|
30
|
+
fun markCanceled(uuid: String, context: Context? = null) {
|
|
23
31
|
canceledUuids.add(uuid)
|
|
24
32
|
if (currentUuid == uuid) {
|
|
25
33
|
currentUuid = null
|
|
26
34
|
}
|
|
35
|
+
// PERSISTENCE: Save to disk so Splash screen can see it after app restart
|
|
36
|
+
context?.let {
|
|
37
|
+
getPrefs(it).edit().putBoolean("canceled_$uuid", true).apply()
|
|
38
|
+
}
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
// ✅ Fixes the "Unresolved reference 'isCanceled'" error
|
|
30
41
|
@Synchronized
|
|
31
|
-
fun isCanceled(uuid: String?): Boolean {
|
|
42
|
+
fun isCanceled(uuid: String?, context: Context? = null): Boolean {
|
|
32
43
|
if (uuid == null) return false
|
|
33
|
-
|
|
44
|
+
// Check memory first
|
|
45
|
+
if (canceledUuids.contains(uuid)) return true
|
|
46
|
+
|
|
47
|
+
// PERSISTENCE: Check disk if memory was wiped (App was killed)
|
|
48
|
+
return context?.let {
|
|
49
|
+
getPrefs(it).getBoolean("canceled_$uuid", false)
|
|
50
|
+
} ?: false
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
@Synchronized
|
|
37
|
-
fun clear(uuid: String?) {
|
|
54
|
+
fun clear(uuid: String?, context: Context? = null) {
|
|
38
55
|
if (uuid == null) return
|
|
39
56
|
if (currentUuid == uuid) currentUuid = null
|
|
40
57
|
canceledUuids.remove(uuid)
|
|
58
|
+
|
|
59
|
+
// PERSISTENCE: Cleanup disk entry
|
|
60
|
+
context?.let {
|
|
61
|
+
getPrefs(it).edit().remove("canceled_$uuid").apply()
|
|
62
|
+
}
|
|
41
63
|
}
|
|
42
64
|
|
|
43
65
|
@Synchronized
|
|
44
|
-
fun shouldProceed(uuid: String?): Boolean {
|
|
66
|
+
fun shouldProceed(uuid: String?, context: Context? = null): Boolean {
|
|
45
67
|
if (uuid == null) return false
|
|
46
|
-
|
|
68
|
+
|
|
69
|
+
// A call should proceed if it is the current UUID AND it hasn't been canceled
|
|
70
|
+
// We use the context-aware isCanceled to check the disk if necessary
|
|
71
|
+
val canceled = isCanceled(uuid, context)
|
|
72
|
+
return (currentUuid == uuid || currentUuid == null) && !canceled
|
|
47
73
|
}
|
|
48
74
|
|
|
49
75
|
@Synchronized
|
|
50
76
|
fun clearAll() {
|
|
51
77
|
currentUuid = null
|
|
52
78
|
canceledUuids.clear()
|
|
79
|
+
// Note: clearAll usually doesn't have context,
|
|
80
|
+
// specific UUIDs are usually cleared via the clear(uuid, context) method
|
|
53
81
|
}
|
|
54
82
|
}
|