rns-nativecall 1.0.8 → 1.0.9
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,34 @@ 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(this, uuid)
|
|
130
146
|
CallState.clear(uuid)
|
|
131
147
|
pendingCallDataMap = null
|
|
132
|
-
|
|
148
|
+
|
|
133
149
|
val notificationManager = reactApplicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
134
150
|
notificationManager.cancel(101)
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
@ReactMethod fun addListener(eventName: String) {}
|
|
154
|
+
|
|
138
155
|
@ReactMethod fun removeListeners(count: Int) {}
|
|
139
156
|
|
|
140
157
|
companion object {
|
|
@@ -149,14 +166,17 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
149
166
|
return reactContext != null && reactContext.hasActiveCatalystInstance()
|
|
150
167
|
}
|
|
151
168
|
|
|
152
|
-
@JvmStatic
|
|
169
|
+
@JvmStatic
|
|
153
170
|
fun setPendingCallData(data: Map<String, String>) {
|
|
154
|
-
|
|
171
|
+
pendingCallDataMap = data
|
|
155
172
|
}
|
|
156
173
|
|
|
157
|
-
@JvmStatic
|
|
158
|
-
fun setPendingCallData(
|
|
159
|
-
|
|
174
|
+
@JvmStatic
|
|
175
|
+
fun setPendingCallData(
|
|
176
|
+
eventName: String,
|
|
177
|
+
data: Map<String, String>,
|
|
178
|
+
) {
|
|
179
|
+
pendingEvents[eventName] = data
|
|
160
180
|
}
|
|
161
181
|
|
|
162
182
|
@JvmStatic
|
|
@@ -174,23 +194,33 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
174
194
|
}
|
|
175
195
|
|
|
176
196
|
@JvmStatic
|
|
177
|
-
fun setPendingEvent(
|
|
197
|
+
fun setPendingEvent(
|
|
198
|
+
eventName: String,
|
|
199
|
+
data: Map<String, String>,
|
|
200
|
+
) {
|
|
178
201
|
pendingEvents[eventName] = data
|
|
179
202
|
}
|
|
180
203
|
|
|
181
204
|
@JvmStatic
|
|
182
|
-
fun sendEventToJS(
|
|
205
|
+
fun sendEventToJS(
|
|
206
|
+
eventName: String,
|
|
207
|
+
params: Any?,
|
|
208
|
+
) {
|
|
183
209
|
val reactContext = instance?.reactApplicationContext
|
|
184
|
-
val bridgeData =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
210
|
+
val bridgeData =
|
|
211
|
+
when (params) {
|
|
212
|
+
is Map<*, *> -> {
|
|
213
|
+
val map = Arguments.createMap()
|
|
214
|
+
params.forEach { (key, value) ->
|
|
215
|
+
map.putString(key.toString(), value.toString())
|
|
216
|
+
}
|
|
217
|
+
map
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
else -> {
|
|
221
|
+
null
|
|
189
222
|
}
|
|
190
|
-
map
|
|
191
223
|
}
|
|
192
|
-
else -> null
|
|
193
|
-
}
|
|
194
224
|
|
|
195
225
|
if (isReady()) {
|
|
196
226
|
reactContext
|
|
@@ -202,4 +232,4 @@ class CallModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMo
|
|
|
202
232
|
}
|
|
203
233
|
}
|
|
204
234
|
}
|
|
205
|
-
}
|
|
235
|
+
}
|
|
@@ -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
|
+
}
|