@telnyx/react-voice-commons-sdk 0.1.0 → 0.1.2

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 (47) hide show
  1. package/README.md +483 -0
  2. package/TelnyxVoiceCommons.podspec +31 -31
  3. package/ios/CallKitBridge.m +43 -43
  4. package/ios/CallKitBridge.swift +879 -879
  5. package/ios/VoicePnBridge.m +30 -30
  6. package/ios/VoicePnBridge.swift +86 -86
  7. package/lib/callkit/callkit-coordinator.d.ts +117 -113
  8. package/lib/callkit/callkit-coordinator.js +727 -681
  9. package/lib/callkit/callkit.d.ts +41 -41
  10. package/lib/callkit/callkit.js +242 -252
  11. package/lib/callkit/index.js +47 -15
  12. package/lib/callkit/use-callkit.d.ts +19 -19
  13. package/lib/callkit/use-callkit.js +310 -270
  14. package/lib/context/TelnyxVoiceContext.d.ts +9 -9
  15. package/lib/context/TelnyxVoiceContext.js +13 -10
  16. package/lib/hooks/use-callkit-coordinator.d.ts +17 -9
  17. package/lib/hooks/use-callkit-coordinator.js +50 -45
  18. package/lib/hooks/useAppReadyNotifier.js +15 -13
  19. package/lib/hooks/useAppStateHandler.d.ts +11 -6
  20. package/lib/hooks/useAppStateHandler.js +110 -95
  21. package/lib/index.d.ts +21 -3
  22. package/lib/index.js +201 -50
  23. package/lib/internal/CallKitHandler.d.ts +6 -6
  24. package/lib/internal/CallKitHandler.js +104 -96
  25. package/lib/internal/callkit-manager.d.ts +57 -57
  26. package/lib/internal/callkit-manager.js +316 -299
  27. package/lib/internal/calls/call-state-controller.d.ts +86 -81
  28. package/lib/internal/calls/call-state-controller.js +307 -269
  29. package/lib/internal/session/session-manager.d.ts +75 -75
  30. package/lib/internal/session/session-manager.js +424 -350
  31. package/lib/internal/user-defaults-helpers.js +39 -49
  32. package/lib/internal/voice-pn-bridge.d.ts +11 -11
  33. package/lib/internal/voice-pn-bridge.js +3 -3
  34. package/lib/models/call-state.d.ts +44 -44
  35. package/lib/models/call-state.js +68 -66
  36. package/lib/models/call.d.ts +133 -133
  37. package/lib/models/call.js +382 -354
  38. package/lib/models/config.d.ts +18 -11
  39. package/lib/models/config.js +35 -37
  40. package/lib/models/connection-state.d.ts +10 -10
  41. package/lib/models/connection-state.js +16 -16
  42. package/lib/telnyx-voice-app.d.ts +28 -28
  43. package/lib/telnyx-voice-app.js +482 -424
  44. package/lib/telnyx-voip-client.d.ts +167 -155
  45. package/lib/telnyx-voip-client.js +392 -331
  46. package/package.json +1 -1
  47. package/src/telnyx-voip-client.ts +64 -0
@@ -6,10 +6,10 @@ import { CredentialConfig, TokenConfig } from './models/config';
6
6
  * Configuration options for TelnyxVoipClient
7
7
  */
8
8
  export interface TelnyxVoipClientOptions {
9
- /** Enable automatic app state management (background/foreground behavior) - default: true */
10
- enableAppStateManagement?: boolean;
11
- /** Enable debug logging */
12
- debug?: boolean;
9
+ /** Enable automatic app state management (background/foreground behavior) - default: true */
10
+ enableAppStateManagement?: boolean;
11
+ /** Enable debug logging */
12
+ debug?: boolean;
13
13
  }
14
14
  /**
15
15
  * The main public interface for the react-voice-commons module.
@@ -23,156 +23,166 @@ export interface TelnyxVoipClientOptions {
23
23
  * into their chosen state management solution naturally.
24
24
  */
