@telnyx/react-voice-commons-sdk 0.1.1 → 0.1.3

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 (51) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +483 -0
  3. package/TelnyxVoiceCommons.podspec +31 -31
  4. package/ios/CallKitBridge.m +43 -43
  5. package/ios/CallKitBridge.swift +874 -879
  6. package/ios/README.md +211 -211
  7. package/ios/VoicePnBridge.m +30 -30
  8. package/ios/VoicePnBridge.swift +86 -86
  9. package/lib/callkit/callkit-coordinator.d.ts +2 -5
  10. package/lib/callkit/callkit-coordinator.js +15 -32
  11. package/lib/callkit/use-callkit-coordinator.d.ts +21 -21
  12. package/lib/callkit/use-callkit-coordinator.js +53 -53
  13. package/lib/hooks/useNetworkStateHandler.d.ts +0 -0
  14. package/lib/hooks/useNetworkStateHandler.js +0 -0
  15. package/lib/internal/calls/call-state-controller.d.ts +2 -10
  16. package/lib/internal/calls/call-state-controller.js +48 -54
  17. package/lib/internal/session/session-manager.d.ts +1 -5
  18. package/lib/internal/session/session-manager.js +35 -25
  19. package/lib/internal/voice-pn-bridge.d.ts +103 -1
  20. package/lib/internal/voice-pn-bridge.js +209 -2
  21. package/lib/models/call-state.d.ts +3 -1
  22. package/lib/models/call-state.js +5 -1
  23. package/lib/models/call.d.ts +31 -3
  24. package/lib/models/call.js +105 -5
  25. package/lib/telnyx-voice-app.js +78 -38
  26. package/lib/telnyx-voip-client.d.ts +4 -2
  27. package/lib/telnyx-voip-client.js +5 -3
  28. package/package.json +111 -104
  29. package/src/callkit/callkit-coordinator.ts +830 -846
  30. package/src/callkit/callkit.ts +322 -322
  31. package/src/callkit/index.ts +4 -4
  32. package/src/callkit/use-callkit.ts +345 -345
  33. package/src/context/TelnyxVoiceContext.tsx +33 -33
  34. package/src/hooks/use-callkit-coordinator.ts +60 -60
  35. package/src/hooks/useAppReadyNotifier.ts +25 -25
  36. package/src/hooks/useAppStateHandler.ts +134 -134
  37. package/src/hooks/useNetworkStateHandler.ts +0 -0
  38. package/src/index.ts +56 -56
  39. package/src/internal/CallKitHandler.tsx +149 -149
  40. package/src/internal/callkit-manager.ts +335 -335
  41. package/src/internal/calls/call-state-controller.ts +407 -384
  42. package/src/internal/session/session-manager.ts +483 -467
  43. package/src/internal/user-defaults-helpers.ts +58 -58
  44. package/src/internal/voice-pn-bridge.ts +266 -18
  45. package/src/models/call-state.ts +105 -98
  46. package/src/models/call.ts +502 -388
  47. package/src/models/config.ts +125 -125
  48. package/src/models/connection-state.ts +50 -50
  49. package/src/telnyx-voice-app.tsx +737 -690
  50. package/src/telnyx-voip-client.ts +551 -539
  51. package/src/types/telnyx-sdk.d.ts +93 -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
+ }