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