@telnyx/react-voice-commons-sdk 0.1.4 → 0.1.5

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 (56) hide show
  1. package/CHANGELOG.md +19 -16
  2. package/README.md +469 -469
  3. package/TelnyxVoiceCommons.podspec +31 -31
  4. package/ios/CallKitBridge.m +43 -43
  5. package/ios/CallKitBridge.swift +874 -874
  6. package/ios/VoicePnBridge.m +30 -30
  7. package/ios/VoicePnBridge.swift +86 -86
  8. package/lib/callkit/callkit-coordinator.d.ts +114 -110
  9. package/lib/callkit/callkit-coordinator.js +706 -664
  10. package/lib/callkit/callkit.d.ts +41 -41
  11. package/lib/callkit/callkit.js +242 -252
  12. package/lib/callkit/index.js +47 -15
  13. package/lib/callkit/use-callkit.d.ts +19 -19
  14. package/lib/callkit/use-callkit.js +310 -270
  15. package/lib/context/TelnyxVoiceContext.d.ts +9 -9
  16. package/lib/context/TelnyxVoiceContext.js +13 -10
  17. package/lib/hooks/use-callkit-coordinator.d.ts +17 -9
  18. package/lib/hooks/use-callkit-coordinator.js +50 -45
  19. package/lib/hooks/useAppReadyNotifier.js +15 -13
  20. package/lib/hooks/useAppStateHandler.d.ts +11 -6
  21. package/lib/hooks/useAppStateHandler.js +110 -95
  22. package/lib/index.d.ts +21 -3
  23. package/lib/index.js +201 -50
  24. package/lib/internal/CallKitHandler.d.ts +6 -6
  25. package/lib/internal/CallKitHandler.js +104 -96
  26. package/lib/internal/callkit-manager.d.ts +57 -57
  27. package/lib/internal/callkit-manager.js +316 -299
  28. package/lib/internal/calls/call-state-controller.d.ts +78 -73
  29. package/lib/internal/calls/call-state-controller.js +326 -265
  30. package/lib/internal/session/session-manager.d.ts +71 -71
  31. package/lib/internal/session/session-manager.js +437 -360
  32. package/lib/internal/user-defaults-helpers.js +39 -49
  33. package/lib/internal/voice-pn-bridge.d.ts +112 -104
  34. package/lib/internal/voice-pn-bridge.js +193 -203
  35. package/lib/models/call-state.d.ts +46 -46
  36. package/lib/models/call-state.js +74 -70
  37. package/lib/models/call.d.ts +173 -157
  38. package/lib/models/call.js +492 -448
  39. package/lib/models/config.d.ts +18 -11
  40. package/lib/models/config.js +35 -37
  41. package/lib/models/connection-state.d.ts +10 -10
  42. package/lib/models/connection-state.js +16 -16
  43. package/lib/telnyx-voice-app.d.ts +28 -28
  44. package/lib/telnyx-voice-app.js +561 -509
  45. package/lib/telnyx-voip-client.d.ts +174 -167
  46. package/lib/telnyx-voip-client.js +397 -385
  47. package/package.json +115 -115
  48. package/src/callkit/callkit-coordinator.ts +830 -830
  49. package/src/internal/calls/call-state-controller.ts +407 -407
  50. package/src/internal/session/session-manager.ts +483 -483
  51. package/src/internal/voice-pn-bridge.ts +266 -266
  52. package/src/models/call-state.ts +105 -105
  53. package/src/models/call.ts +502 -502
  54. package/src/telnyx-voice-app.tsx +787 -788
  55. package/src/telnyx-voip-client.ts +551 -551
  56. package/src/types/telnyx-sdk.d.ts +93 -93
