@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
@@ -2,20 +2,20 @@
2
2
  * Configuration for credential-based authentication
3
3
  */
4
4
  export interface CredentialConfig {
5
- type: 'credential';
6
- sipUser: string;
7
- sipPassword: string;
8
- debug?: boolean;
9
- pushNotificationDeviceToken?: string;
5
+ type: 'credential';
6
+ sipUser: string;
7
+ sipPassword: string;
8
+ debug?: boolean;
9
+ pushNotificationDeviceToken?: string;
10
10
  }
11
11
  /**
12
12
  * Configuration for token-based authentication
13
13
  */
14
14
  export interface TokenConfig {
15
- type: 'token';
16
- token: string;
17
- debug?: boolean;
18
- pushNotificationDeviceToken?: string;
15
+ type: 'token';
16
+ token: string;
17
+ debug?: boolean;
18
+ pushNotificationDeviceToken?: string;
19
19
  }
20
20
  /**
21
21
  * Union type for all supported authentication configurations
@@ -51,11 +51,7 @@ export declare function validateConfig(config: Config): string[];
51
51
  * @param options.pushNotificationDeviceToken - Device token for push notifications
52
52
  * @returns Complete credential configuration object
53
53
  */
54
- export declare function createCredentialConfig(
55
- sipUser: string,
56
- sipPassword: string,
57
- options?: Partial<Omit<CredentialConfig, 'type' | 'sipUser' | 'sipPassword'>>
58
- ): CredentialConfig;
54
+ export declare function createCredentialConfig(sipUser: string, sipPassword: string, options?: Partial<Omit<CredentialConfig, 'type' | 'sipUser' | 'sipPassword'>>): CredentialConfig;
59
55
  /**
60
56
  * Creates a token-based configuration
61
57
  *
@@ -65,7 +61,4 @@ export declare function createCredentialConfig(
65
61
  * @param options.pushNotificationDeviceToken - Device token for push notifications
66
62
  * @returns Complete token configuration object
67
63
  */
68
- export declare function createTokenConfig(
69
- sipToken: string,
70
- options?: Partial<Omit<TokenConfig, 'type' | 'sipToken'>>
71
- ): TokenConfig;
64
+ export declare function createTokenConfig(sipToken: string, options?: Partial<Omit<TokenConfig, 'type' | 'sipToken'>>): TokenConfig;
@@ -1,5 +1,5 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isCredentialConfig = isCredentialConfig;
4
4
  exports.isTokenConfig = isTokenConfig;
5
5
  exports.validateCredentialConfig = validateCredentialConfig;
@@ -11,48 +11,50 @@ exports.createTokenConfig = createTokenConfig;
11
11
  * Type guard to check if config is credential-based
12
12
  */
13
13
  function isCredentialConfig(config) {
14
- return config.type === 'credential';
14
+ return config.type === 'credential';
15
15
  }
16
16
  /**
17
17
  * Type guard to check if config is token-based
18
18
  */
19
19
  function isTokenConfig(config) {
20
- return config.type === 'token';
20
+ return config.type === 'token';
21
21
  }
22
22
  /**
23
23
  * Validates a credential configuration
24
24
  */
25
25
  function validateCredentialConfig(config) {
26
- const errors = [];
27
- if (!config.sipUser || config.sipUser.trim() === '') {
28
- errors.push('sipUser is required');
29
- }
30
- if (!config.sipPassword || config.sipPassword.trim() === '') {
31
- errors.push('sipPassword is required');
32
- }
33
- return errors;
26
+ const errors = [];
27
+ if (!config.sipUser || config.sipUser.trim() === '') {
28
+ errors.push('sipUser is required');
29
+ }
30
+ if (!config.sipPassword || config.sipPassword.trim() === '') {
31
+ errors.push('sipPassword is required');
32
+ }
33
+ return errors;
34
34
  }
35
35
  /**
36
36
  * Validates a token configuration
37
37
  */
38
38
  function validateTokenConfig(config) {
39
- const errors = [];
40
- if (!config.token || config.token.trim() === '') {
41
- errors.push('token is required');
42
- }
43
- return errors;
39
+ const errors = [];
40
+ if (!config.token || config.token.trim() === '') {
41
+ errors.push('token is required');
42
+ }
43
+ return errors;
44
44
  }
45
45
  /**
46
46
  * Validates any configuration
47
47
  */
48
48
  function validateConfig(config) {
49
- if (isCredentialConfig(config)) {
50
- return validateCredentialConfig(config);
51
- } else if (isTokenConfig(config)) {
52
- return validateTokenConfig(config);
53
- } else {
54
- return ['Invalid configuration type'];
55
- }
49
+ if (isCredentialConfig(config)) {
50
+ return validateCredentialConfig(config);
51
+ }
52
+ else if (isTokenConfig(config)) {
53
+ return validateTokenConfig(config);
54
+ }
55
+ else {
56
+ return ['Invalid configuration type'];
57
+ }
56
58
  }
