@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telnyx/react-voice-commons-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A high-level, state-agnostic, drop-in module for the Telnyx React Native SDK that simplifies WebRTC voice calling integration",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -143,6 +143,7 @@ export class TelnyxVoipClient {
143
143
  * @returns A Promise that completes when the connection attempt is initiated
144
144
  *
145
145
  * Listen to connectionState$ to monitor the actual connection status.
146
+ * Credentials are automatically stored for future reconnection.
146
147
  */
147
148
  async login(config: CredentialConfig): Promise<void> {
148
149
  this._throwIfDisposed();
@@ -156,6 +157,9 @@ export class TelnyxVoipClient {
156
157
  console.log('TelnyxVoipClient: Logging in with credentials for user:', config.sipUser);
157
158
  }
158
159
 
160
+ // Store credentials for future reconnection
161
+ await this._storeCredentials(config);
162
+
159
163
  await this._sessionManager.connectWithCredential(config);
160
164
  }
161
165
 
@@ -166,6 +170,7 @@ export class TelnyxVoipClient {
166
170
  * @returns A Promise that completes when the connection attempt is initiated
167
171
  *
168
172
  * Listen to connectionState$ to monitor the actual connection status.
173
+ * Token is automatically stored for future reconnection.
169
174
  */
170
175
  async loginWithToken(config: TokenConfig): Promise<void> {
171
176
  this._throwIfDisposed();
@@ -179,6 +184,9 @@ export class TelnyxVoipClient {
179
184
  console.log('TelnyxVoipClient: Logging in with token');
180
185
  }
181
186
 
187
+ // Store token for future reconnection
188
+ await this._storeToken(config);
189
+
182
190
  await this._sessionManager.connectWithToken(config);
183
191
  }
184
192
 
@@ -446,6 +454,62 @@ export class TelnyxVoipClient {
446
454
 
447
455
  // ========== Private Methods ==========
448
456
 
457
+ /**
458
+ * Store credential configuration for automatic reconnection
459
+ */
460
+ private async _storeCredentials(config: CredentialConfig): Promise<void> {
461
+ try {
462
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
463
+
464
+ await AsyncStorage.setItem('@telnyx_username', config.sipUser);
465
+ await AsyncStorage.setItem('@telnyx_password', config.sipPassword);
466
+
467
+ if (config.pushNotificationDeviceToken) {
468
+ await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
469
+ }
470
+
471
+ // Clear any existing token since we're using credentials
472
+ await AsyncStorage.removeItem('@credential_token');
473
+
474
+ if (this._options.debug) {
475
+ console.log('TelnyxVoipClient: Stored credentials for user:', config.sipUser);
476
+ }
477
+ } catch (error) {
478
+ if (this._options.debug) {
479
+ console.log('TelnyxVoipClient: Failed to store credentials:', error);
480
+ }
481
+ // Don't throw here - storage failure shouldn't prevent login
482
+ }
483
+ }
484
+
485
+ /**
486
+ * Store token configuration for automatic reconnection
487
+ */
488
+ private async _storeToken(config: TokenConfig): Promise<void> {
489
+ try {
490
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
491
+
492
+ await AsyncStorage.setItem('@credential_token', config.token);
493
+
494
+ if (config.pushNotificationDeviceToken) {
495
+ await AsyncStorage.setItem('@push_token', config.pushNotificationDeviceToken);
496
+ }
497
+
498
+ // Clear any existing credentials since we're using token
499
+ await AsyncStorage.removeItem('@telnyx_username');
500
+ await AsyncStorage.removeItem('@telnyx_password');
501
+
502
+ if (this._options.debug) {
503
+ console.log('TelnyxVoipClient: Stored authentication token');
504
+ }
505
+ } catch (error) {
506
+ if (this._options.debug) {
507
+ console.log('TelnyxVoipClient: Failed to store token:', error);
508
+ }
509
+ // Don't throw here - storage failure shouldn't prevent login
510
+ }
511
+ }
512
+
449
513
  /**
450
514
  * Throw an error if the client has been disposed
451
515
  */