@telnyx/react-voice-commons-sdk 0.1.0

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 (73) hide show
  1. package/TelnyxVoiceCommons.podspec +32 -0
  2. package/ios/CallKitBridge.m +44 -0
  3. package/ios/CallKitBridge.swift +879 -0
  4. package/ios/README.md +211 -0
  5. package/ios/VoicePnBridge.m +31 -0
  6. package/ios/VoicePnBridge.swift +87 -0
  7. package/lib/callkit/callkit-coordinator.d.ts +126 -0
  8. package/lib/callkit/callkit-coordinator.js +728 -0
  9. package/lib/callkit/callkit.d.ts +49 -0
  10. package/lib/callkit/callkit.js +262 -0
  11. package/lib/callkit/index.d.ts +4 -0
  12. package/lib/callkit/index.js +15 -0
  13. package/lib/callkit/use-callkit-coordinator.d.ts +21 -0
  14. package/lib/callkit/use-callkit-coordinator.js +53 -0
  15. package/lib/callkit/use-callkit.d.ts +28 -0
  16. package/lib/callkit/use-callkit.js +279 -0
  17. package/lib/context/TelnyxVoiceContext.d.ts +18 -0
  18. package/lib/context/TelnyxVoiceContext.js +18 -0
  19. package/lib/hooks/use-callkit-coordinator.d.ts +13 -0
  20. package/lib/hooks/use-callkit-coordinator.js +48 -0
  21. package/lib/hooks/useAppReadyNotifier.d.ts +9 -0
  22. package/lib/hooks/useAppReadyNotifier.js +25 -0
  23. package/lib/hooks/useAppStateHandler.d.ts +16 -0
  24. package/lib/hooks/useAppStateHandler.js +105 -0
  25. package/lib/index.d.ts +24 -0
  26. package/lib/index.js +66 -0
  27. package/lib/internal/CallKitHandler.d.ts +17 -0
  28. package/lib/internal/CallKitHandler.js +110 -0
  29. package/lib/internal/callkit-manager.d.ts +69 -0
  30. package/lib/internal/callkit-manager.js +326 -0
  31. package/lib/internal/calls/call-state-controller.d.ts +92 -0
  32. package/lib/internal/calls/call-state-controller.js +294 -0
  33. package/lib/internal/session/session-manager.d.ts +87 -0
  34. package/lib/internal/session/session-manager.js +385 -0
  35. package/lib/internal/user-defaults-helpers.d.ts +10 -0
  36. package/lib/internal/user-defaults-helpers.js +69 -0
  37. package/lib/internal/voice-pn-bridge.d.ts +14 -0
  38. package/lib/internal/voice-pn-bridge.js +5 -0
  39. package/lib/models/call-state.d.ts +61 -0
  40. package/lib/models/call-state.js +87 -0
  41. package/lib/models/call.d.ts +145 -0
  42. package/lib/models/call.js +372 -0
  43. package/lib/models/config.d.ts +64 -0
  44. package/lib/models/config.js +92 -0
  45. package/lib/models/connection-state.d.ts +34 -0
  46. package/lib/models/connection-state.js +50 -0
  47. package/lib/telnyx-voice-app.d.ts +48 -0
  48. package/lib/telnyx-voice-app.js +486 -0
  49. package/lib/telnyx-voip-client.d.ts +184 -0
  50. package/lib/telnyx-voip-client.js +386 -0
  51. package/package.json +104 -0
  52. package/src/callkit/callkit-coordinator.ts +846 -0
  53. package/src/callkit/callkit.ts +322 -0
  54. package/src/callkit/index.ts +4 -0
  55. package/src/callkit/use-callkit.ts +345 -0
  56. package/src/context/TelnyxVoiceContext.tsx +33 -0
  57. package/src/hooks/use-callkit-coordinator.ts +60 -0
  58. package/src/hooks/useAppReadyNotifier.ts +25 -0
  59. package/src/hooks/useAppStateHandler.ts +134 -0
  60. package/src/index.ts +56 -0
  61. package/src/internal/CallKitHandler.tsx +149 -0
  62. package/src/internal/callkit-manager.ts +335 -0
  63. package/src/internal/calls/call-state-controller.ts +384 -0
  64. package/src/internal/session/session-manager.ts +467 -0
  65. package/src/internal/user-defaults-helpers.ts +58 -0
  66. package/src/internal/voice-pn-bridge.ts +18 -0
  67. package/src/models/call-state.ts +98 -0
  68. package/src/models/call.ts +388 -0
  69. package/src/models/config.ts +125 -0
  70. package/src/models/connection-state.ts +50 -0
  71. package/src/telnyx-voice-app.tsx +690 -0
  72. package/src/telnyx-voip-client.ts +475 -0
  73. package/src/types/telnyx-sdk.d.ts +79 -0
