@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,5 +1,5 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CallStateHelpers = exports.TelnyxCallState = void 0;
4
4
  exports.isTelnyxCallState = isTelnyxCallState;
5
5
  /**
@@ -10,80 +10,82 @@ exports.isTelnyxCallState = isTelnyxCallState;
10
10
  */
11
11
  var TelnyxCallState;
12
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';
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
+ /** Call was dropped due to network issues */
26
+ TelnyxCallState["DROPPED"] = "DROPPED";
25
27
  })(TelnyxCallState || (exports.TelnyxCallState = TelnyxCallState = {}));
26
28
  /**
27
29
  * Type guard to check if a value is a valid TelnyxCallState
28
30
  */
29
31
  function isTelnyxCallState(value) {
30
- return Object.values(TelnyxCallState).includes(value);
32
+ return Object.values(TelnyxCallState).includes(value);
31
33
  }
32
34
  /**
33
35
  * Helper functions to determine what actions are available in each state
34
36
  */
35
37
  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 (
47
- state === TelnyxCallState.RINGING ||
48
- state === TelnyxCallState.CONNECTING ||
49
- state === TelnyxCallState.ACTIVE ||
50
- state === TelnyxCallState.HELD
51
- );
52
- },
53
- /**
54
- * Can the call be put on hold in this state?
55
- */
56
- canHold(state) {
57
- return state === TelnyxCallState.ACTIVE;
58
- },
59
- /**
60
- * Can the call be resumed from hold in this state?
61
- */
62
- canResume(state) {
63
- return state === TelnyxCallState.HELD;
64
- },
65
- /**
66
- * Can the call be muted/unmuted in this state?
67
- */
68
- canToggleMute(state) {
69
- return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
70
- },
71
- /**
72
- * Is the call in a terminated state?
73
- */
74
- isTerminated(state) {
75
- return state === TelnyxCallState.ENDED || state === TelnyxCallState.FAILED;
76
- },
77
- /**
78
- * Is the call in an active state (can have media)?
79
- */
80
- isActive(state) {
81
- return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
82
- },
83
- /**
84
- * Is the call in a connecting state (answered but not yet active)?
85
- */
86
- isConnecting(state) {
87
- return state === TelnyxCallState.CONNECTING;
88
- },
38
+ /**
39
+ * Can the call be answered in this state?
40
+ */
41
+ canAnswer(state) {
42
+ return state === TelnyxCallState.RINGING;
43
+ },
44
+ /**
45
+ * Can the call be hung up in this state?
46
+ */
47
+ canHangup(state) {
48
+ return (state === TelnyxCallState.RINGING ||
49
+ state === TelnyxCallState.CONNECTING ||
50
+ state === TelnyxCallState.ACTIVE ||
51
+ state === TelnyxCallState.HELD);
52
+ },
53
+ /**
54
+ * Can the call be put on hold in this state?
55
+ */
56
+ canHold(state) {
57
+ return state === TelnyxCallState.ACTIVE;
58
+ },
59
+ /**
60
+ * Can the call be resumed from hold in this state?
61
+ */
62
+ canResume(state) {
63
+ return state === TelnyxCallState.HELD;
64
+ },
65
+ /**
66
+ * Can the call be muted/unmuted in this state?
67
+ */
68
+ canToggleMute(state) {
69
+ return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
70
+ },
71
+ /**
72
+ * Is the call in a terminated state?
73
+ */
74
+ isTerminated(state) {
75
+ return (state === TelnyxCallState.ENDED ||
76
+ state === TelnyxCallState.FAILED ||
77
+ state === TelnyxCallState.DROPPED);
78
+ },
79
+ /**
80
+ * Is the call in an active state (can have media)?
81
+ */
82
+ isActive(state) {
83
+ return state === TelnyxCallState.ACTIVE || state === TelnyxCallState.HELD;
84
+ },
85
+ /**
86
+ * Is the call in a connecting state (answered but not yet active)?
87
+ */
88
+ isConnecting(state) {
89
+ return state === TelnyxCallState.CONNECTING;
90
+ },
89
91
  };
@@ -9,137 +9,165 @@ import { Call as TelnyxCall } from '@telnyx/react-native-voice-sdk';
9
9
  * integrate with any state management solution.
10
10
  */
