react-native-sinch-calling 0.2.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +20 -0
  3. package/README.md +239 -0
  4. package/SinchCalling.podspec +28 -0
  5. package/android/build.gradle +52 -0
  6. package/android/src/main/AndroidManifest.xml +19 -0
  7. package/android/src/main/java/com/sinchcalling/SinchCallManager.kt +302 -0
  8. package/android/src/main/java/com/sinchcalling/SinchCallingModule.kt +184 -0
  9. package/android/src/main/java/com/sinchcalling/SinchCallingPackage.kt +31 -0
  10. package/android/src/main/java/com/sinchcalling/telecom/SinchConnection.kt +43 -0
  11. package/android/src/main/java/com/sinchcalling/telecom/SinchConnectionService.kt +37 -0
  12. package/android/src/main/java/com/sinchcalling/telecom/SinchTelecomManager.kt +106 -0
  13. package/ios/Sinch/SinchCallKitManager.swift +154 -0
  14. package/ios/Sinch/SinchCallManager.swift +195 -0
  15. package/ios/Sinch/SinchPushManager.swift +81 -0
  16. package/ios/SinchCalling.h +5 -0
  17. package/ios/SinchCalling.mm +242 -0
  18. package/lib/module/NativeSinchCalling.js +5 -0
  19. package/lib/module/NativeSinchCalling.js.map +1 -0
  20. package/lib/module/SinchCalling.js +185 -0
  21. package/lib/module/SinchCalling.js.map +1 -0
  22. package/lib/module/index.js +4 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/types.js +4 -0
  26. package/lib/module/types.js.map +1 -0
  27. package/lib/typescript/package.json +1 -0
  28. package/lib/typescript/src/NativeSinchCalling.d.ts +69 -0
  29. package/lib/typescript/src/NativeSinchCalling.d.ts.map +1 -0
  30. package/lib/typescript/src/SinchCalling.d.ts +98 -0
  31. package/lib/typescript/src/SinchCalling.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +4 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/types.d.ts +9 -0
  35. package/lib/typescript/src/types.d.ts.map +1 -0
  36. package/package.json +179 -0
  37. package/src/NativeSinchCalling.ts +148 -0
  38. package/src/SinchCalling.ts +245 -0
  39. package/src/index.tsx +11 -0
  40. package/src/types.ts +9 -0
