@dialstack/sdk-react 2.1.0
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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/ai-agent.cjs +2 -0
- package/dist/ai-agent.cjs.map +1 -0
- package/dist/ai-agent.d.cts +89 -0
- package/dist/ai-agent.d.ts +89 -0
- package/dist/ai-agent.mjs +2 -0
- package/dist/ai-agent.mjs.map +1 -0
- package/dist/call-history.cjs +2 -0
- package/dist/call-history.cjs.map +1 -0
- package/dist/call-history.d.cts +88 -0
- package/dist/call-history.d.ts +88 -0
- package/dist/call-history.mjs +2 -0
- package/dist/call-history.mjs.map +1 -0
- package/dist/call-logs.cjs +2 -0
- package/dist/call-logs.cjs.map +1 -0
- package/dist/call-logs.d.cts +104 -0
- package/dist/call-logs.d.ts +104 -0
- package/dist/call-logs.mjs +2 -0
- package/dist/call-logs.mjs.map +1 -0
- package/dist/dial-plan.cjs +2 -0
- package/dist/dial-plan.cjs.map +1 -0
- package/dist/dial-plan.d.cts +70 -0
- package/dist/dial-plan.d.ts +70 -0
- package/dist/dial-plan.mjs +2 -0
- package/dist/dial-plan.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/onboarding.cjs +2 -0
- package/dist/onboarding.cjs.map +1 -0
- package/dist/onboarding.d.cts +49 -0
- package/dist/onboarding.d.ts +49 -0
- package/dist/onboarding.mjs +2 -0
- package/dist/onboarding.mjs.map +1 -0
- package/dist/phone-number-ordering.cjs +2 -0
- package/dist/phone-number-ordering.cjs.map +1 -0
- package/dist/phone-number-ordering.d.cts +83 -0
- package/dist/phone-number-ordering.d.ts +83 -0
- package/dist/phone-number-ordering.mjs +2 -0
- package/dist/phone-number-ordering.mjs.map +1 -0
- package/dist/phone-numbers.cjs +2 -0
- package/dist/phone-numbers.cjs.map +1 -0
- package/dist/phone-numbers.d.cts +77 -0
- package/dist/phone-numbers.d.ts +77 -0
- package/dist/phone-numbers.mjs +2 -0
- package/dist/phone-numbers.mjs.map +1 -0
- package/dist/softphone.cjs +2 -0
- package/dist/softphone.cjs.map +1 -0
- package/dist/softphone.d.cts +610 -0
- package/dist/softphone.d.ts +610 -0
- package/dist/softphone.mjs +2 -0
- package/dist/softphone.mjs.map +1 -0
- package/dist/voicemails.cjs +2 -0
- package/dist/voicemails.cjs.map +1 -0
- package/dist/voicemails.d.cts +128 -0
- package/dist/voicemails.d.ts +128 -0
- package/dist/voicemails.mjs +2 -0
- package/dist/voicemails.mjs.map +1 -0
- package/package.json +192 -0
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Call, EmergencyAddress, EmergencyAddressInput, CallState, DialStackPhone, CallEndReason } from '@dialstack/sdk-webrtc';
|
|
3
|
+
import { Locale as Locale$1, AppearanceOptions, FormattingOptions } from '@dialstack/sdk-js/pure';
|
|
4
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
5
|
+
import { Locale } from '@dialstack/sdk-js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `usePhone` — sole owner of the softphone's `DialStackPhone` instance and its
|
|
9
|
+
* connection lifecycle, web and React Native.
|
|
10
|
+
*
|
|
11
|
+
* It constructs the phone from credentials, subscribes to the connection events
|
|
12
|
+
* (connected / reconnecting / disconnected / fatal error / network.changed),
|
|
13
|
+
* maps them to a single `connection` state, and tears the phone down on unmount /
|
|
14
|
+
* credential change. It does NOT know about call legs — call state lives in
|
|
15
|
+
* `useCalls(phone, ...)`, and E911 provisioning in `useEmergencyBinding(phone, ...)`.
|
|
16
|
+
* Both are handed the live `phone` this hook owns.
|
|
17
|
+
*
|
|
18
|
+
* It is platform-agnostic: it imports only the headless core (`../../webrtc`),
|
|
19
|
+
* never the DOM or React Native.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Connection lifecycle surfaced to the softphone UI. */
|
|
23
|
+
type SoftphoneConnectionState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `useCallActions` — platform-agnostic per-call imperative actions, shared
|
|
27
|
+
* web ↔ RN.
|
|
28
|
+
*
|
|
29
|
+
* Wraps the foreground `Call`'s imperative actions (answer / reject / hangup /
|
|
30
|
+
* mute / hold / DTMF / transfer) so both softphones call them identically, with
|
|
31
|
+
* the same `PhoneError` → `onError` normalization. This is call CONTROL only —
|
|
32
|
+
* no view-state. In-call presentation state (the keypad/transfer overlay flags of
|
|
33
|
+
* the built-in `OngoingCall`) lives in `useCallOverlays`, so a consumer building a
|
|
34
|
+
* custom layout gets these actions without any built-in-UI plumbing. It
|
|
35
|
+
* deliberately does NOT render anything — it returns plain callbacks the platform
|
|
36
|
+
* UI binds to its own controls.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
interface UseCallActionsOptions {
|
|
40
|
+
/** Fired on a failed action (e.g. DTMF on a call with no sender, transfer). */
|
|
41
|
+
onError?: (e: {
|
|
42
|
+
code: string;
|
|
43
|
+
message: string;
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The imperative actions for one specific call, with core throws contained via
|
|
48
|
+
* `onError`. This is the per-call subset shared by every call surface (the
|
|
49
|
+
* foreground in-call controls AND an incoming/held card): each card binds these
|
|
50
|
+
* to a specific `Call` rather than only the foreground one.
|
|
51
|
+
*/
|
|
52
|
+
interface CallActions {
|
|
53
|
+
answer: () => void;
|
|
54
|
+
reject: () => void;
|
|
55
|
+
hangup: () => void;
|
|
56
|
+
toggleMute: () => void;
|
|
57
|
+
toggleHold: () => void;
|
|
58
|
+
/** Send a DTMF digit (no-op when no call). */
|
|
59
|
+
sendDtmf: (digit: string) => void;
|
|
60
|
+
}
|
|
61
|
+
interface UseCallActions extends CallActions {
|
|
62
|
+
/**
|
|
63
|
+
* Blind-transfer the active call to `destination`. Returns `true` when the
|
|
64
|
+
* transfer was *initiated* (so the UI can close its transfer overlay), `false`
|
|
65
|
+
* on empty input or a synchronous failure routed to `onError`. `true` means
|
|
66
|
+
* initiated, not confirmed — the core call is fire-and-forget, so the outcome
|
|
67
|
+
* arrives later as the call ending ('transferred') or an `onError`.
|
|
68
|
+
*/
|
|
69
|
+
transfer: (destination: string) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Build the per-call action subset for a SPECIFIC call — used by the
|
|
72
|
+
* incoming/held cards, which act on a call that isn't the foreground one. The
|
|
73
|
+
* foreground actions above are exactly `callActionsFor(activeCall)`.
|
|
74
|
+
*/
|
|
75
|
+
callActionsFor: (call: Call | null) => CallActions;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Action callbacks for `call` (the foreground call, may be null). Errors thrown
|
|
79
|
+
* by the core surface via `onError` rather than escaping to the caller.
|
|
80
|
+
*/
|
|
81
|
+
declare function useCallActions(call: Call | null, options?: UseCallActionsOptions): UseCallActions;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `useCallOverlays` — the in-call overlay flags, shared web ↔ RN.
|
|
85
|
+
*
|
|
86
|
+
* These are presentation state for ONE screen (the built-in `OngoingCall`): the
|
|
87
|
+
* DTMF keypad panel, the blind-transfer input, and the audio-device picker, which
|
|
88
|
+
* are mutually exclusive.
|
|
89
|
+
* They are deliberately kept OUT of `useCallActions` (which is platform-agnostic
|
|
90
|
+
* call control) so a consumer building a custom layout gets call control without
|
|
91
|
+
* this built-in-UI plumbing. It's a shared hook rather than local `OngoingCall`
|
|
92
|
+
* state only so web and React Native can't drift on WHEN the overlays reset.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
interface UseCallOverlays {
|
|
96
|
+
/** Whether the in-call DTMF keypad overlay is showing. */
|
|
97
|
+
showKeypad: boolean;
|
|
98
|
+
/** Whether the in-call transfer input overlay is showing. */
|
|
99
|
+
showTransfer: boolean;
|
|
100
|
+
/** Whether the in-call audio-device picker is showing. */
|
|
101
|
+
showDevices: boolean;
|
|
102
|
+
/** Toggle the DTMF keypad (closes the other overlays — they're exclusive). */
|
|
103
|
+
toggleKeypad: () => void;
|
|
104
|
+
/** Toggle the transfer input (closes the other overlays). */
|
|
105
|
+
toggleTransfer: () => void;
|
|
106
|
+
/** Toggle the audio-device picker (closes the other overlays). */
|
|
107
|
+
toggleDevices: () => void;
|
|
108
|
+
/** Close the transfer overlay (e.g. after a transfer is handed off). */
|
|
109
|
+
closeTransfer: () => void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* `useCallDuration` — the live in-call duration readout, shared web ↔ RN.
|
|
114
|
+
*
|
|
115
|
+
* The `Call` updates its `duration` field in place via an internal timer; React
|
|
116
|
+
* doesn't observe that mutation. This hook ticks while a call is up and returns
|
|
117
|
+
* the formatted `m:ss` string so the UI re-renders the readout each second.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns the formatted elapsed time for `call`, ticking every `intervalMs`
|
|
122
|
+
* (default 500ms — twice a second so the readout never visibly lags the wall
|
|
123
|
+
* clock). Returns `0:00` when there is no active call.
|
|
124
|
+
*/
|
|
125
|
+
declare function useCallDuration(call: Call | null, intervalMs?: number): string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* `useEmergencyBinding` — the Softphone's built-in E911 provisioning logic.
|
|
129
|
+
*
|
|
130
|
+
* Model: "always send it, the server decides." The server binds the presented
|
|
131
|
+
* emergency address to the connection's network at the `authenticate` handshake
|
|
132
|
+
* and is the authority on whether it's valid here — it rejects a mismatch via
|
|
133
|
+
* the `network.changed` signal.
|
|
134
|
+
*
|
|
135
|
+
* - On connect, if the session has a saved address but presented none (fresh
|
|
136
|
+
* browser), auto-present it (select + reconnect once). Same network → the
|
|
137
|
+
* server binds it silently (reused). Different network → the server denies
|
|
138
|
+
* (network.changed) → we prompt.
|
|
139
|
+
* - `bound` is true unless the server denied (network.changed) or there is no
|
|
140
|
+
* saved address to present at all.
|
|
141
|
+
*
|
|
142
|
+
* When the host supplies `emergencyAddressId`, it manages E911 itself and this
|
|
143
|
+
* hook stays dormant (`disabled`). 911/933 are never gated by any of this.
|
|
144
|
+
*
|
|
145
|
+
* It talks to the `DialStackPhone` (owned by `usePhone`) DIRECTLY via a narrow
|
|
146
|
+
* interface — the subset of phone methods E911 needs. That interface is the
|
|
147
|
+
* hook's testable seam: a test passes a small phone-shaped stub, no full mock.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
interface UseEmergencyBinding {
|
|
151
|
+
/** True until the first post-connect status resolves. */
|
|
152
|
+
loading: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* True when outbound PSTN is usable for this session — the server accepted the
|
|
155
|
+
* presented address for the current network. False when it denied
|
|
156
|
+
* (network.changed) or there's no saved address → show the prompt.
|
|
157
|
+
*/
|
|
158
|
+
bound: boolean;
|
|
159
|
+
/** Saved addresses to offer as "Are you here?" choices. */
|
|
160
|
+
savedAddresses: EmergencyAddress[];
|
|
161
|
+
/** True while an address submit (confirm/create, which forces a reconnect) is in flight. */
|
|
162
|
+
submitting: boolean;
|
|
163
|
+
/** Last error (e.g. a carrier rejection). */
|
|
164
|
+
error: string | null;
|
|
165
|
+
/** Called from the Softphone when the phone emits `network.changed` (denied). */
|
|
166
|
+
onNetworkChanged: () => void;
|
|
167
|
+
/** Confirm an existing saved address for this network (selects + reconnects). */
|
|
168
|
+
confirm: (id: string) => Promise<void>;
|
|
169
|
+
/** Create + validate a new address, then bind it (reconnect). */
|
|
170
|
+
create: (input: EmergencyAddressInput) => Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface SoftphoneError {
|
|
174
|
+
code: string;
|
|
175
|
+
message: string;
|
|
176
|
+
}
|
|
177
|
+
interface UseLastError {
|
|
178
|
+
/** The last error surfaced to the user, or null. Drives the built-in banner. */
|
|
179
|
+
lastError: SoftphoneError | null;
|
|
180
|
+
/**
|
|
181
|
+
* Error handler to pass into `useCalls`/`useCallActions`. It forwards to the
|
|
182
|
+
* host's `onError` AND stores the error locally so the built-in UI can show it.
|
|
183
|
+
*/
|
|
184
|
+
handleError: (event: SoftphoneError) => void;
|
|
185
|
+
/** Dismiss the current error. */
|
|
186
|
+
clearError: () => void;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Owns the softphone's "last error" state, shared by the web and RN providers so
|
|
190
|
+
* the error-surfacing behavior can't drift between platforms (the same reason
|
|
191
|
+
* shouldRingIncoming was extracted). Wraps the host `onError`: it still fires for
|
|
192
|
+
* the host, and the error is also kept locally for the built-in error banner.
|
|
193
|
+
*/
|
|
194
|
+
declare function useLastError(onError?: (event: SoftphoneError) => void): UseLastError;
|
|
195
|
+
|
|
196
|
+
interface UseDialInput {
|
|
197
|
+
/**
|
|
198
|
+
* Handle a per-keystroke value change: strip display separators only (typing
|
|
199
|
+
* stays natural; no mid-field E.164 rewrite). Pass the raw field value.
|
|
200
|
+
*/
|
|
201
|
+
onType: (raw: string) => void;
|
|
202
|
+
/**
|
|
203
|
+
* Handle a paste: a pasted value is complete, so fully normalize it — a
|
|
204
|
+
* formatted `(581) 319-5082` becomes `+15813195082`, so the user sees exactly
|
|
205
|
+
* what will be dialed. Pass the raw clipboard text.
|
|
206
|
+
*/
|
|
207
|
+
onPasteText: (raw: string) => void;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Shared cleaning for a dial-string input, used by BOTH the dial pad and the
|
|
211
|
+
* transfer field on web + RN so the "what may I type / what does a paste become"
|
|
212
|
+
* rule lives in one place. Each platform wires its native input event (web
|
|
213
|
+
* onChange/onPaste, RN onChangeText) to these — the string logic never diverges.
|
|
214
|
+
*/
|
|
215
|
+
declare function useDialInput(setValue: (value: string) => void): UseDialInput;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Pure, platform-agnostic view-model helpers shared by the web and React Native
|
|
219
|
+
* softphones. No React, no DOM, no React Native — just functions over the headless
|
|
220
|
+
* core's `Call` shape, so both UIs format and route identically and the logic is
|
|
221
|
+
* unit-testable in isolation.
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/** Which screen the softphone should present for the current foreground call. */
|
|
225
|
+
type SoftphoneScreen = 'dial' | 'incoming' | 'in-call';
|
|
226
|
+
/**
|
|
227
|
+
* An inbound call still alerting (the user hasn't answered). `trying` is
|
|
228
|
+
* included because an inbound call is briefly in `trying` before the first
|
|
229
|
+
* `call.ringing` arrives, and it must show the incoming screen throughout.
|
|
230
|
+
*/
|
|
231
|
+
declare function isIncomingRinging(call: Call): boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Whether the softphone should be playing the incoming-call ring right now. Both
|
|
234
|
+
* the web and RN providers drive their ringtone off this one predicate so the
|
|
235
|
+
* "are we ringing?" rule has a single home and can't drift between platforms.
|
|
236
|
+
*
|
|
237
|
+
* Accepts either the single foreground call (back-compat) or the full call list:
|
|
238
|
+
* ring while ANY inbound call is still alerting — a call-waiting interrupt during
|
|
239
|
+
* an active call rings just like an idle inbound one.
|
|
240
|
+
*/
|
|
241
|
+
declare function shouldRingIncoming(calls: Call | Call[] | null): boolean;
|
|
242
|
+
/** A call that has been answered (active or held) — controls/duration apply.
|
|
243
|
+
* Delegates to `Call.isConnected`, the single source of truth for the rule. */
|
|
244
|
+
declare function isCallActive(call: Call): boolean;
|
|
245
|
+
/** Pick the screen for the current foreground call (null → the dial pad). */
|
|
246
|
+
declare function selectScreen(call: Call | null): SoftphoneScreen;
|
|
247
|
+
/** The remote party's raw number/address for a call, by direction. */
|
|
248
|
+
declare function callPeerNumber(call: Call): string;
|
|
249
|
+
/** The remote party's display name, when the server supplied one (inbound only). */
|
|
250
|
+
declare function callPeerName(call: Call): string | null;
|
|
251
|
+
/**
|
|
252
|
+
* `m:ss` elapsed-time formatting for the in-call duration readout. Negative or
|
|
253
|
+
* fractional input is clamped/floored to a whole non-negative second count
|
|
254
|
+
* (`Call.duration` is always ≥0, but this is a public helper).
|
|
255
|
+
*/
|
|
256
|
+
declare function formatCallDuration(seconds: number): string;
|
|
257
|
+
/**
|
|
258
|
+
* Pretty-print an E.164 / national number for display, leaving extensions and
|
|
259
|
+
* partial input untouched. Mirrors the formatting used across the SDK
|
|
260
|
+
* components. `defaultCountry` defaults to `US` (matching the softphone UIs).
|
|
261
|
+
*/
|
|
262
|
+
declare function formatDisplayNumber(value: string, defaultCountry?: CountryCode): string;
|
|
263
|
+
/**
|
|
264
|
+
* The country used to canonicalize a national dial string to E.164. Softphone
|
|
265
|
+
* calling is US-only today; this is the single, deliberately-fixed seam for that.
|
|
266
|
+
* It is intentionally NOT wired to the public `formatting.defaultCountry` (which
|
|
267
|
+
* governs display only) — dialing under a different country than the number was
|
|
268
|
+
* entered in produces wrong/undialable destinations. When calling goes
|
|
269
|
+
* multi-region, thread a real country through `sanitizeDestination` from here.
|
|
270
|
+
*/
|
|
271
|
+
declare const DIAL_COUNTRY: CountryCode;
|
|
272
|
+
/**
|
|
273
|
+
* Strip display separators (spaces, parens, dashes, dots) and cap length,
|
|
274
|
+
* keeping only what the server accepts: digits, +, * and #, DTMF A–D. Does NOT
|
|
275
|
+
* canonicalize to E.164 — use it per-keystroke so typing stays natural, and the
|
|
276
|
+
* result is always within the server allowlist (or empty).
|
|
277
|
+
*/
|
|
278
|
+
declare function stripToDialString(value: string): string;
|
|
279
|
+
/**
|
|
280
|
+
* Normalize a user-entered/pasted dial string into what the softphone actually
|
|
281
|
+
* sends: strip display separators (so `(581) 319-5082` → `15813195082`), and —
|
|
282
|
+
* when the result is a valid PSTN number — canonicalize it to E.164 (`+1…`).
|
|
283
|
+
* Extensions (`1001`), star/# feature codes (`*72`), and DTMF (`A`–`D`) are NOT
|
|
284
|
+
* phone numbers, so they're left as their stripped digits/symbols. The result
|
|
285
|
+
* always fits the server's allowlist, so callers "send something clean".
|
|
286
|
+
*
|
|
287
|
+
* Idempotent and safe on partial input — use it on paste and as the last step
|
|
288
|
+
* before dialing (per-keystroke, prefer `stripToDialString` so E.164 conversion
|
|
289
|
+
* doesn't rewrite the field mid-type).
|
|
290
|
+
*/
|
|
291
|
+
declare function sanitizeDestination(value: string, defaultCountry?: CountryCode): string;
|
|
292
|
+
/**
|
|
293
|
+
* Map a call state to a stable, locale-agnostic label key. The UIs resolve the
|
|
294
|
+
* key to a localized string (web via the component locale table, RN via its own
|
|
295
|
+
* map) — sharing the key→state mapping keeps the two from drifting on which
|
|
296
|
+
* state shows which label, without forcing a shared i18n table.
|
|
297
|
+
*/
|
|
298
|
+
declare function callStateLabelKey(state: CallState): keyof Locale['softphone'];
|
|
299
|
+
declare function errorMessageKey(code: string): keyof Locale['softphone'];
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Shared design tokens for the DialStack Softphone.
|
|
303
|
+
*
|
|
304
|
+
* This module is intentionally framework-agnostic (no DOM, no React Native) so
|
|
305
|
+
* that BOTH the web Softphone (Web Component, consumes these as CSS values) and the
|
|
306
|
+
* React Native Softphone (consumes these in a StyleSheet) render from a single
|
|
307
|
+
* source of truth — that is what makes the two look identical by default.
|
|
308
|
+
*
|
|
309
|
+
* Colors resolve from the same `AppearanceOptions` surface the rest of the SDK
|
|
310
|
+
* uses (theme + variables), so theming through `DialstackComponentsProvider` /
|
|
311
|
+
* the `appearance` prop flows through identically on both platforms.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
/** Flat color set the Softphone paints from, after appearance is resolved. */
|
|
315
|
+
interface SoftphonePalette {
|
|
316
|
+
/** Component background. */
|
|
317
|
+
background: string;
|
|
318
|
+
/** Dial-pad key / control surface fill. */
|
|
319
|
+
surface: string;
|
|
320
|
+
/** Surface fill while pressed/active. */
|
|
321
|
+
surfaceActive: string;
|
|
322
|
+
/** Primary text (digits, destination, peer name). */
|
|
323
|
+
text: string;
|
|
324
|
+
/** Secondary text (letter sub-labels, call state, hints). */
|
|
325
|
+
textSecondary: string;
|
|
326
|
+
/** Hairline borders/dividers. */
|
|
327
|
+
border: string;
|
|
328
|
+
/** Accent (links, focus ring, keypad/secondary control highlight). */
|
|
329
|
+
accent: string;
|
|
330
|
+
/** Call / Answer (green) action color. */
|
|
331
|
+
success: string;
|
|
332
|
+
/** Hang up / Decline (red) action color. */
|
|
333
|
+
danger: string;
|
|
334
|
+
/** Warning / caution (amber) — used by the E911 banner. */
|
|
335
|
+
warning: string;
|
|
336
|
+
/** Foreground used on top of accent/success/danger fills. */
|
|
337
|
+
onAccent: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Shared core of the softphone provider — the wiring both the web and native
|
|
342
|
+
* providers reuse so it can't drift between them. It provides the context and
|
|
343
|
+
* renders `children`; each platform supplies its own side-effects (web:
|
|
344
|
+
* `<style>`/`<audio>`/ringtone; native: InCallManager) as ordinary child
|
|
345
|
+
* components that read the context via `useSoftphoneBase`.
|
|
346
|
+
*
|
|
347
|
+
* Must stay DOM- and React-Native-free: it's part of the shared headless core
|
|
348
|
+
* (src/react/softphone/core) that @dialstack/sdk-native inlines at build time.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
/** Context fields both platforms expose. Platforms add their own via `extra`. */
|
|
352
|
+
interface SoftphoneContextBase {
|
|
353
|
+
connection: SoftphoneConnectionState;
|
|
354
|
+
/**
|
|
355
|
+
* The live WebRTC phone, or null before the first one is constructed. For the
|
|
356
|
+
* phone-scoped settings that aren't per-call — audio device selection, which
|
|
357
|
+
* must work whether or not a call is up. Per-call actions belong on `actions`.
|
|
358
|
+
*/
|
|
359
|
+
webrtcPhone: DialStackPhone | null;
|
|
360
|
+
calls: Call[];
|
|
361
|
+
activeCall: Call | null;
|
|
362
|
+
incomingCalls: Call[];
|
|
363
|
+
/** True while an unanswered inbound call should be audibly ringing. */
|
|
364
|
+
incomingRinging: boolean;
|
|
365
|
+
heldCalls: Call[];
|
|
366
|
+
answerCall: (call: Call) => void;
|
|
367
|
+
switchToCall: (call: Call) => void;
|
|
368
|
+
actions: UseCallActions;
|
|
369
|
+
/**
|
|
370
|
+
* Internal built-in-UI machinery: the mutually-exclusive keypad/transfer
|
|
371
|
+
* overlay flags the bundled `OngoingCall` renders. Not part of the public
|
|
372
|
+
* softphone API — a custom layout owns its own presentation state and ignores
|
|
373
|
+
* this. Kept on the shared context (rather than local to `OngoingCall`) only so
|
|
374
|
+
* web and React Native can't drift on when the overlays reset.
|
|
375
|
+
*/
|
|
376
|
+
overlays: UseCallOverlays;
|
|
377
|
+
duration: string;
|
|
378
|
+
consultCall: Call | null;
|
|
379
|
+
transferOriginal: Call | null;
|
|
380
|
+
startAttendedTransfer: (destination: string) => Promise<void>;
|
|
381
|
+
completeAttendedTransfer: () => void;
|
|
382
|
+
cancelAttendedTransfer: () => void;
|
|
383
|
+
placeCall: (destination: string) => Promise<void>;
|
|
384
|
+
emergency: UseEmergencyBinding;
|
|
385
|
+
emergencyManagedByHost: boolean;
|
|
386
|
+
lastError: {
|
|
387
|
+
code: string;
|
|
388
|
+
message: string;
|
|
389
|
+
} | null;
|
|
390
|
+
clearError: () => void;
|
|
391
|
+
t: (key: keyof Locale$1['softphone']) => string;
|
|
392
|
+
displayNumber: (value: string) => string;
|
|
393
|
+
/** Resolved theme palette — computed on both platforms so mobile themes like web. */
|
|
394
|
+
palette: SoftphonePalette;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* SoftphoneProvider (web). Shared wiring lives in SoftphoneProviderBase; this
|
|
399
|
+
* file adds only the web bits: iceServers/formatting props, live appearance, the
|
|
400
|
+
* scoped `<style>`, the persistent `<audio>` sink, and the WebAudio ringtone.
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
interface SoftphoneProviderProps {
|
|
404
|
+
/**
|
|
405
|
+
* WebRTC user session token. The provider constructs a `DialStackPhone` with it
|
|
406
|
+
* and connects. Changing the token reconnects with the new credentials.
|
|
407
|
+
*/
|
|
408
|
+
token: string;
|
|
409
|
+
/** API base URL (defaults to the SDK's production endpoint). */
|
|
410
|
+
apiBaseUrl?: string;
|
|
411
|
+
/**
|
|
412
|
+
* Called shortly before the session token expires (about 60 seconds ahead).
|
|
413
|
+
* Return a fresh token minted by your backend; the SDK delivers it in-band over
|
|
414
|
+
* the existing connection — no reconnect and no call disruption. If it rejects,
|
|
415
|
+
* the SDK keeps the (still-valid) connection open and surfaces an `error`.
|
|
416
|
+
*/
|
|
417
|
+
onTokenExpiring?: () => Promise<string>;
|
|
418
|
+
/** Override the ICE servers instead of fetching them from the API. */
|
|
419
|
+
iceServers?: RTCIceServer[];
|
|
420
|
+
/**
|
|
421
|
+
* Emergency (E911) address id to present on connect for outbound PSTN. When
|
|
422
|
+
* supplied, the host is managing E911 itself and the built-in "Are you here?"
|
|
423
|
+
* location prompt is disabled. When omitted, the softphone owns the E911 flow.
|
|
424
|
+
*/
|
|
425
|
+
emergencyAddressId?: string;
|
|
426
|
+
/** Connect automatically once mounted (default: true). */
|
|
427
|
+
autoConnect?: boolean;
|
|
428
|
+
/** Theming — the same appearance surface used across the SDK. */
|
|
429
|
+
appearance?: AppearanceOptions;
|
|
430
|
+
/** Locale for UI strings. */
|
|
431
|
+
locale?: Locale$1;
|
|
432
|
+
/** Formatting options (e.g. `defaultCountry` for number display). */
|
|
433
|
+
formatting?: FormattingOptions;
|
|
434
|
+
/** Fired when the connection lifecycle changes. */
|
|
435
|
+
onConnectionStateChange?: (event: {
|
|
436
|
+
state: SoftphoneConnectionState;
|
|
437
|
+
}) => void;
|
|
438
|
+
/** Fired when an inbound call arrives. */
|
|
439
|
+
onIncomingCall?: (event: {
|
|
440
|
+
from: string;
|
|
441
|
+
fromName: string | null;
|
|
442
|
+
}) => void;
|
|
443
|
+
/** Fired when a call (in or out) becomes the foreground call. */
|
|
444
|
+
onCallStarted?: (event: {
|
|
445
|
+
direction: 'inbound' | 'outbound';
|
|
446
|
+
peer: string;
|
|
447
|
+
}) => void;
|
|
448
|
+
/** Fired when the foreground call ends. */
|
|
449
|
+
onCallEnded?: (event: {
|
|
450
|
+
reason: CallEndReason;
|
|
451
|
+
}) => void;
|
|
452
|
+
/** Fired on a non-fatal or fatal phone error. */
|
|
453
|
+
onError?: (event: {
|
|
454
|
+
code: string;
|
|
455
|
+
message: string;
|
|
456
|
+
}) => void;
|
|
457
|
+
/** The softphone UI (or anything that consumes the context). */
|
|
458
|
+
children: React.ReactNode;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* The web softphone context: the shared base plus the web-only `scope` (the CSS
|
|
462
|
+
* class the `.ds-*` styles are nested under). Native adds `locationProvider`
|
|
463
|
+
* instead; components read only the fields their platform provides.
|
|
464
|
+
*/
|
|
465
|
+
interface SoftphoneContextValue extends SoftphoneContextBase {
|
|
466
|
+
/** The scoped class name that wraps the softphone UI (for `.ds-*` styles). */
|
|
467
|
+
scope: string;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Provides the softphone connection + state to its children. Owns the phone, the
|
|
471
|
+
* remote-audio element, the scoped stylesheet, and the E911 flow.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```tsx
|
|
475
|
+
* <SoftphoneProvider token={webrtcToken}>
|
|
476
|
+
* <Softphone />
|
|
477
|
+
* </SoftphoneProvider>
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
declare const SoftphoneProvider: React.FC<SoftphoneProviderProps>;
|
|
481
|
+
/**
|
|
482
|
+
* Access the full softphone context.
|
|
483
|
+
*
|
|
484
|
+
* @throws {Error} If used outside of `<SoftphoneProvider>`.
|
|
485
|
+
*/
|
|
486
|
+
declare const useSoftphone: () => SoftphoneContextValue;
|
|
487
|
+
/**
|
|
488
|
+
* The active foreground call and its actions, or `activeCall: null` when idle.
|
|
489
|
+
*
|
|
490
|
+
* @throws {Error} If used outside of `<SoftphoneProvider>`.
|
|
491
|
+
*/
|
|
492
|
+
declare const useActiveCall: () => {
|
|
493
|
+
activeCall: Call | null;
|
|
494
|
+
actions: UseCallActions;
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* The currently-ringing inbound call, or `null`.
|
|
498
|
+
*
|
|
499
|
+
* @throws {Error} If used outside of `<SoftphoneProvider>`.
|
|
500
|
+
*/
|
|
501
|
+
declare const useIncomingCall: () => Call | null;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Softphone — the batteries-included softphone: dial pad, incoming-call
|
|
505
|
+
* answer/decline, and in-call controls, switching between them based on call
|
|
506
|
+
* state. This is the drop-in "just give me a working softphone" UI.
|
|
507
|
+
*
|
|
508
|
+
* `<Softphone>` is a pure consumer of `<SoftphoneProvider>` — the provider owns
|
|
509
|
+
* the connection and the `token`, and is the SINGLE place credentials enter.
|
|
510
|
+
* Render it under a provider:
|
|
511
|
+
*
|
|
512
|
+
* ```tsx
|
|
513
|
+
* <SoftphoneProvider token={webrtcToken} apiBaseUrl={apiBaseUrl}>
|
|
514
|
+
* <Softphone />
|
|
515
|
+
* </SoftphoneProvider>
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* Because the connection lives in the provider (not this component), the
|
|
519
|
+
* softphone stays connected app-wide while `<Softphone>` mounts/unmounts (e.g.
|
|
520
|
+
* inside a drawer). `useSoftphone().placeCall(...)` places calls from anywhere
|
|
521
|
+
* under the provider. For a bespoke UI, compose `<DialPad>` / `<IncomingCall>` /
|
|
522
|
+
* `<OngoingCall>` yourself under the same provider instead.
|
|
523
|
+
*/
|
|
524
|
+
|
|
525
|
+
interface SoftphoneProps {
|
|
526
|
+
/**
|
|
527
|
+
* Focus the dial pad's destination field on mount so the user can type
|
|
528
|
+
* immediately (e.g. when the softphone opens in a drawer).
|
|
529
|
+
*/
|
|
530
|
+
autoFocusDestination?: boolean;
|
|
531
|
+
}
|
|
532
|
+
declare const Softphone: React.FC<SoftphoneProps>;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* DialPad — the idle/outbound screen of the softphone: connection status chip, a
|
|
536
|
+
* destination field, the 12-key pad, and the call button. Reads connection +
|
|
537
|
+
* `placeCall` from the softphone context and owns only its own `destination` text.
|
|
538
|
+
*
|
|
539
|
+
* The E911 prompt is NOT rendered here — `<EmergencyBanner>` is a separate
|
|
540
|
+
* component so a modular consumer can place it wherever their layout wants (or
|
|
541
|
+
* omit it when the host manages E911). The batteries-included `<Softphone>`
|
|
542
|
+
* renders the banner above this pad itself, so its look is unchanged.
|
|
543
|
+
*
|
|
544
|
+
* Must be rendered inside a `<SoftphoneProvider>`.
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
interface DialPadProps {
|
|
548
|
+
/**
|
|
549
|
+
* Focus the destination field on mount so the user can type immediately (e.g.
|
|
550
|
+
* when the dial pad opens in a drawer). Off by default to avoid stealing focus.
|
|
551
|
+
*/
|
|
552
|
+
autoFocusDestination?: boolean;
|
|
553
|
+
}
|
|
554
|
+
declare const DialPad: React.FC<DialPadProps>;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* IncomingCall / IncomingStack — the ringing inbound UI.
|
|
558
|
+
*
|
|
559
|
+
* `IncomingCall` is the single full-screen incoming screen (the idle,
|
|
560
|
+
* one-caller case) — it renders the first ringing call as a full-size card, and
|
|
561
|
+
* nothing when none is ringing. `IncomingStack` renders ALL ringing calls as
|
|
562
|
+
* stacked cards, compact when there's more than one; it's what `<Softphone>`
|
|
563
|
+
* layers over the base screen for call-waiting and multiple concurrent inbound.
|
|
564
|
+
*
|
|
565
|
+
* Both read from the softphone context and must be rendered inside a
|
|
566
|
+
* `<SoftphoneProvider>`.
|
|
567
|
+
*/
|
|
568
|
+
|
|
569
|
+
declare const IncomingCall: React.FC;
|
|
570
|
+
/**
|
|
571
|
+
* All ringing inbound calls, stacked. Compact when >1 so a burst of calls (or a
|
|
572
|
+
* call-waiting interrupt over an active call) stays small and non-intrusive.
|
|
573
|
+
* Renders nothing when none is ringing.
|
|
574
|
+
*/
|
|
575
|
+
declare const IncomingStack: React.FC<{
|
|
576
|
+
compact?: boolean;
|
|
577
|
+
}>;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* OngoingCall — the in-call screen: peer + call-state + live duration, the
|
|
581
|
+
* optional DTMF keypad / transfer / audio-device overlays, the control row (mute /
|
|
582
|
+
* hold / keypad / transfer / audio), and hang up. Renders nothing when there is no
|
|
583
|
+
* active call.
|
|
584
|
+
*
|
|
585
|
+
* Reads the active call, actions, and duration from the softphone context; owns
|
|
586
|
+
* only its own transient DTMF-readout and transfer-input text. Must be rendered
|
|
587
|
+
* inside a `<SoftphoneProvider>`.
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
declare const OngoingCall: React.FC;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* EmergencyBanner — the built-in "set your emergency location" (E911) prompt
|
|
594
|
+
* shown above the dial pad while the session's emergency address is unbound.
|
|
595
|
+
*
|
|
596
|
+
* Shown only on the idle dialer: the user sets a location before dialing (the
|
|
597
|
+
* server is the authority on outbound PSTN). Hidden when the host manages E911
|
|
598
|
+
* (emergencyAddressId supplied), while binding is loading, once bound, or while
|
|
599
|
+
* a call is active. Submitting an address forces a reconnect, so the dial pad
|
|
600
|
+
* disables placing calls (`canPlaceCall` reads `emergency.submitting`) until it
|
|
601
|
+
* settles — otherwise a call started mid-reconnect would be dropped.
|
|
602
|
+
*
|
|
603
|
+
* Reads the E911 flow (`emergency`) from the softphone context; owns only its own
|
|
604
|
+
* expand/form UI state.
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
declare const EmergencyBanner: React.FC;
|
|
608
|
+
|
|
609
|
+
export { DIAL_COUNTRY, DialPad, EmergencyBanner, IncomingCall, IncomingStack, OngoingCall, Softphone, SoftphoneProvider, callPeerName, callPeerNumber, callStateLabelKey, errorMessageKey, formatCallDuration, formatDisplayNumber, isCallActive, isIncomingRinging, sanitizeDestination, selectScreen, shouldRingIncoming, stripToDialString, useActiveCall, useCallActions, useCallDuration, useDialInput, useIncomingCall, useLastError, useSoftphone };
|
|
610
|
+
export type { DialPadProps, SoftphoneConnectionState, SoftphoneContextValue, SoftphoneError, SoftphoneProps, SoftphoneProviderProps, SoftphoneScreen, UseCallActions, UseCallActionsOptions, UseDialInput, UseLastError };
|