@@ -1,31 +1,31 @@
1
- #import <React/RCTBridgeModule.h>
2
-
3
- @interface RCT_EXTERN_MODULE(VoicePnBridge, NSObject)
4
-
5
- RCT_EXTERN_METHOD(getPendingPushAction:(RCTPromiseResolveBlock)resolve
6
- rejecter:(RCTPromiseRejectBlock)reject)
7
-
8
- RCT_EXTERN_METHOD(setPendingPushAction:(NSString *)action
9
- metadata:(NSString *)metadata
10
- resolver:(RCTPromiseResolveBlock)resolve
11
- rejecter:(RCTPromiseRejectBlock)reject)
12
-
13
- RCT_EXTERN_METHOD(clearPendingPushAction:(RCTPromiseResolveBlock)resolve
14
- rejecter:(RCTPromiseRejectBlock)reject)
15
-
16
- RCT_EXTERN_METHOD(getVoipToken:(RCTPromiseResolveBlock)resolve
17
- rejecter:(RCTPromiseRejectBlock)reject)
18
-
19
- RCT_EXTERN_METHOD(getPendingVoipPush:(RCTPromiseResolveBlock)resolve
20
- rejecter:(RCTPromiseRejectBlock)reject)
21
-
22
- RCT_EXTERN_METHOD(clearPendingVoipPush:(RCTPromiseResolveBlock)resolve
23
- rejecter:(RCTPromiseRejectBlock)reject)
24
-
25
- RCT_EXTERN_METHOD(getPendingVoipAction:(RCTPromiseResolveBlock)resolve
26
- rejecter:(RCTPromiseRejectBlock)reject)
27
-
28
- RCT_EXTERN_METHOD(clearPendingVoipAction:(RCTPromiseResolveBlock)resolve
29
- rejecter:(RCTPromiseRejectBlock)reject)
30
-
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(VoicePnBridge, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(getPendingPushAction:(RCTPromiseResolveBlock)resolve
6
+ rejecter:(RCTPromiseRejectBlock)reject)
7
+
8
+ RCT_EXTERN_METHOD(setPendingPushAction:(NSString *)action
9
+ metadata:(NSString *)metadata
10
+ resolver:(RCTPromiseResolveBlock)resolve
11
+ rejecter:(RCTPromiseRejectBlock)reject)
12
+
13
+ RCT_EXTERN_METHOD(clearPendingPushAction:(RCTPromiseResolveBlock)resolve
14
+ rejecter:(RCTPromiseRejectBlock)reject)
15
+
16
+ RCT_EXTERN_METHOD(getVoipToken:(RCTPromiseResolveBlock)resolve
17
+ rejecter:(RCTPromiseRejectBlock)reject)
18
+
19
+ RCT_EXTERN_METHOD(getPendingVoipPush:(RCTPromiseResolveBlock)resolve
20
+ rejecter:(RCTPromiseRejectBlock)reject)
21
+
22
+ RCT_EXTERN_METHOD(clearPendingVoipPush:(RCTPromiseResolveBlock)resolve
23
+ rejecter:(RCTPromiseRejectBlock)reject)
24
+
25
+ RCT_EXTERN_METHOD(getPendingVoipAction:(RCTPromiseResolveBlock)resolve
26
+ rejecter:(RCTPromiseRejectBlock)reject)
27
+
28
+ RCT_EXTERN_METHOD(clearPendingVoipAction:(RCTPromiseResolveBlock)resolve
29
+ rejecter:(RCTPromiseRejectBlock)reject)
30
+
31
31
  @end
@@ -1,87 +1,87 @@
1
- import Foundation
2
- import React
3
-
4
- @objc(VoicePnBridge)
5
- class VoicePnBridge: NSObject {
6
-
7
- @objc
8
- static func requiresMainQueueSetup() -> Bool {
9
- return false
10
- }
11
-
12
- // MARK: - UserDefaults-based methods for VoIP push handling
13
-
14
- @objc
15
- func getPendingPushAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
16
- let action = UserDefaults.standard.string(forKey: "pending_push_action")
17
- let metadata = UserDefaults.standard.string(forKey: "pending_push_metadata")
18
-
19
- NSLog("[VoicePnBridge] getPendingPushAction - action: \(action ?? "nil"), metadata: \(metadata ?? "nil")")
20
-
21
- let result: [String: Any?] = [
22
- "action": action,
23
- "metadata": metadata
24
- ]
25
-
26
- resolve(result)
27
- }
28
-
29
- @objc
30
- func setPendingPushAction(_ action: String, metadata: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
31
- UserDefaults.standard.set(action, forKey: "pending_push_action")
32
- UserDefaults.standard.set(metadata, forKey: "pending_push_metadata")
33
- UserDefaults.standard.synchronize()
34
-
35
- NSLog("[VoicePnBridge] setPendingPushAction - action: \(action), metadata: \(metadata)")
36
- resolve(true)
37
- }
38
-
39
- @objc
40
- func clearPendingPushAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
41
- UserDefaults.standard.removeObject(forKey: "pending_push_action")
42
- UserDefaults.standard.removeObject(forKey: "pending_push_metadata")
43
- UserDefaults.standard.synchronize()
44
-
45
- NSLog("[VoicePnBridge] clearPendingPushAction - cleared pending push data")
46
- resolve(true)
47
- }
48
-
49
- // MARK: - Additional UserDefaults methods from UserDefaultsModule
50
-
51
- @objc
52
- func getVoipToken(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
53
- let token = UserDefaults.standard.string(forKey: "voip_push_token")
54
- NSLog("[VoicePnBridge] getVoipToken called. token=\(token ?? "(nil)")")
55
- resolve(token)
56
- }
57
-
58
- @objc
59
- func getPendingVoipPush(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
60
- let pending = UserDefaults.standard.string(forKey: "pending_voip_push")
61
- NSLog("[VoicePnBridge] getPendingVoipPush called. pending=\(pending ?? "(nil)")")
62
- resolve(pending)
63
- }
64
-
65
- @objc
66
- func clearPendingVoipPush(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
67
- UserDefaults.standard.removeObject(forKey: "pending_voip_push")
68
- UserDefaults.standard.synchronize()
69
- NSLog("[VoicePnBridge] clearPendingVoipPush called. Cleared key pending_voip_push")
70
- resolve(true)
71
- }
72
-
73
- @objc
74
- func getPendingVoipAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
75
- let pending = UserDefaults.standard.string(forKey: "pending_voip_action")
76
- NSLog("[VoicePnBridge] getPendingVoipAction called. pending=\(pending ?? "(nil)")")
77
- resolve(pending)
78
- }
79
-
80
- @objc
81
- func clearPendingVoipAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
82
- UserDefaults.standard.removeObject(forKey: "pending_voip_action")
83
- UserDefaults.standard.synchronize()
84
- NSLog("[VoicePnBridge] clearPendingVoipAction called. Cleared key pending_voip_action")
85
- resolve(true)
86
- }
1
+ import Foundation
2
+ import React
3
+
4
+ @objc(VoicePnBridge)
5
+ class VoicePnBridge: NSObject {
6
+
7
+ @objc
8
+ static func requiresMainQueueSetup() -> Bool {
9
+ return false
10
+ }
11
+
12
+ // MARK: - UserDefaults-based methods for VoIP push handling
13
+
14
+ @objc
15
+ func getPendingPushAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
16
+ let action = UserDefaults.standard.string(forKey: "pending_push_action")
17
+ let metadata = UserDefaults.standard.string(forKey: "pending_push_metadata")
18
+
19
+ NSLog("[VoicePnBridge] getPendingPushAction - action: \(action ?? "nil"), metadata: \(metadata ?? "nil")")
20
+
21
+ let result: [String: Any?] = [
22
+ "action": action,
23
+ "metadata": metadata
24
+ ]
25
+
26
+ resolve(result)
27
+ }
28
+
29
+ @objc
30
+ func setPendingPushAction(_ action: String, metadata: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
31
+ UserDefaults.standard.set(action, forKey: "pending_push_action")
32
+ UserDefaults.standard.set(metadata, forKey: "pending_push_metadata")
33
+ UserDefaults.standard.synchronize()
34
+
35
+ NSLog("[VoicePnBridge] setPendingPushAction - action: \(action), metadata: \(metadata)")
36
+ resolve(true)
37
+ }
38
+
39
+ @objc
40
+ func clearPendingPushAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
41
+ UserDefaults.standard.removeObject(forKey: "pending_push_action")
42
+ UserDefaults.standard.removeObject(forKey: "pending_push_metadata")
43
+ UserDefaults.standard.synchronize()
44
+
45
+ NSLog("[VoicePnBridge] clearPendingPushAction - cleared pending push data")
46
+ resolve(true)
47
+ }
48
+
49
+ // MARK: - Additional UserDefaults methods from UserDefaultsModule
50
+
51
+ @objc
52
+ func getVoipToken(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
53
+ let token = UserDefaults.standard.string(forKey: "voip_push_token")
54
+ NSLog("[VoicePnBridge] getVoipToken called. token=\(token ?? "(nil)")")
55
+ resolve(token)
56
+ }
57
+
58
+ @objc
59
+ func getPendingVoipPush(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
60
+ let pending = UserDefaults.standard.string(forKey: "pending_voip_push")
61
+ NSLog("[VoicePnBridge] getPendingVoipPush called. pending=\(pending ?? "(nil)")")
62
+ resolve(pending)
63
+ }
64
+
65
+ @objc
66
+ func clearPendingVoipPush(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
67
+ UserDefaults.standard.removeObject(forKey: "pending_voip_push")
68
+ UserDefaults.standard.synchronize()
69
+ NSLog("[VoicePnBridge] clearPendingVoipPush called. Cleared key pending_voip_push")
70
+ resolve(true)
71
+ }
72
+
73
+ @objc
74
+ func getPendingVoipAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
75
+ let pending = UserDefaults.standard.string(forKey: "pending_voip_action")
76
+ NSLog("[VoicePnBridge] getPendingVoipAction called. pending=\(pending ?? "(nil)")")
77
+ resolve(pending)
78
+ }
79
+
80
+ @objc
81
+ func clearPendingVoipAction(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
82
+ UserDefaults.standard.removeObject(forKey: "pending_voip_action")
83
+ UserDefaults.standard.synchronize()
84
+ NSLog("[VoicePnBridge] clearPendingVoipAction called. Cleared key pending_voip_action")
85
+ resolve(true)
86
+ }
87
87
  }