@@ -0,0 +1,154 @@
1
+ import AVFoundation
2
+ import CallKit
3
+ import Foundation
4
+
5
+ @objc public protocol SinchCallKitManagerDelegate: AnyObject {
6
+ func sinchCallKitManagerDidAnswerCall(_ callId: String)
7
+ func sinchCallKitManagerDidEndCall(_ callId: String)
8
+ // Fired instead of the two methods above when the call was reported via
9
+ // `reportExternalIncomingCall` and hasn't been resolved into a real Sinch
10
+ // call yet (see `resolveCallUIToConference`) — answering/declining it is
11
+ // the consumer app's business, not the native call API's.
12
+ func sinchCallKitManagerDidAnswerExternalCall(_ callId: String)
13
+ func sinchCallKitManagerDidDeclineExternalCall(_ callId: String)
14
+ func sinchCallKitManagerDidActivateAudioSession(_ audioSession: AVAudioSession)
15
+ func sinchCallKitManagerDidDeactivateAudioSession(_ audioSession: AVAudioSession)
16
+ }
17
+
18
+ // A PSTN incoming call's `remoteUserId` is the caller's phone number;
19
+ // an app-to-app call's is our own opaque Sinch userId. Distinguishing them
20
+ // lets CallKit show/format the caller ID correctly.
21
+ private func isPhoneNumber(_ value: String) -> Bool {
22
+ return value.range(of: "^\\+?[0-9]{6,15}$", options: .regularExpression) != nil
23
+ }
24
+
25
+ @objc(SinchCallKitManager)
26
+ public final class SinchCallKitManager: NSObject {
27
+ @objc public weak var delegate: SinchCallKitManagerDelegate?
28
+
29
+ private let provider: CXProvider
30
+ private var callIdToUUID: [String: UUID] = [:]
31
+ private var uuidToCallId: [UUID: String] = [:]
32
+ private var externallyReportedCallIds: Set<String> = []
33
+
34
+ @objc override public init() {
35
+ let configuration = CXProviderConfiguration()
36
+ configuration.supportsVideo = false
37
+ configuration.maximumCallGroups = 1
38
+ configuration.maximumCallsPerCallGroup = 1
39
+ configuration.supportedHandleTypes = [.generic, .phoneNumber]
40
+
41
+ provider = CXProvider(configuration: configuration)
42
+ super.init()
43
+ provider.setDelegate(self, queue: nil)
44
+ }
45
+
46
+ @objc public func reportIncomingCall(_ callId: String, remoteUserId: String) {
47
+ reportNewIncomingCall(callId, remoteUserId: remoteUserId)
48
+ }
49
+
50
+ // A call the consumer app decided to show a system call UI for (a custom
51
+ // push, a socket event, anything) — not a Sinch-native incoming call.
52
+ // Answering/declining goes through the app's own logic instead of the
53
+ // native call API until `remapCallId` ties it to a real call.
54
+ @objc public func reportExternalIncomingCall(_ callId: String, displayName: String) {
55
+ externallyReportedCallIds.insert(callId)
56
+ reportNewIncomingCall(callId, remoteUserId: displayName)
57
+ }
58
+
59
+ // Re-associates the system call UI already showing for `oldCallId` (an
60
+ // externally-reported, not-yet-real call) with the real Sinch call
61
+ // created once the consumer app resolved it.
62
+ @objc public func remapCallId(_ oldCallId: String, toCallId newCallId: String) {
63
+ guard let uuid = callIdToUUID[oldCallId] else { return }
64
+ callIdToUUID.removeValue(forKey: oldCallId)
65
+ callIdToUUID[newCallId] = uuid
66
+ uuidToCallId[uuid] = newCallId
67
+ externallyReportedCallIds.remove(oldCallId)
68
+ }
69
+
70
+ // Overrides the caller name shown on the system call UI (e.g. once a
71
+ // caller-ID lookup resolves) without disturbing the phone number already
72
+ // reported as the handle.
73
+ @objc public func updateCallerDisplayName(_ callId: String, displayName: String) {
74
+ guard let uuid = callIdToUUID[callId] else { return }
75
+ let update = CXCallUpdate()
76
+ update.localizedCallerName = displayName
77
+ provider.reportCall(with: uuid, updated: update)
78
+ }
79
+
80
+ @objc public func reportCallEnded(_ callId: String) {
81
+ guard let uuid = callIdToUUID[callId] else { return }
82
+ provider.reportCall(with: uuid, endedAt: nil, reason: .remoteEnded)
83
+ callIdToUUID.removeValue(forKey: callId)
84
+ uuidToCallId.removeValue(forKey: uuid)
85
+ externallyReportedCallIds.remove(callId)
86
+ }
87
+
88
+ private func reportNewIncomingCall(_ callId: String, remoteUserId: String) {
89
+ if callIdToUUID[callId] != nil {
90
+ return
91
+ }
92
+
93
+ let uuid = UUID()
94
+ callIdToUUID[callId] = uuid
95
+ uuidToCallId[uuid] = callId
96
+
97
+ let update = CXCallUpdate()
98
+ let handleType: CXHandle.HandleType = isPhoneNumber(remoteUserId) ? .phoneNumber : .generic
99
+ update.remoteHandle = CXHandle(type: handleType, value: remoteUserId)
100
+ update.hasVideo = false
101
+
102
+ provider.reportNewIncomingCall(with: uuid, update: update) { [weak self] error in
103
+ guard error != nil else { return }
104
+ self?.callIdToUUID.removeValue(forKey: callId)
105
+ self?.uuidToCallId.removeValue(forKey: uuid)
106
+ self?.externallyReportedCallIds.remove(callId)
107
+ }
108
+ }
109
+ }
110
+
111
+ extension SinchCallKitManager: CXProviderDelegate {
112
+ public func providerDidReset(_ provider: CXProvider) {
113
+ callIdToUUID.removeAll()
114
+ uuidToCallId.removeAll()
115
+ }
116
+
117
+ public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
118
+ guard let callId = uuidToCallId[action.callUUID] else {
119
+ action.fail()
120
+ return
121
+ }
122
+ if externallyReportedCallIds.contains(callId) {
123
+ delegate?.sinchCallKitManagerDidAnswerExternalCall(callId)
124
+ } else {
125
+ delegate?.sinchCallKitManagerDidAnswerCall(callId)
126
+ }
127
+ action.fulfill()
128
+ }
129
+
130
+ public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
131
+ guard let callId = uuidToCallId[action.callUUID] else {
132
+ action.fail()
133
+ return
134
+ }
135
+ let wasExternallyReported = externallyReportedCallIds.contains(callId)
136
+ callIdToUUID.removeValue(forKey: callId)
137
+ uuidToCallId.removeValue(forKey: action.callUUID)
138
+ externallyReportedCallIds.remove(callId)
139
+ if wasExternallyReported {
140
+ delegate?.sinchCallKitManagerDidDeclineExternalCall(callId)
141
+ } else {
142
+ delegate?.sinchCallKitManagerDidEndCall(callId)
143
+ }
144
+ action.fulfill()
145
+ }
146
+
147
+ public func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
148
+ delegate?.sinchCallKitManagerDidActivateAudioSession(audioSession)
149
+ }
150
+
151
+ public func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
152
+ delegate?.sinchCallKitManagerDidDeactivateAudioSession(audioSession)
153
+ }
154
+ }
@@ -0,0 +1,195 @@
1
+ import AVFoundation
2
+ import Foundation
3
+ import SinchRTC
4
+
5
+ @objc public protocol SinchCallManagerDelegate: AnyObject {
6
+ func sinchCallManagerDidStartClient()
7
+ func sinchCallManagerDidFailWithMessage(_ message: String, code: Int)
8
+ func sinchCallManagerRequiresRegistrationCredentials()
9
+
10
+ func sinchCallManagerDidReceiveIncomingCall(_ callId: String, remoteUserId: String)
11
+ func sinchCallManagerCallDidProgress(_ callId: String)
12
+ func sinchCallManagerCallDidEstablish(_ callId: String)
13
+ func sinchCallManagerCallDidEnd(_ callId: String, endCause: String)
14
+ }
15
+
16
+ private func endCauseString(_ endCause: SINCallEndCause) -> String {
17
+ switch endCause {
18
+ case .none: return "none"
19
+ case .timeout: return "timeout"
20
+ case .denied: return "denied"
21
+ case .noAnswer: return "noAnswer"
22
+ case .error: return "error"
23
+ case .hungUp: return "hungUp"
24
+ case .canceled: return "canceled"
25
+ case .otherDeviceAnswered: return "otherDeviceAnswered"
26
+ case .inactive: return "inactive"
27
+ case .voIPCallDetected: return "voipCallDetected"
28
+ case .gsmCallDetected: return "gsmCallDetected"
29
+ @unknown default: return "none"
30
+ }
31
+ }
32
+
33
+ @objc(SinchCallManager)
34
+ public final class SinchCallManager: NSObject {
35
+ @objc public weak var delegate: SinchCallManagerDelegate?
36
+
37
+ private var client: SINClient?
38
+ private var pendingRegistration: SINClientRegistration?
39
+ private var calls: [String: SINCall] = [:]
40
+
41
+ @objc public func configure(appKey: String, environmentHost: String, userId: String) {
42
+ do {
43
+ let sinchClient = try Sinch.client(
44
+ withApplicationKey: appKey,
45
+ environmentHost: environmentHost,
46
+ userId: userId
47
+ )
48
+ sinchClient.delegate = self
49
+ sinchClient.call().delegate = self
50
+ client = sinchClient
51
+ } catch {
52
+ let nsError = error as NSError
53
+ delegate?.sinchCallManagerDidFailWithMessage(nsError.localizedDescription, code: nsError.code)
54
+ }
55
+ }
56
+
57
+ @objc public func start() {
58
+ client?.start()
59
+ }
60
+
61
+ @objc public func stop() {
62
+ client?.terminateGracefully()
63
+ client = nil
64
+ calls.removeAll()
65
+ }
66
+
67
+ @objc public func provideRegistrationCredentials(_ jwt: String) {
68
+ pendingRegistration?.register(withJWT: jwt)
69
+ pendingRegistration = nil
70
+ }
71
+
72
+ @objc public func failRegistration(_ message: String) {
73
+ let error = NSError(
74
+ domain: "SinchCalling",
75
+ code: -1,
76
+ userInfo: [NSLocalizedDescriptionKey: message]
77
+ )
78
+ pendingRegistration?.registerDidFail(error)
79
+ pendingRegistration = nil
80
+ }
81
+
82
+ @objc public func callUser(_ userId: String) -> String {
83
+ guard let call = client?.call().callUser(withId: userId) else {
84
+ return ""
85
+ }
86
+ track(call)
87
+ return call.callId
88
+ }
89
+
90
+ @objc public func callPhoneNumber(_ phoneNumber: String) -> String {
91
+ guard let call = client?.call().callPhoneNumber(phoneNumber) else {
92
+ return ""
93
+ }
94
+ track(call)
95
+ return call.callId
96
+ }
97
+
98
+ @objc public func callConference(_ conferenceId: String) -> String {
99
+ guard let call = client?.call().callConference(withId: conferenceId) else {
100
+ return ""
101
+ }
102
+ track(call)
103
+ return call.callId
104
+ }
105
+
106
+ @objc public func answerCall(_ callId: String) {
107
+ calls[callId]?.answer()
108
+ }
109
+
110
+ @objc public func hangupCall(_ callId: String) {
111
+ calls[callId]?.hangup()
112
+ }
113
+
114
+ @objc public func sendDTMF(_ callId: String, key: String) -> Bool {
115
+ return calls[callId]?.sendDTMF(key) ?? false
116
+ }
117
+
118
+ @objc public func setMuted(_ muted: Bool) {
119
+ if muted {
120
+ client?.audioController().mute()
121
+ } else {
122
+ client?.audioController().unmute()
123
+ }
124
+ }
125
+
126
+ @objc public func setSpeakerEnabled(_ enabled: Bool) {
127
+ if enabled {
128
+ client?.audioController().enableSpeaker()
129
+ } else {
130
+ client?.audioController().disableSpeaker()
131
+ }
132
+ }
133
+
134
+ @objc public func enableManagedPushNotifications() {
135
+ client?.enableManagedPushNotifications()
136
+ }
137
+
138
+ @objc public func relayPushNotification(_ payload: [AnyHashable: Any]) {
139
+ _ = client?.relayPushNotification(payload)
140
+ }
141
+
142
+ @objc public func didActivateAudioSession(_ audioSession: AVAudioSession) {
143
+ client?.call().didActivate(audioSession)
144
+ }
145
+
146
+ @objc public func didDeactivateAudioSession(_ audioSession: AVAudioSession) {
147
+ client?.call().didDeactivate(audioSession)
148
+ }
149
+
150
+ private func track(_ call: SINCall) {
151
+ calls[call.callId] = call
152
+ call.delegate = self
153
+ }
154
+ }
155
+
156
+ extension SinchCallManager: SINClientDelegate {
157
+ public func clientDidStart(_ client: SINClient) {
158
+ delegate?.sinchCallManagerDidStartClient()
159
+ }
160
+
161
+ public func clientDidFail(_ client: SINClient, error: Error) {
162
+ let nsError = error as NSError
163
+ delegate?.sinchCallManagerDidFailWithMessage(nsError.localizedDescription, code: nsError.code)
164
+ }
165
+
166
+ public func client(
167
+ _ client: SINClient,
168
+ requiresRegistrationCredentials registrationCallback: SINClientRegistration
169
+ ) {
170
+ pendingRegistration = registrationCallback
171
+ delegate?.sinchCallManagerRequiresRegistrationCredentials()
172
+ }
173
+ }
174
+
175
+ extension SinchCallManager: SINCallClientDelegate {
176
+ public func client(_ client: SINCallClient, didReceiveIncomingCall call: SINCall) {
177
+ track(call)
178
+ delegate?.sinchCallManagerDidReceiveIncomingCall(call.callId, remoteUserId: call.remoteUserId)
179
+ }
180
+ }
181
+
182
+ extension SinchCallManager: SINCallDelegate {
183
+ public func callDidProgress(_ call: SINCall) {
184
+ delegate?.sinchCallManagerCallDidProgress(call.callId)
185
+ }
186
+
187
+ public func callDidEstablish(_ call: SINCall) {
188
+ delegate?.sinchCallManagerCallDidEstablish(call.callId)
189
+ }
190
+
191
+ public func callDidEnd(_ call: SINCall) {
192
+ calls.removeValue(forKey: call.callId)
193
+ delegate?.sinchCallManagerCallDidEnd(call.callId, endCause: endCauseString(call.details.endCause))
194
+ }
195
+ }
@@ -0,0 +1,81 @@
1
+ import Foundation
2
+ import PushKit
3
+ import SinchRTC
4
+
5
+ @objc public protocol SinchPushManagerDelegate: AnyObject {
6
+ func sinchPushManagerDidUpdateToken(_ tokenHex: String)
7
+ // A configured custom incoming-call push was detected — distinct from a
8
+ // Sinch-relayed push (e.g. an app-to-app incoming call), which is instead
9
+ // forwarded straight to the Sinch client and surfaces as `onIncomingCall`.
10
+ func sinchPushManagerDidDetectCustomIncomingCall(_ callId: String, displayName: String)
11
+ }
12
+
13
+ // A single `PKPushRegistry` can only have one delegate per push type, so this
14
+ // owns VoIP push end-to-end. By default every payload is relayed straight to
15
+ // Sinch (the library's original behavior). If the consumer app opts in via
16
+ // `configureCustomIncomingCallPush`, payloads containing both configured
17
+ // fields are instead reported as an external incoming call and skip the
18
+ // Sinch relay for that push.
19
+ @objc(SinchPushManager)
20
+ public final class SinchPushManager: NSObject {
21
+ @objc public weak var delegate: SinchPushManagerDelegate?
22
+
23
+ private weak var callManager: SinchCallManager?
24
+ private var registry: PKPushRegistry?
25
+ private var customIdField: String?
26
+ private var customDisplayField: String?
27
+
28
+ @objc public init(callManager: SinchCallManager) {
29
+ self.callManager = callManager
30
+ super.init()
31
+ }
32
+
33
+ @objc public func enable(useProductionAps: Bool) {
34
+ callManager?.enableManagedPushNotifications()
35
+
36
+ let registry = PKPushRegistry(queue: .main)
37
+ registry.delegate = self
38
+ registry.desiredPushTypes = [.voIP]
39
+ self.registry = registry
40
+ }
41
+
42
+ @objc public func configureCustomIncomingCallPush(idField: String, displayField: String) {
43
+ customIdField = idField
44
+ customDisplayField = displayField
45
+ }
46
+ }
47
+
48
+ extension SinchPushManager: PKPushRegistryDelegate {
49
+ public func pushRegistry(
50
+ _ registry: PKPushRegistry,
51
+ didUpdate pushCredentials: PKPushCredentials,
52
+ for type: PKPushType
53
+ ) {
54
+ guard type == .voIP else { return }
55
+ let tokenHex = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
56
+ delegate?.sinchPushManagerDidUpdateToken(tokenHex)
57
+ }
58
+
59
+ public func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {}
60
+
61
+ public func pushRegistry(
62
+ _ registry: PKPushRegistry,
63
+ didReceiveIncomingPushWith payload: PKPushPayload,
64
+ for type: PKPushType,
65
+ completion: @escaping () -> Void
66
+ ) {
67
+ guard type == .voIP else {
68
+ completion()
69
+ return
70
+ }
71
+
72
+ let dict = payload.dictionaryPayload
73
+ if let idField = customIdField, let callId = dict[idField] as? String {
74
+ let displayName = customDisplayField.flatMap { dict[$0] as? String } ?? ""
75
+ delegate?.sinchPushManagerDidDetectCustomIncomingCall(callId, displayName: displayName)
76
+ } else {
77
+ callManager?.relayPushNotification(dict)
78
+ }
79
+ completion()
80
+ }
81
+ }
@@ -0,0 +1,5 @@
1
+ #import <SinchCallingSpec/SinchCallingSpec.h>
2
+
3
+ @interface SinchCalling : NativeSinchCallingSpecBase <NativeSinchCallingSpec>
4
+
5
+ @end
@@ -0,0 +1,242 @@
1
+ #import <AVFoundation/AVFoundation.h>
2
+
3
+ #import "SinchCalling.h"
4
+
5
+ #if __has_include("SinchCalling-Swift.h")
6
+ #import "SinchCalling-Swift.h"
7
+ #else
8
+ #import <SinchCalling/SinchCalling-Swift.h>
9
+ #endif
10
+
11
+ @interface SinchCalling () <SinchCallManagerDelegate, SinchCallKitManagerDelegate, SinchPushManagerDelegate>
12
+ @end
13
+
14
+ @implementation SinchCalling {
15
+ SinchCallManager *_callManager;
16
+ SinchPushManager *_pushManager;
17
+ SinchCallKitManager *_callKitManager;
18
+ }
19
+
20
+ - (instancetype)init
21
+ {
22
+ if (self = [super init]) {
23
+ _callManager = [SinchCallManager new];
24
+ _callManager.delegate = self;
25
+ _pushManager = [[SinchPushManager alloc] initWithCallManager:_callManager];
26
+ _pushManager.delegate = self;
27
+ _callKitManager = [SinchCallKitManager new];
28
+ _callKitManager.delegate = self;
29
+ }
30
+ return self;
31
+ }
32
+
33
+ - (void)configure:(NSString *)appKey environmentHost:(NSString *)environmentHost userId:(NSString *)userId
34
+ {
35
+ [_callManager configureWithAppKey:appKey environmentHost:environmentHost userId:userId];
36
+ }
37
+
38
+ - (void)start
39
+ {
40
+ [_callManager start];
41
+ }
42
+
43
+ - (void)stop
44
+ {
45
+ [_callManager stop];
46
+ }
47
+
48
+ - (void)provideRegistrationCredentials:(NSString *)jwt
49
+ {
50
+ [_callManager provideRegistrationCredentials:jwt];
51
+ }
52
+
53
+ - (void)failRegistration:(NSString *)message
54
+ {
55
+ [_callManager failRegistration:message];
56
+ }
57
+
58
+ - (NSString *)callUser:(NSString *)userId
59
+ {
60
+ return [_callManager callUser:userId];
61
+ }
62
+
63
+ - (NSString *)callPhoneNumber:(NSString *)phoneNumber callerId:(NSString *)callerId
64
+ {
65
+ return [_callManager callPhoneNumber:phoneNumber];
66
+ }
67
+
68
+ - (NSString *)callConference:(NSString *)conferenceId callerId:(NSString *)callerId
69
+ {
70
+ return [_callManager callConference:conferenceId];
71
+ }
72
+
73
+ - (BOOL)sendDTMF:(NSString *)callId key:(NSString *)key
74
+ {
75
+ return [_callManager sendDTMF:callId key:key];
76
+ }
77
+
78
+ - (void)configureCustomIncomingCallPush:(NSString *)idField displayField:(NSString *)displayField
79
+ {
80
+ [_pushManager configureCustomIncomingCallPushWithIdField:idField displayField:displayField];
81
+ }
82
+
83
+ - (void)reportIncomingCallUI:(NSString *)callId displayName:(NSString *)displayName
84
+ {
85
+ [_callKitManager reportExternalIncomingCall:callId displayName:displayName];
86
+ [self emitOnIncomingCallUIShown:@{ @"callId" : callId, @"displayName" : displayName }];
87
+ }
88
+
89
+ - (NSString *)resolveCallUIToConference:(NSString *)callId
90
+ conferenceId:(NSString *)conferenceId
91
+ callerId:(NSString *)callerId
92
+ {
93
+ NSString *realCallId = [_callManager callConference:conferenceId];
94
+ if (realCallId.length == 0) {
95
+ [_callKitManager reportCallEnded:callId];
96
+ return @"";
97
+ }
98
+ [_callKitManager remapCallId:callId toCallId:realCallId];
99
+ return realCallId;
100
+ }
101
+
102
+ - (void)dismissCallUI:(NSString *)callId
103
+ {
104
+ [_callKitManager reportCallEnded:callId];
105
+ }
106
+
107
+ - (void)updateIncomingCallDisplayName:(NSString *)callId displayName:(NSString *)displayName
108
+ {
109
+ [_callKitManager updateCallerDisplayName:callId displayName:displayName];
110
+ }
111
+
112
+ - (void)answerCall:(NSString *)callId
113
+ {
114
+ [_callManager answerCall:callId];
115
+ }
116
+
117
+ - (void)hangupCall:(NSString *)callId
118
+ {
119
+ [_callManager hangupCall:callId];
120
+ }
121
+
122
+ - (void)setMuted:(BOOL)muted
123
+ {
124
+ [_callManager setMuted:muted];
125
+ }
126
+
127
+ - (void)setSpeakerEnabled:(BOOL)enabled
128
+ {
129
+ [_callManager setSpeakerEnabled:enabled];
130
+ }
131
+
132
+ - (void)registerFcmPush:(NSString *)senderId token:(NSString *)token
133
+ {
134
+ // Android only — iOS uses SINManagedPush (see enablePushNotifications).
135
+ }
136
+
137
+ - (void)enablePushNotifications:(BOOL)useProductionAps
138
+ {
139
+ [_pushManager enableWithUseProductionAps:useProductionAps];
140
+ }
141
+
142
+ - (void)relayRemotePushNotification:(NSDictionary *)payload
143
+ {
144
+ // Android only — iOS relays VoIP pushes internally via SinchPushManager.
145
+ }
146
+
147
+ #pragma mark - SinchCallManagerDelegate
148
+
149
+ - (void)sinchCallManagerDidStartClient
150
+ {
151
+ [self emitOnClientStarted];
152
+ }
153
+
154
+ - (void)sinchCallManagerDidFailWithMessage:(NSString *)message code:(NSInteger)code
155
+ {
156
+ [self emitOnClientStartFailed:@{ @"message" : message, @"code" : @(code) }];
157
+ }
158
+
159
+ - (void)sinchCallManagerRequiresRegistrationCredentials
160
+ {
161
+ [self emitOnRegistrationCredentialsRequired];
162
+ }
163
+
164
+ - (void)sinchCallManagerDidReceiveIncomingCall:(NSString *)callId remoteUserId:(NSString *)remoteUserId
165
+ {
166
+ [_callKitManager reportIncomingCall:callId remoteUserId:remoteUserId];
167
+ [self emitOnIncomingCall:@{ @"callId" : callId, @"remoteUserId" : remoteUserId }];
168
+ }
169
+
170
+ - (void)sinchCallManagerCallDidProgress:(NSString *)callId
171
+ {
172
+ [self emitOnCallProgressing:@{ @"callId" : callId }];
173
+ }
174
+
175
+ - (void)sinchCallManagerCallDidEstablish:(NSString *)callId
176
+ {
177
+ [self emitOnCallEstablished:@{ @"callId" : callId }];
178
+ }
179
+
180
+ - (void)sinchCallManagerCallDidEnd:(NSString *)callId endCause:(NSString *)endCause
181
+ {
182
+ [_callKitManager reportCallEnded:callId];
183
+ [self emitOnCallEnded:@{ @"callId" : callId, @"endCause" : endCause }];
184
+ }
185
+
186
+ #pragma mark - SinchCallKitManagerDelegate
187
+
188
+ - (void)sinchCallKitManagerDidAnswerCall:(NSString *)callId
189
+ {
190
+ [_callManager answerCall:callId];
191
+ }
192
+
193
+ - (void)sinchCallKitManagerDidEndCall:(NSString *)callId
194
+ {
195
+ [_callManager hangupCall:callId];
196
+ }
197
+
198
+ - (void)sinchCallKitManagerDidAnswerExternalCall:(NSString *)callId
199
+ {
200
+ [self emitOnCallUIAnswered:@{ @"callId" : callId }];
201
+ }
202
+
203
+ - (void)sinchCallKitManagerDidDeclineExternalCall:(NSString *)callId
204
+ {
205
+ [self emitOnCallUIDeclined:@{ @"callId" : callId }];
206
+ }
207
+
208
+ - (void)sinchCallKitManagerDidActivateAudioSession:(AVAudioSession *)audioSession
209
+ {
210
+ [_callManager didActivateAudioSession:audioSession];
211
+ }
212
+
213
+ - (void)sinchCallKitManagerDidDeactivateAudioSession:(AVAudioSession *)audioSession
214
+ {
215
+ [_callManager didDeactivateAudioSession:audioSession];
216
+ }
217
+
218
+ #pragma mark - SinchPushManagerDelegate
219
+
220
+ - (void)sinchPushManagerDidUpdateToken:(NSString *)tokenHex
221
+ {
222
+ [self emitOnVoipPushTokenUpdated:@{ @"token" : tokenHex }];
223
+ }
224
+
225
+ - (void)sinchPushManagerDidDetectCustomIncomingCall:(NSString *)callId displayName:(NSString *)displayName
226
+ {
227
+ [_callKitManager reportExternalIncomingCall:callId displayName:displayName];
228
+ [self emitOnIncomingCallUIShown:@{ @"callId" : callId, @"displayName" : displayName }];
229
+ }
230
+
231
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
232
+ (const facebook::react::ObjCTurboModule::InitParams &)params
233
+ {
234
+ return std::make_shared<facebook::react::NativeSinchCallingSpecJSI>(params);
235
+ }
236
+
237
+ + (NSString *)moduleName
238
+ {
239
+ return @"SinchCalling";
240
+ }
241
+
242
+ @end
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('SinchCalling');
5
+ //# sourceMappingURL=NativeSinchCalling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSinchCalling.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAmJpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,cAAc,CAAC","ignoreList":[]}