react-native-sinch-calling 0.5.0 → 0.6.1

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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,24 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
- ## 0.4.0
5
+ ## 0.7.0
6
+
7
+ ### Fixed
8
+
9
+ - `SinchCalling.eagerlyRegisterForVoipPush()` (added in 0.6.0) was unreachable from a consumer app's Swift code (`Module 'SinchCalling' has no member named 'eagerlyRegisterForVoipPush'`) — the podspec marked its only header (`SinchCalling.h`) as private, which hid it from anything outside this pod's own target. The RN TurboModule bridge never needed it public (it dispatches via the ObjC runtime), but a plain `import SinchCalling` from an app's `AppDelegate` does.
10
+
11
+ ## 0.6.0
12
+
13
+ ### Added
14
+
15
+ - `SinchCalling.eagerlyRegisterForVoipPush()` (iOS, native — not exposed to JS). Call it as the first line of `application(_:didFinishLaunchingWithOptions:)` to register `PKPushRegistry` and configure the custom incoming/cancel-call push fields immediately, independent of React Native. Without this, VoIP push registration only happened once the JS bridge called `enablePushNotifications()` deep into app bootstrap (after the RN bundle loaded, state rehydrated, etc.) — too late for the app to reliably report a call when iOS relaunches it from killed purely to deliver that push.
16
+
17
+ ### Changed
18
+
19
+ - `SinchPushManager` (iOS) now reports directly to `SinchCallKitManager` for a detected custom incoming/cancel push, instead of only notifying its delegate (which the JS-driven `SinchCalling` TurboModule instance implements). This means CallKit gets its report even if the delegate/JS bridge doesn't exist yet — the delegate now exists purely to notify JS (e.g. for a caller-ID lookup), not to perform the report itself.
20
+ - `SinchCallManager`, `SinchPushManager`, and `SinchCallKitManager` (iOS) are now shared singletons across the process rather than per-`SinchCalling`-instance, so the eager native call above and the later JS-driven TurboModule instance operate on the same `PKPushRegistry`/`CXProvider` instead of each creating their own (a single `PKPushRegistry` only supports one delegate per push type).
21
+
22
+ ## 0.5.0
6
23
 
7
24
  ### Added
8
25
 
package/README.md CHANGED
@@ -50,6 +50,7 @@ npm install react-native-sinch-calling
50
50
  </array>
51
51
  ```
52
52
  - Enable the **Push Notifications** capability in Xcode (adds `aps-environment` to your entitlements) — required for `enablePushNotifications()`.
53
+ - **Strongly recommended**: call `+[SinchCalling eagerlyRegisterForVoipPush]` as the first line of `application(_:didFinishLaunchingWithOptions:)` in your `AppDelegate` (native, not exposed to JS — see [Registering for VoIP push before React Native boots](#registering-for-voip-push-before-react-native-boots)). Registering only from JS via `enablePushNotifications()` means a killed app has no `PKPushRegistry` set up yet at the moment iOS relaunches it to deliver a VoIP push, so it may fail to ring.
53
54
 
54
55
  ### Android
55
56
 
@@ -121,6 +122,32 @@ const callId = SinchCalling.callConference('conf_abc123', '+14155550100');
121
122
  SinchCalling.sendDTMF(callId, '5');
122
123
  ```
123
124
 
