react-native-sinch-calling 0.7.0 → 0.8.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.
@@ -69,10 +69,6 @@ class SinchCallManager(private val context: Context) {
69
69
  private var pendingRegistration: ClientRegistration? = null
70
70
  private var pendingPushConfiguration: PushConfiguration? = null
71
71
  private val calls = mutableMapOf<String, Call>()
72
- private var customPushIdField: String? = null
73
- private var customPushDisplayField: String? = null
74
- private var customCancelTypeField: String? = null
75
- private var customCancelValue: String? = null
76
72
 
77
73
  // Proximity-screen-off during an established earpiece call, same as the
78
74
  // system Phone app: on while at least one call is established and the
@@ -136,10 +132,11 @@ class SinchCallManager(private val context: Context) {
136
132
 
137
133
  // Opts into recognizing the consumer app's own backend's incoming-call
138
134
  // push payloads. Until called, every payload is relayed straight to
139
- // Sinch (see `relayRemotePushNotification`).
135
+ // Sinch (see `relayRemotePushNotification`). Delegates to
136
+ // `SinchTelecomManager` — see its header comment for why this state
137
+ // doesn't live here.
140
138
  fun configureCustomIncomingCallPush(idField: String, displayField: String) {
141
- customPushIdField = idField
142
- customPushDisplayField = displayField
139
+ SinchTelecomManager.configureCustomIncomingCallPush(idField, displayField)
143
140
  }
144
141
 
145
142
  // Opts into recognizing a cancel/end push shaped like the configured
@@ -149,28 +146,36 @@ class SinchCallManager(private val context: Context) {
149
146
  // `relayRemotePushNotification`, so a payload satisfying both is treated
150
147
  // as a cancel.
151
148
  fun configureCustomCancelCallPush(typeField: String, cancelValue: String) {
152
- customCancelTypeField = typeField
153
- customCancelValue = cancelValue
149
+ SinchTelecomManager.configureCustomCancelCallPush(typeField, cancelValue)
154
150
  }
155
151
 
156
152
  fun relayRemotePushNotification(payload: Map<String, String>) {
157
- val idField = customPushIdField
153
+ val idField = SinchTelecomManager.customPushIdField
158
154
  val callId = idField?.let { payload[it] }
159
155
  if (callId != null) {
160
- val typeField = customCancelTypeField
161
- val cancelValue = customCancelValue
156
+ val typeField = SinchTelecomManager.customCancelTypeField
157
+ val cancelValue = SinchTelecomManager.customCancelValue
162
158
  if (typeField != null && cancelValue != null && payload[typeField] == cancelValue) {
163
159
  SinchTelecomManager.reportCallEnded(callId)
164
160
  listener?.onIncomingCallUICancelled(callId)
165
161
  return
166
162
  }
167
163
 
168
- val displayName = customPushDisplayField?.let { payload[it] } ?: ""
164
+ val displayName = SinchTelecomManager.customPushDisplayField?.let { payload[it] } ?: ""
169
165
  reportIncomingCallUI(callId, displayName)
170
166
  return
171
167
  }
172
168
 
173
- val result = SinchPush.queryPushNotificationPayload(context.applicationContext, payload)
169
+ // The consumer app's own unrelated notifications (a task reminder, a new
170
+ // message, ...) share this same FCM sender and get relayed here too —
171
+ // `queryPushNotificationPayload` throws for anything that isn't shaped
172
+ // like a genuine Sinch-issued payload, so a non-call push must not
173
+ // propagate that as an uncaught native exception up through the bridge.
174
+ val result = try {
175
+ SinchPush.queryPushNotificationPayload(context.applicationContext, payload)
176
+ } catch (error: IllegalArgumentException) {
177
+ return
178
+ }
174
179
  client?.relayRemotePushNotification(result)
175
180
  }
176
181
 
@@ -0,0 +1,30 @@
1
+ package com.sinchcalling
2
+
3
+ import android.content.Context
4
+ import com.sinchcalling.telecom.SinchTelecomManager
5
+
6
+ /**
7
+ * Mirrors iOS's `SinchCallingBootstrap.eagerlyRegisterForVoipPush` — a
8
+ * plain entry point a consumer app's `Application.onCreate()` can call
9
+ * before React Native (or any Activity) exists.
10
+ *
11
+ * A killed app woken purely by an incoming-call FCM push runs its
12
+ * background handler (e.g. `messaging().setBackgroundMessageHandler` on the
13
+ * JS side) in a process that never mounts the app's React component tree —
14
+ * so a JS-side `useEffect` that would otherwise call
15
+ * `SinchCalling.configureCustomIncomingCallPush(...)` (typically on login,
16
+ * deep inside the navigation tree) never runs there, and
17
+ * `SinchCallManager.relayRemotePushNotification` has no way to recognize
18
+ * the custom incoming/cancel-call push shape. `Application.onCreate()` runs
19
+ * for every process launch — including one spun up solely to handle a
20
+ * background push — so configuring it there guarantees it's set before any
21
+ * push can arrive, matching the iOS bootstrap's guarantee.
22
+ */
23
+ object SinchCallingBootstrap {
24
+ @JvmStatic
25
+ fun eagerlyConfigureCustomIncomingCallPush(context: Context) {
26
+ SinchTelecomManager.registerPhoneAccount(context.applicationContext)
27
+ SinchTelecomManager.configureCustomIncomingCallPush("callId", "callerNumber")
28
+ SinchTelecomManager.configureCustomCancelCallPush("type", "call_cancelled")
29
+ }
30
+ }
@@ -34,6 +34,33 @@ object SinchTelecomManager {
34
34
  // below so they don't all need a `Context` param just to cancel a notification.
35
35
  private var appContext: Context? = null
36
36
 
37
+ // Lives here rather than on `SinchCallManager` so `SinchCallingBootstrap`
38
+ // can configure it before any `SinchCallManager`/TurboModule instance
39
+ // exists — see that class's header comment for why that matters.
40
+ internal var customPushIdField: String? = null
41
+ private set
42
+ internal var customPushDisplayField: String? = null
43
+ private set
44
+ internal var customCancelTypeField: String? = null
45
+ private set
46
+ internal var customCancelValue: String? = null
47
+ private set
48
+
49
+ // Opts into recognizing the consumer app's own backend's incoming-call
50
+ // push payloads. Until called, every payload is relayed straight to Sinch
51
+ // (see `SinchCallManager.relayRemotePushNotification`).
52
+ fun configureCustomIncomingCallPush(idField: String, displayField: String) {
53
+ customPushIdField = idField
54
+ customPushDisplayField = displayField
55
+ }
56
+
57
+ // Opts into recognizing a cancel/end push shaped like the configured
58
+ // incoming-call push but carrying `typeField == cancelValue`.
59
+ fun configureCustomCancelCallPush(typeField: String, cancelValue: String) {
60
+ customCancelTypeField = typeField
61
+ customCancelValue = cancelValue
62
+ }
63
+
37
64
  fun phoneAccountHandle(context: Context): PhoneAccountHandle {
38
65
  val componentName = ComponentName(context, SinchConnectionService::class.java)
39
66
  return PhoneAccountHandle(componentName, ACCOUNT_ID)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-sinch-calling",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "React Native TurboModule wrapper for Sinch Voice Calling SDK (Android & iOS)",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",