@telnyx/react-voice-commons-sdk 0.1.7-beta.0 → 0.1.7-beta.1

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.
@@ -89,7 +89,10 @@ declare class CallKitCoordinator {
89
89
  */
90
90
  linkExistingCallKitCall(call: Call, callKitUUID: string): void;
91
91
  /**
92
- * Set the VoIP client reference for triggering reconnection
92
+ * Set the VoIP client reference for triggering reconnection.
93
+ *
94
+ * @deprecated No longer needed — TelnyxVoiceApp now auto-wires the voipClient
95
+ * on mount. Kept for backwards compatibility.
93
96
  */
94
97
  setVoipClient(voipClient: TelnyxVoipClient): void;
95
98
  /**
@@ -673,7 +673,10 @@ class CallKitCoordinator {
673
673
  this.setupWebRTCCallListeners(call, callKitUUID);
674
674
  }
675
675
  /**
676
- * Set the VoIP client reference for triggering reconnection
676
+ * Set the VoIP client reference for triggering reconnection.
677
+ *
678
+ * @deprecated No longer needed — TelnyxVoiceApp now auto-wires the voipClient
679
+ * on mount. Kept for backwards compatibility.
677
680
  */
678
681
  setVoipClient(voipClient) {
679
682
  this.voipClient = voipClient;
@@ -36,6 +36,11 @@ function useCallKitCoordinator() {
36
36
  const isAvailable = (0, react_1.useCallback)(() => {
37
37
  return callkit_coordinator_1.default.isAvailable();
38
38
  }, []);
39
+ /**
40
+ * @deprecated No longer needed — TelnyxVoiceApp now auto-wires the voipClient
41
+ * on the CallKit coordinator when it receives the voipClient prop.
42
+ * This method is kept for backwards compatibility and will be removed in a future release.
43
+ */
39
44
  const setVoipClient = (0, react_1.useCallback)((voipClient) => {
40
45
  callkit_coordinator_1.default.setVoipClient(voipClient);
41
46
  }, []);
package/lib/index.d.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  export {
12
12
  TelnyxVoipClient,
13
13
  createTelnyxVoipClient,
14
+ destroyTelnyxVoipClient,
14
15
  createBackgroundTelnyxVoipClient,
15
16
  } from './telnyx-voip-client';
16
17
  export type { TelnyxVoipClientOptions } from './telnyx-voip-client';
package/lib/index.js CHANGED
@@ -58,6 +58,7 @@ exports.useAppReadyNotifier =
58
58
  exports.useAppStateHandler =
59
59
  exports.TelnyxVoiceApp =
60
60
  exports.createBackgroundTelnyxVoipClient =
61
+ exports.destroyTelnyxVoipClient =
61
62
  exports.createTelnyxVoipClient =
62
63
  exports.TelnyxVoipClient =
63
64
  void 0;
@@ -75,6 +76,12 @@ Object.defineProperty(exports, 'createTelnyxVoipClient', {
75
76
  return telnyx_voip_client_1.createTelnyxVoipClient;
76
77
  },
77
78
  });
79
+ Object.defineProperty(exports, 'destroyTelnyxVoipClient', {
80
+ enumerable: true,
81
+ get: function () {
82
+ return telnyx_voip_client_1.destroyTelnyxVoipClient;
83
+ },
84
+ });
78
85
  Object.defineProperty(exports, 'createBackgroundTelnyxVoipClient', {
79
86
  enumerable: true,
80
87
  get: function () {
@@ -378,6 +378,19 @@ const TelnyxVoiceAppComponent = ({
378
378
  });
379
379
  return backgroundClient;
380
380
  }, [debug, log]);
381
+ // Auto-wire the voipClient on the CallKit coordinator so consumers don't
382
+ // have to call setVoipClient() manually at the right level.
383
+ (0, react_1.useEffect)(() => {
384
+ if (react_native_1.Platform.OS === 'ios') {
385
+ try {
386
+ const { callKitCoordinator } = require('./callkit/callkit-coordinator');
387
+ callKitCoordinator.setVoipClient(voipClient);
388
+ log('Auto-wired voipClient on CallKit coordinator');
389
+ } catch (e) {
390
+ log('Error auto-wiring voipClient on CallKit coordinator:', e);
391
+ }
392
+ }
393
+ }, [voipClient, log]);
381
394
  // Setup effect
382
395
  (0, react_1.useEffect)(() => {
383
396
  // Listen to connection state changes
@@ -27,6 +27,16 @@ export declare class TelnyxVoipClient {
27
27
  private readonly _callStateController;
28
28
  private readonly _options;
29
29
  private _disposed;
30
+ /**
31
+ * Check if the app was launched from a push notification.
32
+ *
33
+ * Use this to avoid double-login on cold start. When true, the SDK will
34
+ * handle login internally via the push notification flow, so you should
35
+ * skip your normal auto-login.
36
+ *
37
+ * @returns true if there is pending push notification data indicating a push-launched app
38
+ */
39
+ static isLaunchedFromPushNotification(): Promise<boolean>;
30
40
  /**
31
41
  * Creates a new TelnyxVoipClient instance.
32
42
  *
@@ -213,11 +223,25 @@ export declare class TelnyxVoipClient {
213
223
  private _throwIfDisposed;
214
224
  }
215
225
  /**
216
- * Create a new TelnyxVoipClient instance for normal app usage
226
+ * Create or retrieve the shared TelnyxVoipClient instance.
227
+ *
228
+ * This uses a singleton pattern — calling it multiple times (e.g., inside a
229
+ * React component body) always returns the same instance. If you need to
230
+ * reset the instance, call `destroyTelnyxVoipClient()` first.
217
231
  */
218
232
  export declare function createTelnyxVoipClient(options?: TelnyxVoipClientOptions): TelnyxVoipClient;
219
233
  /**
220
- * Create a new TelnyxVoipClient instance for background push notification handling
234
+ * Destroy the shared TelnyxVoipClient instance.
235
+ *
236
+ * Disposes the current singleton so that a subsequent call to
237
+ * `createTelnyxVoipClient()` will create a fresh instance.
238
+ */
239
+ export declare function destroyTelnyxVoipClient(): void;
240
+ /**
241
+ * Create a new TelnyxVoipClient instance for background push notification handling.
242
+ *
243
+ * Unlike `createTelnyxVoipClient`, this always creates a new instance because
244
+ * background isolates need their own independent client.
221
245
  */
222
246
  export declare function createBackgroundTelnyxVoipClient(
223
247
  options?: TelnyxVoipClientOptions
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.TelnyxVoipClient = void 0;
4
4
  exports.createTelnyxVoipClient = createTelnyxVoipClient;
5
+ exports.destroyTelnyxVoipClient = destroyTelnyxVoipClient;
5
6
  exports.createBackgroundTelnyxVoipClient = createBackgroundTelnyxVoipClient;
6
7
  const connection_state_1 = require('./models/connection-state');
7
8
  const call_state_1 = require('./models/call-state');
8
9
  const config_1 = require('./models/config');
9
10
  const session_manager_1 = require('./internal/session/session-manager');
10
11
  const call_state_controller_1 = require('./internal/calls/call-state-controller');
12
+ const voice_pn_bridge_1 = require('./internal/voice-pn-bridge');
11
13
  /**
12
14
  * The main public interface for the react-voice-commons module.
13
15
  *
@@ -20,6 +22,26 @@ const call_state_controller_1 = require('./internal/calls/call-state-controller'
20
22
  * into their chosen state management solution naturally.
21
23
  */
22
24
  class TelnyxVoipClient {
25
+ /**
26
+ * Check if the app was launched from a push notification.
27
+ *
28
+ * Use this to avoid double-login on cold start. When true, the SDK will
29
+ * handle login internally via the push notification flow, so you should
30
+ * skip your normal auto-login.
31
+ *
32
+ * @returns true if there is pending push notification data indicating a push-launched app
33
+ */
34
+ static async isLaunchedFromPushNotification() {
35
+ try {
36
+ const pendingAction = await voice_pn_bridge_1.VoicePnBridge.getPendingPushAction();
37
+ if (pendingAction?.action) return true;
38
+ const pendingVoipPush = await voice_pn_bridge_1.VoicePnBridge.getPendingVoipPush();
39
+ if (pendingVoipPush) return true;
40
+ return false;
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
23
45
  /**
24
46
  * Creates a new TelnyxVoipClient instance.
25
47
  *
@@ -470,14 +492,38 @@ class TelnyxVoipClient {
470
492
  }
471
493
  exports.TelnyxVoipClient = TelnyxVoipClient;
472
494
  // ========== Factory Functions ==========
495
+ let _sharedInstance = null;
473
496
  /**
474
- * Create a new TelnyxVoipClient instance for normal app usage
497
+ * Create or retrieve the shared TelnyxVoipClient instance.
498
+ *
499
+ * This uses a singleton pattern — calling it multiple times (e.g., inside a
500
+ * React component body) always returns the same instance. If you need to
501
+ * reset the instance, call `destroyTelnyxVoipClient()` first.
475
502
  */
476
503
  function createTelnyxVoipClient(options) {
477
- return new TelnyxVoipClient(options);
504
+ if (_sharedInstance) {
505
+ return _sharedInstance;
506
+ }
507
+ _sharedInstance = new TelnyxVoipClient(options);
508
+ return _sharedInstance;
478
509
  }
479
510
  /**
480
- * Create a new TelnyxVoipClient instance for background push notification handling
511
+ * Destroy the shared TelnyxVoipClient instance.
512
+ *
513
+ * Disposes the current singleton so that a subsequent call to
514
+ * `createTelnyxVoipClient()` will create a fresh instance.
515
+ */
516
+ function destroyTelnyxVoipClient() {
517
+ if (_sharedInstance) {
518
+ _sharedInstance.dispose();
519
+ _sharedInstance = null;
520
+ }
521
+ }
522
+ /**
523
+ * Create a new TelnyxVoipClient instance for background push notification handling.
524
+ *
525
+ * Unlike `createTelnyxVoipClient`, this always creates a new instance because
526
+ * background isolates need their own independent client.
481
527
  */
482
528
  function createBackgroundTelnyxVoipClient(options) {
483
529
  return new TelnyxVoipClient(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telnyx/react-voice-commons-sdk",
3
- "version": "0.1.7-beta.0",
3
+ "version": "0.1.7-beta.1",
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",
@@ -740,7 +740,10 @@ class CallKitCoordinator {
740
740
  }
741
741
 
742
742
  /**
743
- * Set the VoIP client reference for triggering reconnection
743
+ * Set the VoIP client reference for triggering reconnection.
744
+ *
745
+ * @deprecated No longer needed — TelnyxVoiceApp now auto-wires the voipClient
746
+ * on mount. Kept for backwards compatibility.
744
747
  */
745
748
  setVoipClient(voipClient: TelnyxVoipClient): void {
746
749
  this.voipClient = voipClient;
@@ -42,6 +42,11 @@ export function useCallKitCoordinator() {
42
42
  return callKitCoordinator.isAvailable();
43
43
  }, []);
44
44
 
45
+ /**
46
+ * @deprecated No longer needed — TelnyxVoiceApp now auto-wires the voipClient
47
+ * on the CallKit coordinator when it receives the voipClient prop.
48
+ * This method is kept for backwards compatibility and will be removed in a future release.
49
+ */
45
50
  const setVoipClient = useCallback((voipClient: TelnyxVoipClient): void => {
46
51
  callKitCoordinator.setVoipClient(voipClient);
47
52
  }, []);
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  export {
14
14
  TelnyxVoipClient,
15
15
  createTelnyxVoipClient,
16
+ destroyTelnyxVoipClient,
16
17
  createBackgroundTelnyxVoipClient,
17
18
  } from './telnyx-voip-client';
18
19
  export type { TelnyxVoipClientOptions } from './telnyx-voip-client';
@@ -494,6 +494,20 @@ const TelnyxVoiceAppComponent: React.FC<TelnyxVoiceAppProps> = ({
494
494
  return backgroundClient;
495
495
  }, [debug, log]);
496
496
 
497
+ // Auto-wire the voipClient on the CallKit coordinator so consumers don't
498
+ // have to call setVoipClient() manually at the right level.
499
+ useEffect(() => {
500
+ if (Platform.OS === 'ios') {
501
+ try {
502
+ const { callKitCoordinator } = require('./callkit/callkit-coordinator');
503
+ callKitCoordinator.setVoipClient(voipClient);
504
+ log('Auto-wired voipClient on CallKit coordinator');
505
+ } catch (e) {
506
+ log('Error auto-wiring voipClient on CallKit coordinator:', e);
507
+ }
508
+ }
509
+ }, [voipClient, log]);
510
+
497
511
  // Setup effect
498
512
  useEffect(() => {
499
513
  // Listen to connection state changes
@@ -5,6 +5,7 @@ import { TelnyxCallState } from './models/call-state';
5
5
  import { Config, CredentialConfig, TokenConfig, validateConfig } from './models/config';
6
6
  import { SessionManager } from './internal/session/session-manager';
7
7
  import { CallStateController } from './internal/calls/call-state-controller';
8
+ import { VoicePnBridge } from './internal/voice-pn-bridge';
8
9
 
9
10
  /**
10
11
  * Configuration options for TelnyxVoipClient
@@ -34,6 +35,29 @@ export class TelnyxVoipClient {
34
35
  private readonly _options: Required<TelnyxVoipClientOptions>;
35
36
  private _disposed = false;
36
37
 
38
+ /**
39
+ * Check if the app was launched from a push notification.
40
+ *
41
+ * Use this to avoid double-login on cold start. When true, the SDK will
42
+ * handle login internally via the push notification flow, so you should
43
+ * skip your normal auto-login.
44
+ *
45
+ * @returns true if there is pending push notification data indicating a push-launched app
46
+ */
47
+ static async isLaunchedFromPushNotification(): Promise<boolean> {
48
+ try {
49
+ const pendingAction = await VoicePnBridge.getPendingPushAction();
50
+ if (pendingAction?.action) return true;
51
+
52
+ const pendingVoipPush = await VoicePnBridge.getPendingVoipPush();
53
+ if (pendingVoipPush) return true;
54
+
55
+ return false;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+
37
61
  /**
38
62
  * Creates a new TelnyxVoipClient instance.
39
63
  *
@@ -565,15 +589,41 @@ export class TelnyxVoipClient {
565
589
 
566
590
  // ========== Factory Functions ==========
567
591
 
592
+ let _sharedInstance: TelnyxVoipClient | null = null;
593
+
568
594
  /**
569
- * Create a new TelnyxVoipClient instance for normal app usage
595
+ * Create or retrieve the shared TelnyxVoipClient instance.
596
+ *
597
+ * This uses a singleton pattern — calling it multiple times (e.g., inside a
598
+ * React component body) always returns the same instance. If you need to
599
+ * reset the instance, call `destroyTelnyxVoipClient()` first.
570
600
  */
571
601
  export function createTelnyxVoipClient(options?: TelnyxVoipClientOptions): TelnyxVoipClient {
572
- return new TelnyxVoipClient(options);
602
+ if (_sharedInstance) {
603
+ return _sharedInstance;
604
+ }
605
+ _sharedInstance = new TelnyxVoipClient(options);
606
+ return _sharedInstance;
573
607
  }
574
608
 
575
609
  /**
576
- * Create a new TelnyxVoipClient instance for background push notification handling
610
+ * Destroy the shared TelnyxVoipClient instance.
611
+ *
612
+ * Disposes the current singleton so that a subsequent call to
613
+ * `createTelnyxVoipClient()` will create a fresh instance.
614
+ */
615
+ export function destroyTelnyxVoipClient(): void {
616
+ if (_sharedInstance) {
617
+ _sharedInstance.dispose();
618
+ _sharedInstance = null;
619
+ }
620
+ }
621
+
622
+ /**
623
+ * Create a new TelnyxVoipClient instance for background push notification handling.
624
+ *
625
+ * Unlike `createTelnyxVoipClient`, this always creates a new instance because
626
+ * background isolates need their own independent client.
577
627
  */
578
628
  export function createBackgroundTelnyxVoipClient(
579
629
  options?: TelnyxVoipClientOptions