@telnyx/react-voice-commons-sdk 0.1.0 → 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/TelnyxVoiceCommons.podspec +31 -31
- package/ios/CallKitBridge.m +43 -43
- package/ios/CallKitBridge.swift +879 -879
- package/ios/VoicePnBridge.m +30 -30
- package/ios/VoicePnBridge.swift +86 -86
- 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.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 -155
- package/lib/telnyx-voip-client.js +392 -331
- package/package.json +1 -1
- package/src/telnyx-voip-client.ts +64 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.CallStateController = void 0;
|
|
4
|
-
const rxjs_1 = require(
|
|
5
|
-
const operators_1 = require(
|
|
6
|
-
const call_1 = require(
|
|
7
|
-
const call_state_1 = require(
|
|
8
|
-
const callkit_coordinator_1 = require(
|
|
4
|
+
const rxjs_1 = require('rxjs');
|
|
5
|
+
const operators_1 = require('rxjs/operators');
|
|
6
|
+
const call_1 = require('../../models/call');
|
|
7
|
+
const call_state_1 = require('../../models/call-state');
|
|
8
|
+
const callkit_coordinator_1 = require('../../callkit/callkit-coordinator');
|
|
9
9
|
/**
|
|
10
10
|
* Central state machine for call management.
|
|
11
11
|
*
|
|
@@ -13,282 +13,320 @@ const callkit_coordinator_1 = require("../../callkit/callkit-coordinator");
|
|
|
13
13
|
* and provides reactive streams for call-related state changes.
|
|
14
14
|
*/
|
|
15
15
|
class CallStateController {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
constructor(_sessionManager) {
|
|
17
|
+
this._sessionManager = _sessionManager;
|
|
18
|
+
this._calls = new rxjs_1.BehaviorSubject([]);
|
|
19
|
+
this._callMap = new Map();
|
|
20
|
+
this._disposed = false;
|
|
21
|
+
// Don't set up client listeners here - client doesn't exist yet
|
|
22
|
+
// Will be called when client is available
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Observable stream of all current calls
|
|
26
|
+
*/
|
|
27
|
+
get calls$() {
|
|
28
|
+
return this._calls.asObservable().pipe((0, operators_1.distinctUntilChanged)());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Observable stream of the currently active call
|
|
32
|
+
*/
|
|
33
|
+
get activeCall$() {
|
|
34
|
+
return this.calls$.pipe(
|
|
35
|
+
(0, operators_1.map)((calls) => {
|
|
36
|
+
// Find the first call that is not terminated (includes RINGING, CONNECTING, ACTIVE, HELD)
|
|
37
|
+
return (
|
|
38
|
+
calls.find(
|
|
39
|
+
(call) =>
|
|
40
|
+
call.currentState === call_state_1.TelnyxCallState.RINGING ||
|
|
41
|
+
call.currentState === call_state_1.TelnyxCallState.CONNECTING ||
|
|
42
|
+
call.currentState === call_state_1.TelnyxCallState.ACTIVE ||
|
|
43
|
+
call.currentState === call_state_1.TelnyxCallState.HELD
|
|
44
|
+
) || null
|
|
45
|
+
);
|
|
46
|
+
}),
|
|
47
|
+
(0, operators_1.distinctUntilChanged)()
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Current list of calls (synchronous access)
|
|
52
|
+
*/
|
|
53
|
+
get currentCalls() {
|
|
54
|
+
return this._calls.value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Current active call (synchronous access)
|
|
58
|
+
*/
|
|
59
|
+
get currentActiveCall() {
|
|
60
|
+
const calls = this.currentCalls;
|
|
61
|
+
return (
|
|
62
|
+
calls.find(
|
|
63
|
+
(call) =>
|
|
64
|
+
call.currentState === call_state_1.TelnyxCallState.RINGING ||
|
|
65
|
+
call.currentState === call_state_1.TelnyxCallState.CONNECTING ||
|
|
66
|
+
call.currentState === call_state_1.TelnyxCallState.ACTIVE ||
|
|
67
|
+
call.currentState === call_state_1.TelnyxCallState.HELD
|
|
68
|
+
) || null
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set a call to connecting state (used for push notification calls when answered via CallKit)
|
|
73
|
+
* @param callId The ID of the call to set to connecting state
|
|
74
|
+
*/
|
|
75
|
+
setCallConnecting(callId) {
|
|
76
|
+
const call = this._callMap.get(callId);
|
|
77
|
+
if (call) {
|
|
78
|
+
console.log('CallStateController: Setting call to connecting state:', callId);
|
|
79
|
+
call.setConnecting();
|
|
80
|
+
} else {
|
|
81
|
+
console.warn('CallStateController: Could not find call to set connecting:', callId);
|
|
23
82
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Find a call by its underlying Telnyx call ID
|
|
86
|
+
* @param telnyxCall The Telnyx call object to find
|
|
87
|
+
*/
|
|
88
|
+
findCallByTelnyxCall(telnyxCall) {
|
|
89
|
+
for (const call of this._callMap.values()) {
|
|
90
|
+
if (call.telnyxCall === telnyxCall || call.telnyxCall.callId === telnyxCall.callId) {
|
|
91
|
+
return call;
|
|
92
|
+
}
|
|
29
93
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Initialize client listeners when the Telnyx client becomes available
|
|
98
|
+
* This should be called by the session manager after client creation
|
|
99
|
+
*/
|
|
100
|
+
initializeClientListeners() {
|
|
101
|
+
console.log('🔧 CallStateController: initializeClientListeners called');
|
|
102
|
+
this._setupClientListeners();
|
|
103
|
+
// CallKit integration now handled by CallKitCoordinator
|
|
104
|
+
console.log('🔧 CallStateController: Using CallKitCoordinator for CallKit integration');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Initiate a new outgoing call
|
|
108
|
+
*/
|
|
109
|
+
async newCall(destination, callerName, callerNumber, debug = false) {
|
|
110
|
+
if (this._disposed) {
|
|
111
|
+
throw new Error('CallStateController has been disposed');
|
|
41
112
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
get currentCalls() {
|
|
46
|
-
return this._calls.value;
|
|
113
|
+
if (!this._sessionManager.telnyxClient) {
|
|
114
|
+
throw new Error('Telnyx client not available');
|
|
47
115
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
116
|
+
try {
|
|
117
|
+
// Create the call using the Telnyx SDK
|
|
118
|
+
const callOptions = {
|
|
119
|
+
destinationNumber: destination,
|
|
120
|
+
callerIdName: callerName,
|
|
121
|
+
callerIdNumber: callerNumber,
|
|
122
|
+
};
|
|
123
|
+
const telnyxCall = await this._sessionManager.telnyxClient.newCall(callOptions);
|
|
124
|
+
// Create our wrapper Call object
|
|
125
|
+
const call = new call_1.Call(
|
|
126
|
+
telnyxCall,
|
|
127
|
+
telnyxCall.callId || this._generateCallId(),
|
|
128
|
+
destination,
|
|
129
|
+
false // outgoing call
|
|
130
|
+
);
|
|
131
|
+
// Add to our call tracking
|
|
132
|
+
this._addCall(call);
|
|
133
|
+
return call;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('Failed to create new call:', error);
|
|
136
|
+
throw error;
|
|
57
137
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set callbacks for waiting for invite logic (used for push notifications)
|
|
141
|
+
*/
|
|
142
|
+
setWaitingForInviteCallbacks(callbacks) {
|
|
143
|
+
this._isWaitingForInvite = callbacks.isWaitingForInvite;
|
|
144
|
+
this._onInviteAutoAccepted = callbacks.onInviteAutoAccepted;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Dispose of the controller and clean up resources
|
|
148
|
+
*/
|
|
149
|
+
dispose() {
|
|
150
|
+
if (this._disposed) {
|
|
151
|
+
return;
|
|
71
152
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
153
|
+
this._disposed = true;
|
|
154
|
+
// Dispose of all calls
|
|
155
|
+
this.currentCalls.forEach((call) => call.dispose());
|
|
156
|
+
this._callMap.clear();
|
|
157
|
+
// CallKit cleanup is now handled by CallKitCoordinator automatically
|
|
158
|
+
this._calls.complete();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Set up event listeners for the Telnyx client
|
|
162
|
+
*/
|
|
163
|
+
_setupClientListeners() {
|
|
164
|
+
console.log('🔧 CallStateController: Setting up client listeners...');
|
|
165
|
+
if (!this._sessionManager.telnyxClient) {
|
|
166
|
+
console.log('🔧 CallStateController: No telnyxClient available yet, skipping listener setup');
|
|
167
|
+
return;
|
|
83
168
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
169
|
+
console.log('🔧 CallStateController: TelnyxClient found, setting up incoming call listener');
|
|
170
|
+
// Listen for incoming calls
|
|
171
|
+
this._sessionManager.telnyxClient.on('telnyx.call.incoming', (telnyxCall, msg) => {
|
|
172
|
+
console.log('📞 CallStateController: Incoming call received:', telnyxCall.callId);
|
|
173
|
+
this._handleIncomingCall(telnyxCall, msg);
|
|
174
|
+
});
|
|
175
|
+
// Listen for other call events if needed
|
|
176
|
+
// this._sessionManager.telnyxClient.on('telnyx.call.stateChange', this._handleCallStateChange.bind(this));
|
|
177
|
+
console.log('🔧 CallStateController: Client listeners set up successfully');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Handle incoming call
|
|
181
|
+
*/
|
|
182
|
+
_handleIncomingCall(telnyxCall, inviteMsg) {
|
|
183
|
+
const callId = telnyxCall.callId || this._generateCallId();
|
|
184
|
+
console.log('📞 CallStateController: Handling incoming call:', callId);
|
|
185
|
+
console.log('📞 CallStateController: TelnyxCall object:', telnyxCall);
|
|
186
|
+
console.log('📞 CallStateController: Invite message:', inviteMsg);
|
|
187
|
+
// Check if we already have this call
|
|
188
|
+
if (this._callMap.has(callId)) {
|
|
189
|
+
console.log('Call already exists:', callId);
|
|
190
|
+
return;
|
|
93
191
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this._addCall(call);
|
|
117
|
-
return call;
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
console.error('Failed to create new call:', error);
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
192
|
+
// Get caller information from the invite message (preferred) or fallback to TelnyxCall
|
|
193
|
+
let callerNumber = 'Unknown';
|
|
194
|
+
let callerName = 'Unknown';
|
|
195
|
+
if (inviteMsg && inviteMsg.params) {
|
|
196
|
+
callerNumber = inviteMsg.params.caller_id_number || 'Unknown';
|
|
197
|
+
callerName = inviteMsg.params.caller_id_name || callerNumber;
|
|
198
|
+
console.log(
|
|
199
|
+
'📞 CallStateController: Extracted caller info from invite - Number:',
|
|
200
|
+
callerNumber,
|
|
201
|
+
'Name:',
|
|
202
|
+
callerName
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
// Fallback to TelnyxCall properties
|
|
206
|
+
callerNumber = telnyxCall.remoteCallerIdNumber || 'Unknown';
|
|
207
|
+
callerName = telnyxCall.remoteCallerIdName || callerNumber;
|
|
208
|
+
console.log(
|
|
209
|
+
'📞 CallStateController: Extracted caller info from TelnyxCall - Number:',
|
|
210
|
+
callerNumber,
|
|
211
|
+
'Name:',
|
|
212
|
+
callerName
|
|
213
|
+
);
|
|
123
214
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
215
|
+
// Create our wrapper Call object
|
|
216
|
+
const call = new call_1.Call(
|
|
217
|
+
telnyxCall,
|
|
218
|
+
callId,
|
|
219
|
+
callerNumber, // Use caller number as destination for incoming calls
|
|
220
|
+
true // incoming call
|
|
221
|
+
);
|
|
222
|
+
// Check if we're waiting for an invite (push notification scenario)
|
|
223
|
+
if (this._isWaitingForInvite && this._isWaitingForInvite()) {
|
|
224
|
+
console.log('Auto-accepting call from push notification');
|
|
225
|
+
call.answer().catch((error) => {
|
|
226
|
+
console.error('Failed to auto-accept call:', error);
|
|
227
|
+
});
|
|
228
|
+
if (this._onInviteAutoAccepted) {
|
|
229
|
+
this._onInviteAutoAccepted();
|
|
230
|
+
}
|
|
130
231
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
232
|
+
// Add to our call tracking - CallKit integration happens in _addCall
|
|
233
|
+
this._addCall(call);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Handle call state changes from the Telnyx client
|
|
237
|
+
*/
|
|
238
|
+
_handleCallStateChange(event) {
|
|
239
|
+
const callId = event.callId || event.id;
|
|
240
|
+
const call = this._callMap.get(callId);
|
|
241
|
+
if (call) {
|
|
242
|
+
// The Call object will handle its own state updates through its listeners
|
|
243
|
+
console.log(`Call ${callId} state changed to ${event.state}`);
|
|
244
|
+
} else {
|
|
245
|
+
console.warn(`Received state change for unknown call: ${callId}`);
|
|
144
246
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
console.log('📞 CallStateController: Incoming call received:', telnyxCall.callId);
|
|
158
|
-
this._handleIncomingCall(telnyxCall, msg);
|
|
159
|
-
});
|
|
160
|
-
// Listen for other call events if needed
|
|
161
|
-
// this._sessionManager.telnyxClient.on('telnyx.call.stateChange', this._handleCallStateChange.bind(this));
|
|
162
|
-
console.log('🔧 CallStateController: Client listeners set up successfully');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Handle call updates from notifications
|
|
250
|
+
*/
|
|
251
|
+
_handleCallUpdate(callData) {
|
|
252
|
+
const callId = callData.id;
|
|
253
|
+
const call = this._callMap.get(callId);
|
|
254
|
+
if (call) {
|
|
255
|
+
// Update call state based on the notification
|
|
256
|
+
console.log(`Call ${callId} updated:`, callData);
|
|
257
|
+
} else {
|
|
258
|
+
console.warn(`Received update for unknown call: ${callId}`);
|
|
163
259
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
// Fallback to TelnyxCall properties
|
|
187
|
-
callerNumber = telnyxCall.remoteCallerIdNumber || 'Unknown';
|
|
188
|
-
callerName = telnyxCall.remoteCallerIdName || callerNumber;
|
|
189
|
-
console.log('📞 CallStateController: Extracted caller info from TelnyxCall - Number:', callerNumber, 'Name:', callerName);
|
|
190
|
-
}
|
|
191
|
-
// Create our wrapper Call object
|
|
192
|
-
const call = new call_1.Call(telnyxCall, callId, callerNumber, // Use caller number as destination for incoming calls
|
|
193
|
-
true // incoming call
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Add a call to our tracking
|
|
263
|
+
*/
|
|
264
|
+
_addCall(call) {
|
|
265
|
+
this._callMap.set(call.callId, call);
|
|
266
|
+
const currentCalls = this.currentCalls;
|
|
267
|
+
currentCalls.push(call);
|
|
268
|
+
this._calls.next([...currentCalls]);
|
|
269
|
+
// Integrate with CallKit using CallKitCoordinator
|
|
270
|
+
if (callkit_coordinator_1.callKitCoordinator.isAvailable()) {
|
|
271
|
+
// Get the underlying TelnyxCall for CallKitCoordinator
|
|
272
|
+
const telnyxCall = call.telnyxCall;
|
|
273
|
+
// Check if this call already has CallKit integration (e.g., from push notification)
|
|
274
|
+
const existingCallKitUUID =
|
|
275
|
+
callkit_coordinator_1.callKitCoordinator.getCallKitUUID(telnyxCall);
|
|
276
|
+
if (existingCallKitUUID) {
|
|
277
|
+
console.log(
|
|
278
|
+
'CallStateController: Call already has CallKit integration, skipping duplicate report:',
|
|
279
|
+
existingCallKitUUID
|
|
194
280
|
);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const callId = event.callId || event.id;
|
|
213
|
-
const call = this._callMap.get(callId);
|
|
214
|
-
if (call) {
|
|
215
|
-
// The Call object will handle its own state updates through its listeners
|
|
216
|
-
console.log(`Call ${callId} state changed to ${event.state}`);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
console.warn(`Received state change for unknown call: ${callId}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Handle call updates from notifications
|
|
224
|
-
*/
|
|
225
|
-
_handleCallUpdate(callData) {
|
|
226
|
-
const callId = callData.id;
|
|
227
|
-
const call = this._callMap.get(callId);
|
|
228
|
-
if (call) {
|
|
229
|
-
// Update call state based on the notification
|
|
230
|
-
console.log(`Call ${callId} updated:`, callData);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
console.warn(`Received update for unknown call: ${callId}`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Add a call to our tracking
|
|
238
|
-
*/
|
|
239
|
-
_addCall(call) {
|
|
240
|
-
this._callMap.set(call.callId, call);
|
|
241
|
-
const currentCalls = this.currentCalls;
|
|
242
|
-
currentCalls.push(call);
|
|
243
|
-
this._calls.next([...currentCalls]);
|
|
244
|
-
// Integrate with CallKit using CallKitCoordinator
|
|
245
|
-
if (callkit_coordinator_1.callKitCoordinator.isAvailable()) {
|
|
246
|
-
// Get the underlying TelnyxCall for CallKitCoordinator
|
|
247
|
-
const telnyxCall = call.telnyxCall;
|
|
248
|
-
// Check if this call already has CallKit integration (e.g., from push notification)
|
|
249
|
-
const existingCallKitUUID = callkit_coordinator_1.callKitCoordinator.getCallKitUUID(telnyxCall);
|
|
250
|
-
if (existingCallKitUUID) {
|
|
251
|
-
console.log('CallStateController: Call already has CallKit integration, skipping duplicate report:', existingCallKitUUID);
|
|
252
|
-
}
|
|
253
|
-
else if (call.isIncoming) {
|
|
254
|
-
// Handle incoming call with CallKit (only if not already integrated)
|
|
255
|
-
console.log('CallStateController: Reporting incoming call to CallKitCoordinator');
|
|
256
|
-
callkit_coordinator_1.callKitCoordinator.reportIncomingCall(telnyxCall, call.destination, call.destination);
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
// Handle outgoing call with CallKit
|
|
260
|
-
console.log('CallStateController: Starting outgoing call with CallKitCoordinator');
|
|
261
|
-
callkit_coordinator_1.callKitCoordinator.startOutgoingCall(telnyxCall, call.destination, call.destination);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// Listen for call state changes - CallKitCoordinator handles this automatically
|
|
265
|
-
call.callState$.subscribe((state) => {
|
|
266
|
-
// CallKitCoordinator automatically updates CallKit via setupWebRTCCallListeners
|
|
267
|
-
console.log('CallStateController: Call state changed to:', state);
|
|
268
|
-
// Clean up when call ends
|
|
269
|
-
if (state === call_state_1.TelnyxCallState.ENDED || state === call_state_1.TelnyxCallState.FAILED) {
|
|
270
|
-
this._removeCall(call.callId);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Remove a call from our tracking
|
|
276
|
-
*/
|
|
277
|
-
_removeCall(callId) {
|
|
278
|
-
const call = this._callMap.get(callId);
|
|
279
|
-
if (call) {
|
|
280
|
-
// CallKit cleanup is handled automatically by CallKitCoordinator
|
|
281
|
-
call.dispose();
|
|
282
|
-
this._callMap.delete(callId);
|
|
283
|
-
const currentCalls = this.currentCalls.filter((c) => c.callId !== callId);
|
|
284
|
-
this._calls.next(currentCalls);
|
|
285
|
-
}
|
|
281
|
+
} else if (call.isIncoming) {
|
|
282
|
+
// Handle incoming call with CallKit (only if not already integrated)
|
|
283
|
+
console.log('CallStateController: Reporting incoming call to CallKitCoordinator');
|
|
284
|
+
callkit_coordinator_1.callKitCoordinator.reportIncomingCall(
|
|
285
|
+
telnyxCall,
|
|
286
|
+
call.destination,
|
|
287
|
+
call.destination
|
|
288
|
+
);
|
|
289
|
+
} else {
|
|
290
|
+
// Handle outgoing call with CallKit
|
|
291
|
+
console.log('CallStateController: Starting outgoing call with CallKitCoordinator');
|
|
292
|
+
callkit_coordinator_1.callKitCoordinator.startOutgoingCall(
|
|
293
|
+
telnyxCall,
|
|
294
|
+
call.destination,
|
|
295
|
+
call.destination
|
|
296
|
+
);
|
|
297
|
+
}
|
|
286
298
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
299
|
+
// Listen for call state changes - CallKitCoordinator handles this automatically
|
|
300
|
+
call.callState$.subscribe((state) => {
|
|
301
|
+
// CallKitCoordinator automatically updates CallKit via setupWebRTCCallListeners
|
|
302
|
+
console.log('CallStateController: Call state changed to:', state);
|
|
303
|
+
// Clean up when call ends
|
|
304
|
+
if (
|
|
305
|
+
state === call_state_1.TelnyxCallState.ENDED ||
|
|
306
|
+
state === call_state_1.TelnyxCallState.FAILED
|
|
307
|
+
) {
|
|
308
|
+
this._removeCall(call.callId);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Remove a call from our tracking
|
|
314
|
+
*/
|
|
315
|
+
_removeCall(callId) {
|
|
316
|
+
const call = this._callMap.get(callId);
|
|
317
|
+
if (call) {
|
|
318
|
+
// CallKit cleanup is handled automatically by CallKitCoordinator
|
|
319
|
+
call.dispose();
|
|
320
|
+
this._callMap.delete(callId);
|
|
321
|
+
const currentCalls = this.currentCalls.filter((c) => c.callId !== callId);
|
|
322
|
+
this._calls.next(currentCalls);
|
|
292
323
|
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Generate a unique call ID
|
|
327
|
+
*/
|
|
328
|
+
_generateCallId() {
|
|
329
|
+
return `call_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
330
|
+
}
|
|
293
331
|
}
|
|
294
332
|
exports.CallStateController = CallStateController;
|