rns-nativecall 1.0.8 → 1.1.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.
|
@@ -2,16 +2,17 @@ package com.rnsnativecall
|
|
|
2
2
|
|
|
3
3
|
import android.app.NotificationManager
|
|
4
4
|
import android.content.Context
|
|
5
|
-
import com.facebook.react.bridge.*
|
|
6
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
7
5
|
import android.content.Intent
|
|
6
|
+
import android.net.Uri
|
|
8
7
|
import android.os.Build
|
|
9
8
|
import android.provider.Settings
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
9
|
+
import com.facebook.react.bridge.*
|
|
10
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
class CallModule(
|
|
13
|
+
reactContext: ReactApplicationContext,
|
|
14
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
15
|
+
init {
|
|
15
16
|
instance = this
|
|
16
17
|
notifyReady()
|
|
17
18
|
}
|
|
@@ -40,20 +41,26 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
@ReactMethod
|
|
43
|
-
fun displayIncomingCall(
|
|
44
|
+
fun displayIncomingCall(
|
|
45
|
+
uuid: String,
|
|
46
|
+
name: String,
|
|
47
|
+
callType: String,
|
|
48
|
+
promise: Promise,
|
|
49
|
+
) {
|
|
44
50
|
try {
|
|
45
|
-
val data =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
val data =
|
|
52
|
+
mapOf(
|
|
53
|
+
"callUuid" to uuid,
|
|
54
|
+
"name" to name,
|
|
55
|
+
"callType" to callType,
|
|
56
|
+
)
|
|
50
57
|
NativeCallManager.handleIncomingPush(reactApplicationContext, data)
|
|
51
58
|
promise.resolve(true)
|
|
52
59
|
} catch (e: Exception) {
|
|
53
60
|
promise.reject("CALL_ERROR", e.message)
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
|
|
57
64
|
// Inside your CallModule class
|
|
58
65
|
@ReactMethod
|
|
59
66
|
fun checkOverlayPermission(promise: Promise) {
|
|
@@ -64,34 +71,39 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
@ReactMethod
|
|
75
|
+
fun requestOverlayPermission() {
|
|
76
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
77
|
+
if (!Settings.canDrawOverlays(reactApplicationContext)) {
|
|
78
|
+
val intent =
|
|
79
|
+
Intent(
|
|
80
|
+
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
81
|
+
Uri.parse("package:${reactApplicationContext.packageName}"),
|
|
82
|
+
)
|
|
83
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
84
|
+
reactApplicationContext.startActivity(intent)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
80
88
|
|
|
81
89
|
/**
|
|
82
|
-
* Combined Validity Check:
|
|
90
|
+
* Combined Validity Check:
|
|
83
91
|
* Used by Headless Task to see if it should proceed with the UI.
|
|
84
92
|
*/
|
|
85
93
|
@ReactMethod
|
|
86
|
-
fun checkCallValidity(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
fun checkCallValidity(
|
|
95
|
+
uuid: String,
|
|
96
|
+
promise: Promise,
|
|
97
|
+
) {
|
|
98
|
+
// Pass context so it can check the persistent disk storage
|
|
99
|
+
val isValid = CallState.shouldProceed(uuid, reactApplicationContext)
|
|
100
|
+
val isCanceled = CallState.isCanceled(uuid, reactApplicationContext)
|
|
101
|
+
|
|
102
|
+
val map =
|
|
103
|
+
Arguments.createMap().apply {
|
|
104
|
+
putBoolean("isValid", isValid)
|
|
105
|
+
putBoolean("isCanceled", isCanceled)
|
|
106
|
+
}
|
|
95
107
|
promise.resolve(map)
|
|
96
108
|
}
|
|
97
109
|
|
|
@@ -112,29 +124,31 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
112
124
|
* Useful for checking if the UI is still relevant.
|
|
113
125
|
*/
|
|
114
126
|
@ReactMethod
|
|
115
|
-
fun checkCallStatus(
|
|
127
|
+
fun checkCallStatus(
|
|
128
|
+
uuid: String,
|
|
129
|
+
promise: Promise,
|
|
130
|
+
) {
|
|
116
131
|
val isCanceled = CallState.isCanceled(uuid)
|
|
117
132
|
val isCurrent = CallState.getCurrent() == uuid
|
|
118
|
-
|
|
119
|
-
val map =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
|
|
134
|
+
val map =
|
|
135
|
+
Arguments.createMap().apply {
|
|
136
|
+
putBoolean("isCanceled", isCanceled)
|
|
137
|
+
putBoolean("isActive", isCurrent)
|
|
138
|
+
putBoolean("shouldDisplay", isCurrent && !isCanceled)
|
|
139
|
+
}
|
|
124
140
|
promise.resolve(map)
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
@ReactMethod
|
|
128
144
|
fun endNativeCall(uuid: String) {
|
|
129
|
-
NativeCallManager.
|
|
145
|
+
NativeCallManager.dismissIncomingCall(reactApplicationContext, uuid)
|
|
130
146
|
CallState.clear(uuid)
|
|
131
147
|
pendingCallDataMap = null
|
|
132
|
-
|
|
133
|
-
val notificationManager = reactApplicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
134
|
-
notificationManager.cancel(101)
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
@ReactMethod fun addListener(eventName: String) {}
|
|
151
|
+
|
|
138
152
|
@ReactMethod fun removeListeners(count: Int) {}
|
|
139
153
|
|
|
140
154
|
companion object {
|
|
@@ -149,14 +163,17 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
149
163
|
return reactContext != null && reactContext.hasActiveCatalystInstance()
|
|
150
164
|
}
|
|
151
165
|
|
|
152
|
-
@JvmStatic
|
|
166
|
+
@JvmStatic
|
|
153
167
|
fun setPendingCallData(data: Map<String, String>) {
|
|
154
|
-
|
|
168
|
+
pendingCallDataMap = data
|
|
155
169
|
}
|
|
156
170
|
|
|
157
|
-
@JvmStatic
|
|
158
|
-
fun setPendingCallData(
|
|
159
|
-
|
|
171
|
+
@JvmStatic
|
|
172
|
+
fun setPendingCallData(
|
|
173
|
+
eventName: String,
|
|
174
|
+
data: Map<String, String>,
|
|
175
|
+
) {
|
|
176
|
+
pendingEvents[eventName] = data
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
@JvmStatic
|
|
@@ -174,23 +191,33 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
174
191
|
}
|
|
175
192
|
|
|
176
193
|
@JvmStatic
|
|
177
|
-
fun setPendingEvent(
|
|
194
|
+
fun setPendingEvent(
|
|
195
|
+
eventName: String,
|
|
196
|
+
data: Map<String, String>,
|
|
197
|
+
) {
|
|
178
198
|
pendingEvents[eventName] = data
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
@JvmStatic
|
|
182
|
-
fun sendEventToJS(
|
|
202
|
+
fun sendEventToJS(
|
|
203
|
+
eventName: String,
|
|
204
|
+
params: Any?,
|
|
205
|
+
) {
|
|
183
206
|
val reactContext = instance?.reactApplicationContext
|
|
184
|
-
val bridgeData =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
207
|
+
val bridgeData =
|
|
208
|
+
when (params) {
|
|
209
|
+
is Map<*, *> -> {
|
|
210
|
+
val map = Arguments.createMap()
|
|
211
|
+
params.forEach { (key, value) ->
|
|
212
|
+
map.putString(key.toString(), value.toString())
|
|
213
|
+
}
|
|
214
|
+
map
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
else -> {
|
|
218
|
+
null
|
|
189
219
|
}
|
|
190
|
-
map
|
|
191
220
|
}
|
|
192
|
-
else -> null
|
|
193
|
-
}
|
|
194
221
|
|
|
195
222
|
if (isReady()) {
|
|
196
223
|
reactContext
|
|
@@ -202,4 +229,4 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
202
229
|
}
|
|
203
230
|
}
|
|
204
231
|
}
|
|
205
|
-
}
|
|
232
|
+
}
|
|
@@ -5,18 +5,20 @@ import android.content.Context
|
|
|
5
5
|
import android.content.Intent
|
|
6
6
|
|
|
7
7
|
class UnlockReceiver : BroadcastReceiver() {
|
|
8
|
-
override fun onReceive(
|
|
8
|
+
override fun onReceive(
|
|
9
|
+
context: Context,
|
|
10
|
+
intent: Intent,
|
|
11
|
+
) {
|
|
9
12
|
android.util.Log.d("UnlockReceiver", "Device Unlocked! Action: ${intent.action}")
|
|
10
|
-
|
|
13
|
+
|
|
11
14
|
if (intent.action == Intent.ACTION_USER_PRESENT) {
|
|
12
|
-
val activeData = NativeCallManager.getCurrentCallData()
|
|
13
|
-
|
|
14
|
-
if (activeData != null) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
15
|
+
// val activeData = NativeCallManager.getCurrentCallData()
|
|
16
|
+
|
|
17
|
+
// if (activeData != null) {
|
|
18
|
+
// NativeCallManager.handleIncomingPush(context, activeData)
|
|
19
|
+
// } else {
|
|
20
|
+
// android.util.Log.d("UnlockReceiver", "No active call data found to re-trigger.")
|
|
21
|
+
// }
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
}
|
|
24
|
+
}
|