57
59
  /**
58
60
  * Creates a credential configuration
@@ -65,12 +67,12 @@ function validateConfig(config) {
65
67
  * @returns Complete credential configuration object
66
68
  */
67
69
  function createCredentialConfig(sipUser, sipPassword, options) {
68
- return {
69
- type: 'credential',
70
- sipUser,
71
- sipPassword,
72
- ...options,
73
- };
70
+ return {
71
+ type: 'credential',
72
+ sipUser,
73
+ sipPassword,
74
+ ...options,
75
+ };
74
76
  }
75
77
  /**
76
78
  * Creates a token-based configuration
@@ -82,9 +84,9 @@ function createCredentialConfig(sipUser, sipPassword, options) {
82
84
  * @returns Complete token configuration object
83
85
  */
84
86
  function createTokenConfig(sipToken, options) {
85
- return {
86
- type: 'token',
87
- token: sipToken,
88
- ...options,
89
- };
87
+ return {
88
+ type: 'token',
89
+ token: sipToken,
90
+ ...options,
91
+ };
90
92
  }
@@ -5,16 +5,16 @@
5
5
  * abstracting away the complexity of the underlying WebSocket states.
6
6
  */
7
7
  export declare enum TelnyxConnectionState {
8
- /** Initial state before any connection attempt */
9
- DISCONNECTED = 'DISCONNECTED',
10
- /** Attempting to establish connection */
11
- CONNECTING = 'CONNECTING',
12
- /** Successfully connected and authenticated */
13
- CONNECTED = 'CONNECTED',
14
- /** Connection lost, attempting to reconnect */
15
- RECONNECTING = 'RECONNECTING',
16
- /** Connection failed or authentication error */
17
- ERROR = 'ERROR',
8
+ /** Initial state before any connection attempt */
9
+ DISCONNECTED = "DISCONNECTED",
10
+ /** Attempting to establish connection */
11
+ CONNECTING = "CONNECTING",
12
+ /** Successfully connected and authenticated */
13
+ CONNECTED = "CONNECTED",
14
+ /** Connection lost, attempting to reconnect */
15
+ RECONNECTING = "RECONNECTING",
16
+ /** Connection failed or authentication error */
17
+ ERROR = "ERROR"
18
18
  }
19
19
  /**
20
20
  * Type guard to check if a value is a valid TelnyxConnectionState
@@ -1,5 +1,5 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TelnyxConnectionState = void 0;
4
4
  exports.isTelnyxConnectionState = isTelnyxConnectionState;
5
5
  exports.canMakeCalls = canMakeCalls;
@@ -13,38 +13,38 @@ exports.isTransitioning = isTransitioning;
13
13
  */
14
14
  var TelnyxConnectionState;
15
15
  (function (TelnyxConnectionState) {
16
- /** Initial state before any connection attempt */
17
- TelnyxConnectionState['DISCONNECTED'] = 'DISCONNECTED';
18
- /** Attempting to establish connection */
19
- TelnyxConnectionState['CONNECTING'] = 'CONNECTING';
20
- /** Successfully connected and authenticated */
21
- TelnyxConnectionState['CONNECTED'] = 'CONNECTED';
22
- /** Connection lost, attempting to reconnect */
23
- TelnyxConnectionState['RECONNECTING'] = 'RECONNECTING';
24
- /** Connection failed or authentication error */
25
- TelnyxConnectionState['ERROR'] = 'ERROR';
16
+ /** Initial state before any connection attempt */
17
+ TelnyxConnectionState["DISCONNECTED"] = "DISCONNECTED";
18
+ /** Attempting to establish connection */
19
+ TelnyxConnectionState["CONNECTING"] = "CONNECTING";
20
+ /** Successfully connected and authenticated */
21
+ TelnyxConnectionState["CONNECTED"] = "CONNECTED";
22
+ /** Connection lost, attempting to reconnect */
23
+ TelnyxConnectionState["RECONNECTING"] = "RECONNECTING";
24
+ /** Connection failed or authentication error */
25
+ TelnyxConnectionState["ERROR"] = "ERROR";
26
26
  })(TelnyxConnectionState || (exports.TelnyxConnectionState = TelnyxConnectionState = {}));
27
27
  /**
28
28
  * Type guard to check if a value is a valid TelnyxConnectionState
29
29
  */
30
30
  function isTelnyxConnectionState(value) {
31
- return Object.values(TelnyxConnectionState).includes(value);
31
+ return Object.values(TelnyxConnectionState).includes(value);
32
32
  }
33
33
  /**
34
34
  * Helper function to determine if the connection state allows making calls
35
35
  */
