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

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 (55) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +469 -483
  3. package/ios/CallKitBridge.swift +2 -7
  4. package/lib/callkit/callkit-coordinator.d.ts +110 -117
  5. package/lib/callkit/callkit-coordinator.js +664 -727
  6. package/lib/callkit/callkit.d.ts +41 -41
  7. package/lib/callkit/callkit.js +252 -242
  8. package/lib/callkit/index.js +15 -47
  9. package/lib/callkit/use-callkit.d.ts +19 -19
  10. package/lib/callkit/use-callkit.js +270 -310
  11. package/lib/context/TelnyxVoiceContext.d.ts +9 -9
  12. package/lib/context/TelnyxVoiceContext.js +10 -13
  13. package/lib/hooks/use-callkit-coordinator.d.ts +9 -17
  14. package/lib/hooks/use-callkit-coordinator.js +45 -50
  15. package/lib/hooks/useAppReadyNotifier.js +13 -15
  16. package/lib/hooks/useAppStateHandler.d.ts +6 -11
  17. package/lib/hooks/useAppStateHandler.js +95 -110
  18. package/lib/hooks/useNetworkStateHandler.d.ts +0 -0
  19. package/lib/hooks/useNetworkStateHandler.js +0 -0
  20. package/lib/index.d.ts +3 -21
  21. package/lib/index.js +50 -201
  22. package/lib/internal/CallKitHandler.d.ts +6 -6
  23. package/lib/internal/CallKitHandler.js +96 -104
  24. package/lib/internal/callkit-manager.d.ts +57 -57
  25. package/lib/internal/callkit-manager.js +299 -316
  26. package/lib/internal/calls/call-state-controller.d.ts +73 -86
  27. package/lib/internal/calls/call-state-controller.js +263 -307
  28. package/lib/internal/session/session-manager.d.ts +71 -75
  29. package/lib/internal/session/session-manager.js +360 -424
  30. package/lib/internal/user-defaults-helpers.js +49 -39
  31. package/lib/internal/voice-pn-bridge.d.ts +114 -12
  32. package/lib/internal/voice-pn-bridge.js +212 -5
  33. package/lib/models/call-state.d.ts +46 -44
  34. package/lib/models/call-state.js +70 -68
  35. package/lib/models/call.d.ts +161 -133
  36. package/lib/models/call.js +454 -382
  37. package/lib/models/config.d.ts +11 -18
  38. package/lib/models/config.js +37 -35
  39. package/lib/models/connection-state.d.ts +10 -10
  40. package/lib/models/connection-state.js +16 -16
  41. package/lib/telnyx-voice-app.d.ts +28 -28
  42. package/lib/telnyx-voice-app.js +513 -480
  43. package/lib/telnyx-voip-client.d.ts +167 -167
  44. package/lib/telnyx-voip-client.js +385 -390
  45. package/package.json +115 -104
  46. package/src/callkit/callkit-coordinator.ts +830 -846
  47. package/src/hooks/useNetworkStateHandler.ts +0 -0
  48. package/src/internal/calls/call-state-controller.ts +407 -384
  49. package/src/internal/session/session-manager.ts +483 -467
  50. package/src/internal/voice-pn-bridge.ts +266 -18
  51. package/src/models/call-state.ts +105 -98
  52. package/src/models/call.ts +502 -388
  53. package/src/telnyx-voice-app.tsx +788 -690
  54. package/src/telnyx-voip-client.ts +551 -539
  55. package/src/types/telnyx-sdk.d.ts +93 -79
@@ -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,166 +23,168 @@ 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
- * 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;
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 callerName Optional caller name to display
121
+ * @param callerNumber Optional caller ID number
122
+ * @param customHeaders Optional custom headers to include with the call
123
+ * @returns A Promise that completes with the Call object once the invitation has been sent
124
+ *
125
+ * The call's state can be monitored through the returned Call object's streams.
126
+ */
127
+ newCall(destination: string, callerName?: string, callerNumber?: string, customHeaders?: Record<string, string>): Promise<Call>;
128
+ /**
129
+ * Handle push notification payload.
130
+ *
131
+ * This is the unified entry point for all push notifications. It intelligently
132
+ * determines whether to show a new incoming call UI or to process an already
133
+ * actioned (accepted/declined) call upon app launch.
134
+ *
135
+ * @param payload The push notification payload
136
+ */
137
+ handlePushNotification(payload: Record<string, any>): Promise<void>;
138
+ /**
139
+ * Disables push notifications for the current session.
140
+ *
141
+ * This method sends a request to the Telnyx backend to disable push
142
+ * notifications for the current registered device/session.
143
+ */
144
+ disablePushNotifications(): void;
145
+ /**
146
+ * Set a call to connecting state (used for push notification calls when answered via CallKit)
147
+ * @param callId The ID of the call to set to connecting state
148
+ * @internal
149
+ */
150
+ setCallConnecting(callId: string): void;
151
+ /**
152
+ * Find a call by its underlying Telnyx call object
153
+ * @param telnyxCall The Telnyx call object to find
154
+ * @internal
155
+ */
156
+ findCallByTelnyxCall(telnyxCall: any): Call | null;
157
+ /**
158
+ * Queue an answer action for when the call invite arrives (for CallKit integration)
159
+ * This should be called when the user answers from CallKit before the socket connection is established
160
+ * @param customHeaders Optional custom headers to include with the answer
161
+ */
162
+ queueAnswerFromCallKit(customHeaders?: Record<string, string>): void;
163
+ /**
164
+ * Queue an end action for when the call invite arrives (for CallKit integration)
165
+ * This should be called when the user ends from CallKit before the socket connection is established
166
+ */
167
+ queueEndFromCallKit(): void;
168
+ /**
169
+ * Dispose of the client and clean up all resources.
170
+ *
171
+ * After calling this method, the client instance should not be used anymore.
172
+ * This is particularly important for background clients that should be
173
+ * disposed after handling push notifications.
174
+ */
175
+ dispose(): void;
176
+ /**
177
+ * Store credential configuration for automatic reconnection
178
+ */
179
+ private _storeCredentials;
180
+ /**
181
+ * Store token configuration for automatic reconnection
182
+ */
183
+ private _storeToken;
184
+ /**
185
+ * Throw an error if the client has been disposed
186
+ */
187
+ private _throwIfDisposed;
186
188
  }
187
189
  /**
188
190
  * Create a new TelnyxVoipClient instance for normal app usage
@@ -191,6 +193,4 @@ export declare function createTelnyxVoipClient(options?: TelnyxVoipClientOptions
191
193
  /**
192
194
  * Create a new TelnyxVoipClient instance for background push notification handling
193
195
  */
194
- export declare function createBackgroundTelnyxVoipClient(
195
- options?: TelnyxVoipClientOptions
196
- ): TelnyxVoipClient;
196
+ export declare function createBackgroundTelnyxVoipClient(options?: TelnyxVoipClientOptions): TelnyxVoipClient;