125
+ ### Registering for VoIP push before React Native boots
126
+
127
+ `SinchCalling.enablePushNotifications()` (JS) only runs once the RN bundle has loaded, your app's state has rehydrated, and your code decides to call it — often well after your session/login logic runs. That's fine while the app is already running, but it's too late for the one case VoIP push exists for: iOS relaunching your app from **killed** purely to deliver a push. If `PKPushRegistry` isn't already registered by the time that happens, the call can't be reported and the launch is wasted.
128
+
129
+ On iOS, register natively instead, as the first line of `application(_:didFinishLaunchingWithOptions:)` — before React Native starts:
130
+
131
+ ```swift
132
+ import SinchCalling
133
+
134
+ func application(
135
+ _ application: UIApplication,
136
+ didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
137
+ ) -> Bool {
138
+ SinchCalling.eagerlyRegisterForVoipPush()
139
+
140
+ // ... start React Native as usual
141
+ return true
142
+ }
143
+ ```
144
+
145
+ This is a native-only entry point (not exposed to JS) that registers `PKPushRegistry` and configures the same custom incoming/cancel-call push fields as `configureCustomIncomingCallPush`/`configureCustomCancelCallPush` (hardcoded to `"callId"`/`"callerNumber"` and `"type"`/`"call_cancelled"` — update it in `SinchCalling.mm` if your backend's payload uses different field names). It's safe to also still call the JS APIs later — they operate on the same shared native objects, so nothing gets double-registered.
146
+
147
+ Picks `useProductionAps` automatically from the build configuration (`#if DEBUG`) rather than a JS-supplied flag, since it runs before any JS exists.
148
+
149
+ Android is different in kind, not necessarily gap-free: FCM data messages delivered while the app is killed run through RN Firebase's headless JS task mechanism (`setBackgroundMessageHandler`), which starts a fresh JS engine/bridge specifically to handle that one message — independent of whether your app has "launched" in the normal sense. But that also means it's a fresh native module instance too: if `configureCustomIncomingCallPush`/`configureCustomCancelCallPush` are only called from your app's normal boot sequence (e.g. after checking a login token), that boot sequence may never run in this headless context, leaving those fields unconfigured for that invocation. If you see the same "doesn't ring when killed" symptom on Android, call `configureCustomIncomingCallPush`/`configureCustomCancelCallPush` directly inside your `setBackgroundMessageHandler` callback (before forwarding to `relayRemotePushNotification`), not only from your app's regular init path.
150
+
124
151
  ### Custom incoming-call flows
125
152
 
126
153
  Some backends don't let Sinch route calls directly to a registered client — e.g. an inbound PSTN call gets parked and bridged into a Sinch conference only after your backend decides to connect it (fraud checks, business hours routing, a "ring multiple agents" pattern, etc). For that, your backend sends your app its own push/socket signal, and you tell this library about it explicitly:
@@ -15,7 +15,11 @@ Pod::Spec.new do |s|
15
15
 
16
16
  s.swift_version = "5.0"
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
18
- s.private_header_files = "ios/**/*.h"
18
+ # `SinchCalling.h` (the only header in this pod) must stay public — the
19
+ # RN TurboModule bridge itself doesn't need this (it dispatches via the
20
+ # ObjC runtime, not compile-time imports), but `eagerlyRegisterForVoipPush`
21
+ # is meant to be called directly from a consumer app's native AppDelegate
22
+ # via `import SinchCalling`, which only sees public headers.
19
23
 
20
24
  s.dependency "SinchRTC"
21
25
 
@@ -7,10 +7,14 @@ import SinchRTC
7
7
  // A configured custom incoming-call push was detected — distinct from a
8
8
  // Sinch-relayed push (e.g. an app-to-app incoming call), which is instead
9
9
  // forwarded straight to the Sinch client and surfaces as `onIncomingCall`.
10
+ // The system call UI has already been reported by the time this fires
11
+ // (see `callKitManager` below) — this is purely for observers (e.g. the
12
+ // JS bridge) that want to react, such as kicking off a caller-ID lookup.
10
13
  func sinchPushManagerDidDetectCustomIncomingCall(_ callId: String, displayName: String)
11
14
  // A configured cancel push was detected for a call already reported via
12
15
  // `sinchPushManagerDidDetectCustomIncomingCall` — see
13
- // `configureCustomCancelCallPush`.
16
+ // `configureCustomCancelCallPush`. The call UI has already been ended by
17
+ // the time this fires.
14
18
  func sinchPushManagerDidDetectCustomCancelCall(_ callId: String)
15
19
  }
16
20
 
@@ -20,19 +24,26 @@ import SinchRTC
20
24
  // `configureCustomIncomingCallPush`, payloads containing both configured
21
25
  // fields are instead reported as an external incoming call and skip the
22
26
  // Sinch relay for that push.
27
+ //
28
+ // Reports directly to `callKitManager` (rather than only notifying
29
+ // `delegate`) so a killed app can ring from a cold launch triggered by the
30
+ // push itself, before React Native has booted and any delegate/JS bridge
31
+ // exists to receive it — see `SinchCalling.eagerlyRegisterForVoipPush`.
23
32
  @objc(SinchPushManager)