25
25
  export declare class TelnyxVoipClient {
26
- private readonly _sessionManager;
27
- private readonly _callStateController;
28
- private readonly _options;
29
- private _disposed;
30
- /**
31
- * Creates a new TelnyxVoipClient instance.
32
- *
33
- * @param options Configuration options for the client
34
- */
35
- constructor(options?: TelnyxVoipClientOptions);
36
- /**
37
- * Stream of connection state changes.
38
- *
39
- * Emits the current status of the connection to the Telnyx backend.
40
- * Values include connecting, connected, disconnected, and error states.
41
- * Listen to this to show connection indicators in your UI.
42
- */
43
- get connectionState$(): Observable<TelnyxConnectionState>;
44
- /**
45
- * Stream of all current calls.
46
- *
47
- * Emits a list of all current Call objects. Use this for applications
48
- * that need to support multiple simultaneous calls (e.g., call waiting,
49
- * conference calls).
50
- */
51
- get calls$(): Observable<Call[]>;
52
- /**
53
- * Stream of the currently active call.
54
- *
55
- * A convenience stream that emits the currently active Call object.
56
- * It emits null when no call is in progress. Ideal for applications
57
- * that only handle a single call at a time.
58
- */
59
- get activeCall$(): Observable<Call | null>;
60
- /**
61
- * Current connection state (synchronous access).
62
- */
63
- get currentConnectionState(): TelnyxConnectionState;
64
- /**
65
- * Current list of calls (synchronous access).
66
- */
67
- get currentCalls(): Call[];
68
- /**
69
- * Current active call (synchronous access).
70
- */
71
- get currentActiveCall(): Call | null;
72
- /**
73
- * Current session ID (UUID) for this connection.
74
- */
75
- get sessionId(): string;
76
- /**
77
- * Configuration options for this client instance.
78
- */
79
- get options(): Required<TelnyxVoipClientOptions>;
80
- /**
81
- * Connects to the Telnyx platform using credential authentication.
82
- *
83
- * @param config The credential configuration containing SIP username and password
84
- * @returns A Promise that completes when the connection attempt is initiated
85
- *
86
- * Listen to connectionState$ to monitor the actual connection status.
87
- */
88
- login(config: CredentialConfig): Promise<void>;
89
- /**
90
- * Connects to the Telnyx platform using token authentication.
91
- *
92
- * @param config The token configuration containing the authentication token
93
- * @returns A Promise that completes when the connection attempt is initiated
94
- *
95
- * Listen to connectionState$ to monitor the actual connection status.
96
- */
97
- loginWithToken(config: TokenConfig): Promise<void>;
98
- /**
99
- * Disconnects from the Telnyx platform.
100
- *
101
- * This method terminates the connection, ends any active calls, and
102
- * cleans up all related resources.
103
- */
104
- logout(): Promise<void>;
105
- /**
106
- * Attempts to reconnect using previously stored configuration.
107
- *
108
- * This method is used for auto-reconnection scenarios where the app
109
- * comes back to the foreground and needs to restore the connection.
110
- *
111
- * @returns Promise<boolean> - true if reconnection was successful, false otherwise
112
- */
113
- loginFromStoredConfig(): Promise<boolean>;
114
- /**
115
- * Initiates a new outgoing call.
116
- *
117
- * @param destination The destination number or SIP URI to call
118
- * @param debug Optional flag to enable call quality metrics for this call
119
- * @returns A Promise that completes with the Call object once the invitation has been sent
120
- *
121
- * The call's state can be monitored through the returned Call object's streams.
122
- */
123
- newCall(destination: string, debug?: boolean): Promise<Call>;
124
- /**
125
- * Handle push notification payload.
126
- *
127
- * This is the unified entry point for all push notifications. It intelligently
128
- * determines whether to show a new incoming call UI or to process an already
129
- * actioned (accepted/declined) call upon app launch.
130
- *
131
- * @param payload The push notification payload
132
- */
133
- handlePushNotification(payload: Record<string, any>): Promise<void>;
134
- /**
135
- * Disables push notifications for the current session.
136
- *
137
- * This method sends a request to the Telnyx backend to disable push
138
- * notifications for the current registered device/session.
139
- */
140
- disablePushNotifications(): void;
141
- /**
142
- * Set a call to connecting state (used for push notification calls when answered via CallKit)
143
- * @param callId The ID of the call to set to connecting state
144
- * @internal
145
- */
146
- setCallConnecting(callId: string): void;
147
- /**
148
- * Find a call by its underlying Telnyx call object
149
- * @param telnyxCall The Telnyx call object to find
150
- * @internal
151
- */
152
- findCallByTelnyxCall(telnyxCall: any): Call | null;
153
- /**
154
- * Queue an answer action for when the call invite arrives (for CallKit integration)
155
- * This should be called when the user answers from CallKit before the socket connection is established
156
- * @param customHeaders Optional custom headers to include with the answer
157
- */
158
- queueAnswerFromCallKit(customHeaders?: Record<string, string>): void;
159
- /**
160
- * Queue an end action for when the call invite arrives (for CallKit integration)
161
- * This should be called when the user ends from CallKit before the socket connection is established
162
- */
163
- queueEndFromCallKit(): void;
164
- /**
165
- * Dispose of the client and clean up all resources.
166
- *
167
- * After calling this method, the client instance should not be used anymore.
168
- * This is particularly important for background clients that should be
169
- * disposed after handling push notifications.
170
- */
171
- dispose(): void;
172
- /**
173
- * Throw an error if the client has been disposed
174
- */
175
- private _throwIfDisposed;
26
+ private readonly _sessionManager;
27
+ private readonly _callStateController;
28
+ private readonly _options;
29
+ private _disposed;
30
+ /**
31
+ * Creates a new TelnyxVoipClient instance.
32
+ *
33
+ * @param options Configuration options for the client
34
+ */
35
+ constructor(options?: TelnyxVoipClientOptions);
36
+ /**
37
+ * Stream of connection state changes.
38
+ *
39
+ * Emits the current status of the connection to the Telnyx backend.
40
+ * Values include connecting, connected, disconnected, and error states.
41
+ * Listen to this to show connection indicators in your UI.
42
+ */
43
+ get connectionState$(): Observable<TelnyxConnectionState>;
44
+ /**
45
+ * Stream of all current calls.
46
+ *
47
+ * Emits a list of all current Call objects. Use this for applications
48
+ * that need to support multiple simultaneous calls (e.g., call waiting,
49
+ * conference calls).
50
+ */
51
+ get calls$(): Observable<Call[]>;
52
+ /**
53
+ * Stream of the currently active call.
54
+ *
55
+ * A convenience stream that emits the currently active Call object.
56
+ * It emits null when no call is in progress. Ideal for applications
57
+ * that only handle a single call at a time.
58
+ */
59
+ get activeCall$(): Observable<Call | null>;
60
+ /**
61
+ * Current connection state (synchronous access).
62
+ */
63
+ get currentConnectionState(): TelnyxConnectionState;
64
+ /**
65
+ * Current list of calls (synchronous access).
66
+ */
67
+ get currentCalls(): Call[];
68
+ /**
69
+ * Current active call (synchronous access).
70
+ */
71
+ get currentActiveCall(): Call | null;
72
+ /**
73
+ * Current session ID (UUID) for this connection.
74
+ */
75
+ get sessionId(): string;
76
+ /**
77
+ * Configuration options for this client instance.
78
+ */
79
+ get options(): Required<TelnyxVoipClientOptions>;
80
+ /**
81
+ * Connects to the Telnyx platform using credential authentication.
82
+ *
83
+ * @param config The credential configuration containing SIP username and password
84
+ * @returns A Promise that completes when the connection attempt is initiated
85
+ *
86
+ * Listen to connectionState$ to monitor the actual connection status.
87
+ * Credentials are automatically stored for future reconnection.
88
+ */
89
+ login(config: CredentialConfig): Promise<void>;
90
+ /**
91
+ * Connects to the Telnyx platform using token authentication.
92
+ *
93
+ * @param config The token configuration containing the authentication token
94
+ * @returns A Promise that completes when the connection attempt is initiated
95
+ *
96
+ * Listen to connectionState$ to monitor the actual connection status.
97
+ * Token is automatically stored for future reconnection.
98
+ */
99
+ loginWithToken(config: TokenConfig): Promise<void>;
100
+ /**
101
+ * Disconnects from the Telnyx platform.
102
+ *
103
+ * This method terminates the connection, ends any active calls, and
104
+ * cleans up all related resources.
105
+ */
106
+ logout(): Promise<void>;
107
+ /**
108
+ * Attempts to reconnect using previously stored configuration.
109
+ *
110
+ * This method is used for auto-reconnection scenarios where the app
111
+ * comes back to the foreground and needs to restore the connection.
112
+ *
113
+ * @returns Promise<boolean> - true if reconnection was successful, false otherwise
114
+ */
115
+ loginFromStoredConfig(): Promise<boolean>;
116
+ /**
117
+ * Initiates a new outgoing call.
118
+ *
119
+ * @param destination The destination number or SIP URI to call
120
+ * @param debug Optional flag to enable call quality metrics for this call
121
+ * @returns A Promise that completes with the Call object once the invitation has been sent
122
+ *
123
+ * The call's state can be monitored through the returned Call object's streams.
124
+ */
125
+ newCall(destination: string, debug?: boolean): Promise<Call>;
126
+ /**
127
+ * Handle push notification payload.
128
+ *
129
+ * This is the unified entry point for all push notifications. It intelligently
130
+ * determines whether to show a new incoming call UI or to process an already
131
+ * actioned (accepted/declined) call upon app launch.
132
+ *
133
+ * @param payload The push notification payload
134
+ */
135
+ handlePushNotification(payload: Record<string, any>): Promise<void>;
136
+ /**
137
+ * Disables push notifications for the current session.
138
+ *
139
+ * This method sends a request to the Telnyx backend to disable push
140
+ * notifications for the current registered device/session.
141
+ */
142
+ disablePushNotifications(): void;
143
+ /**
144
+ * Set a call to connecting state (used for push notification calls when answered via CallKit)
145
+ * @param callId The ID of the call to set to connecting state
146
+ * @internal
147
+ */
148
+ setCallConnecting(callId: string): void;
149
+ /**
150
+ * Find a call by its underlying Telnyx call object
151
+ * @param telnyxCall The Telnyx call object to find
152
+ * @internal
153
+ */
154
+ findCallByTelnyxCall(telnyxCall: any): Call | null;
155
+ /**
156
+ * Queue an answer action for when the call invite arrives (for CallKit integration)
157
+ * This should be called when the user answers from CallKit before the socket connection is established
158
+ * @param customHeaders Optional custom headers to include with the answer
159
+ */
160
+ queueAnswerFromCallKit(customHeaders?: Record<string, string>): void;
161
+ /**
162
+ * Queue an end action for when the call invite arrives (for CallKit integration)
163
+ * This should be called when the user ends from CallKit before the socket connection is established
164
+ */
165
+ queueEndFromCallKit(): void;
166
+ /**
167
+ * Dispose of the client and clean up all resources.
168
+ *
169
+ * After calling this method, the client instance should not be used anymore.
170
+ * This is particularly important for background clients that should be
171
+ * disposed after handling push notifications.
172
+ */
173
+ dispose(): void;
174
+ /**
175
+ * Store credential configuration for automatic reconnection
176
+ */
177
+ private _storeCredentials;
178
+ /**
179
+ * Store token configuration for automatic reconnection
180
+ */
181
+ private _storeToken;
182
+ /**
183
+ * Throw an error if the client has been disposed
184
+ */
185
+ private _throwIfDisposed;
176
186
  }
177
187
  /**
178
188
  * Create a new TelnyxVoipClient instance for normal app usage
@@ -181,4 +191,6 @@ export declare function createTelnyxVoipClient(options?: TelnyxVoipClientOptions
181
191
  /**
182
192
  * Create a new TelnyxVoipClient instance for background push notification handling
183
193
  */
184
- export declare function createBackgroundTelnyxVoipClient(options?: TelnyxVoipClientOptions): TelnyxVoipClient;
194
+ export declare function createBackgroundTelnyxVoipClient(
195
+ options?: TelnyxVoipClientOptions
196
+ ): TelnyxVoipClient;