@telnyx/react-voice-commons-sdk 0.1.1 → 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 (66) hide show
  1. package/README.md +483 -0
  2. package/ios/README.md +211 -211
  3. package/lib/callkit/callkit-coordinator.d.ts +117 -113
  4. package/lib/callkit/callkit-coordinator.js +727 -681
  5. package/lib/callkit/callkit.d.ts +41 -41
  6. package/lib/callkit/callkit.js +242 -252
  7. package/lib/callkit/index.js +47 -15
  8. package/lib/callkit/use-callkit-coordinator.d.ts +21 -21
  9. package/lib/callkit/use-callkit-coordinator.js +53 -53
  10. package/lib/callkit/use-callkit.d.ts +19 -19
  11. package/lib/callkit/use-callkit.js +310 -270
  12. package/lib/context/TelnyxVoiceContext.d.ts +9 -9
  13. package/lib/context/TelnyxVoiceContext.js +13 -10
  14. package/lib/hooks/use-callkit-coordinator.d.ts +17 -9
  15. package/lib/hooks/use-callkit-coordinator.js +50 -45
  16. package/lib/hooks/useAppReadyNotifier.js +15 -13
  17. package/lib/hooks/useAppStateHandler.d.ts +11 -6
  18. package/lib/hooks/useAppStateHandler.js +110 -95
  19. package/lib/index.d.ts +21 -3
  20. package/lib/index.js +201 -50
  21. package/lib/internal/CallKitHandler.d.ts +6 -6
  22. package/lib/internal/CallKitHandler.js +104 -96
  23. package/lib/internal/callkit-manager.d.ts +57 -57
  24. package/lib/internal/callkit-manager.js +316 -299
  25. package/lib/internal/calls/call-state-controller.d.ts +86 -81
  26. package/lib/internal/calls/call-state-controller.js +307 -269
  27. package/lib/internal/session/session-manager.d.ts +75 -75
  28. package/lib/internal/session/session-manager.js +424 -350
  29. package/lib/internal/user-defaults-helpers.js +39 -49
  30. package/lib/internal/voice-pn-bridge.d.ts +11 -11
  31. package/lib/internal/voice-pn-bridge.js +3 -3
  32. package/lib/models/call-state.d.ts +44 -44
  33. package/lib/models/call-state.js +68 -66
  34. package/lib/models/call.d.ts +133 -133
  35. package/lib/models/call.js +382 -354
  36. package/lib/models/config.d.ts +18 -11
  37. package/lib/models/config.js +35 -37
  38. package/lib/models/connection-state.d.ts +10 -10
  39. package/lib/models/connection-state.js +16 -16
  40. package/lib/telnyx-voice-app.d.ts +28 -28
  41. package/lib/telnyx-voice-app.js +482 -424
  42. package/lib/telnyx-voip-client.d.ts +167 -165
  43. package/lib/telnyx-voip-client.js +390 -383
  44. package/package.json +104 -104
  45. package/src/callkit/callkit-coordinator.ts +846 -846
  46. package/src/callkit/callkit.ts +322 -322
  47. package/src/callkit/index.ts +4 -4
  48. package/src/callkit/use-callkit.ts +345 -345
  49. package/src/context/TelnyxVoiceContext.tsx +33 -33
  50. package/src/hooks/use-callkit-coordinator.ts +60 -60
  51. package/src/hooks/useAppReadyNotifier.ts +25 -25
  52. package/src/hooks/useAppStateHandler.ts +134 -134
  53. package/src/index.ts +56 -56
  54. package/src/internal/CallKitHandler.tsx +149 -149
  55. package/src/internal/callkit-manager.ts +335 -335
  56. package/src/internal/calls/call-state-controller.ts +384 -384
  57. package/src/internal/session/session-manager.ts +467 -467
  58. package/src/internal/user-defaults-helpers.ts +58 -58
  59. package/src/internal/voice-pn-bridge.ts +18 -18
  60. package/src/models/call-state.ts +98 -98
  61. package/src/models/call.ts +388 -388
  62. package/src/models/config.ts +125 -125
  63. package/src/models/connection-state.ts +50 -50
  64. package/src/telnyx-voice-app.tsx +690 -690
  65. package/src/telnyx-voip-client.ts +539 -539
  66. package/src/types/telnyx-sdk.d.ts +79 -79