@@ -8,116 +8,120 @@ import { TelnyxVoipClient } from '../telnyx-voip-client';
8
8
  * guidelines for proper CallKit integration.
9
9
  */
10
10
  declare class CallKitCoordinator {
11
- private static instance;
12
- private callMap;
13
- private processingCalls;
14
- private endedCalls;
15
- private connectedCalls;
16
- private isCallFromPush;
17
- private shouldAutoAnswerNextCall;
18
- private voipClient;
19
- static getInstance(): CallKitCoordinator;
20
- private constructor();
21
- private setupCallKitListeners;
22
- /**
23
- * Report an incoming call to CallKit (from push notification or socket)
24
- * For push notifications, the call is already reported - we just need to map it
25
- */
26
- reportIncomingCall(call: Call, callerName: string, callerNumber: string): Promise<string | null>;
27
- /**
28
- * Start an outgoing call through CallKit
29
- */
30
- startOutgoingCall(call: Call, destinationNumber: string, displayName?: string): Promise<string | null>;
31
- /**
32
- * Answer a call from the app UI (CallKit-first approach)
33
- */
34
- answerCallFromUI(call: Call): Promise<boolean>;
35
- /**
36
- * End a call from the app UI (CallKit-first approach)
37
- */
38
- endCallFromUI(call: Call): Promise<boolean>;
39
- /**
40
- * Handle CallKit answer action (triggered by CallKit)
41
- */
42
- handleCallKitAnswer(callKitUUID: string, event?: any): Promise<void>;
43
- /**
44
- * Handle CallKit end action (triggered by CallKit)
45
- */
46
- private handleCallKitEnd;
47
- /**
48
- * Handle CallKit start action (triggered by CallKit for outgoing calls)
49
- */
50
- private handleCallKitStart;
51
- /**
52
- * Handle CallKit push received event
53
- * This allows us to coordinate between the push notification and any subsequent WebRTC calls
54
- */
55
- handleCallKitPushReceived(callKitUUID: string, event?: any): Promise<void>;
56
- /**
57
- * Handle push notification answer - when user answers from CallKit but we don't have a WebRTC call yet
58
- * This is the iOS equivalent of the Android FCM handler
59
- */
60
- private handlePushNotificationAnswer;
61
- /**
62
- * Handle push notification reject - when user rejects from CallKit but we don't have a WebRTC call yet
63
- * This is the iOS equivalent of the Android FCM handler reject
64
- */
65
- private handlePushNotificationReject;
66
- /**
67
- * Set up listeners for WebRTC call state changes
68
- */
69
- private setupWebRTCCallListeners;
70
- /**
71
- * Clean up call mappings and listeners
72
- */
73
- private cleanupCall;
74
- /**
75
- * Get CallKit UUID for a WebRTC call
76
- */
77
- getCallKitUUID(call: Call): string | null;
78
- /**
79
- * Get WebRTC call for a CallKit UUID
80
- */
81
- getWebRTCCall(callKitUUID: string): Call | null;
82
- /**
83
- * Link an existing CallKit call (from push notification) with a WebRTC call
84
- * This should be called when a WebRTC call arrives that corresponds to an existing CallKit call
85
- */
86
- linkExistingCallKitCall(call: Call, callKitUUID: string): void;
87
- /**
88
- * Set the VoIP client reference for triggering reconnection
89
- */
90
- setVoipClient(voipClient: TelnyxVoipClient): void;
91
- /**
92
- * Helper method to clean up push notification state
93
- */
94
- private cleanupPushNotificationState;
95
- /**
96
- * Get reference to the SDK client (for queuing actions when call doesn't exist yet)
97
- */
98
- private getSDKClient;
99
- /**
100
- * Check if app is in background and disconnect client if no active calls
101
- */
102
- private checkBackgroundDisconnection;
103
- /**
104
- * Reset only flags (keeping active call mappings intact)
105
- */
106
- resetFlags(): void;
107
- /**
108
- * Check if there are any calls currently being processed by CallKit
109
- * This helps prevent premature flag resets during CallKit operations
110
- */
111
- hasProcessingCalls(): boolean;
112
- /**
113
- * Check if there's currently a call from push notification being processed
114
- * This helps prevent disconnection during push call handling
115
- */
116
- getIsCallFromPush(): boolean;
117
- /**
118
- * Check if CallKit is available and coordinator is active
119
- */
120
- isAvailable(): boolean;
11
+ private static instance;
12
+ private callMap;
13
+ private processingCalls;
14
+ private endedCalls;
15
+ private connectedCalls;
16
+ private isCallFromPush;
17
+ private shouldAutoAnswerNextCall;
18
+ private voipClient;
19
+ static getInstance(): CallKitCoordinator;
20
+ private constructor();
21
+ private setupCallKitListeners;
22
+ /**
23
+ * Report an incoming call to CallKit (from push notification or socket)
24
+ * For push notifications, the call is already reported - we just need to map it
25
+ */
26
+ reportIncomingCall(call: Call, callerName: string, callerNumber: string): Promise<string | null>;
27
+ /**
28
+ * Start an outgoing call through CallKit
29
+ */
30
+ startOutgoingCall(
31
+ call: Call,
32
+ destinationNumber: string,
33
+ displayName?: string
34
+ ): Promise<string | null>;
35
+ /**
36
+ * Answer a call from the app UI (CallKit-first approach)
37
+ */
38
+ answerCallFromUI(call: Call): Promise<boolean>;
39
+ /**
40
+ * End a call from the app UI (CallKit-first approach)
41
+ */
42
+ endCallFromUI(call: Call): Promise<boolean>;
43
+ /**
44
+ * Handle CallKit answer action (triggered by CallKit)
45
+ */
46
+ handleCallKitAnswer(callKitUUID: string, event?: any): Promise<void>;
47
+ /**
48
+ * Handle CallKit end action (triggered by CallKit)
49
+ */
50
+ private handleCallKitEnd;
51
+ /**
52
+ * Handle CallKit start action (triggered by CallKit for outgoing calls)
53
+ */
54
+ private handleCallKitStart;
55
+ /**
56
+ * Handle CallKit push received event
57
+ * This allows us to coordinate between the push notification and any subsequent WebRTC calls
58
+ */
59
+ handleCallKitPushReceived(callKitUUID: string, event?: any): Promise<void>;
60
+ /**
61
+ * Handle push notification answer - when user answers from CallKit but we don't have a WebRTC call yet
62
+ * This is the iOS equivalent of the Android FCM handler
63
+ */
64
+ private handlePushNotificationAnswer;
65
+ /**
66
+ * Handle push notification reject - when user rejects from CallKit but we don't have a WebRTC call yet
67
+ * This is the iOS equivalent of the Android FCM handler reject
68
+ */
69
+ private handlePushNotificationReject;
70
+ /**
71
+ * Set up listeners for WebRTC call state changes
72
+ */
73
+ private setupWebRTCCallListeners;
74
+ /**
75
+ * Clean up call mappings and listeners
76
+ */
77
+ private cleanupCall;
78
+ /**
79
+ * Get CallKit UUID for a WebRTC call
80
+ */
81
+ getCallKitUUID(call: Call): string | null;
82
+ /**
83
+ * Get WebRTC call for a CallKit UUID
84
+ */
85
+ getWebRTCCall(callKitUUID: string): Call | null;
86
+ /**
87
+ * Link an existing CallKit call (from push notification) with a WebRTC call
88
+ * This should be called when a WebRTC call arrives that corresponds to an existing CallKit call
89
+ */
90
+ linkExistingCallKitCall(call: Call, callKitUUID: string): void;
91
+ /**
92
+ * Set the VoIP client reference for triggering reconnection
93
+ */
94
+ setVoipClient(voipClient: TelnyxVoipClient): void;
95
+ /**
96
+ * Helper method to clean up push notification state
97
+ */
98
+ private cleanupPushNotificationState;
99
+ /**
100
+ * Get reference to the SDK client (for queuing actions when call doesn't exist yet)
101
+ */
102
+ private getSDKClient;
103
+ /**
104
+ * Check if app is in background and disconnect client if no active calls
105
+ */
106
+ private checkBackgroundDisconnection;
107
+ /**
108
+ * Reset only flags (keeping active call mappings intact)
109
+ */
110
+ resetFlags(): void;
111
+ /**
112
+ * Check if there are any calls currently being processed by CallKit
113
+ * This helps prevent premature flag resets during CallKit operations
114
+ */
115
+ hasProcessingCalls(): boolean;
116
+ /**
117
+ * Check if there's currently a call from push notification being processed
118
+ * This helps prevent disconnection during push call handling
119
+ */
120
+ getIsCallFromPush(): boolean;
121
+ /**
122
+ * Check if CallKit is available and coordinator is active
123
+ */
124
+ isAvailable(): boolean;
121
125
  }
122
126
  export declare const callKitCoordinator: CallKitCoordinator;
123
127
  export default callKitCoordinator;