@telnyx/react-voice-commons-sdk 0.1.2 → 0.1.4

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 (55) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +469 -483
  3. package/ios/CallKitBridge.swift +2 -7
  4. package/lib/callkit/callkit-coordinator.d.ts +110 -117
  5. package/lib/callkit/callkit-coordinator.js +664 -727
  6. package/lib/callkit/callkit.d.ts +41 -41
  7. package/lib/callkit/callkit.js +252 -242
  8. package/lib/callkit/index.js +15 -47
  9. package/lib/callkit/use-callkit.d.ts +19 -19
  10. package/lib/callkit/use-callkit.js +270 -310
  11. package/lib/context/TelnyxVoiceContext.d.ts +9 -9
  12. package/lib/context/TelnyxVoiceContext.js +10 -13
  13. package/lib/hooks/use-callkit-coordinator.d.ts +9 -17
  14. package/lib/hooks/use-callkit-coordinator.js +45 -50
  15. package/lib/hooks/useAppReadyNotifier.js +13 -15
  16. package/lib/hooks/useAppStateHandler.d.ts +6 -11
  17. package/lib/hooks/useAppStateHandler.js +95 -110
  18. package/lib/hooks/useNetworkStateHandler.d.ts +0 -0
  19. package/lib/hooks/useNetworkStateHandler.js +0 -0
  20. package/lib/index.d.ts +3 -21
  21. package/lib/index.js +50 -201
  22. package/lib/internal/CallKitHandler.d.ts +6 -6
  23. package/lib/internal/CallKitHandler.js +96 -104
  24. package/lib/internal/callkit-manager.d.ts +57 -57
  25. package/lib/internal/callkit-manager.js +299 -316
  26. package/lib/internal/calls/call-state-controller.d.ts +73 -86
  27. package/lib/internal/calls/call-state-controller.js +263 -307
  28. package/lib/internal/session/session-manager.d.ts +71 -75
  29. package/lib/internal/session/session-manager.js +360 -424
  30. package/lib/internal/user-defaults-helpers.js +49 -39
  31. package/lib/internal/voice-pn-bridge.d.ts +114 -12
  32. package/lib/internal/voice-pn-bridge.js +212 -5
  33. package/lib/models/call-state.d.ts +46 -44
  34. package/lib/models/call-state.js +70 -68
  35. package/lib/models/call.d.ts +161 -133
  36. package/lib/models/call.js +454 -382
  37. package/lib/models/config.d.ts +11 -18
  38. package/lib/models/config.js +37 -35
  39. package/lib/models/connection-state.d.ts +10 -10
  40. package/lib/models/connection-state.js +16 -16
  41. package/lib/telnyx-voice-app.d.ts +28 -28
  42. package/lib/telnyx-voice-app.js +513 -480
  43. package/lib/telnyx-voip-client.d.ts +167 -167
  44. package/lib/telnyx-voip-client.js +385 -390
  45. package/package.json +115 -104
  46. package/src/callkit/callkit-coordinator.ts +830 -846
  47. package/src/hooks/useNetworkStateHandler.ts +0 -0
  48. package/src/internal/calls/call-state-controller.ts +407 -384
  49. package/src/internal/session/session-manager.ts +483 -467
  50. package/src/internal/voice-pn-bridge.ts +266 -18
  51. package/src/models/call-state.ts +105 -98
  52. package/src/models/call.ts +502 -388
  53. package/src/telnyx-voice-app.tsx +788 -690
  54. package/src/telnyx-voip-client.ts +551 -539
  55. package/src/types/telnyx-sdk.d.ts +93 -79
@@ -1,61 +1,42 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- (function () {
34
- var ownKeys = function (o) {
35
- ownKeys =
36
- Object.getOwnPropertyNames ||
37
- function (o) {
38
- var ar = [];
39
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
- return ar;
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;
41
24
  };
42
- return ownKeys(o);
25
+ return ownKeys(o);
43
26
  };
44
27
  return function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null)
48
- for (var k = ownKeys(mod), i = 0; i < k.length; i++)
49
- if (k[i] !== 'default') __createBinding(result, mod, k[i]);
50
- __setModuleDefault(result, mod);
51
- return result;
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;
52
33
  };
