@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.
- package/README.md +483 -0
- package/ios/README.md +211 -211
- package/lib/callkit/callkit-coordinator.d.ts +117 -113
- package/lib/callkit/callkit-coordinator.js +727 -681
- package/lib/callkit/callkit.d.ts +41 -41
- package/lib/callkit/callkit.js +242 -252
- package/lib/callkit/index.js +47 -15
- package/lib/callkit/use-callkit-coordinator.d.ts +21 -21
- package/lib/callkit/use-callkit-coordinator.js +53 -53
- package/lib/callkit/use-callkit.d.ts +19 -19
- package/lib/callkit/use-callkit.js +310 -270
- package/lib/context/TelnyxVoiceContext.d.ts +9 -9
- package/lib/context/TelnyxVoiceContext.js +13 -10
- package/lib/hooks/use-callkit-coordinator.d.ts +17 -9
- package/lib/hooks/use-callkit-coordinator.js +50 -45
- package/lib/hooks/useAppReadyNotifier.js +15 -13
- package/lib/hooks/useAppStateHandler.d.ts +11 -6
- package/lib/hooks/useAppStateHandler.js +110 -95
- package/lib/index.d.ts +21 -3
- package/lib/index.js +201 -50
- package/lib/internal/CallKitHandler.d.ts +6 -6
- package/lib/internal/CallKitHandler.js +104 -96
- package/lib/internal/callkit-manager.d.ts +57 -57
- package/lib/internal/callkit-manager.js +316 -299
- package/lib/internal/calls/call-state-controller.d.ts +86 -81
- package/lib/internal/calls/call-state-controller.js +307 -269
- package/lib/internal/session/session-manager.d.ts +75 -75
- package/lib/internal/session/session-manager.js +424 -350
- package/lib/internal/user-defaults-helpers.js +39 -49
- package/lib/internal/voice-pn-bridge.d.ts +11 -11
- package/lib/internal/voice-pn-bridge.js +3 -3
- package/lib/models/call-state.d.ts +44 -44
- package/lib/models/call-state.js +68 -66
- package/lib/models/call.d.ts +133 -133
- package/lib/models/call.js +382 -354
- package/lib/models/config.d.ts +18 -11
- package/lib/models/config.js +35 -37
- package/lib/models/connection-state.d.ts +10 -10
- package/lib/models/connection-state.js +16 -16
- package/lib/telnyx-voice-app.d.ts +28 -28
- package/lib/telnyx-voice-app.js +482 -424
- package/lib/telnyx-voip-client.d.ts +167 -165
- package/lib/telnyx-voip-client.js +390 -383
- package/package.json +104 -104
- package/src/callkit/callkit-coordinator.ts +846 -846
- package/src/callkit/callkit.ts +322 -322
- package/src/callkit/index.ts +4 -4
- package/src/callkit/use-callkit.ts +345 -345
- package/src/context/TelnyxVoiceContext.tsx +33 -33
- package/src/hooks/use-callkit-coordinator.ts +60 -60
- package/src/hooks/useAppReadyNotifier.ts +25 -25
- package/src/hooks/useAppStateHandler.ts +134 -134
- package/src/index.ts +56 -56
- package/src/internal/CallKitHandler.tsx +149 -149
- package/src/internal/callkit-manager.ts +335 -335
- package/src/internal/calls/call-state-controller.ts +384 -384
- package/src/internal/session/session-manager.ts +467 -467
- package/src/internal/user-defaults-helpers.ts +58 -58
- package/src/internal/voice-pn-bridge.ts +18 -18
- package/src/models/call-state.ts +98 -98
- package/src/models/call.ts +388 -388
- package/src/models/config.ts +125 -125
- package/src/models/connection-state.ts +50 -50
- package/src/telnyx-voice-app.tsx +690 -690
- package/src/telnyx-voip-client.ts +539 -539
- package/src/types/telnyx-sdk.d.ts +79 -79
package/src/models/config.ts
CHANGED
|
@@ -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
|
+
}
|