@@ -1,125 +1,125 @@
1
- /**
2
- * Configuration for credential-based authentication
3
- */
4
- export interface CredentialConfig {
5
- type: 'credential';
6
- sipUser: string;
7
- sipPassword: string;
8
- debug?: boolean;
9
- pushNotificationDeviceToken?: string;
10
- }
11
-
12
- /**
13
- * Configuration for token-based authentication
14
- */
15
- export interface TokenConfig {
16
- type: 'token';
17
- token: string;
18
- debug?: boolean;
19
- pushNotificationDeviceToken?: string;
20
- }
21
-
22
- /**
23
- * Union type for all supported authentication configurations
24
- */
25
- export type Config = CredentialConfig | TokenConfig;
26
-
27
- /**
28
- * Type guard to check if config is credential-based
29
- */
30
- export function isCredentialConfig(config: Config): config is CredentialConfig {
31
- return config.type === 'credential';
32
- }
33
-
34
- /**
35
- * Type guard to check if config is token-based
36
- */
37
- export function isTokenConfig(config: Config): config is TokenConfig {
38
- return config.type === 'token';
39
- }
40
-
41
- /**
42
- * Validates a credential configuration
43
- */
44
- export function validateCredentialConfig(config: CredentialConfig): string[] {
45
- const errors: string[] = [];
46
-
47
- if (!config.sipUser || config.sipUser.trim() === '') {
48
- errors.push('sipUser is required');
49
- }
50
-
51
- if (!config.sipPassword || config.sipPassword.trim() === '') {
52
- errors.push('sipPassword is required');
53
- }
54
-
55
- return errors;
56
- }
57
-
58
- /**
59
- * Validates a token configuration
60
- */
61
- export function validateTokenConfig(config: TokenConfig): string[] {
62
- const errors: string[] = [];
63
-
64
- if (!config.token || config.token.trim() === '') {
65
- errors.push('token is required');
66
- }
67
-
68
- return errors;
69
- }
70
-
71
- /**
72
- * Validates any configuration
73
- */
74
- export function validateConfig(config: Config): string[] {
75
- if (isCredentialConfig(config)) {
76
- return validateCredentialConfig(config);
77
- } else if (isTokenConfig(config)) {
78
- return validateTokenConfig(config);
79
- } else {
80
- return ['Invalid configuration type'];
81
- }
82
- }
83
-
84
- /**
85
- * Creates a credential configuration
86
- *
87
- * @param sipUser - SIP username for authentication
88
- * @param sipPassword - SIP password for authentication
89
- * @param options - Optional configuration settings
90
- * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
91
- * @param options.pushNotificationDeviceToken - Device token for push notifications
92
- * @returns Complete credential configuration object
93
- */
94
- export function createCredentialConfig(
95
- sipUser: string,
96
- sipPassword: string,
97
- options?: Partial<Omit<CredentialConfig, 'type' | 'sipUser' | 'sipPassword'>>
98
- ): CredentialConfig {
99
- return {
100
- type: 'credential',
101
- sipUser,
102
- sipPassword,
103
- ...options,
104
- };
105
- }
106
-
107
- /**
108
- * Creates a token-based configuration
109
- *
110
- * @param sipToken - JWT token for authentication
111
- * @param options - Optional configuration settings
112
- * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
113
- * @param options.pushNotificationDeviceToken - Device token for push notifications
114
- * @returns Complete token configuration object
115
- */
116
- export function createTokenConfig(
117
- sipToken: string,
118
- options?: Partial<Omit<TokenConfig, 'type' | 'sipToken'>>
119
- ): TokenConfig {
120
- return {
121
- type: 'token',
122
- token: sipToken,
123
- ...options,
124
- };
125
- }
1
+ /**
2
+ * Configuration for credential-based authentication
3
+ */
4
+ export interface CredentialConfig {
5
+ type: 'credential';
6
+ sipUser: string;
7
+ sipPassword: string;
8
+ debug?: boolean;
9
+ pushNotificationDeviceToken?: string;
10
+ }
11
+
12
+ /**
13
+ * Configuration for token-based authentication
14
+ */
15
+ export interface TokenConfig {
16
+ type: 'token';
17
+ token: string;
18
+ debug?: boolean;
19
+ pushNotificationDeviceToken?: string;
20
+ }
21
+
22
+ /**
23
+ * Union type for all supported authentication configurations
24
+ */
25
+ export type Config = CredentialConfig | TokenConfig;
26
+
27
+ /**
28
+ * Type guard to check if config is credential-based
29
+ */
30
+ export function isCredentialConfig(config: Config): config is CredentialConfig {
31
+ return config.type === 'credential';
32
+ }
33
+
34
+ /**
35
+ * Type guard to check if config is token-based
36
+ */
37
+ export function isTokenConfig(config: Config): config is TokenConfig {
38
+ return config.type === 'token';
39
+ }
40
+
41
+ /**
42
+ * Validates a credential configuration
43
+ */
44
+ export function validateCredentialConfig(config: CredentialConfig): string[] {
45
+ const errors: string[] = [];
46
+
47
+ if (!config.sipUser || config.sipUser.trim() === '') {
48
+ errors.push('sipUser is required');
49
+ }
50
+
51
+ if (!config.sipPassword || config.sipPassword.trim() === '') {
52
+ errors.push('sipPassword is required');
53
+ }
54
+
55
+ return errors;
56
+ }
57
+
58
+ /**
59
+ * Validates a token configuration
60
+ */
61
+ export function validateTokenConfig(config: TokenConfig): string[] {
62
+ const errors: string[] = [];
63
+
64
+ if (!config.token || config.token.trim() === '') {
65
+ errors.push('token is required');
66
+ }
67
+
68
+ return errors;
69
+ }
70
+
71
+ /**
72
+ * Validates any configuration
73
+ */
74
+ export function validateConfig(config: Config): string[] {
75
+ if (isCredentialConfig(config)) {
76
+ return validateCredentialConfig(config);
77
+ } else if (isTokenConfig(config)) {
78
+ return validateTokenConfig(config);
79
+ } else {
80
+ return ['Invalid configuration type'];
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Creates a credential configuration
86
+ *
87
+ * @param sipUser - SIP username for authentication
88
+ * @param sipPassword - SIP password for authentication
89
+ * @param options - Optional configuration settings
90
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
91
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
92
+ * @returns Complete credential configuration object
93
+ */
94
+ export function createCredentialConfig(
95
+ sipUser: string,
96
+ sipPassword: string,
97
+ options?: Partial<Omit<CredentialConfig, 'type' | 'sipUser' | 'sipPassword'>>
98
+ ): CredentialConfig {
99
+ return {
100
+ type: 'credential',
101
+ sipUser,
102
+ sipPassword,
103
+ ...options,
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Creates a token-based configuration
109
+ *
110
+ * @param sipToken - JWT token for authentication
111
+ * @param options - Optional configuration settings
112
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
113
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
114
+ * @returns Complete token configuration object
115
+ */
116
+ export function createTokenConfig(
117
+ sipToken: string,
118
+ options?: Partial<Omit<TokenConfig, 'type' | 'sipToken'>>
119
+ ): TokenConfig {
120
+ return {
121
+ type: 'token',
122
+ token: sipToken,
123
+ ...options,
124
+ };
125
+ }
@@ -1,50 +1,50 @@
1
- /**
2
- * Represents the connection state to the Telnyx platform.
3
- *
4
- * This enum provides a simplified view of the connection status,
5
- * abstracting away the complexity of the underlying WebSocket states.
6
- */
7
- export enum TelnyxConnectionState {
8
- /** Initial state before any connection attempt */
9
- DISCONNECTED = 'DISCONNECTED',
10
-
11
- /** Attempting to establish connection */
12
- CONNECTING = 'CONNECTING',
13
-
14
- /** Successfully connected and authenticated */
15
- CONNECTED = 'CONNECTED',
16
-
17
- /** Connection lost, attempting to reconnect */
18
- RECONNECTING = 'RECONNECTING',
19
-
20
- /** Connection failed or authentication error */
21
- ERROR = 'ERROR',
22
- }
23
-
24
- /**
25
- * Type guard to check if a value is a valid TelnyxConnectionState
26
- */
27
- export function isTelnyxConnectionState(value: any): value is TelnyxConnectionState {
28
- return Object.values(TelnyxConnectionState).includes(value);
29
- }
30
-
31
- /**
32
- * Helper function to determine if the connection state allows making calls
33
- */
34
- export function canMakeCalls(state: TelnyxConnectionState): boolean {
35
- return state === TelnyxConnectionState.CONNECTED;
36
- }
37
-
38
- /**
39
- * Helper function to determine if the connection state indicates an active connection
40
- */
41
- export function isConnected(state: TelnyxConnectionState): boolean {
42
- return state === TelnyxConnectionState.CONNECTED;
43
- }
44
-
45
- /**
46
- * Helper function to determine if the connection is in a transitional state
47
- */
48
- export function isTransitioning(state: TelnyxConnectionState): boolean {
49
- return state === TelnyxConnectionState.CONNECTING || state === TelnyxConnectionState.RECONNECTING;
50
- }
1
+ /**
2
+ * Represents the connection state to the Telnyx platform.
3
+ *
4
+ * This enum provides a simplified view of the connection status,
5
+ * abstracting away the complexity of the underlying WebSocket states.
6
+ */
7
+ export enum TelnyxConnectionState {
8
+ /** Initial state before any connection attempt */
9
+ DISCONNECTED = 'DISCONNECTED',
10
+
11
+ /** Attempting to establish connection */
12
+ CONNECTING = 'CONNECTING',
13
+
14
+ /** Successfully connected and authenticated */
15
+ CONNECTED = 'CONNECTED',
16
+
17
+ /** Connection lost, attempting to reconnect */
18
+ RECONNECTING = 'RECONNECTING',
19
+
20
+ /** Connection failed or authentication error */
21
+ ERROR = 'ERROR',
22
+ }
23
+
24
+ /**
25
+ * Type guard to check if a value is a valid TelnyxConnectionState
26
+ */
27
+ export function isTelnyxConnectionState(value: any): value is TelnyxConnectionState {
28
+ return Object.values(TelnyxConnectionState).includes(value);
29
+ }
30
+
31
+ /**
32
+ * Helper function to determine if the connection state allows making calls
33
+ */
34
+ export function canMakeCalls(state: TelnyxConnectionState): boolean {
35
+ return state === TelnyxConnectionState.CONNECTED;
36
+ }
37
+
38
+ /**
39
+ * Helper function to determine if the connection state indicates an active connection
40
+ */
41
+ export function isConnected(state: TelnyxConnectionState): boolean {
42
+ return state === TelnyxConnectionState.CONNECTED;
43
+ }
44
+
45
+ /**
46
+ * Helper function to determine if the connection is in a transitional state
47
+ */
48
+ export function isTransitioning(state: TelnyxConnectionState): boolean {
49
+ return state === TelnyxConnectionState.CONNECTING || state === TelnyxConnectionState.RECONNECTING;
50
+ }