@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.
- package/CHANGELOG.md +60 -0
- package/README.md +469 -483
- package/ios/CallKitBridge.swift +2 -7
- package/lib/callkit/callkit-coordinator.d.ts +110 -117
- package/lib/callkit/callkit-coordinator.js +664 -727
- package/lib/callkit/callkit.d.ts +41 -41
- package/lib/callkit/callkit.js +252 -242
- package/lib/callkit/index.js +15 -47
- package/lib/callkit/use-callkit.d.ts +19 -19
- package/lib/callkit/use-callkit.js +270 -310
- package/lib/context/TelnyxVoiceContext.d.ts +9 -9
- package/lib/context/TelnyxVoiceContext.js +10 -13
- package/lib/hooks/use-callkit-coordinator.d.ts +9 -17
- package/lib/hooks/use-callkit-coordinator.js +45 -50
- package/lib/hooks/useAppReadyNotifier.js +13 -15
- package/lib/hooks/useAppStateHandler.d.ts +6 -11
- package/lib/hooks/useAppStateHandler.js +95 -110
- package/lib/hooks/useNetworkStateHandler.d.ts +0 -0
- package/lib/hooks/useNetworkStateHandler.js +0 -0
- package/lib/index.d.ts +3 -21
- package/lib/index.js +50 -201
- package/lib/internal/CallKitHandler.d.ts +6 -6
- package/lib/internal/CallKitHandler.js +96 -104
- package/lib/internal/callkit-manager.d.ts +57 -57
- package/lib/internal/callkit-manager.js +299 -316
- package/lib/internal/calls/call-state-controller.d.ts +73 -86
- package/lib/internal/calls/call-state-controller.js +263 -307
- package/lib/internal/session/session-manager.d.ts +71 -75
- package/lib/internal/session/session-manager.js +360 -424
- package/lib/internal/user-defaults-helpers.js +49 -39
- package/lib/internal/voice-pn-bridge.d.ts +114 -12
- package/lib/internal/voice-pn-bridge.js +212 -5
- package/lib/models/call-state.d.ts +46 -44
- package/lib/models/call-state.js +70 -68
- package/lib/models/call.d.ts +161 -133
- package/lib/models/call.js +454 -382
- package/lib/models/config.d.ts +11 -18
- package/lib/models/config.js +37 -35
- 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 +513 -480
- package/lib/telnyx-voip-client.d.ts +167 -167
- package/lib/telnyx-voip-client.js +385 -390
- package/package.json +115 -104
- package/src/callkit/callkit-coordinator.ts +830 -846
- package/src/hooks/useNetworkStateHandler.ts +0 -0
- package/src/internal/calls/call-state-controller.ts +407 -384
- package/src/internal/session/session-manager.ts +483 -467
- package/src/internal/voice-pn-bridge.ts +266 -18
- package/src/models/call-state.ts +105 -98
- package/src/models/call.ts +502 -388
- package/src/telnyx-voice-app.tsx +788 -690
- package/src/telnyx-voip-client.ts +551 -539
- package/src/types/telnyx-sdk.d.ts +93 -79
package/lib/models/call-state.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
};
|
package/lib/models/call.d.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
}
|