@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,385 @@
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.SessionManager = void 0;
37
+ const rxjs_1 = require("rxjs");
38
+ const operators_1 = require("rxjs/operators");
39
+ const TelnyxSDK = __importStar(require("@telnyx/react-native-voice-sdk"));
40
+ const connection_state_1 = require("../../models/connection-state");
41
+ const config_1 = require("../../models/config");
42
+ /**
43
+ * Manages the connection lifecycle to the Telnyx platform.
44
+ *
45
+ * This class handles authentication, connection state management,
46
+ * and automatic reconnection logic.
47
+ */
48
+ class SessionManager {
49
+ constructor() {
50
+ this._connectionState = new rxjs_1.BehaviorSubject(connection_state_1.TelnyxConnectionState.DISCONNECTED);
51
+ this._disposed = false;
52
+ this._sessionId = this._generateSessionId();
53
+ }
54
+ /**
55
+ * Observable stream of connection state changes
56
+ */
57
+ get connectionState$() {
58
+ return this._connectionState.asObservable().pipe((0, operators_1.distinctUntilChanged)());
59
+ }
60
+ /**
61
+ * Set callback to be called when the Telnyx client is ready
62
+ */
63
+ setOnClientReady(callback) {
64
+ this._onClientReady = callback;
65
+ }
66
+ /**
67
+ * Current connection state (synchronous access)
68
+ */
69
+ get currentState() {
70
+ return this._connectionState.value;
71
+ }
72
+ /**
73
+ * Current session ID
74
+ */
75
+ get sessionId() {
76
+ return this._sessionId;
77
+ }
78
+ /**
79
+ * Get the underlying Telnyx client instance
80
+ */
81
+ get telnyxClient() {
82
+ return this._telnyxClient;
83
+ }
84
+ /**
85
+ * Connect using credential authentication
86
+ */
87
+ async connectWithCredential(config) {
88
+ if (this._disposed) {
89
+ throw new Error('SessionManager has been disposed');
90
+ }
91
+ this._currentConfig = config;
92
+ await this._connect();
93
+ }
94
+ /**
95
+ * Connect using token authentication
96
+ */
97
+ async connectWithToken(config) {
98
+ if (this._disposed) {
99
+ throw new Error('SessionManager has been disposed');
100
+ }
101
+ this._currentConfig = config;
102
+ await this._connect();
103
+ }
104
+ /**
105
+ * Disconnect from the Telnyx platform
106
+ */
107
+ async disconnect() {
108
+ if (this._disposed) {
109
+ return;
110
+ }
111
+ this._currentConfig = undefined;
112
+ if (this._telnyxClient) {
113
+ try {
114
+ await this._telnyxClient.disconnect();
115
+ }
116
+ catch (error) {
117
+ console.error('Error during disconnect:', error);
118
+ }
119
+ }
120
+ this._connectionState.next(connection_state_1.TelnyxConnectionState.DISCONNECTED);
121
+ }
122
+ /**
123
+ * Disable push notifications for the current session
124
+ */
125
+ disablePushNotifications() {
126
+ if (this._telnyxClient && this.currentState === connection_state_1.TelnyxConnectionState.CONNECTED) {
127
+ // Implementation depends on the actual Telnyx SDK API
128
+ // This is a placeholder for the actual implementation
129
+ console.log('Disabling push notifications for session:', this._sessionId);
130
+ }
131
+ }
132
+ /**
133
+ * Handle push notification with stored config
134
+ */
135
+ handlePushNotificationWithConfig(pushMetaData, config) {
136
+ if (this._disposed) {
137
+ return;
138
+ }
139
+ this._currentConfig = config;
140
+ // Implementation for handling push notifications
141
+ // This would integrate with the actual Telnyx SDK push handling
142
+ console.log('Handling push notification with config:', { pushMetaData, config: config.type });
143
+ }
144
+ /**
145
+ * Handle push notification (async version)
146
+ */
147
+ async handlePushNotification(payload) {
148
+ if (this._disposed) {
149
+ return;
150
+ }
151
+ console.log('SessionManager: RELEASE DEBUG - Processing push notification, payload:', JSON.stringify(payload));
152
+ // Store the push notification payload for when the client is created
153
+ this._pendingPushPayload = payload;
154
+ // If we don't have a config yet but we're processing a push notification,
155
+ // attempt to load stored config first (for terminated app startup)
156
+ if (!this._currentConfig && !this._telnyxClient) {
157
+ console.log('SessionManager: RELEASE DEBUG - No config available, attempting to load from stored config for push notification');
158
+ try {
159
+ // Try to retrieve stored credentials and token from AsyncStorage
160
+ const AsyncStorage = require('@react-native-async-storage/async-storage').default;
161
+ const storedUsername = await AsyncStorage.getItem('@telnyx_username');
162
+ const storedPassword = await AsyncStorage.getItem('@telnyx_password');
163
+ const storedCredentialToken = await AsyncStorage.getItem('@credential_token');
164
+ const storedPushToken = await AsyncStorage.getItem('@push_token');
165
+ // Check if we have credential-based authentication data
166
+ if (storedUsername && storedPassword) {
167
+ console.log('SessionManager: RELEASE DEBUG - Found stored credentials, creating config');
168
+ const { createCredentialConfig } = require('../../models/config');
169
+ this._currentConfig = createCredentialConfig(storedUsername, storedPassword, {
170
+ pushNotificationDeviceToken: storedPushToken,
171
+ });
172
+ }
173
+ // Check if we have token-based authentication data
174
+ else if (storedCredentialToken) {
175
+ console.log('SessionManager: RELEASE DEBUG - Found stored token, creating config');
176
+ const { createTokenConfig } = require('../../models/config');
177
+ this._currentConfig = createTokenConfig(storedCredentialToken, {
178
+ pushNotificationDeviceToken: storedPushToken,
179
+ });
180
+ }
181
+ if (this._currentConfig) {
182
+ console.log('SessionManager: RELEASE DEBUG - Successfully loaded stored config for push notification');
183
+ }
184
+ else {
185
+ console.log('SessionManager: RELEASE DEBUG - No stored authentication data found');
186
+ }
187
+ }
188
+ catch (error) {
189
+ console.warn('SessionManager: Failed to load stored config for push notification:', error);
190
+ }
191
+ }
192
+ // If we already have a client, process the push notification immediately
193
+ if (this._telnyxClient) {
194
+ console.log('SessionManager: RELEASE DEBUG - Client available, processing push notification immediately');
195
+ // Use type assertion to access the processVoIPNotification method
196
+ // This method sets the isCallFromPush flag which is needed for proper push handling
197
+ if (typeof this._telnyxClient.processVoIPNotification === 'function') {
198
+ console.log('SessionManager: RELEASE DEBUG - Calling processVoIPNotification with payload:', JSON.stringify(payload));
199
+ // Extract the actual push notification metadata that the client expects
200
+ const actualPayload = this._extractPushPayload(payload);
201
+ this._telnyxClient.processVoIPNotification(actualPayload);
202
+ console.log('SessionManager: RELEASE DEBUG - Called processVoIPNotification successfully');
203
+ }
204
+ else {
205
+ console.warn('SessionManager: processVoIPNotification method not available on TelnyxRTC client');
206
+ }
207
+ // Clear the pending payload since it was processed
208
+ this._pendingPushPayload = null;
209
+ }
210
+ else {
211
+ console.log('SessionManager: RELEASE DEBUG - No client available, checking if we can trigger immediate connection');
212
+ // If we have config (either existing or newly loaded from storage) and are disconnected, trigger immediate connection
213
+ // The _connect() method will process the pending push payload BEFORE calling connect()
214
+ if (this._currentConfig && this.currentState === connection_state_1.TelnyxConnectionState.DISCONNECTED) {
215
+ console.log('SessionManager: RELEASE DEBUG - Triggering immediate connection for push notification with config type:', this._currentConfig.type || 'credential');
216
+ try {
217
+ await this._connect();
218
+ console.log('SessionManager: RELEASE DEBUG - Successfully connected after push notification trigger');
219
+ }
220
+ catch (error) {
221
+ console.error('SessionManager: Failed to connect after push notification trigger:', error);
222
+ }
223
+ }
224
+ else {
225
+ console.log('SessionManager: RELEASE DEBUG - Cannot trigger connection, config available:', !!this._currentConfig, 'current state:', this.currentState);
226
+ console.log('SessionManager: RELEASE DEBUG - Push payload stored for later processing when client becomes available');
227
+ }
228
+ }
229
+ console.log('SessionManager: RELEASE DEBUG - Push notification handling complete');
230
+ }
231
+ /**
232
+ * Dispose of the session manager and clean up resources
233
+ */
234
+ dispose() {
235
+ if (this._disposed) {
236
+ return;
237
+ }
238
+ this._disposed = true;
239
+ this.disconnect();
240
+ this._connectionState.complete();
241
+ }
242
+ /**
243
+ * Internal method to establish connection
244
+ */
245
+ async _connect() {
246
+ if (!this._currentConfig) {
247
+ throw new Error('No configuration provided');
248
+ }
249
+ this._connectionState.next(connection_state_1.TelnyxConnectionState.CONNECTING);
250
+ try {
251
+ // Clean up existing client
252
+ if (this._telnyxClient) {
253
+ await this._telnyxClient.disconnect();
254
+ }
255
+ // Create new client instance with authentication options
256
+ let clientOptions;
257
+ if ((0, config_1.isCredentialConfig)(this._currentConfig)) {
258
+ clientOptions = {
259
+ login: this._currentConfig.sipUser,
260
+ password: this._currentConfig.sipPassword,
261
+ logLevel: this._currentConfig.debug ? 'debug' : 'warn',
262
+ pushNotificationDeviceToken: this._currentConfig.pushNotificationDeviceToken,
263
+ };
264
+ console.log('🔧 SessionManager: Creating TelnyxRTC with credential config, logLevel:', clientOptions.logLevel, 'pushToken:', !!this._currentConfig.pushNotificationDeviceToken);
265
+ }
266
+ else if ((0, config_1.isTokenConfig)(this._currentConfig)) {
267
+ clientOptions = {
268
+ login_token: this._currentConfig.token,
269
+ logLevel: this._currentConfig.debug ? 'debug' : 'warn',
270
+ pushNotificationDeviceToken: this._currentConfig.pushNotificationDeviceToken,
271
+ };
272
+ console.log('🔧 SessionManager: Creating TelnyxRTC with token config, logLevel:', clientOptions.logLevel, 'pushToken:', !!this._currentConfig.pushNotificationDeviceToken);
273
+ }
274
+ else {
275
+ throw new Error('Invalid configuration type');
276
+ }
277
+ this._telnyxClient = new TelnyxSDK.TelnyxRTC(clientOptions);
278
+ // CRITICAL: Process any pending push notification payload BEFORE connecting
279
+ // This ensures voice_sdk_id and other payload variables are set before connect() is called
280
+ const pendingPushPayload = this._pendingPushPayload;
281
+ if (pendingPushPayload) {
282
+ console.log('SessionManager: RELEASE DEBUG - Processing pending push notification BEFORE connect:', JSON.stringify(pendingPushPayload));
283
+ if (typeof this._telnyxClient.processVoIPNotification === 'function') {
284
+ console.log('SessionManager: RELEASE DEBUG - Calling processVoIPNotification BEFORE connect to set voice_sdk_id');
285
+ // Extract the actual push notification metadata that the client expects
286
+ const actualPayload = this._extractPushPayload(pendingPushPayload);
287
+ this._telnyxClient.processVoIPNotification(actualPayload);
288
+ console.log('SessionManager: RELEASE DEBUG - Successfully processed pending push notification before connect');
289
+ }
290
+ else {
291
+ console.warn('SessionManager: processVoIPNotification method not available on new client');
292
+ }
293
+ // Clear the pending payload
294
+ this._pendingPushPayload = null;
295
+ }
296
+ this._setupClientListeners();
297
+ // Set up CallStateController listeners immediately after client creation
298
+ // This ensures they're ready before any incoming call events are emitted
299
+ console.log('🔧 SessionManager: Setting up CallStateController listeners before connection...');
300
+ if (this._onClientReady) {
301
+ this._onClientReady();
302
+ }
303
+ // Connect to the platform AFTER processing push notification
304
+ console.log('SessionManager: RELEASE DEBUG - About to call connect() after processing push notification');
305
+ await this._telnyxClient.connect();
306
+ // Notify that client is ready for event listeners
307
+ console.log('🔧 SessionManager: Client connected successfully');
308
+ }
309
+ catch (error) {
310
+ console.error('Connection failed:', error);
311
+ this._connectionState.next(connection_state_1.TelnyxConnectionState.ERROR);
312
+ throw error;
313
+ }
314
+ }
315
+ /**
316
+ * Set up event listeners for the Telnyx client
317
+ */
318
+ _setupClientListeners() {
319
+ if (!this._telnyxClient) {
320
+ return;
321
+ }
322
+ this._telnyxClient.on('telnyx.client.ready', () => {
323
+ console.log('Telnyx client ready');
324
+ this._connectionState.next(connection_state_1.TelnyxConnectionState.CONNECTED);
325
+ });
326
+ this._telnyxClient.on('telnyx.client.error', (error) => {
327
+ console.error('Telnyx client error:', error);
328
+ this._connectionState.next(connection_state_1.TelnyxConnectionState.ERROR);
329
+ });
330
+ // Note: Socket-level events are not exposed in the current SDK
331
+ // We'll rely on the client-level events for now
332
+ }
333
+ /**
334
+ * Attempt to reconnect after connection loss
335
+ */
336
+ async _attemptReconnection() {
337
+ if (this._disposed || !this._currentConfig) {
338
+ return;
339
+ }
340
+ // Simple reconnection logic - in production, this should include
341
+ // exponential backoff and maximum retry attempts
342
+ setTimeout(async () => {
343
+ if (this.currentState === connection_state_1.TelnyxConnectionState.RECONNECTING) {
344
+ try {
345
+ await this._connect();
346
+ }
347
+ catch (error) {
348
+ console.error('Reconnection failed:', error);
349
+ // Could implement retry logic here
350
+ }
351
+ }
352
+ }, 3000);
353
+ }
354
+ /**
355
+ * Extract the actual payload metadata from wrapped push notification payload
356
+ */
357
+ _extractPushPayload(payload) {
358
+ // The payload might be wrapped, so we need to extract the core metadata
359
+ let actualPayload = payload;
360
+ if (payload.metadata && typeof payload.metadata === 'object') {
361
+ // If there's a metadata wrapper, use that
362
+ actualPayload = payload.metadata;
363
+ console.log('SessionManager: RELEASE DEBUG - Using metadata portion of payload:', JSON.stringify(actualPayload));
364
+ }
365
+ else if (payload.action === 'incoming_call' && payload.metadata) {
366
+ // Handle the case where metadata is a string that needs parsing
367
+ try {
368
+ const parsedMetadata = typeof payload.metadata === 'string' ? JSON.parse(payload.metadata) : payload.metadata;
369
+ actualPayload = parsedMetadata;
370
+ console.log('SessionManager: RELEASE DEBUG - Using parsed metadata:', JSON.stringify(actualPayload));
371
+ }
372
+ catch (error) {
373
+ console.warn('SessionManager: Failed to parse metadata:', error);
374
+ }
375
+ }
376
+ return actualPayload;
377
+ }
378
+ /**
379
+ * Generate a unique session ID
380
+ */
381
+ _generateSessionId() {
382
+ return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
383
+ }
384
+ }
385
+ exports.SessionManager = SessionManager;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Helper functions that use VoicePnBridge for UserDefaults functionality on iOS
3
+ * These functions provide the same interface as the UserDefaultsModule from main branch
4
+ * but route through the VoicePnBridge instead
5
+ */
6
+ export declare function getVoipToken(): Promise<string | null>;
7
+ export declare function getPendingVoipPush(): Promise<string | null>;
8
+ export declare function clearPendingVoipPush(): Promise<boolean>;
9
+ export declare function getPendingVoipAction(): Promise<string | null>;
10
+ export declare function clearPendingVoipAction(): Promise<boolean>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVoipToken = getVoipToken;
4
+ exports.getPendingVoipPush = getPendingVoipPush;
5
+ exports.clearPendingVoipPush = clearPendingVoipPush;
6
+ exports.getPendingVoipAction = getPendingVoipAction;
7
+ exports.clearPendingVoipAction = clearPendingVoipAction;
8
+ const voice_pn_bridge_1 = require("./voice-pn-bridge");
9
+ const react_native_1 = require("react-native");
10
+ /**
11
+ * Helper functions that use VoicePnBridge for UserDefaults functionality on iOS
12
+ * These functions provide the same interface as the UserDefaultsModule from main branch
13
+ * but route through the VoicePnBridge instead
14
+ */
15
+ async function getVoipToken() {
16
+ if (react_native_1.Platform.OS !== 'ios')
17
+ return null;
18
+ try {
19
+ return await voice_pn_bridge_1.VoicePnBridge.getVoipToken();
20
+ }
21
+ catch (error) {
22
+ console.warn('[UserDefaults] getVoipToken error:', error);
23
+ return null;
24
+ }
25
+ }
26
+ async function getPendingVoipPush() {
27
+ if (react_native_1.Platform.OS !== 'ios')
28
+ return null;
29
+ try {
30
+ return await voice_pn_bridge_1.VoicePnBridge.getPendingVoipPush();
31
+ }
32
+ catch (error) {
33
+ console.warn('[UserDefaults] getPendingVoipPush error:', error);
34
+ return null;
35
+ }
36
+ }
37
+ async function clearPendingVoipPush() {
38
+ if (react_native_1.Platform.OS !== 'ios')
39
+ return true;
40
+ try {
41
+ return await voice_pn_bridge_1.VoicePnBridge.clearPendingVoipPush();
42
+ }
43
+ catch (error) {
44
+ console.warn('[UserDefaults] clearPendingVoipPush error:', error);
45
+ return false;
46
+ }
47
+ }
48
+ async function getPendingVoipAction() {
49
+ if (react_native_1.Platform.OS !== 'ios')
50
+ return null;
51
+ try {
52
+ return await voice_pn_bridge_1.VoicePnBridge.getPendingVoipAction();
53
+ }
54
+ catch (error) {
55
+ console.warn('[UserDefaults] getPendingVoipAction error:', error);
56
+ return null;
57
+ }
58
+ }
59
+ async function clearPendingVoipAction() {
60
+ if (react_native_1.Platform.OS !== 'ios')
61
+ return true;
62
+ try {
63
+ return await voice_pn_bridge_1.VoicePnBridge.clearPendingVoipAction();
64
+ }
65
+ catch (error) {
66
+ console.warn('[UserDefaults] clearPendingVoipAction error:', error);
67
+ return false;
68
+ }
69
+ }
@@ -0,0 +1,14 @@
1
+ export interface VoicePnBridgeInterface {
2
+ getPendingPushAction(): Promise<{
3
+ action: string | null;
4
+ metadata: string | null;
5
+ }>;
6
+ setPendingPushAction(action: string, metadata: string): Promise<boolean>;
7
+ clearPendingPushAction(): Promise<boolean>;
8
+ getVoipToken(): Promise<string | null>;
9
+ getPendingVoipPush(): Promise<string | null>;
10
+ clearPendingVoipPush(): Promise<boolean>;
11
+ getPendingVoipAction(): Promise<string | null>;
12
+ clearPendingVoipAction(): Promise<boolean>;
13
+ }
14
+ export declare const VoicePnBridge: VoicePnBridgeInterface;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoicePnBridge = void 0;
4
+ const react_native_1 = require("react-native");
5
+ exports.VoicePnBridge = react_native_1.NativeModules.VoicePnBridge;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Represents the state of a call in the Telnyx system.
3
+ *
4
+ * This enum provides a simplified view of call states, abstracting away
5
+ * the complexity of the underlying SIP call states.
6
+ */
7
+ export declare enum TelnyxCallState {
8
+ /** Call is being initiated (outgoing) or received (incoming) */
9
+ RINGING = "RINGING",
10
+ /** Call is connecting after being answered (usually from push notification) */
11
+ CONNECTING = "CONNECTING",
12
+ /** Call has been answered and media is flowing */
13
+ ACTIVE = "ACTIVE",
14
+ /** Call is on hold */
15
+ HELD = "HELD",
16
+ /** Call has ended normally */
17
+ ENDED = "ENDED",
18
+ /** Call failed to connect or was rejected */
19
+ FAILED = "FAILED"
20
+ }
21
+ /**
22
+ * Type guard to check if a value is a valid TelnyxCallState
23
+ */
24
+ export declare function isTelnyxCallState(value: any): value is TelnyxCallState;
25
+ /**
26
+ * Helper functions to determine what actions are available in each state
27
+ */
28
+ export declare const CallStateHelpers: {
29
+ /**
30
+ * Can the call be answered in this state?
31
+ */
32
+ canAnswer(state: TelnyxCallState): boolean;
33
+ /**
34
+ * Can the call be hung up in this state?
35
+ */
36
+ canHangup(state: TelnyxCallState): boolean;
37
+ /**
38
+ * Can the call be put on hold in this state?
39
+ */
40
+ canHold(state: TelnyxCallState): boolean;
41
+ /**
42
+ * Can the call be resumed from hold in this state?
43
+ */
44
+ canResume(state: TelnyxCallState): boolean;
45
+ /**
46
+ * Can the call be muted/unmuted in this state?
47
+ */
48
+ canToggleMute(state: TelnyxCallState): boolean;
49
+ /**
50
+ * Is the call in a terminated state?
51
+ */
52
+ isTerminated(state: TelnyxCallState): boolean;
53
+ /**
54
+ * Is the call in an active state (can have media)?
55
+ */
56
+ isActive(state: TelnyxCallState): boolean;
57
+ /**
58
+ * Is the call in a connecting state (answered but not yet active)?
59
+ */
60
+ isConnecting(state: TelnyxCallState): boolean;
61
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallStateHelpers = exports.TelnyxCallState = void 0;
4
+ exports.isTelnyxCallState = isTelnyxCallState;
5
+ /**
6
+ * Represents the state of a call in the Telnyx system.
7
+ *
8
+ * This enum provides a simplified view of call states, abstracting away
9
+ * the complexity of the underlying SIP call states.
10
+ */
11
+ var TelnyxCallState;
12
+ (function (TelnyxCallState) {
13
+ /** Call is being initiated (outgoing) or received (incoming) */
14
+ TelnyxCallState["RINGING"] = "RINGING";
15
+ /** Call is connecting after being answered (usually from push notification) */
16
+ TelnyxCallState["CONNECTING"] = "CONNECTING";
17
+ /** Call has been answered and media is flowing */
18
+ TelnyxCallState["ACTIVE"] = "ACTIVE";
19
+ /** Call is on hold */
20
+ TelnyxCallState["HELD"] = "HELD";
21
+ /** Call has ended normally */
22
+ TelnyxCallState["ENDED"] = "ENDED";
23
+ /** Call failed to connect or was rejected */
24
+ TelnyxCallState["FAILED"] = "FAILED";
25
+ })(TelnyxCallState || (exports.TelnyxCallState = TelnyxCallState = {}));
26
+ /**
27
+ * Type guard to check if a value is a valid TelnyxCallState
28
+ */
29
+ function isTelnyxCallState(value) {
30
+ return Object.values(TelnyxCallState).includes(value);
31
+ }
32
+ /**
33
+ * Helper functions to determine what actions are available in each state
34
+ */
35
+ exports.CallStateHelpers = {
36
+ /**
37
+ * Can the call be answered in this state?
38
+ */
39
+ canAnswer(state) {
40
+ return state === TelnyxCallState.RINGING;
41
+ },
42
+ /**
43
+ * Can the call be hung up in this state?
44
+ */
45
+ canHangup(state) {
46
+ return (state === TelnyxCallState.RINGING ||
47
+ state === TelnyxCallState.CONNECTING ||
48
+ state === TelnyxCallState.ACTIVE ||
49
+ state === TelnyxCallState.HELD);
50
+ },
51
+ /**
52
+ * Can the call be put on hold in this state?
53
+ */
54
+ canHold(state) {
55
+ return state === TelnyxCallState.ACTIVE;
56
+ },
57
+ /**
58
+ * Can the call be resumed from hold in this state?
59
+ */
60
+ canResume(state) {
61
+ return state === TelnyxCallState.HELD;
62
+ },
63
+ /**
64
+ * Can the call be muted/unmuted in this state?
65
+ */
66
+ canToggleMute(state) {
67
+ return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
68
+ },
69
+ /**
70
+ * Is the call in a terminated state?
71
+ */
72
+ isTerminated(state) {
73
+ return state === TelnyxCallState.ENDED || state === TelnyxCallState.FAILED;
74
+ },
75
+ /**
76
+ * Is the call in an active state (can have media)?
77
+ */
78
+ isActive(state) {
79
+ return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
80
+ },
81
+ /**
82
+ * Is the call in a connecting state (answered but not yet active)?
83
+ */
84
+ isConnecting(state) {
85
+ return state === TelnyxCallState.CONNECTING;
86
+ },
87
+ };