24
33
  public final class SinchPushManager: NSObject {
25
34
  @objc public weak var delegate: SinchPushManagerDelegate?
26
35
 
27
36
  private weak var callManager: SinchCallManager?
37
+ private weak var callKitManager: SinchCallKitManager?
28
38
  private var registry: PKPushRegistry?
29
39
  private var customIdField: String?
30
40
  private var customDisplayField: String?
31
41
  private var customCancelTypeField: String?
32
42
  private var customCancelValue: String?
33
43
 
34
- @objc public init(callManager: SinchCallManager) {
44
+ @objc public init(callManager: SinchCallManager, callKitManager: SinchCallKitManager) {
35
45
  self.callManager = callManager
46
+ self.callKitManager = callKitManager
36
47
  super.init()
37
48
  }
38
49
 
@@ -93,9 +104,11 @@ extension SinchPushManager: PKPushRegistryDelegate {
93
104
  let typeValue = dict[typeField] as? String,
94
105
  typeValue == cancelValue
95
106
  {
107
+ callKitManager?.reportCallEnded(callId)
96
108
  delegate?.sinchPushManagerDidDetectCustomCancelCall(callId)
97
109
  } else {
98
110
  let displayName = customDisplayField.flatMap { dict[$0] as? String } ?? ""
111
+ callKitManager?.reportExternalIncomingCall(callId, displayName: displayName)
99
112
  delegate?.sinchPushManagerDidDetectCustomIncomingCall(callId, displayName: displayName)
100
113
  }
101
114
  } else {
@@ -2,4 +2,14 @@
2
2
 
3
3
  @interface SinchCalling : NativeSinchCallingSpecBase <NativeSinchCallingSpec>
4
4
 
5
+ // Registers for VoIP push (PKPushRegistry) and configures the custom
6
+ // incoming/cancel-call push field names immediately, independent of React
7
+ // Native and any consumer-app login state. Call this as early as possible —
8
+ // ideally the first line of `application(_:didFinishLaunchingWithOptions:)`
9
+ // — so a killed app can still ring and report to CallKit from a cold launch
10
+ // triggered by the push itself, before the JS bridge exists. Safe to call
11
+ // even if the RN-driven `SinchCalling` TurboModule instance is created
12
+ // later in the same process — both share the same underlying managers.
13
+ + (void)eagerlyRegisterForVoipPush;
14
+
5
15
  @end
@@ -11,20 +11,55 @@
11
11
  @interface SinchCalling () <SinchCallManagerDelegate, SinchCallKitManagerDelegate, SinchPushManagerDelegate>
12
12
  @end
13
13
 
14
+ // Shared across every `SinchCalling` instance in the process, and reachable
15
+ // before any instance exists at all via `+eagerlyRegisterForVoipPush` — see
16
+ // that method and `SinchPushManager`'s header comment for why: VoIP push
17
+ // registration and CallKit reporting must work even when the app is woken
18
+ // from killed purely by the incoming push, before React Native (and this
19
+ // TurboModule instance) has been created.
20
+ static SinchCallManager *sSharedCallManager = nil;
21
+ static SinchPushManager *sSharedPushManager = nil;
22
+ static SinchCallKitManager *sSharedCallKitManager = nil;
23
+
24
+ static void SinchCallingEnsureSharedManagers(void)
25
+ {
26
+ if (sSharedCallManager != nil) {
27
+ return;
28
+ }
29
+ sSharedCallManager = [SinchCallManager new];
30
+ sSharedCallKitManager = [SinchCallKitManager new];
31
+ sSharedPushManager = [[SinchPushManager alloc] initWithCallManager:sSharedCallManager
32
+ callKitManager:sSharedCallKitManager];
33
+ }
34
+
14
35
  @implementation SinchCalling {
15
36
  SinchCallManager *_callManager;
16
37
  SinchPushManager *_pushManager;
17
38
  SinchCallKitManager *_callKitManager;
18
39
  }
19
40
 
41
+ + (void)eagerlyRegisterForVoipPush
42
+ {
43
+ SinchCallingEnsureSharedManagers();
44
+ #if DEBUG
45
+ BOOL useProductionAps = NO;
46
+ #else
47
+ BOOL useProductionAps = YES;
48
+ #endif
49
+ [sSharedPushManager enableWithUseProductionAps:useProductionAps];
50
+ [sSharedPushManager configureCustomIncomingCallPushWithIdField:@"callId" displayField:@"callerNumber"];
51
+ [sSharedPushManager configureCustomCancelCallPushWithTypeField:@"type" cancelValue:@"call_cancelled"];
52
+ }
53
+
20
54
  - (instancetype)init
21
55
  {
22
56
  if (self = [super init]) {
23
- _callManager = [SinchCallManager new];
57
+ SinchCallingEnsureSharedManagers();
58
+ _callManager = sSharedCallManager;
59
+ _pushManager = sSharedPushManager;
60
+ _callKitManager = sSharedCallKitManager;
24
61
  _callManager.delegate = self;
25
- _pushManager = [[SinchPushManager alloc] initWithCallManager:_callManager];
26
62
  _pushManager.delegate = self;
27
- _callKitManager = [SinchCallKitManager new];
28
63
  _callKitManager.delegate = self;
29
64
  }
30
65
  return self;
@@ -229,13 +264,13 @@
229
264
 
230
265
  - (void)sinchPushManagerDidDetectCustomIncomingCall:(NSString *)callId displayName:(NSString *)displayName
231
266
  {
232
- [_callKitManager reportExternalIncomingCall:callId displayName:displayName];
267
+ // `SinchPushManager` already reported this to CallKit directly (works
268
+ // even before this instance/delegate exists) — just relay to JS.
233
269
  [self emitOnIncomingCallUIShown:@{ @"callId" : callId, @"displayName" : displayName }];
234
270
  }
235
271
 
236
272
  - (void)sinchPushManagerDidDetectCustomCancelCall:(NSString *)callId
237
273
  {
238
- [_callKitManager reportCallEnded:callId];
239
274
  [self emitOnIncomingCallUICancelled:@{ @"callId" : callId }];
240
275
  }
241
276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-sinch-calling",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
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",