53
- })();
54
- Object.defineProperty(exports, '__esModule', { value: true });
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
55
36
  exports.CallKitManager = void 0;
56
- const react_native_1 = require('react-native');
57
- const callkit_1 = __importStar(require('../callkit/callkit'));
58
- const call_state_1 = require('../models/call-state');
37
+ const react_native_1 = require("react-native");
38
+ const callkit_1 = __importStar(require("../callkit/callkit"));
39
+ const call_state_1 = require("../models/call-state");
59
40
  /**
60
41
  * Internal CallKit integration manager for react-voice-commons.
61
42
  *
@@ -65,279 +46,281 @@ const call_state_1 = require('../models/call-state');
65
46
  * @internal
66
47
  */
67
48
  class CallKitManager {
68
- constructor() {
69
- this._callMappings = new Map(); // Call ID -> CallKit UUID
70
- this._reverseCallMappings = new Map(); // CallKit UUID -> Call ID
71
- this._isEnabled = false;
72
- // DISABLED: Using external CallKit implementations (useCallKit, useCallKitCoordinator)
73
- this._isEnabled = false; // Disable to prevent conflicts
74
- console.log('🔧 CallKitManager: Initialized');
75
- console.log('🔧 CallKitManager: Platform.OS =', react_native_1.Platform.OS);
76
- console.log('🔧 CallKitManager: CallKit.isAvailable() =', callkit_1.default.isAvailable());
77
- console.log(
78
- '🔧 CallKitManager: _isEnabled =',
79
- this._isEnabled,
80
- '(DISABLED to use external CallKit)'
81
- );
82
- // DISABLED: Conflicts with external CallKit implementations (useCallKit, useCallKitCoordinator)
83
- // if (this._isEnabled) {
84
- // this._setupCallKitEventListeners();
85
- // }
86
- console.log(
87
- '🔧 CallKitManager: Automatic CallKit integration DISABLED - using external CallKit implementations'
88
- );
89
- }
90
- /**
91
- * Set up CallKit event listeners to handle user actions
92
- */
93
- _setupCallKitEventListeners() {
94
- console.log('🔧 CallKitManager: Setting up CallKit event listeners');
95
- // Listen for answer actions from CallKit
96
- callkit_1.default.onAnswerCall((event) => {
97
- console.log('📞 CallKitManager: CallKit answer event received:', event);
98
- this._handleCallKitAnswer(event.callUUID);
99
- });
100
- // Listen for end actions from CallKit
101
- callkit_1.default.onEndCall((event) => {
102
- console.log('📞 CallKitManager: CallKit end event received:', event);
103
- this._handleCallKitEnd(event.callUUID);
104
- });
105
- console.log('🔧 CallKitManager: CallKit event listeners set up');
106
- }
107
- /**
108
- * Initialize CallKit integration
109
- */
110
- initialize(onAnswerCall, onEndCall) {
111
- if (!this._isEnabled) return;
112
- try {
113
- // This would need to be called from a React component context
114
- // For now, we'll handle this differently in the call-state-controller
115
- console.log('CallKitManager: CallKit integration initialized');
116
- } catch (error) {
117
- console.warn('CallKitManager: Failed to initialize CallKit:', error);
118
- this._isEnabled = false;
49
+ constructor() {
50
+ this._callMappings = new Map(); // Call ID -> CallKit UUID
51
+ this._reverseCallMappings = new Map(); // CallKit UUID -> Call ID
52
+ this._isEnabled = false;
53
+ // DISABLED: Using external CallKit implementations (useCallKit, useCallKitCoordinator)
54
+ this._isEnabled = false; // Disable to prevent conflicts
55
+ console.log('🔧 CallKitManager: Initialized');
56
+ console.log('🔧 CallKitManager: Platform.OS =', react_native_1.Platform.OS);
57
+ console.log('🔧 CallKitManager: CallKit.isAvailable() =', callkit_1.default.isAvailable());
58
+ console.log('🔧 CallKitManager: _isEnabled =', this._isEnabled, '(DISABLED to use external CallKit)');
59
+ // DISABLED: Conflicts with external CallKit implementations (useCallKit, useCallKitCoordinator)
60
+ // if (this._isEnabled) {
61
+ // this._setupCallKitEventListeners();
62
+ // }
63
+ console.log('🔧 CallKitManager: Automatic CallKit integration DISABLED - using external CallKit implementations');
119
64
  }
120
- }
121
- /**
122
- * Handle outgoing call - start CallKit session
123
- */
124
- async handleOutgoingCall(call) {
125
- console.log('🔵 CallKitManager.handleOutgoingCall() CALLED');
126
- console.log('🔵 CallKitManager: call.callId =', call.callId);
127
- console.log('🔵 CallKitManager: call.destination =', call.destination);
128
- console.log('🔵 CallKitManager: call.isIncoming =', call.isIncoming);
129
- console.log('🔵 CallKitManager: _isEnabled =', this._isEnabled);
130
- if (!this._isEnabled) {
131
- console.log('🔴 CallKitManager: CallKit NOT ENABLED - skipping outgoing call');
132
- return null;
65
+ /**
66
+ * Set up CallKit event listeners to handle user actions
67
+ */
68
+ _setupCallKitEventListeners() {
69
+ console.log('🔧 CallKitManager: Setting up CallKit event listeners');
70
+ // Listen for answer actions from CallKit
71
+ callkit_1.default.onAnswerCall((event) => {
72
+ console.log('📞 CallKitManager: CallKit answer event received:', event);
73
+ this._handleCallKitAnswer(event.callUUID);
74
+ });
75
+ // Listen for end actions from CallKit
76
+ callkit_1.default.onEndCall((event) => {
77
+ console.log('📞 CallKitManager: CallKit end event received:', event);
78
+ this._handleCallKitEnd(event.callUUID);
79
+ });
80
+ console.log('🔧 CallKitManager: CallKit event listeners set up');
133
81
  }
134
- try {
135
- console.log('🔵 CallKitManager: Starting CallKit session for outgoing call:', call.callId);
136
- const callKitUUID = callkit_1.default.generateCallUUID();
137
- console.log('🔵 CallKitManager: Generated CallKit UUID:', callKitUUID);
138
- // Call the native CallKit bridge
139
- console.log('🔵 CallKitManager: Calling native CallKit.startOutgoingCall...');
140
- const success = await callkit_1.default.startOutgoingCall(
141
- callKitUUID,
142
- call.destination,
143
- call.destination // Using destination as display name for now
144
- );
145
- if (success) {
146
- console.log('CallKitManager: Native CallKit.startOutgoingCall SUCCESS!');
147
- this._callMappings.set(call.callId, callKitUUID);
148
- console.log('� CallKitManager: Stored call mapping:', call.callId, '->', callKitUUID);
149
- return callKitUUID;
150
- } else {
151
- console.log('� CallKitManager: Native CallKit.startOutgoingCall FAILED');
152
- return null;
153
- }
154
- } catch (error) {
155
- console.error('🔴 CallKitManager: Failed to start outgoing call:', error);
156
- return null;
82
+ /**
83
+ * Initialize CallKit integration
84
+ */
85
+ initialize(onAnswerCall, onEndCall) {
86
+ if (!this._isEnabled)
87
+ return;
88
+ try {
89
+ // This would need to be called from a React component context
90
+ // For now, we'll handle this differently in the call-state-controller
91
+ console.log('CallKitManager: CallKit integration initialized');
92
+ }
93
+ catch (error) {
94
+ console.warn('CallKitManager: Failed to initialize CallKit:', error);
95
+ this._isEnabled = false;
96
+ }
157
97
  }
158
- }
159
- /**
160
- * Handle incoming call - show CallKit UI
161
- */
162
- async handleIncomingCall(call) {
163
- console.log('🟡 CallKitManager.handleIncomingCall() CALLED');
164
- console.log('🟡 CallKitManager: call.callId =', call.callId);
165
- console.log('🟡 CallKitManager: call.destination =', call.destination);
166
- console.log('🟡 CallKitManager: call.isIncoming =', call.isIncoming);
167
- console.log('🟡 CallKitManager: _isEnabled =', this._isEnabled);
168
- if (!this._isEnabled) {
169
- console.log('🔴 CallKitManager: CallKit NOT ENABLED - skipping incoming call');
170
- return null;
98
+ /**
99
+ * Handle outgoing call - start CallKit session
100
+ */
101
+ async handleOutgoingCall(call) {
102
+ console.log('🔵 CallKitManager.handleOutgoingCall() CALLED');
103
+ console.log('🔵 CallKitManager: call.callId =', call.callId);
104
+ console.log('🔵 CallKitManager: call.destination =', call.destination);
105
+ console.log('🔵 CallKitManager: call.isIncoming =', call.isIncoming);
106
+ console.log('🔵 CallKitManager: _isEnabled =', this._isEnabled);
107
+ if (!this._isEnabled) {
108
+ console.log('🔴 CallKitManager: CallKit NOT ENABLED - skipping outgoing call');
109
+ return null;
110
+ }
111
+ try {
112
+ console.log('🔵 CallKitManager: Starting CallKit session for outgoing call:', call.callId);
113
+ const callKitUUID = callkit_1.default.generateCallUUID();
114
+ console.log('🔵 CallKitManager: Generated CallKit UUID:', callKitUUID);
115
+ // Call the native CallKit bridge
116
+ console.log('🔵 CallKitManager: Calling native CallKit.startOutgoingCall...');
117
+ const success = await callkit_1.default.startOutgoingCall(callKitUUID, call.destination, call.destination // Using destination as display name for now
118
+ );
119
+ if (success) {
120
+ console.log('� CallKitManager: Native CallKit.startOutgoingCall SUCCESS!');
121
+ this._callMappings.set(call.callId, callKitUUID);
122
+ console.log('� CallKitManager: Stored call mapping:', call.callId, '->', callKitUUID);
123
+ return callKitUUID;
124
+ }
125
+ else {
126
+ console.log('� CallKitManager: Native CallKit.startOutgoingCall FAILED');
127
+ return null;
128
+ }
129
+ }
130
+ catch (error) {
131
+ console.error('🔴 CallKitManager: Failed to start outgoing call:', error);
132
+ return null;
133
+ }
171
134
  }
172
- try {
173
- console.log('🟡 CallKitManager: Showing CallKit UI for incoming call:', call.callId);
174
- const callKitUUID = callkit_1.default.generateCallUUID();
175
- console.log('🟡 CallKitManager: Generated CallKit UUID for incoming call:', callKitUUID);
176
- // Call the native CallKit bridge
177
- console.log('🟡 CallKitManager: Calling native CallKit.reportIncomingCall...');
178
- // For incoming calls, the call.destination contains the caller number
179
- // We should use a more descriptive name if available
180
- const handle = call.destination;
181
- const displayName = call.destination; // For now, use the number as display name too
182
- console.log('🟡 CallKitManager: Using handle:', handle, 'displayName:', displayName);
183
- const success = await callkit_1.default.reportIncomingCall(callKitUUID, handle, displayName);
184
- if (success) {
185
- console.log('� CallKitManager: Native CallKit.reportIncomingCall SUCCESS!');
186
- this._callMappings.set(call.callId, callKitUUID);
187
- console.log(
188
- ' CallKitManager: Stored incoming call mapping:',
189
- call.callId,
190
- '->',
191
- callKitUUID
192
- );
193
- return callKitUUID;
194
- } else {
195
- console.log(' CallKitManager: Native CallKit.reportIncomingCall FAILED');
196
- return null;
197
- }
198
- } catch (error) {
199
- console.error('🔴 CallKitManager: Failed to show incoming call:', error);
200
- return null;
135
+ /**
136
+ * Handle incoming call - show CallKit UI
137
+ */
138
+ async handleIncomingCall(call) {
139
+ console.log('🟡 CallKitManager.handleIncomingCall() CALLED');
140
+ console.log('🟡 CallKitManager: call.callId =', call.callId);
141
+ console.log('🟡 CallKitManager: call.destination =', call.destination);
142
+ console.log('🟡 CallKitManager: call.isIncoming =', call.isIncoming);
143
+ console.log('🟡 CallKitManager: _isEnabled =', this._isEnabled);
144
+ if (!this._isEnabled) {
145
+ console.log('🔴 CallKitManager: CallKit NOT ENABLED - skipping incoming call');
146
+ return null;
147
+ }
148
+ try {
149
+ console.log('🟡 CallKitManager: Showing CallKit UI for incoming call:', call.callId);
150
+ const callKitUUID = callkit_1.default.generateCallUUID();
151
+ console.log('🟡 CallKitManager: Generated CallKit UUID for incoming call:', callKitUUID);
152
+ // Call the native CallKit bridge
153
+ console.log('🟡 CallKitManager: Calling native CallKit.reportIncomingCall...');
154
+ // For incoming calls, the call.destination contains the caller number
155
+ // We should use a more descriptive name if available
156
+ const handle = call.destination;
157
+ const displayName = call.destination; // For now, use the number as display name too
158
+ console.log('🟡 CallKitManager: Using handle:', handle, 'displayName:', displayName);
159
+ const success = await callkit_1.default.reportIncomingCall(callKitUUID, handle, displayName);
160
+ if (success) {
161
+ console.log('� CallKitManager: Native CallKit.reportIncomingCall SUCCESS!');
162
+ this._callMappings.set(call.callId, callKitUUID);
163
+ console.log('� CallKitManager: Stored incoming call mapping:', call.callId, '->', callKitUUID);
164
+ return callKitUUID;
165
+ }
166
+ else {
167
+ console.log('� CallKitManager: Native CallKit.reportIncomingCall FAILED');
168
+ return null;
169
+ }
170
+ }
171
+ catch (error) {
172
+ console.error('🔴 CallKitManager: Failed to show incoming call:', error);
173
+ return null;
174
+ }
201
175
  }
202
- }
203
- /**
204
- * Update call state in CallKit
205
- */
206
- async updateCallState(call, state) {
207
- if (!this._isEnabled) return;
208
- const callKitUUID = this._callMappings.get(call.callId);
209
- if (!callKitUUID) return;
210
- try {
211
- console.log(`🔧 CallKitManager: Updating CallKit state for call ${call.callId} to ${state}`);
212
- console.log(`🔧 CallKitManager: CallKit UUID: ${callKitUUID}`);
213
- switch (state) {
214
- case call_state_1.TelnyxCallState.ACTIVE:
215
- console.log('🟢 CallKitManager: Reporting call connected to CallKit');
216
- await callkit_1.default.reportCallConnected(callKitUUID);
217
- break;
218
- case call_state_1.TelnyxCallState.ENDED:
219
- console.log('🔴 CallKitManager: Reporting call ended to CallKit (remote ended)');
220
- await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.RemoteEnded);
221
- this._callMappings.delete(call.callId);
222
- break;
223
- case call_state_1.TelnyxCallState.FAILED:
224
- console.log('🔴 CallKitManager: Reporting call ended to CallKit (failed)');
225
- await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.Failed);
226
- this._callMappings.delete(call.callId);
227
- break;
228
- case call_state_1.TelnyxCallState.RINGING:
229
- console.log('🟡 CallKitManager: Call ringing - no CallKit update needed');
230
- break;
231
- default:
232
- console.log(`🔧 CallKitManager: Unhandled state: ${state}`);
233
- break;
234
- }
235
- } catch (error) {
236
- console.error('🔴 CallKitManager: Failed to update call state:', error);
176
+ /**
177
+ * Update call state in CallKit
178
+ */
179
+ async updateCallState(call, state) {
180
+ if (!this._isEnabled)
181
+ return;
182
+ const callKitUUID = this._callMappings.get(call.callId);
183
+ if (!callKitUUID)
184
+ return;
185
+ try {
186
+ console.log(`🔧 CallKitManager: Updating CallKit state for call ${call.callId} to ${state}`);
187
+ console.log(`🔧 CallKitManager: CallKit UUID: ${callKitUUID}`);
188
+ switch (state) {
189
+ case call_state_1.TelnyxCallState.ACTIVE:
190
+ console.log('🟢 CallKitManager: Reporting call connected to CallKit');
191
+ await callkit_1.default.reportCallConnected(callKitUUID);
192
+ break;
193
+ case call_state_1.TelnyxCallState.ENDED:
194
+ console.log('🔴 CallKitManager: Reporting call ended to CallKit (remote ended)');
195
+ await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.RemoteEnded);
196
+ this._callMappings.delete(call.callId);
197
+ break;
198
+ case call_state_1.TelnyxCallState.FAILED:
199
+ console.log('🔴 CallKitManager: Reporting call ended to CallKit (failed)');
200
+ await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.Failed);
201
+ this._callMappings.delete(call.callId);
202
+ break;
203
+ case call_state_1.TelnyxCallState.RINGING:
204
+ console.log('🟡 CallKitManager: Call ringing - no CallKit update needed');
205
+ break;
206
+ default:
207
+ console.log(`🔧 CallKitManager: Unhandled state: ${state}`);
208
+ break;
209
+ }
210
+ }
211
+ catch (error) {
212
+ console.error('🔴 CallKitManager: Failed to update call state:', error);
213
+ }
214
+ }
215
+ /**
216
+ * End CallKit session
217
+ */
218
+ async endCall(call) {
219
+ if (!this._isEnabled)
220
+ return;
221
+ const callKitUUID = this._callMappings.get(call.callId);
222
+ if (!callKitUUID)
223
+ return;
224
+ try {
225
+ console.log('🔴 CallKitManager: Ending CallKit session for call:', call.callId);
226
+ console.log('🔴 CallKitManager: CallKit UUID:', callKitUUID);
227
+ // Report call ended with user-initiated reason
228
+ await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.RemoteEnded);
229
+ this._callMappings.delete(call.callId);
230
+ console.log('🔴 CallKitManager: CallKit session ended successfully');
231
+ }
232
+ catch (error) {
233
+ console.error('🔴 CallKitManager: Failed to end call:', error);
234
+ }
235
+ }
236
+ /**
237
+ * Handle CallKit answer action
238
+ */
239
+ _handleCallKitAnswer(callKitUUID) {
240
+ console.log('📞 CallKitManager: Handling CallKit answer for UUID:', callKitUUID);
241
+ // Find the call ID from the CallKit UUID
242
+ const callId = this._reverseCallMappings.get(callKitUUID);
243
+ if (!callId) {
244
+ console.error('🔴 CallKitManager: No call found for CallKit UUID:', callKitUUID);
245
+ return;
246
+ }
247
+ console.log('📞 CallKitManager: Found call ID:', callId);
248
+ // Find the call object and answer it
249
+ if (this._callMap) {
250
+ const call = this._callMap.get(callId);
251
+ if (call) {
252
+ console.log('📞 CallKitManager: Answering call:', callId);
253
+ call.answer();
254
+ }
255
+ else {
256
+ console.error('🔴 CallKitManager: Call object not found for ID:', callId);
257
+ }
258
+ }
259
+ else {
260
+ console.error('🔴 CallKitManager: Call map not available');
261
+ }
262
+ }
263
+ /**
264
+ * Handle CallKit end action
265
+ */
266
+ _handleCallKitEnd(callKitUUID) {
267
+ console.log('📞 CallKitManager: Handling CallKit end for UUID:', callKitUUID);
268
+ // Find the call ID from the CallKit UUID
269
+ const callId = this._reverseCallMappings.get(callKitUUID);
270
+ if (!callId) {
271
+ console.error('🔴 CallKitManager: No call found for CallKit UUID:', callKitUUID);
272
+ return;
273
+ }
274
+ console.log('📞 CallKitManager: Found call ID:', callId);
275
+ // Find the call object and hang up
276
+ if (this._callMap) {
277
+ const call = this._callMap.get(callId);
278
+ if (call) {
279
+ console.log('📞 CallKitManager: Hanging up call:', callId);
280
+ call.hangup();
281
+ }
282
+ else {
283
+ console.error('🔴 CallKitManager: Call object not found for ID:', callId);
284
+ }
285
+ }
286
+ else {
287
+ console.error('🔴 CallKitManager: Call map not available');
288
+ }
237
289
  }
238
- }
239
- /**
240
- * End CallKit session
241
- */
242
- async endCall(call) {
243
- if (!this._isEnabled) return;
244
- const callKitUUID = this._callMappings.get(call.callId);
245
- if (!callKitUUID) return;
246
- try {
247
- console.log('🔴 CallKitManager: Ending CallKit session for call:', call.callId);
248
- console.log('🔴 CallKitManager: CallKit UUID:', callKitUUID);
249
- // Report call ended with user-initiated reason
250
- await callkit_1.default.reportCallEnded(callKitUUID, callkit_1.CallEndReason.RemoteEnded);
251
- this._callMappings.delete(call.callId);
252
- console.log('🔴 CallKitManager: CallKit session ended successfully');
253
- } catch (error) {
254
- console.error('🔴 CallKitManager: Failed to end call:', error);
290
+ /**
291
+ * Set the call map reference for handling CallKit actions
292
+ */
293
+ setCallMap(callMap) {
294
+ this._callMap = callMap;
295
+ console.log('🔧 CallKitManager: Call map reference set');
255
296
  }
256
- }
257
- /**
258
- * Handle CallKit answer action
259
- */
260
- _handleCallKitAnswer(callKitUUID) {
261
- console.log('📞 CallKitManager: Handling CallKit answer for UUID:', callKitUUID);
262
- // Find the call ID from the CallKit UUID
263
- const callId = this._reverseCallMappings.get(callKitUUID);
264
- if (!callId) {
265
- console.error('🔴 CallKitManager: No call found for CallKit UUID:', callKitUUID);
266
- return;
297
+ /**
298
+ * Check if CallKit is available
299
+ */
300
+ get isAvailable() {
301
+ return this._isEnabled;
267
302
  }
268
- console.log('📞 CallKitManager: Found call ID:', callId);
269
- // Find the call object and answer it
270
- if (this._callMap) {
271
- const call = this._callMap.get(callId);
272
- if (call) {
273
- console.log('📞 CallKitManager: Answering call:', callId);
274
- call.answer();
275
- } else {
276
- console.error('🔴 CallKitManager: Call object not found for ID:', callId);
277
- }
278
- } else {
279
- console.error('🔴 CallKitManager: Call map not available');
303
+ /**
304
+ * Get CallKit UUID for a call
305
+ */
306
+ getCallKitUUID(callId) {
307
+ return this._callMappings.get(callId) || null;
280
308
  }
281
- }
282
- /**
283
- * Handle CallKit end action
284
- */
285
- _handleCallKitEnd(callKitUUID) {
286
- console.log('📞 CallKitManager: Handling CallKit end for UUID:', callKitUUID);
287
- // Find the call ID from the CallKit UUID
288
- const callId = this._reverseCallMappings.get(callKitUUID);
289
- if (!callId) {
290
- console.error('🔴 CallKitManager: No call found for CallKit UUID:', callKitUUID);
291
- return;
309
+ /**
310
+ * Generate a UUID for CallKit
311
+ */
312
+ generateUUID() {
313
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
314
+ const r = (Math.random() * 16) | 0;
315
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
316
+ return v.toString(16);
317
+ });
292
318
  }
293
- console.log('📞 CallKitManager: Found call ID:', callId);
294
- // Find the call object and hang up
295
- if (this._callMap) {
296
- const call = this._callMap.get(callId);
297
- if (call) {
298
- console.log('📞 CallKitManager: Hanging up call:', callId);
299
- call.hangup();
300
- } else {
301
- console.error('🔴 CallKitManager: Call object not found for ID:', callId);
302
- }
303
- } else {
304
- console.error('🔴 CallKitManager: Call map not available');
319
+ /**
320
+ * Dispose of the CallKit manager
321
+ */
322
+ dispose() {
323
+ this._callMappings.clear();
305
324
  }
306
- }
307
- /**
308
- * Set the call map reference for handling CallKit actions
309
- */
310
- setCallMap(callMap) {
311
- this._callMap = callMap;
312
- console.log('🔧 CallKitManager: Call map reference set');
313
- }
314
- /**
315
- * Check if CallKit is available
316
- */
317
- get isAvailable() {
318
- return this._isEnabled;
319
- }
320
- /**
321
- * Get CallKit UUID for a call
322
- */
323
- getCallKitUUID(callId) {
324
- return this._callMappings.get(callId) || null;
325
- }
326
- /**
327
- * Generate a UUID for CallKit
328
- */
329
- generateUUID() {
330
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
331
- const r = (Math.random() * 16) | 0;
332
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
333
- return v.toString(16);
334
- });
335
- }
336
- /**
337
- * Dispose of the CallKit manager
338
- */
339
- dispose() {
340
- this._callMappings.clear();
341
- }
342
325
  }
343
326
  exports.CallKitManager = CallKitManager;