@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
@@ -1,12 +1,12 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TelnyxVoipClient = void 0;
4
4
  exports.createTelnyxVoipClient = createTelnyxVoipClient;
5
5
  exports.createBackgroundTelnyxVoipClient = createBackgroundTelnyxVoipClient;
6
- const connection_state_1 = require('./models/connection-state');
7
- const config_1 = require('./models/config');
8
- const session_manager_1 = require('./internal/session/session-manager');
9
- const call_state_controller_1 = require('./internal/calls/call-state-controller');
6
+ const connection_state_1 = require("./models/connection-state");
7
+ const config_1 = require("./models/config");
8
+ const session_manager_1 = require("./internal/session/session-manager");
9
+ const call_state_controller_1 = require("./internal/calls/call-state-controller");
10
10
  /**
11
11
  * The main public interface for the react-voice-commons module.
12
12
  *
@@ -19,417 +19,412 @@ const call_state_controller_1 = require('./internal/calls/call-state-controller'
19
19
  * into their chosen state management solution naturally.
20
20
  */
21
21
  class TelnyxVoipClient {
22
- /**
23
- * Creates a new TelnyxVoipClient instance.
24
- *
25
- * @param options Configuration options for the client
26
- */
27
- constructor(options = {}) {
28
- this._disposed = false;
29
- this._options = {
30
- enableAppStateManagement: true,
31
- debug: false,
32
- ...options,
33
- };
34
- // Initialize core components
35
- this._sessionManager = new session_manager_1.SessionManager();
36
- this._callStateController = new call_state_controller_1.CallStateController(
37
- this._sessionManager
38
- );
39
- // Set up callback to initialize call state controller listeners when client is ready
40
- this._sessionManager.setOnClientReady(() => {
41
- console.log(
42
- '🔧 TelnyxVoipClient: Client ready, initializing call state controller listeners'
43
- );
44
- this._callStateController.initializeClientListeners();
45
- });
46
- if (this._options.debug) {
47
- console.log('TelnyxVoipClient initialized with options:', this._options);
22
+ /**
23
+ * Creates a new TelnyxVoipClient instance.
24
+ *
25
+ * @param options Configuration options for the client
26
+ */
27
+ constructor(options = {}) {
28
+ this._disposed = false;
29
+ this._options = {
30
+ enableAppStateManagement: true,
31
+ debug: false,
32
+ ...options,
33
+ };
34
+ // Initialize core components
35
+ this._sessionManager = new session_manager_1.SessionManager();
36
+ this._callStateController = new call_state_controller_1.CallStateController(this._sessionManager);
37
+ // Set up callback to initialize call state controller listeners when client is ready
38
+ this._sessionManager.setOnClientReady(() => {
39
+ console.log('🔧 TelnyxVoipClient: Client ready, initializing call state controller listeners');
40
+ this._callStateController.initializeClientListeners();
41
+ });
42
+ if (this._options.debug) {
43
+ console.log('TelnyxVoipClient initialized with options:', this._options);
44
+ }
48
45
  }
49
- }
50
- // ========== Observable Streams ==========
51
- /**
52
- * Stream of connection state changes.
53
- *
54
- * Emits the current status of the connection to the Telnyx backend.
55
- * Values include connecting, connected, disconnected, and error states.
56
- * Listen to this to show connection indicators in your UI.
57
- */
58
- get connectionState$() {
59
- return this._sessionManager.connectionState$;
60
- }
61
- /**
62
- * Stream of all current calls.
63
- *
64
- * Emits a list of all current Call objects. Use this for applications
65
- * that need to support multiple simultaneous calls (e.g., call waiting,
66
- * conference calls).
67
- */
68
- get calls$() {
69
- return this._callStateController.calls$;
70
- }
71
- /**
72
- * Stream of the currently active call.
73
- *
74
- * A convenience stream that emits the currently active Call object.
75
- * It emits null when no call is in progress. Ideal for applications
76
- * that only handle a single call at a time.
77
- */
78
- get activeCall$() {
79
- return this._callStateController.activeCall$;
80
- }
81
- // ========== Synchronous State Access ==========
82
- /**
83
- * Current connection state (synchronous access).
84
- */
85
- get currentConnectionState() {
86
- return this._sessionManager.currentState;
87
- }
88
- /**
89
- * Current list of calls (synchronous access).
90
- */
91
- get currentCalls() {
92
- return this._callStateController.currentCalls;
93
- }
94
- /**
95
- * Current active call (synchronous access).
96
- */
97
- get currentActiveCall() {
98
- return this._callStateController.currentActiveCall;
99
- }
100
- /**
101
- * Current session ID (UUID) for this connection.
102
- */
103
- get sessionId() {
104
- return this._sessionManager.sessionId;
105
- }
106
- /**
107
- * Configuration options for this client instance.
108
- */
109
- get options() {
110
- return this._options;
111
- }
112
- // ========== Authentication Methods ==========
113
- /**
114
- * Connects to the Telnyx platform using credential authentication.
115
- *
116
- * @param config The credential configuration containing SIP username and password
117
- * @returns A Promise that completes when the connection attempt is initiated
118
- *
119
- * Listen to connectionState$ to monitor the actual connection status.
120
- * Credentials are automatically stored for future reconnection.
121
- */
122
- async login(config) {
123
- this._throwIfDisposed();
124
- const errors = (0, config_1.validateConfig)(config);
125
- if (errors.length > 0) {
126
- throw new Error(`Invalid configuration: ${errors.join(', ')}`);
46
+ // ========== Observable Streams ==========
47
+ /**
48
+ * Stream of connection state changes.
49
+ *
50
+ * Emits the current status of the connection to the Telnyx backend.
51
+ * Values include connecting, connected, disconnected, and error states.
52
+ * Listen to this to show connection indicators in your UI.
53
+ */
54
+ get connectionState$() {
55
+ return this._sessionManager.connectionState$;
127
56
  }
128
- if (this._options.debug) {
129
- console.log('TelnyxVoipClient: Logging in with credentials for user:', config.sipUser);
57
+ /**
58
+ * Stream of all current calls.
59
+ *
60
+ * Emits a list of all current Call objects. Use this for applications
61
+ * that need to support multiple simultaneous calls (e.g., call waiting,
62
+ * conference calls).
63
+ */
64
+ get calls$() {
65
+ return this._callStateController.calls$;
130
66
  }
131
- // Store credentials for future reconnection
132
- await this._storeCredentials(config);
133
- await this._sessionManager.connectWithCredential(config);
134
- }
135
- /**
136
- * Connects to the Telnyx platform using token authentication.
137
- *
138
- * @param config The token configuration containing the authentication token
139
- * @returns A Promise that completes when the connection attempt is initiated
140
- *
141
- * Listen to connectionState$ to monitor the actual connection status.
142
- * Token is automatically stored for future reconnection.
143
- */
144
- async loginWithToken(config) {
145
- this._throwIfDisposed();
146
- const errors = (0, config_1.validateConfig)(config);
147
- if (errors.length > 0) {
148
- throw new Error(`Invalid configuration: ${errors.join(', ')}`);
67
+ /**
68
+ * Stream of the currently active call.
69
+ *
70
+ * A convenience stream that emits the currently active Call object.
71
+ * It emits null when no call is in progress. Ideal for applications
72
+ * that only handle a single call at a time.
73
+ */
74
+ get activeCall$() {
75
+ return this._callStateController.activeCall$;
149
76
  }
150
- if (this._options.debug) {
151
- console.log('TelnyxVoipClient: Logging in with token');
77
+ // ========== Synchronous State Access ==========
78
+ /**
79
+ * Current connection state (synchronous access).
80
+ */
81
+ get currentConnectionState() {
82
+ return this._sessionManager.currentState;
152
83
  }
153
- // Store token for future reconnection
154
- await this._storeToken(config);
155
- await this._sessionManager.connectWithToken(config);
156
- }
157
- /**
158
- * Disconnects from the Telnyx platform.
159
- *
160
- * This method terminates the connection, ends any active calls, and
161
- * cleans up all related resources.
162
- */
163
- async logout() {
164
- if (this._disposed) {
165
- return;
84
+ /**
85
+ * Current list of calls (synchronous access).
86
+ */
87
+ get currentCalls() {
88
+ return this._callStateController.currentCalls;
166
89
  }
167
- if (this._options.debug) {
168
- console.log('TelnyxVoipClient: Logging out');
90
+ /**
91
+ * Current active call (synchronous access).
92
+ */
93
+ get currentActiveCall() {
94
+ return this._callStateController.currentActiveCall;
169
95
  }
170
- await this._sessionManager.disconnect();
171
- }
172
- /**
173
- * Attempts to reconnect using previously stored configuration.
174
- *
175
- * This method is used for auto-reconnection scenarios where the app
176
- * comes back to the foreground and needs to restore the connection.
177
- *
178
- * @returns Promise<boolean> - true if reconnection was successful, false otherwise
179
- */
180
- async loginFromStoredConfig() {
181
- this._throwIfDisposed();
182
- if (this._options.debug) {
183
- console.log('TelnyxVoipClient: Attempting to login from stored config');
96
+ /**
97
+ * Current session ID (UUID) for this connection.
98
+ */
99
+ get sessionId() {
100
+ return this._sessionManager.sessionId;
184
101
  }
185
- try {
186
- // Try to retrieve stored credentials and token from AsyncStorage
187
- const AsyncStorage = require('@react-native-async-storage/async-storage').default;
188
- const storedUsername = await AsyncStorage.getItem('@telnyx_username');
189
- const storedPassword = await AsyncStorage.getItem('@telnyx_password');
190
- const storedCredentialToken = await AsyncStorage.getItem('@credential_token');
191
- const storedPushToken = await AsyncStorage.getItem('@push_token');
192
- // Check if we have credential-based authentication data
193
- if (storedUsername && storedPassword) {
194
- // Create credential config from stored data
195
- const { createCredentialConfig } = require('./models/config');
196
- const config = createCredentialConfig(storedUsername, storedPassword, {
197
- pushNotificationDeviceToken: storedPushToken,
198
- });
102
+ /**
103
+ * Configuration options for this client instance.
104
+ */
105
+ get options() {
106
+ return this._options;
107
+ }
108
+ // ========== Authentication Methods ==========
109
+ /**
110
+ * Connects to the Telnyx platform using credential authentication.
111
+ *
112
+ * @param config The credential configuration containing SIP username and password
113
+ * @returns A Promise that completes when the connection attempt is initiated
114
+ *
115
+ * Listen to connectionState$ to monitor the actual connection status.
116
+ * Credentials are automatically stored for future reconnection.
117
+ */
118
+ async login(config) {
119
+ this._throwIfDisposed();
120
+ const errors = (0, config_1.validateConfig)(config);
121
+ if (errors.length > 0) {
122
+ throw new Error(`Invalid configuration: ${errors.join(', ')}`);
123
+ }
199
124
  if (this._options.debug) {
200
- console.log(
201
- 'TelnyxVoipClient: Reconnecting with stored credentials for user:',
202
- storedUsername
203
- );
125
+ console.log('TelnyxVoipClient: Logging in with credentials for user:', config.sipUser);
204
126
  }
127
+ // Store credentials for future reconnection
128
+ await this._storeCredentials(config);
205
129
  await this._sessionManager.connectWithCredential(config);
206
- return true;
207
- }
208
- // Check if we have token-based authentication data
209
- if (storedCredentialToken) {
210
- // Create token config from stored data
211
- const { createTokenConfig } = require('./models/config');
212
- const config = createTokenConfig(storedCredentialToken, {
213
- pushNotificationDeviceToken: storedPushToken,
214
- });
130
+ }
131
+ /**
132
+ * Connects to the Telnyx platform using token authentication.
133
+ *
134
+ * @param config The token configuration containing the authentication token
135
+ * @returns A Promise that completes when the connection attempt is initiated
136
+ *
137
+ * Listen to connectionState$ to monitor the actual connection status.
138
+ * Token is automatically stored for future reconnection.
139
+ */
140
+ async loginWithToken(config) {
141
+ this._throwIfDisposed();
142
+ const errors = (0, config_1.validateConfig)(config);
143
+ if (errors.length > 0) {
144
+ throw new Error(`Invalid configuration: ${errors.join(', ')}`);
145
+ }
215
146
  if (this._options.debug) {
216
- console.log('TelnyxVoipClient: Reconnecting with stored token');
147
+ console.log('TelnyxVoipClient: Logging in with token');
217
148
  }
149
+ // Store token for future reconnection
150
+ await this._storeToken(config);
218
151
  await this._sessionManager.connectWithToken(config);
219
- return true;
220
- }
221
- // No stored authentication data found
222
- if (this._options.debug) {
223
- console.log('TelnyxVoipClient: No stored credentials or token found');
224
- }
225
- return false;
226
- } catch (error) {
227
- if (this._options.debug) {
228
- console.log('TelnyxVoipClient: Failed to login from stored config:', error);
229
- }
230
- return false;
231
- }
232
- }
233
- // ========== Call Management Methods ==========
234
- /**
235
- * Initiates a new outgoing call.
236
- *
237
- * @param destination The destination number or SIP URI to call
238
- * @param debug Optional flag to enable call quality metrics for this call
239
- * @returns A Promise that completes with the Call object once the invitation has been sent
240
- *
241
- * The call's state can be monitored through the returned Call object's streams.
242
- */
243
- async newCall(destination, debug = false) {
244
- this._throwIfDisposed();
245
- if (!destination || destination.trim() === '') {
246
- throw new Error('Destination is required');
247
- }
248
- if (this.currentConnectionState !== connection_state_1.TelnyxConnectionState.CONNECTED) {
249
- throw new Error(`Cannot make call when connection state is: ${this.currentConnectionState}`);
250
152
  }
251
- if (this._options.debug) {
252
- console.log('TelnyxVoipClient: Creating new call to:', destination);
153
+ /**
154
+ * Disconnects from the Telnyx platform.
155
+ *
156
+ * This method terminates the connection, ends any active calls, and
157
+ * cleans up all related resources.
158
+ */
159
+ async logout() {
160
+ if (this._disposed) {
161
+ return;
162
+ }
163
+ if (this._options.debug) {
164
+ console.log('TelnyxVoipClient: Logging out');
165
+ }
166
+ await this._sessionManager.disconnect();
253
167
  }
254
- return await this._callStateController.newCall(destination, undefined, undefined, debug);
255
- }
256
- // ========== Push Notification Methods ==========
257
- /**
258
- * Handle push notification payload.
259
- *
260
- * This is the unified entry point for all push notifications. It intelligently
261
- * determines whether to show a new incoming call UI or to process an already
262
- * actioned (accepted/declined) call upon app launch.
263
- *
264
- * @param payload The push notification payload
265
- */
266
- async handlePushNotification(payload) {
267
- this._throwIfDisposed();
268
- if (this._options.debug) {
269
- console.log('TelnyxVoipClient: Handling push notification:', payload);
168
+ /**
169
+ * Attempts to reconnect using previously stored configuration.
170
+ *
171
+ * This method is used for auto-reconnection scenarios where the app
172
+ * comes back to the foreground and needs to restore the connection.
173
+ *
174
+ * @returns Promise<boolean> - true if reconnection was successful, false otherwise
175
+ */
176
+ async loginFromStoredConfig() {
177
+ this._throwIfDisposed();
178
+ if (this._options.debug) {
179
+ console.log('TelnyxVoipClient: Attempting to login from stored config');
180
+ }
181
+ try {
182
+ // Try to retrieve stored credentials and token from AsyncStorage
183
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
184
+ const storedUsername = await AsyncStorage.getItem('@telnyx_username');
185
+ const storedPassword = await AsyncStorage.getItem('@telnyx_password');
186
+ const storedCredentialToken = await AsyncStorage.getItem('@credential_token');
187
+ const storedPushToken = await AsyncStorage.getItem('@push_token');
188
+ // Check if we have credential-based authentication data
189
+ if (storedUsername && storedPassword) {
190
+ // Create credential config from stored data
191
+ const { createCredentialConfig } = require('./models/config');
192
+ const config = createCredentialConfig(storedUsername, storedPassword, {
193
+ pushNotificationDeviceToken: storedPushToken,
194
+ });
195
+ if (this._options.debug) {
196
+ console.log('TelnyxVoipClient: Reconnecting with stored credentials for user:', storedUsername);
197
+ }
198
+ await this._sessionManager.connectWithCredential(config);
199
+ return true;
200
+ }
201
+ // Check if we have token-based authentication data
202
+ if (storedCredentialToken) {
203
+ // Create token config from stored data
204
+ const { createTokenConfig } = require('./models/config');
205
+ const config = createTokenConfig(storedCredentialToken, {
206
+ pushNotificationDeviceToken: storedPushToken,
207
+ });
208
+ if (this._options.debug) {
209
+ console.log('TelnyxVoipClient: Reconnecting with stored token');
210
+ }
211
+ await this._sessionManager.connectWithToken(config);
212
+ return true;
213
+ }
214
+ // No stored authentication data found
215
+ if (this._options.debug) {
216
+ console.log('TelnyxVoipClient: No stored credentials or token found');
217
+ }
218
+ return false;
219
+ }
220
+ catch (error) {
221
+ if (this._options.debug) {
222
+ console.log('TelnyxVoipClient: Failed to login from stored config:', error);
223
+ }
224
+ return false;
225
+ }
270
226
  }
271
- try {
272
- // First, pass the push notification to the session manager for processing
273
- // This will set the isCallFromPush flag on the TelnyxRTC client
274
- await this._sessionManager.handlePushNotification(payload);
275
- // Connect if not already connected
276
- const currentState = this.currentConnectionState;
277
- if (currentState !== connection_state_1.TelnyxConnectionState.CONNECTED) {
278
- // Try to login from stored config - now the push flags should be set
279
- const loginSuccess = await this.loginFromStoredConfig();
280
- if (!loginSuccess) {
281
- console.warn(
282
- 'TelnyxVoipClient: Could not login from stored config for push notification'
283
- );
284
- return;
227
+ // ========== Call Management Methods ==========
228
+ /**
229
+ * Initiates a new outgoing call.
230
+ *
231
+ * @param destination The destination number or SIP URI to call
232
+ * @param callerName Optional caller name to display
233
+ * @param callerNumber Optional caller ID number
234
+ * @param customHeaders Optional custom headers to include with the call
235
+ * @returns A Promise that completes with the Call object once the invitation has been sent
236
+ *
237
+ * The call's state can be monitored through the returned Call object's streams.
238
+ */
239
+ async newCall(destination, callerName, callerNumber, customHeaders) {
240
+ this._throwIfDisposed();
241
+ if (!destination || destination.trim() === '') {
242
+ throw new Error('Destination is required');
243
+ }
244
+ if (this.currentConnectionState !== connection_state_1.TelnyxConnectionState.CONNECTED) {
245
+ throw new Error(`Cannot make call when connection state is: ${this.currentConnectionState}`);
285
246
  }
286
- }
287
- } catch (error) {
288
- console.error('TelnyxVoipClient: Error handling push notification:', error);
289
- throw error;
247
+ if (this._options.debug) {
248
+ console.log('TelnyxVoipClient: Creating new call to:', destination);
249
+ }
250
+ return await this._callStateController.newCall(destination, callerName, callerNumber, customHeaders);
290
251
  }
291
- }
292
- /**
293
- * Disables push notifications for the current session.
294
- *
295
- * This method sends a request to the Telnyx backend to disable push
296
- * notifications for the current registered device/session.
297
- */
298
- disablePushNotifications() {
299
- this._throwIfDisposed();
300
- if (this._options.debug) {
301
- console.log('TelnyxVoipClient: Disabling push notifications');
252
+ // ========== Push Notification Methods ==========
253
+ /**
254
+ * Handle push notification payload.
255
+ *
256
+ * This is the unified entry point for all push notifications. It intelligently
257
+ * determines whether to show a new incoming call UI or to process an already
258
+ * actioned (accepted/declined) call upon app launch.
259
+ *
260
+ * @param payload The push notification payload
261
+ */
262
+ async handlePushNotification(payload) {
263
+ this._throwIfDisposed();
264
+ if (this._options.debug) {
265
+ console.log('TelnyxVoipClient: Handling push notification:', payload);
266
+ }
267
+ try {
268
+ // First, pass the push notification to the session manager for processing
269
+ // This will set the isCallFromPush flag on the TelnyxRTC client
270
+ await this._sessionManager.handlePushNotification(payload);
271
+ // Connect if not already connected
272
+ const currentState = this.currentConnectionState;
273
+ if (currentState !== connection_state_1.TelnyxConnectionState.CONNECTED) {
274
+ // Try to login from stored config - now the push flags should be set
275
+ const loginSuccess = await this.loginFromStoredConfig();
276
+ if (!loginSuccess) {
277
+ console.warn('TelnyxVoipClient: Could not login from stored config for push notification');
278
+ return;
279
+ }
280
+ }
281
+ }
282
+ catch (error) {
283
+ console.error('TelnyxVoipClient: Error handling push notification:', error);
284
+ throw error;
285
+ }
302
286
  }
303
- this._sessionManager.disablePushNotifications();
304
- }
305
- // ========== CallKit Integration Methods ==========
306
- /**
307
- * Set a call to connecting state (used for push notification calls when answered via CallKit)
308
- * @param callId The ID of the call to set to connecting state
309
- * @internal
310
- */
311
- setCallConnecting(callId) {
312
- this._callStateController.setCallConnecting(callId);
313
- }
314
- /**
315
- * Find a call by its underlying Telnyx call object
316
- * @param telnyxCall The Telnyx call object to find
317
- * @internal
318
- */
319
- findCallByTelnyxCall(telnyxCall) {
320
- return this._callStateController.findCallByTelnyxCall(telnyxCall);
321
- }
322
- /**
323
- * Queue an answer action for when the call invite arrives (for CallKit integration)
324
- * This should be called when the user answers from CallKit before the socket connection is established
325
- * @param customHeaders Optional custom headers to include with the answer
326
- */
327
- queueAnswerFromCallKit(customHeaders = {}) {
328
- this._throwIfDisposed();
329
- if (this._options.debug) {
330
- console.log('TelnyxVoipClient: Queuing answer action from CallKit', customHeaders);
287
+ /**
288
+ * Disables push notifications for the current session.
289
+ *
290
+ * This method sends a request to the Telnyx backend to disable push
291
+ * notifications for the current registered device/session.
292
+ */
293
+ disablePushNotifications() {
294
+ this._throwIfDisposed();
295
+ if (this._options.debug) {
296
+ console.log('TelnyxVoipClient: Disabling push notifications');
297
+ }
298
+ this._sessionManager.disablePushNotifications();
331
299
  }
332
- const telnyxClient = this._sessionManager.telnyxClient;
333
- if (telnyxClient && typeof telnyxClient.queueAnswerFromCallKit === 'function') {
334
- telnyxClient.queueAnswerFromCallKit(customHeaders);
335
- } else {
336
- console.warn(
337
- 'TelnyxVoipClient: TelnyxRTC client not available or method not found for queueAnswerFromCallKit'
338
- );
300
+ // ========== CallKit Integration Methods ==========
301
+ /**
302
+ * Set a call to connecting state (used for push notification calls when answered via CallKit)
303
+ * @param callId The ID of the call to set to connecting state
304
+ * @internal
305
+ */
306
+ setCallConnecting(callId) {
307
+ this._callStateController.setCallConnecting(callId);
339
308
  }
340
- }
341
- /**
342
- * Queue an end action for when the call invite arrives (for CallKit integration)
343
- * This should be called when the user ends from CallKit before the socket connection is established
344
- */
345
- queueEndFromCallKit() {
346
- this._throwIfDisposed();
347
- if (this._options.debug) {
348
- console.log('TelnyxVoipClient: Queuing end action from CallKit');
309
+ /**
310
+ * Find a call by its underlying Telnyx call object
311
+ * @param telnyxCall The Telnyx call object to find
312
+ * @internal
313
+ */
314
+ findCallByTelnyxCall(telnyxCall) {
315
+ return this._callStateController.findCallByTelnyxCall(telnyxCall);
349
316
  }
350
- const telnyxClient = this._sessionManager.telnyxClient;
351
- if (telnyxClient && typeof telnyxClient.queueEndFromCallKit === 'function') {
352
- telnyxClient.queueEndFromCallKit();
353
- } else {
354
- console.warn(
355
- 'TelnyxVoipClient: TelnyxRTC client not available or method not found for queueEndFromCallKit'
356
- );
317
+ /**
318
+ * Queue an answer action for when the call invite arrives (for CallKit integration)
319
+ * This should be called when the user answers from CallKit before the socket connection is established
320
+ * @param customHeaders Optional custom headers to include with the answer
321
+ */
322
+ queueAnswerFromCallKit(customHeaders = {}) {
323
+ this._throwIfDisposed();
324
+ if (this._options.debug) {
325
+ console.log('TelnyxVoipClient: Queuing answer action from CallKit', customHeaders);
326
+ }
327
+ const telnyxClient = this._sessionManager.telnyxClient;
328
+ if (telnyxClient && typeof telnyxClient.queueAnswerFromCallKit === 'function') {
329
+ telnyxClient.queueAnswerFromCallKit(customHeaders);
330
+ }
331
+ else {
332
+ console.warn('TelnyxVoipClient: TelnyxRTC client not available or method not found for queueAnswerFromCallKit');
333
+ }
357
334
  }
358
- }
359
- // ========== Lifecycle Methods ==========
360
- /**
361
- * Dispose of the client and clean up all resources.
362
- *
363
- * After calling this method, the client instance should not be used anymore.
364
- * This is particularly important for background clients that should be
365
- * disposed after handling push notifications.
366
- */
367
- dispose() {
368
- if (this._disposed) {
369
- return;
335
+ /**
336
+ * Queue an end action for when the call invite arrives (for CallKit integration)
337
+ * This should be called when the user ends from CallKit before the socket connection is established
338
+ */
339
+ queueEndFromCallKit() {
340
+ this._throwIfDisposed();
341
+ if (this._options.debug) {
342
+ console.log('TelnyxVoipClient: Queuing end action from CallKit');
343
+ }
344
+ const telnyxClient = this._sessionManager.telnyxClient;
345
+ if (telnyxClient && typeof telnyxClient.queueEndFromCallKit === 'function') {
346
+ telnyxClient.queueEndFromCallKit();
347
+ }
348
+ else {
349
+ console.warn('TelnyxVoipClient: TelnyxRTC client not available or method not found for queueEndFromCallKit');
350
+ }
370
351
  }
371
- if (this._options.debug) {
372
- console.log('TelnyxVoipClient: Disposing client');
352
+ // ========== Lifecycle Methods ==========
353
+ /**
354
+ * Dispose of the client and clean up all resources.
355
+ *
356
+ * After calling this method, the client instance should not be used anymore.
357
+ * This is particularly important for background clients that should be
358
+ * disposed after handling push notifications.
359
+ */
360
+ dispose() {
361
+ if (this._disposed) {
362
+ return;
363
+ }
364
+ if (this._options.debug) {
365
+ console.log('TelnyxVoipClient: Disposing client');
366
+ }
367
+ this._disposed = true;
368
+ this._callStateController.dispose();
369
+ this._sessionManager.dispose();
373
370
  }
374
- this._disposed = true;
375
- this._callStateController.dispose();
376
- this._sessionManager.dispose();
377
- }
378
- // ========== Private Methods ==========
379
- /**
380
- * Store credential configuration for automatic reconnection
381
- */
382
- async _storeCredentials(config) {
383
- try {
384
- const AsyncStorage = require('@react-native-async-storage/async-storage').default;
385
- await AsyncStorage.setItem('@telnyx_username', config.sipUser);
386
- await AsyncStorage.setItem('@telnyx_password', config.sipPassword);
387
- if (config.pushNotificationDeviceToken) {
388
- await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
389
- }
390
- // Clear any existing token since we're using credentials
391
- await AsyncStorage.removeItem('@credential_token');
392
- if (this._options.debug) {
393
- console.log('TelnyxVoipClient: Stored credentials for user:', config.sipUser);
394
- }
395
- } catch (error) {
396
- if (this._options.debug) {
397
- console.log('TelnyxVoipClient: Failed to store credentials:', error);
398
- }
399
- // Don't throw here - storage failure shouldn't prevent login
371
+ // ========== Private Methods ==========
372
+ /**
373
+ * Store credential configuration for automatic reconnection
374
+ */
375
+ async _storeCredentials(config) {
376
+ try {
377
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
378
+ await AsyncStorage.setItem('@telnyx_username', config.sipUser);
379
+ await AsyncStorage.setItem('@telnyx_password', config.sipPassword);
380
+ if (config.pushNotificationDeviceToken) {
381
+ await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
382
+ }
383
+ // Clear any existing token since we're using credentials
384
+ await AsyncStorage.removeItem('@credential_token');
385
+ if (this._options.debug) {
386
+ console.log('TelnyxVoipClient: Stored credentials for user:', config.sipUser);
387
+ }
388
+ }
389
+ catch (error) {
390
+ if (this._options.debug) {
391
+ console.log('TelnyxVoipClient: Failed to store credentials:', error);
392
+ }
393
+ // Don't throw here - storage failure shouldn't prevent login
394
+ }
400
395
  }
401
- }
402
- /**
403
- * Store token configuration for automatic reconnection
404
- */
405
- async _storeToken(config) {
406
- try {
407
- const AsyncStorage = require('@react-native-async-storage/async-storage').default;
408
- await AsyncStorage.setItem('@credential_token', config.token);
409
- if (config.pushNotificationDeviceToken) {
410
- await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
411
- }
412
- // Clear any existing credentials since we're using token
413
- await AsyncStorage.removeItem('@telnyx_username');
414
- await AsyncStorage.removeItem('@telnyx_password');
415
- if (this._options.debug) {
416
- console.log('TelnyxVoipClient: Stored authentication token');
417
- }
418
- } catch (error) {
419
- if (this._options.debug) {
420
- console.log('TelnyxVoipClient: Failed to store token:', error);
421
- }
422
- // Don't throw here - storage failure shouldn't prevent login
396
+ /**
397
+ * Store token configuration for automatic reconnection
398
+ */
399
+ async _storeToken(config) {
400
+ try {
401
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
402
+ await AsyncStorage.setItem('@credential_token', config.token);
403
+ if (config.pushNotificationDeviceToken) {
404
+ await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
405
+ }
406
+ // Clear any existing credentials since we're using token
407
+ await AsyncStorage.removeItem('@telnyx_username');
408
+ await AsyncStorage.removeItem('@telnyx_password');
409
+ if (this._options.debug) {
410
+ console.log('TelnyxVoipClient: Stored authentication token');
411
+ }
412
+ }
413
+ catch (error) {
414
+ if (this._options.debug) {
415
+ console.log('TelnyxVoipClient: Failed to store token:', error);
416
+ }
417
+ // Don't throw here - storage failure shouldn't prevent login
418
+ }
423
419
  }
424
- }
425
- /**
426
- * Throw an error if the client has been disposed
427
- */
428
- _throwIfDisposed() {
429
- if (this._disposed) {
430
- throw new Error('TelnyxVoipClient has been disposed');
420
+ /**
421
+ * Throw an error if the client has been disposed
422
+ */
423
+ _throwIfDisposed() {
424
+ if (this._disposed) {
425
+ throw new Error('TelnyxVoipClient has been disposed');
426
+ }
431
427
  }
432
- }
433
428
  }
434
429
  exports.TelnyxVoipClient = TelnyxVoipClient;
435
430
  // ========== Factory Functions ==========
@@ -437,11 +432,11 @@ exports.TelnyxVoipClient = TelnyxVoipClient;
437
432
  * Create a new TelnyxVoipClient instance for normal app usage
438
433
  */
439
434
  function createTelnyxVoipClient(options) {
440
- return new TelnyxVoipClient(options);
435
+ return new TelnyxVoipClient(options);
441
436
  }
442
437
  /**
443
438
  * Create a new TelnyxVoipClient instance for background push notification handling
444
439
  */
445
440
  function createBackgroundTelnyxVoipClient(options) {
446
- return new TelnyxVoipClient(options);
441
+ return new TelnyxVoipClient(options);
447
442
  }