36
36
  function canMakeCalls(state) {
37
- return state === TelnyxConnectionState.CONNECTED;
37
+ return state === TelnyxConnectionState.CONNECTED;
38
38
  }
39
39
  /**
40
40
  * Helper function to determine if the connection state indicates an active connection
41
41
  */
42
42
  function isConnected(state) {
43
- return state === TelnyxConnectionState.CONNECTED;
43
+ return state === TelnyxConnectionState.CONNECTED;
44
44
  }
45
45
  /**
46
46
  * Helper function to determine if the connection is in a transitional state
47
47
  */
48
48
  function isTransitioning(state) {
49
- return state === TelnyxConnectionState.CONNECTING || state === TelnyxConnectionState.RECONNECTING;
49
+ return state === TelnyxConnectionState.CONNECTING || state === TelnyxConnectionState.RECONNECTING;
50
50
  }
@@ -5,44 +5,44 @@ import { TelnyxVoipClient } from './telnyx-voip-client';
5
5
  * Configuration options for TelnyxVoiceApp
6
6
  */
7
7
  export interface TelnyxVoiceAppOptions {
8
- /** The TelnyxVoipClient instance to manage */
9
- voipClient: TelnyxVoipClient;
10
- /** Optional callback when push notification processing starts */
11
- onPushNotificationProcessingStarted?: () => void;
12
- /** Optional callback when push notification processing completes */
13
- onPushNotificationProcessingCompleted?: () => void;
14
- /** Optional callback for additional background/foreground handling */
15
- onAppStateChanged?: (state: AppStateStatus) => void;
16
- /** Whether to enable automatic login/reconnection (default: true) */
17
- enableAutoReconnect?: boolean;
18
- /** Whether to skip web platform for background detection (default: true) */
19
- skipWebBackgroundDetection?: boolean;
20
- /** Enable debug logging */
21
- debug?: boolean;
8
+ /** The TelnyxVoipClient instance to manage */
9
+ voipClient: TelnyxVoipClient;
10
+ /** Optional callback when push notification processing starts */
11
+ onPushNotificationProcessingStarted?: () => void;
12
+ /** Optional callback when push notification processing completes */
13
+ onPushNotificationProcessingCompleted?: () => void;
14
+ /** Optional callback for additional background/foreground handling */
15
+ onAppStateChanged?: (state: AppStateStatus) => void;
16
+ /** Whether to enable automatic login/reconnection (default: true) */
17
+ enableAutoReconnect?: boolean;
18
+ /** Whether to skip web platform for background detection (default: true) */
19
+ skipWebBackgroundDetection?: boolean;
20
+ /** Enable debug logging */
21
+ debug?: boolean;
22
22
  }
23
23
  /**
24
24
  * Props for the TelnyxVoiceApp component
25
25
  */
26
26
  export interface TelnyxVoiceAppProps extends TelnyxVoiceAppOptions {
27
- /** The child components to render */
28
- children: React.ReactNode;
27
+ /** The child components to render */
28
+ children: React.ReactNode;
29
29
  }
30
30
  /**
31
31
  * Interface for the TelnyxVoiceApp component with static methods
32
32
  */
33
33
  export interface TelnyxVoiceAppComponent extends React.FC<TelnyxVoiceAppProps> {
34
- initializeAndCreate: (options: {
35
- voipClient: TelnyxVoipClient;
36
- children: React.ReactNode;
37
- backgroundMessageHandler?: (message: any) => Promise<void>;
38
- onPushNotificationProcessingStarted?: () => void;
39
- onPushNotificationProcessingCompleted?: () => void;
40
- onAppStateChanged?: (state: AppStateStatus) => void;
41
- enableAutoReconnect?: boolean;
42
- skipWebBackgroundDetection?: boolean;
43
- debug?: boolean;
44
- }) => Promise<React.ComponentType>;
45
- handleBackgroundPush: (message: any) => Promise<void>;
34
+ initializeAndCreate: (options: {
35
+ voipClient: TelnyxVoipClient;
36
+ children: React.ReactNode;
37
+ backgroundMessageHandler?: (message: any) => Promise<void>;
38
+ onPushNotificationProcessingStarted?: () => void;
39
+ onPushNotificationProcessingCompleted?: () => void;
40
+ onAppStateChanged?: (state: AppStateStatus) => void;
41
+ enableAutoReconnect?: boolean;
42
+ skipWebBackgroundDetection?: boolean;
43
+ debug?: boolean;
44
+ }) => Promise<React.ComponentType>;
45
+ handleBackgroundPush: (message: any) => Promise<void>;
46
46
  }
47
47
  export declare const TelnyxVoiceApp: TelnyxVoiceAppComponent;
48
48
  export default TelnyxVoiceApp;