@@ -0,0 +1,145 @@
1
+ import { Observable } from 'rxjs';
2
+ import { TelnyxCallState } from './call-state';
3
+ import { Call as TelnyxCall } from '@telnyx/react-native-voice-sdk';
4
+ /**
5
+ * Represents a call with reactive state streams.
6
+ *
7
+ * This class wraps the underlying Telnyx Call object and provides
8
+ * reactive streams for all call state changes, making it easy to
9
+ * integrate with any state management solution.
10
+ */
11
+ export declare class Call {
12
+ private readonly _telnyxCall;
13
+ private readonly _callId;
14
+ private readonly _destination;
15
+ private readonly _isIncoming;
16
+ private readonly _callState;
17
+ private readonly _isMuted;
18
+ private readonly _isHeld;
19
+ private readonly _duration;
20
+ private _durationTimer?;
21
+ private _startTime?;
22
+ constructor(_telnyxCall: TelnyxCall, _callId: string, _destination: string, _isIncoming: boolean);
23
+ /**
24
+ * Unique identifier for this call
25
+ */
26
+ get callId(): string;
27
+ /**
28
+ * The destination number or SIP URI
29
+ */
30
+ get destination(): string;
31
+ /**
32
+ * Whether this is an incoming call
33
+ */
34
+ get isIncoming(): boolean;
35
+ /**
36
+ * Whether this is an outgoing call
37
+ */
38
+ get isOutgoing(): boolean;
39
+ /**
40
+ * Current call state (synchronous access)
41
+ */
42
+ get currentState(): TelnyxCallState;
43
+ /**
44
+ * Current mute state (synchronous access)
45
+ */
46
+ get currentIsMuted(): boolean;
47
+ /**
48
+ * Current hold state (synchronous access)
49
+ */
50
+ get currentIsHeld(): boolean;
51
+ /**
52
+ * Current call duration in seconds (synchronous access)
53
+ */
54
+ get currentDuration(): number;
55
+ /**
56
+ * Get the underlying Telnyx Call object (for internal use)
57
+ * @internal
58
+ */
59
+ get telnyxCall(): TelnyxCall;
60
+ /**
61
+ * Observable stream of call state changes
62
+ */
63
+ get callState$(): Observable<TelnyxCallState>;
64
+ /**
65
+ * Observable stream of mute state changes
66
+ */
67
+ get isMuted$(): Observable<boolean>;
68
+ /**
69
+ * Observable stream of hold state changes
70
+ */
71
+ get isHeld$(): Observable<boolean>;
72
+ /**
73
+ * Observable stream of call duration changes (in seconds)
74
+ */
75
+ get duration$(): Observable<number>;
76
+ /**
77
+ * Observable that emits true when the call can be answered
78
+ */
79
+ get canAnswer$(): Observable<boolean>;
80
+ /**
81
+ * Observable that emits true when the call can be hung up
82
+ */
83
+ get canHangup$(): Observable<boolean>;
84
+ /**
85
+ * Observable that emits true when the call can be put on hold
86
+ */
87
+ get canHold$(): Observable<boolean>;
88
+ /**
89
+ * Observable that emits true when the call can be resumed from hold
90
+ */
91
+ get canResume$(): Observable<boolean>;
92
+ /**
93
+ * Answer the incoming call
94
+ */
95
+ answer(): Promise<void>;
96
+ /**
97
+ * Hang up the call
98
+ */
99
+ hangup(): Promise<void>;
100
+ /**
101
+ * Put the call on hold
102
+ */
103
+ hold(): Promise<void>;
104
+ /**
105
+ * Resume the call from hold
106
+ */
107
+ resume(): Promise<void>;
108
+ /**
109
+ * Mute the call
110
+ */
111
+ mute(): Promise<void>;
112
+ /**
113
+ * Unmute the call
114
+ */
115
+ unmute(): Promise<void>;
116
+ /**
117
+ * Toggle mute state
118
+ */
119
+ toggleMute(): Promise<void>;
120
+ /**
121
+ * Set the call to connecting state (used for push notification calls when answered via CallKit)
122
+ * @internal
123
+ */
124
+ setConnecting(): void;
125
+ /**
126
+ * Clean up resources when the call is disposed
127
+ */
128
+ dispose(): void;
129
+ /**
130
+ * Set up listeners for the underlying Telnyx call
131
+ */
132
+ private _setupCallListeners;
133
+ /**
134
+ * Map Telnyx SDK call states to our simplified call states
135
+ */
136
+ private _mapToTelnyxCallState;
137
+ /**
138
+ * Start the duration timer
139
+ */
140
+ private _startDurationTimer;
141
+ /**
142
+ * Stop the duration timer
143
+ */
144
+ private _stopDurationTimer;
145
+ }
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Call = void 0;
37
+ const rxjs_1 = require("rxjs");
38
+ const operators_1 = require("rxjs/operators");
39
+ const call_state_1 = require("./call-state");
40
+ const react_native_1 = require("react-native");
41
+ /**
42
+ * Represents a call with reactive state streams.
43
+ *
44
+ * This class wraps the underlying Telnyx Call object and provides
45
+ * reactive streams for all call state changes, making it easy to
46
+ * integrate with any state management solution.
47
+ */
48
+ class Call {
49
+ constructor(_telnyxCall, _callId, _destination, _isIncoming) {
50
+ this._telnyxCall = _telnyxCall;
51
+ this._callId = _callId;
52
+ this._destination = _destination;
53
+ this._isIncoming = _isIncoming;
54
+ this._callState = new rxjs_1.BehaviorSubject(call_state_1.TelnyxCallState.RINGING);
55
+ this._isMuted = new rxjs_1.BehaviorSubject(false);
56
+ this._isHeld = new rxjs_1.BehaviorSubject(false);
57
+ this._duration = new rxjs_1.BehaviorSubject(0);
58
+ this._setupCallListeners();
59
+ }
60
+ /**
61
+ * Unique identifier for this call
62
+ */
63
+ get callId() {
64
+ return this._callId;
65
+ }
66
+ /**
67
+ * The destination number or SIP URI
68
+ */
69
+ get destination() {
70
+ return this._destination;
71
+ }
72
+ /**
73
+ * Whether this is an incoming call
74
+ */
75
+ get isIncoming() {
76
+ return this._isIncoming;
77
+ }
78
+ /**
79
+ * Whether this is an outgoing call
80
+ */
81
+ get isOutgoing() {
82
+ return !this._isIncoming;
83
+ }
84
+ /**
85
+ * Current call state (synchronous access)
86
+ */
87
+ get currentState() {
88
+ return this._callState.value;
89
+ }
90
+ /**
91
+ * Current mute state (synchronous access)
92
+ */
93
+ get currentIsMuted() {
94
+ return this._isMuted.value;
95
+ }
96
+ /**
97
+ * Current hold state (synchronous access)
98
+ */
99
+ get currentIsHeld() {
100
+ return this._isHeld.value;
101
+ }
102
+ /**
103
+ * Current call duration in seconds (synchronous access)
104
+ */
105
+ get currentDuration() {
106
+ return this._duration.value;
107
+ }
108
+ /**
109
+ * Get the underlying Telnyx Call object (for internal use)
110
+ * @internal
111
+ */
112
+ get telnyxCall() {
113
+ return this._telnyxCall;
114
+ }
115
+ /**
116
+ * Observable stream of call state changes
117
+ */
118
+ get callState$() {
119
+ return this._callState.asObservable().pipe((0, operators_1.distinctUntilChanged)());
120
+ }
121
+ /**
122
+ * Observable stream of mute state changes
123
+ */
124
+ get isMuted$() {
125
+ return this._isMuted.asObservable().pipe((0, operators_1.distinctUntilChanged)());
126
+ }
127
+ /**
128
+ * Observable stream of hold state changes
129
+ */
130
+ get isHeld$() {
131
+ return this._isHeld.asObservable().pipe((0, operators_1.distinctUntilChanged)());
132
+ }
133
+ /**
134
+ * Observable stream of call duration changes (in seconds)
135
+ */
136
+ get duration$() {
137
+ return this._duration.asObservable().pipe((0, operators_1.distinctUntilChanged)());
138
+ }
139
+ /**
140
+ * Observable that emits true when the call can be answered
141
+ */
142
+ get canAnswer$() {
143
+ return this.callState$.pipe((0, operators_1.map)((state) => call_state_1.CallStateHelpers.canAnswer(state)), (0, operators_1.distinctUntilChanged)());
144
+ }
145
+ /**
146
+ * Observable that emits true when the call can be hung up
147
+ */
148
+ get canHangup$() {
149
+ return this.callState$.pipe((0, operators_1.map)((state) => call_state_1.CallStateHelpers.canHangup(state)), (0, operators_1.distinctUntilChanged)());
150
+ }
151
+ /**
152
+ * Observable that emits true when the call can be put on hold
153
+ */
154
+ get canHold$() {
155
+ return this.callState$.pipe((0, operators_1.map)((state) => call_state_1.CallStateHelpers.canHold(state)), (0, operators_1.distinctUntilChanged)());
156
+ }
157
+ /**
158
+ * Observable that emits true when the call can be resumed from hold
159
+ */
160
+ get canResume$() {
161
+ return this.callState$.pipe((0, operators_1.map)((state) => call_state_1.CallStateHelpers.canResume(state)), (0, operators_1.distinctUntilChanged)());
162
+ }
163
+ /**
164
+ * Answer the incoming call
165
+ */
166
+ async answer() {
167
+ if (!call_state_1.CallStateHelpers.canAnswer(this.currentState)) {
168
+ throw new Error(`Cannot answer call in state: ${this.currentState}`);
169
+ }
170
+ try {
171
+ // On iOS, use CallKit coordinator for proper audio session handling
172
+ if (react_native_1.Platform.OS === 'ios') {
173
+ const { callKitCoordinator } = await Promise.resolve().then(() => __importStar(require('../callkit/callkit-coordinator')));
174
+ if (callKitCoordinator.isAvailable()) {
175
+ console.log('Call: Using CallKit coordinator to answer call (iOS)');
176
+ await callKitCoordinator.answerCallFromUI(this._telnyxCall);
177
+ return;
178
+ }
179
+ }
180
+ // Fallback for Android or when CallKit is not available
181
+ console.log('Call: Setting state to CONNECTING before answering');
182
+ this._callState.next(call_state_1.TelnyxCallState.CONNECTING);
183
+ await this._telnyxCall.answer();
184
+ }
185
+ catch (error) {
186
+ console.error('Failed to answer call:', error);
187
+ throw error;
188
+ }
189
+ }
190
+ /**
191
+ * Hang up the call
192
+ */
193
+ async hangup() {
194
+ if (!call_state_1.CallStateHelpers.canHangup(this.currentState)) {
195
+ throw new Error(`Cannot hang up call in state: ${this.currentState}`);
196
+ }
197
+ try {
198
+ // On iOS, use CallKit coordinator for proper CallKit cleanup
199
+ if (react_native_1.Platform.OS === 'ios') {
200
+ const { callKitCoordinator } = await Promise.resolve().then(() => __importStar(require('../callkit/callkit-coordinator')));
201
+ if (callKitCoordinator.isAvailable()) {
202
+ console.log('Call: Using CallKit coordinator to end call (iOS)');
203
+ await callKitCoordinator.endCallFromUI(this._telnyxCall);
204
+ return;
205
+ }
206
+ }
207
+ // Fallback for Android or when CallKit is not available
208
+ await this._telnyxCall.hangup();
209
+ }
210
+ catch (error) {
211
+ console.error('Failed to hang up call:', error);
212
+ throw error;
213
+ }
214
+ }
215
+ /**
216
+ * Put the call on hold
217
+ */
218
+ async hold() {
219
+ if (!call_state_1.CallStateHelpers.canHold(this.currentState)) {
220
+ throw new Error(`Cannot hold call in state: ${this.currentState}`);
221
+ }
222
+ try {
223
+ await this._telnyxCall.hold();
224
+ }
225
+ catch (error) {
226
+ console.error('Failed to hold call:', error);
227
+ throw error;
228
+ }
229
+ }
230
+ /**
231
+ * Resume the call from hold
232
+ */
233
+ async resume() {
234
+ if (!call_state_1.CallStateHelpers.canResume(this.currentState)) {
235
+ throw new Error(`Cannot resume call in state: ${this.currentState}`);
236
+ }
237
+ try {
238
+ await this._telnyxCall.unhold();
239
+ }
240
+ catch (error) {
241
+ console.error('Failed to resume call:', error);
242
+ throw error;
243
+ }
244
+ }
245
+ /**
246
+ * Mute the call
247
+ */
248
+ async mute() {
249
+ if (!call_state_1.CallStateHelpers.canToggleMute(this.currentState)) {
250
+ throw new Error(`Cannot mute call in state: ${this.currentState}`);
251
+ }
252
+ try {
253
+ this._telnyxCall.mute();
254
+ this._isMuted.next(true);
255
+ }
256
+ catch (error) {
257
+ console.error('Failed to mute call:', error);
258
+ throw error;
259
+ }
260
+ }
261
+ /**
262
+ * Unmute the call
263
+ */
264
+ async unmute() {
265
+ if (!call_state_1.CallStateHelpers.canToggleMute(this.currentState)) {
266
+ throw new Error(`Cannot unmute call in state: ${this.currentState}`);
267
+ }
268
+ try {
269
+ this._telnyxCall.unmute();
270
+ this._isMuted.next(false);
271
+ }
272
+ catch (error) {
273
+ console.error('Failed to unmute call:', error);
274
+ throw error;
275
+ }
276
+ }
277
+ /**
278
+ * Toggle mute state
279
+ */
280
+ async toggleMute() {
281
+ if (this.currentIsMuted) {
282
+ await this.unmute();
283
+ }
284
+ else {
285
+ await this.mute();
286
+ }
287
+ }
288
+ /**
289
+ * Set the call to connecting state (used for push notification calls when answered via CallKit)
290
+ * @internal
291
+ */
292
+ setConnecting() {
293
+ console.log('Call: Setting state to CONNECTING for push notification answer');
294
+ this._callState.next(call_state_1.TelnyxCallState.CONNECTING);
295
+ }
296
+ /**
297
+ * Clean up resources when the call is disposed
298
+ */
299
+ dispose() {
300
+ this._stopDurationTimer();
301
+ this._callState.complete();
302
+ this._isMuted.complete();
303
+ this._isHeld.complete();
304
+ this._duration.complete();
305
+ }
306
+ /**
307
+ * Set up listeners for the underlying Telnyx call
308
+ */
309
+ _setupCallListeners() {
310
+ // Map Telnyx call states to our simplified states
311
+ this._telnyxCall.on('telnyx.call.state', (call, state) => {
312
+ const telnyxState = this._mapToTelnyxCallState(state);
313
+ this._callState.next(telnyxState);
314
+ // Start duration timer when call becomes active
315
+ if (telnyxState === call_state_1.TelnyxCallState.ACTIVE && !this._startTime) {
316
+ this._startDurationTimer();
317
+ }
318
+ // Stop duration timer when call ends
319
+ if (call_state_1.CallStateHelpers.isTerminated(telnyxState)) {
320
+ this._stopDurationTimer();
321
+ }
322
+ });
323
+ }
324
+ /**
325
+ * Map Telnyx SDK call states to our simplified call states
326
+ */
327
+ _mapToTelnyxCallState(telnyxState) {
328
+ // This mapping will depend on the actual Telnyx SDK call states
329
+ // For now, using a basic mapping - this should be updated based on actual SDK
330
+ switch (telnyxState) {
331
+ case 'ringing':
332
+ case 'new':
333
+ return call_state_1.TelnyxCallState.RINGING;
334
+ case 'active':
335
+ case 'answered':
336
+ return call_state_1.TelnyxCallState.ACTIVE;
337
+ case 'held':
338
+ return call_state_1.TelnyxCallState.HELD;
339
+ case 'ended':
340
+ case 'hangup':
341
+ return call_state_1.TelnyxCallState.ENDED;
342
+ case 'failed':
343
+ case 'rejected':
344
+ return call_state_1.TelnyxCallState.FAILED;
345
+ default:
346
+ console.warn(`Unknown call state: ${telnyxState}`);
347
+ return call_state_1.TelnyxCallState.RINGING;
348
+ }
349
+ }
350
+ /**
351
+ * Start the duration timer
352
+ */
353
+ _startDurationTimer() {
354
+ this._startTime = new Date();
355
+ this._durationTimer = setInterval(() => {
356
+ if (this._startTime) {
357
+ const duration = Math.floor((Date.now() - this._startTime.getTime()) / 1000);
358
+ this._duration.next(duration);
359
+ }
360
+ }, 1000);
361
+ }
362
+ /**
363
+ * Stop the duration timer
364
+ */
365
+ _stopDurationTimer() {
366
+ if (this._durationTimer) {
367
+ clearInterval(this._durationTimer);
368
+ this._durationTimer = undefined;
369
+ }
370
+ }
371
+ }
372
+ exports.Call = Call;
@@ -0,0 +1,64 @@
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
+ * Configuration for token-based authentication
13
+ */
14
+ export interface TokenConfig {
15
+ type: 'token';
16
+ token: string;
17
+ debug?: boolean;
18
+ pushNotificationDeviceToken?: string;
19
+ }
20
+ /**
21
+ * Union type for all supported authentication configurations
22
+ */
23
+ export type Config = CredentialConfig | TokenConfig;
24
+ /**
25
+ * Type guard to check if config is credential-based
26
+ */
27
+ export declare function isCredentialConfig(config: Config): config is CredentialConfig;
28
+ /**
29
+ * Type guard to check if config is token-based
30
+ */
31
+ export declare function isTokenConfig(config: Config): config is TokenConfig;
32
+ /**
33
+ * Validates a credential configuration
34
+ */
35
+ export declare function validateCredentialConfig(config: CredentialConfig): string[];
36
+ /**
37
+ * Validates a token configuration
38
+ */
39
+ export declare function validateTokenConfig(config: TokenConfig): string[];
40
+ /**
41
+ * Validates any configuration
42
+ */
43
+ export declare function validateConfig(config: Config): string[];
44
+ /**
45
+ * Creates a credential configuration
46
+ *
47
+ * @param sipUser - SIP username for authentication
48
+ * @param sipPassword - SIP password for authentication
49
+ * @param options - Optional configuration settings
50
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
51
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
52
+ * @returns Complete credential configuration object
53
+ */
54
+ export declare function createCredentialConfig(sipUser: string, sipPassword: string, options?: Partial<Omit<CredentialConfig, 'type' | 'sipUser' | 'sipPassword'>>): CredentialConfig;
55
+ /**
56
+ * Creates a token-based configuration
57
+ *
58
+ * @param sipToken - JWT token for authentication
59
+ * @param options - Optional configuration settings
60
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
61
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
62
+ * @returns Complete token configuration object
63
+ */
64
+ export declare function createTokenConfig(sipToken: string, options?: Partial<Omit<TokenConfig, 'type' | 'sipToken'>>): TokenConfig;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCredentialConfig = isCredentialConfig;
4
+ exports.isTokenConfig = isTokenConfig;
5
+ exports.validateCredentialConfig = validateCredentialConfig;
6
+ exports.validateTokenConfig = validateTokenConfig;
7
+ exports.validateConfig = validateConfig;
8
+ exports.createCredentialConfig = createCredentialConfig;
9
+ exports.createTokenConfig = createTokenConfig;
10
+ /**
11
+ * Type guard to check if config is credential-based
12
+ */
13
+ function isCredentialConfig(config) {
14
+ return config.type === 'credential';
15
+ }
16
+ /**
17
+ * Type guard to check if config is token-based
18
+ */
19
+ function isTokenConfig(config) {
20
+ return config.type === 'token';
21
+ }
22
+ /**
23
+ * Validates a credential configuration
24
+ */
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;
34
+ }
35
+ /**
36
+ * Validates a token configuration
37
+ */
38
+ function validateTokenConfig(config) {
39
+ const errors = [];
40
+ if (!config.token || config.token.trim() === '') {
41
+ errors.push('token is required');
42
+ }
43
+ return errors;
44
+ }
45
+ /**
46
+ * Validates any configuration
47
+ */
48
+ function validateConfig(config) {
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
+ }
58
+ }
59
+ /**
60
+ * Creates a credential configuration
61
+ *
62
+ * @param sipUser - SIP username for authentication
63
+ * @param sipPassword - SIP password for authentication
64
+ * @param options - Optional configuration settings
65
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
66
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
67
+ * @returns Complete credential configuration object
68
+ */
69
+ function createCredentialConfig(sipUser, sipPassword, options) {
70
+ return {
71
+ type: 'credential',
72
+ sipUser,
73
+ sipPassword,
74
+ ...options,
75
+ };
76
+ }
77
+ /**
78
+ * Creates a token-based configuration
79
+ *
80
+ * @param sipToken - JWT token for authentication
81
+ * @param options - Optional configuration settings
82
+ * @param options.debug - Enable debug logging (sets SDK logLevel to 'debug')
83
+ * @param options.pushNotificationDeviceToken - Device token for push notifications
84
+ * @returns Complete token configuration object
85
+ */
86
+ function createTokenConfig(sipToken, options) {
87
+ return {
88
+ type: 'token',
89
+ token: sipToken,
90
+ ...options,
91
+ };
92
+ }
@@ -0,0 +1,34 @@
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 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"
18
+ }
19
+ /**
20
+ * Type guard to check if a value is a valid TelnyxConnectionState
21
+ */
22
+ export declare function isTelnyxConnectionState(value: any): value is TelnyxConnectionState;
23
+ /**
24
+ * Helper function to determine if the connection state allows making calls
25
+ */
26
+ export declare function canMakeCalls(state: TelnyxConnectionState): boolean;
27
+ /**
28
+ * Helper function to determine if the connection state indicates an active connection
29
+ */
30
+ export declare function isConnected(state: TelnyxConnectionState): boolean;
31
+ /**
32
+ * Helper function to determine if the connection is in a transitional state
33
+ */
34
+ export declare function isTransitioning(state: TelnyxConnectionState): boolean;