11
11
  export declare class Call {
12
- private readonly _telnyxCall;
13
- private readonly _callId;
14
- private readonly _destination;
15
- private readonly _isIncoming;
16
- private readonly _callState;
17
- private readonly _isMuted;
18
- private readonly _isHeld;
19
- private readonly _duration;
20
- private _durationTimer?;
21
- private _startTime?;
22
- constructor(_telnyxCall: TelnyxCall, _callId: string, _destination: string, _isIncoming: boolean);
23
- /**
24
- * Unique identifier for this call
25
- */
26
- get callId(): string;
27
- /**
28
- * The destination number or SIP URI
29
- */
30
- get destination(): string;
31
- /**
32
- * Whether this is an incoming call
33
- */
34
- get isIncoming(): boolean;
35
- /**
36
- * Whether this is an outgoing call
37
- */
38
- get isOutgoing(): boolean;
39
- /**
40
- * Current call state (synchronous access)
41
- */
42
- get currentState(): TelnyxCallState;
43
- /**
44
- * Current mute state (synchronous access)
45
- */
46
- get currentIsMuted(): boolean;
47
- /**
48
- * Current hold state (synchronous access)
49
- */
50
- get currentIsHeld(): boolean;
51
- /**
52
- * Current call duration in seconds (synchronous access)
53
- */
54
- get currentDuration(): number;
55
- /**
56
- * Get the underlying Telnyx Call object (for internal use)
57
- * @internal
58
- */
59
- get telnyxCall(): TelnyxCall;
60
- /**
61
- * Observable stream of call state changes
62
- */
63
- get callState$(): Observable<TelnyxCallState>;
64
- /**
65
- * Observable stream of mute state changes
66
- */
67
- get isMuted$(): Observable<boolean>;
68
- /**
69
- * Observable stream of hold state changes
70
- */
71
- get isHeld$(): Observable<boolean>;
72
- /**
73
- * Observable stream of call duration changes (in seconds)
74
- */
75
- get duration$(): Observable<number>;
76
- /**
77
- * Observable that emits true when the call can be answered
78
- */
79
- get canAnswer$(): Observable<boolean>;
80
- /**
81
- * Observable that emits true when the call can be hung up
82
- */
83
- get canHangup$(): Observable<boolean>;
84
- /**
85
- * Observable that emits true when the call can be put on hold
86
- */
87
- get canHold$(): Observable<boolean>;
88
- /**
89
- * Observable that emits true when the call can be resumed from hold
90
- */
91
- get canResume$(): Observable<boolean>;
92
- /**
93
- * Answer the incoming call
94
- */
95
- answer(): Promise<void>;
96
- /**
97
- * Hang up the call
98
- */
99
- hangup(): Promise<void>;
100
- /**
101
- * Put the call on hold
102
- */
103
- hold(): Promise<void>;
104
- /**
105
- * Resume the call from hold
106
- */
107
- resume(): Promise<void>;
108
- /**
109
- * Mute the call
110
- */
111
- mute(): Promise<void>;
112
- /**
113
- * Unmute the call
114
- */
115
- unmute(): Promise<void>;
116
- /**
117
- * Toggle mute state
118
- */
119
- toggleMute(): Promise<void>;
120
- /**
121
- * Set the call to connecting state (used for push notification calls when answered via CallKit)
122
- * @internal
123
- */
124
- setConnecting(): void;
125
- /**
126
- * Clean up resources when the call is disposed
127
- */
128
- dispose(): void;
129
- /**
130
- * Set up listeners for the underlying Telnyx call
131
- */
132
- private _setupCallListeners;
133
- /**
134
- * Map Telnyx SDK call states to our simplified call states
135
- */
136
- private _mapToTelnyxCallState;
137
- /**
138
- * Start the duration timer
139
- */
140
- private _startDurationTimer;
141
- /**
142
- * Stop the duration timer
143
- */
144
- private _stopDurationTimer;
12
+ private readonly _telnyxCall;
13
+ private readonly _callId;
14
+ private readonly _destination;
15
+ private readonly _isIncoming;
16
+ private readonly _originalCallerName?;
17
+ private readonly _originalCallerNumber?;
18
+ private readonly _callState;
19
+ private readonly _isMuted;
20
+ private readonly _isHeld;
21
+ private readonly _duration;
22
+ private _durationTimer?;
23
+ private _startTime?;
24
+ constructor(_telnyxCall: TelnyxCall, _callId: string, _destination: string, _isIncoming: boolean, isReattached?: boolean, _originalCallerName?: string, _originalCallerNumber?: string);
25
+ /**
26
+ * Unique identifier for this call
27
+ */
28
+ get callId(): string;
29
+ /**
30
+ * The destination number or SIP URI
31
+ */
32
+ get destination(): string;
33
+ /**
34
+ * Whether this is an incoming call
35
+ */
36
+ get isIncoming(): boolean;
37
+ /**
38
+ * Whether this is an outgoing call
39
+ */
40
+ get isOutgoing(): boolean;
41
+ /**
42
+ * Current call state (synchronous access)
43
+ */
44
+ get currentState(): TelnyxCallState;
45
+ /**
46
+ * Current mute state (synchronous access)
47
+ */
48
+ get currentIsMuted(): boolean;
49
+ /**
50
+ * Current hold state (synchronous access)
51
+ */
52
+ get currentIsHeld(): boolean;
53
+ /**
54
+ * Current call duration in seconds (synchronous access)
55
+ */
56
+ get currentDuration(): number;
57
+ /**
58
+ * Custom headers received from the WebRTC INVITE message.
59
+ * These headers are passed during call initiation and can contain application-specific information.
60
+ * Format should be [{"name": "X-Header-Name", "value": "Value"}] where header names must start with "X-".
61
+ */
62
+ get inviteCustomHeaders(): {
63
+ name: string;
64
+ value: string;
65
+ }[] | null;
66
+ /**
67
+ * Custom headers received from the WebRTC ANSWER message.
68
+ * These headers are passed during call acceptance and can contain application-specific information.
69
+ * Format should be [{"name": "X-Header-Name", "value": "Value"}] where header names must start with "X-".
70
+ */
71
+ get answerCustomHeaders(): {
72
+ name: string;
73
+ value: string;
74
+ }[] | null;
75
+ /**
76
+ * Get the underlying Telnyx Call object (for internal use)
77
+ * @internal
78
+ */
79
+ get telnyxCall(): TelnyxCall;
80
+ /**
81
+ * Observable stream of call state changes
82
+ */
83
+ get callState$(): Observable<TelnyxCallState>;
84
+ /**
85
+ * Observable stream of mute state changes
86
+ */
87
+ get isMuted$(): Observable<boolean>;
88
+ /**
89
+ * Observable stream of hold state changes
90
+ */
91
+ get isHeld$(): Observable<boolean>;
92
+ /**
93
+ * Observable stream of call duration changes (in seconds)
94
+ */
95
+ get duration$(): Observable<number>;
96
+ /**
97
+ * Observable that emits true when the call can be answered
98
+ */
99
+ get canAnswer$(): Observable<boolean>;
100
+ /**
101
+ * Observable that emits true when the call can be hung up
102
+ */
103
+ get canHangup$(): Observable<boolean>;
104
+ /**
105
+ * Observable that emits true when the call can be put on hold
106
+ */
107
+ get canHold$(): Observable<boolean>;
108
+ /**
109
+ * Observable that emits true when the call can be resumed from hold
110
+ */
111
+ get canResume$(): Observable<boolean>;
112
+ /**
113
+ * Answer the incoming call
114
+ * @param customHeaders Optional custom headers to include with the answer
115
+ */
116
+ answer(customHeaders?: {
117
+ name: string;
118
+ value: string;
119
+ }[]): Promise<void>;
120
+ /**
121
+ * Hang up the call
122
+ * @param customHeaders Optional custom headers to include with the hangup request
123
+ */
124
+ hangup(customHeaders?: {
125
+ name: string;
126
+ value: string;
127
+ }[]): Promise<void>;
128
+ /**
129
+ * Put the call on hold
130
+ */
131
+ hold(): Promise<void>;
132
+ /**
133
+ * Resume the call from hold
134
+ */
135
+ resume(): Promise<void>;
136
+ /**
137
+ * Mute the call
138
+ */
139
+ mute(): Promise<void>;
140
+ /**
141
+ * Unmute the call
142
+ */
143
+ unmute(): Promise<void>;
144
+ /**
145
+ * Toggle mute state
146
+ */
147
+ toggleMute(): Promise<void>;
148
+ /**
149
+ * Set the call to connecting state (used for push notification calls when answered via CallKit)
150
+ * @internal
151
+ */
152
+ setConnecting(): void;
153
+ /**
154
+ * Clean up resources when the call is disposed
155
+ */
156
+ dispose(): void;
157
+ /**
158
+ * Set up listeners for the underlying Telnyx call
159
+ */
160
+ private _setupCallListeners;
161
+ /**
162
+ * Map Telnyx SDK call states to our simplified call states
163
+ */
164
+ private _mapToTelnyxCallState;
165
+ /**
166
+ * Start the duration timer
167
+ */
168
+ private _startDurationTimer;
169
+ /**
170
+ * Stop the duration timer
171
+ */
172
+ private _stopDurationTimer;
145
173
  }