@dialstack/sdk-react 3.1.0 → 3.3.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/dist/ai-agent.cjs +1 -1
- package/dist/ai-agent.cjs.map +1 -1
- package/dist/ai-agent.d.cts +9 -0
- package/dist/ai-agent.d.ts +9 -0
- package/dist/ai-agent.mjs +1 -1
- package/dist/ai-agent.mjs.map +1 -1
- package/dist/call-history.cjs +1 -1
- package/dist/call-history.cjs.map +1 -1
- package/dist/call-history.mjs +1 -1
- package/dist/call-history.mjs.map +1 -1
- package/dist/call-logs.cjs +1 -1
- package/dist/call-logs.cjs.map +1 -1
- package/dist/call-logs.mjs +1 -1
- package/dist/call-logs.mjs.map +1 -1
- package/dist/dial-plan.cjs +1 -1
- package/dist/dial-plan.cjs.map +1 -1
- package/dist/dial-plan.mjs +1 -1
- package/dist/dial-plan.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/onboarding.cjs +1 -1
- package/dist/onboarding.cjs.map +1 -1
- package/dist/onboarding.mjs +1 -1
- package/dist/onboarding.mjs.map +1 -1
- package/dist/phone-number-ordering.cjs +1 -1
- package/dist/phone-number-ordering.cjs.map +1 -1
- package/dist/phone-number-ordering.mjs +1 -1
- package/dist/phone-number-ordering.mjs.map +1 -1
- package/dist/phone-numbers.cjs +1 -1
- package/dist/phone-numbers.cjs.map +1 -1
- package/dist/phone-numbers.mjs +1 -1
- package/dist/phone-numbers.mjs.map +1 -1
- package/dist/softphone.cjs +1 -1
- package/dist/softphone.cjs.map +1 -1
- package/dist/softphone.d.cts +42 -7
- package/dist/softphone.d.ts +42 -7
- package/dist/softphone.mjs +1 -1
- package/dist/softphone.mjs.map +1 -1
- package/dist/voicemails.cjs +1 -1
- package/dist/voicemails.cjs.map +1 -1
- package/dist/voicemails.mjs +1 -1
- package/dist/voicemails.mjs.map +1 -1
- package/package.json +4 -4
package/dist/softphone.d.ts
CHANGED
|
@@ -84,8 +84,8 @@ declare function useCallActions(call: Call | null, options?: UseCallActionsOptio
|
|
|
84
84
|
* `useCallOverlays` — the in-call overlay flags, shared web ↔ RN.
|
|
85
85
|
*
|
|
86
86
|
* These are presentation state for ONE screen (the built-in `OngoingCall`): the
|
|
87
|
-
* DTMF keypad panel, the blind-transfer input,
|
|
88
|
-
* are mutually exclusive.
|
|
87
|
+
* DTMF keypad panel, the blind-transfer input, the add-call dial input, and the
|
|
88
|
+
* audio-device picker, which are mutually exclusive.
|
|
89
89
|
* They are deliberately kept OUT of `useCallActions` (which is platform-agnostic
|
|
90
90
|
* call control) so a consumer building a custom layout gets call control without
|
|
91
91
|
* this built-in-UI plumbing. It's a shared hook rather than local `OngoingCall`
|
|
@@ -99,14 +99,20 @@ interface UseCallOverlays {
|
|
|
99
99
|
showTransfer: boolean;
|
|
100
100
|
/** Whether the in-call audio-device picker is showing. */
|
|
101
101
|
showDevices: boolean;
|
|
102
|
+
/** Whether the in-call add-call dial input is showing. */
|
|
103
|
+
showAddCall: boolean;
|
|
102
104
|
/** Toggle the DTMF keypad (closes the other overlays — they're exclusive). */
|
|
103
105
|
toggleKeypad: () => void;
|
|
104
106
|
/** Toggle the transfer input (closes the other overlays). */
|
|
105
107
|
toggleTransfer: () => void;
|
|
106
108
|
/** Toggle the audio-device picker (closes the other overlays). */
|
|
107
109
|
toggleDevices: () => void;
|
|
110
|
+
/** Toggle the add-call dial input (closes the other overlays). */
|
|
111
|
+
toggleAddCall: () => void;
|
|
108
112
|
/** Close the transfer overlay (e.g. after a transfer is handed off). */
|
|
109
113
|
closeTransfer: () => void;
|
|
114
|
+
/** Close the add-call overlay (e.g. once the second call is placed). */
|
|
115
|
+
closeAddCall: () => void;
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
/**
|
|
@@ -381,6 +387,19 @@ interface SoftphoneContextBase {
|
|
|
381
387
|
completeAttendedTransfer: () => void;
|
|
382
388
|
cancelAttendedTransfer: () => void;
|
|
383
389
|
placeCall: (destination: string) => Promise<void>;
|
|
390
|
+
/** The calls bridged into a local three-way conference (empty when not merged). */
|
|
391
|
+
mergedCalls: Call[];
|
|
392
|
+
isMerged: boolean;
|
|
393
|
+
/** While merged, every remote party mixed — what the local user hears. */
|
|
394
|
+
conferenceAudio: MediaStream | null;
|
|
395
|
+
/** Whether merging is possible: two connected calls, no transfer, WebAudio present. */
|
|
396
|
+
canMerge: boolean;
|
|
397
|
+
mergeCalls: () => void;
|
|
398
|
+
splitMerge: () => void;
|
|
399
|
+
/** Hang up every leg of the conference (the merged UI shows one Hang up). */
|
|
400
|
+
hangupConference: () => void;
|
|
401
|
+
/** Hold or resume every leg of the conference together. */
|
|
402
|
+
holdConference: (held: boolean) => void;
|
|
384
403
|
emergency: UseEmergencyBinding;
|
|
385
404
|
emergencyManagedByHost: boolean;
|
|
386
405
|
lastError: {
|
|
@@ -401,9 +420,18 @@ interface SoftphoneContextBase {
|
|
|
401
420
|
*/
|
|
402
421
|
|
|
403
422
|
interface SoftphoneProviderProps {
|
|
423
|
+
/**
|
|
424
|
+
* Adopt an EXISTING phone instead of constructing one from `token`.
|
|
425
|
+
*
|
|
426
|
+
* For hosts where the phone outlives the UI — with a native call surface a
|
|
427
|
+
* call can exist before any phone does. Neither connected nor disconnected by
|
|
428
|
+
* the provider; the host that created it owns its lifecycle.
|
|
429
|
+
*/
|
|
430
|
+
existingPhone?: DialStackPhone | null;
|
|
404
431
|
/**
|
|
405
432
|
* WebRTC user session token. The provider constructs a `DialStackPhone` with it
|
|
406
433
|
* and connects. Changing the token reconnects with the new credentials.
|
|
434
|
+
* Ignored when `existingPhone` is set.
|
|
407
435
|
*/
|
|
408
436
|
token: string;
|
|
409
437
|
/** API base URL (defaults to the SDK's production endpoint). */
|
|
@@ -437,6 +465,13 @@ interface SoftphoneProviderProps {
|
|
|
437
465
|
}) => void;
|
|
438
466
|
/** Fired when an inbound call arrives. */
|
|
439
467
|
onIncomingCall?: (event: {
|
|
468
|
+
/**
|
|
469
|
+
* The call's id — the handle for `callActionsFor()` / `answerCall()`, and
|
|
470
|
+
* what a host bridging to a native call UI (CallKit / Android Telecom) uses
|
|
471
|
+
* to bind its OS session to THIS call. Without it the host must guess from
|
|
472
|
+
* `incomingCalls`, which is wrong as soon as two calls are ringing.
|
|
473
|
+
*/
|
|
474
|
+
callId: string;
|
|
440
475
|
from: string;
|
|
441
476
|
fromName: string | null;
|
|
442
477
|
}) => void;
|
|
@@ -578,13 +613,13 @@ declare const IncomingStack: React.FC<{
|
|
|
578
613
|
|
|
579
614
|
/**
|
|
580
615
|
* OngoingCall — the in-call screen: peer + call-state + live duration, the
|
|
581
|
-
* optional DTMF keypad / transfer / audio-device overlays, the control
|
|
582
|
-
* hold / keypad / transfer / audio), and hang up. Renders
|
|
583
|
-
* active call.
|
|
616
|
+
* optional DTMF keypad / transfer / add-call / audio-device overlays, the control
|
|
617
|
+
* row (mute / hold / keypad / transfer / add call / audio), and hang up. Renders
|
|
618
|
+
* nothing when there is no active call.
|
|
584
619
|
*
|
|
585
620
|
* Reads the active call, actions, and duration from the softphone context; owns
|
|
586
|
-
* only its own transient DTMF-readout
|
|
587
|
-
* inside a `<SoftphoneProvider>`.
|
|
621
|
+
* only its own transient DTMF-readout, transfer-input and add-call text. Must be
|
|
622
|
+
* rendered inside a `<SoftphoneProvider>`.
|
|
588
623
|
*/
|
|
589
624
|
|
|
590
625
|
declare const OngoingCall: React.FC;
|
package/dist/softphone.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useRef as n,useEffect as t,useState as a,useReducer as r,useMemo as s,useCallback as l,createContext as c,useContext as o,useId as i}from"react";import{DialStackPhone as d,createPaginatedList as u,storage as p}from"@dialstack/sdk-webrtc";import{parsePhoneNumber as m}from"libphonenumber-js";import{defaultLocale as g}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as f}from"@dialstack/sdk-react";function h(e){const a=n(e);return t(()=>{a.current=e},[e]),a}function v(e){const{autoConnect:n=!0,onError:r}=e,[s,l]=a(null),[c,o]=a(n&&e.token?"connecting":"idle"),i=h({onError:r}),u=h(e.emergencyAddressId),p=h(e.iceServers),m=h(e.storage),g=h(e.ringback),f=h(e.createSignalingSocket),v=h(e.onAppResume),b=h(e.onTokenExpiring),{token:y,apiBaseUrl:x,signalingBaseUrl:E,autoReconnect:w}=e;return t(()=>{if(!y)return;let e=!1;const t=(a={token:y,apiBaseUrl:x,signalingBaseUrl:E,emergencyAddressId:u.current,iceServers:p.current,storage:m.current,ringback:g.current,createSignalingSocket:f.current,onAppResume:v.current,autoReconnect:w,onTokenExpiring:b.current?()=>{const e=b.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new d(a));var a;l(t);const r=n=>()=>{e||n()};return t.on("connected",r(()=>o("connected"))),t.on("reconnected",r(()=>o("connected"))),t.on("reconnecting",r(()=>o("reconnecting"))),t.on("disconnected",r(()=>o("disconnected"))),t.on("error",n=>{var t,a;e||(null===(a=(t=i.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&o("error"))}),n&&(o("connecting"),t.connect().catch(n=>{var t,a,r,s;"transport_closed"!==(null==n?void 0:n.code)&&(null===(a=(t=i.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==n?void 0:n.code)&&void 0!==r?r:"internal_error",message:null!==(s=null==n?void 0:n.message)&&void 0!==s?s:String(n)}),e||o("error"))})),()=>{e=!0,t.disconnect(),l(null),o("idle")}},[y,x,E,w,n,i,u,p,m,g,f,v,b]),{phone:s,connection:c}}function b(e,n,t,a){return new(t||(t=Promise))(function(r,s){function l(e){try{o(a.next(e))}catch(e){s(e)}}function c(e){try{o(a.throw(e))}catch(e){s(e)}}function o(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(l,c)}o((a=a.apply(e,n||[])).next())})}function y(e){return"inbound"===e.direction&&("ringing"===e.state||"trying"===e.state)}function x(e){return!!e&&(Array.isArray(e)?e.some(y):y(e))}function E(e){return e.isConnected}function w(e){return e?y(e)?"incoming":"in-call":"dial"}function k(e){return"inbound"===e.direction?e.from:e.to}function $(e){return"inbound"===e.direction?e.fromName:null}function C(e){const n=Math.max(0,Math.floor(e));return`${Math.floor(n/60)}:${(n%60).toString().padStart(2,"0")}`}function N(e,n="US"){if(!e)return"";try{const t=m(e,n);if(t){return"US"===t.country||"1"===t.countryCallingCode?t.formatNational():t.formatInternational()}}catch(e){}return e}"function"==typeof SuppressedError&&SuppressedError;const S=/[^+*#0-9A-Da-d]/g,A="US";function I(e){return e.replace(S,"").slice(0,32).toUpperCase()}function T(e,n="US"){const t=I(e);if(!t)return"";if(!/[*#]/.test(t)&&/^\+?[0-9]+$/.test(t))try{const e=m(t,n);if(null==e?void 0:e.isValid())return e.number}catch(e){}return t}const z={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function D(e,n,{silentWhenEmpty:t=!1}={}){const a=T(e,A);return a||(t&&!e.trim()||null==n||n(Object.assign({},z)),"")}function O(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const j=new Set(["auth_failed","auth_expired","session_limit","session_revoked","going_away","idle_timeout","slow_consumer","transport_closed","ice_fetch_failed"]);function M(e){return"mic_permission_denied"===e?"micPermissionError":j.has(e)?"connectionError":"callError"}const P={calls:[]};function _(e,n){const t=function(e,n){var t,a;switch(n.type){case"active":{const t=e.calls.find(e=>e.call===n.call),a=e.calls.filter(e=>e.call!==n.call).map(e=>Object.assign(Object.assign({},e),{active:!1})),r=t?Object.assign(Object.assign({},t),{active:!0}):{call:n.call,active:!0,transferPeer:null,transferRole:null};return Object.assign(Object.assign({},e),{calls:[...a,r]})}case"incomingAdded":return e.calls.some(e=>e.call===n.call)?e:Object.assign(Object.assign({},e),{calls:[...e.calls,{call:n.call,active:!1,transferPeer:null,transferRole:null}]});case"answered":case"switchActive":return e.calls.some(e=>e.call===n.call)?Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"answeredInPlace":return e.calls.find(e=>e.call===n.call)?e.calls.some(e=>e.active)?e:Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"consultStarted":{const r=null!==(a=null===(t=e.calls.find(e=>e.active))||void 0===t?void 0:t.call)&&void 0!==a?a:null,s=e.calls.filter(e=>e.call!==r).map(e=>Object.assign(Object.assign({},e),{active:!1})),l=r?[{call:r,active:!1,transferPeer:n.call,transferRole:"original"}]:[];return Object.assign(Object.assign({},e),{calls:[...s,...l,{call:n.call,active:!0,transferPeer:r,transferRole:"consult"}]})}case"cancelConsult":{const n=e.calls.find(e=>"consult"===e.transferRole),t=e.calls.find(e=>"original"===e.transferRole);if(!n||!t)return e;const a=e.calls.filter(e=>e.call!==n.call&&e.call!==t.call);return Object.assign(Object.assign({},e),{calls:[...a,{call:t.call,active:!0,transferPeer:null,transferRole:null}]})}case"callEnded":{const t=e.calls.find(e=>e.call===n.call);if(!t)return e;let a=e.calls.filter(e=>e.call!==n.call);return t.transferPeer&&(a=a.map(e=>e.call===t.transferPeer?{call:e.call,active:!0,transferPeer:null,transferRole:null}:e)),Object.assign(Object.assign({},e),{calls:a})}case"reset":return 0===e.calls.length?e:P}}(e,n);if(t===e)return e;const a=function(e){const n=e.filter(e=>e.active).length;if(0===n){const n=[...e].reverse().find(e=>!y(e.call));return n?e.map(e=>e.call===n.call?Object.assign(Object.assign({},e),{active:!0}):e):e}if(1===n)return e;let t=!1;return[...e].reverse().map(e=>e.active?t?Object.assign(Object.assign({},e),{active:!1}):(t=!0,e):e).reverse()}(t.calls);return a===t.calls?t:Object.assign(Object.assign({},t),{calls:a})}function B(e,n={}){const{onError:t}=n,[,r]=a(0),s=l(()=>r(e=>e+1),[]),c=l((e,n)=>{var a,r;const s=e;null==t||t({code:null!==(a=null==s?void 0:s.code)&&void 0!==a?a:n,message:null!==(r=null==s?void 0:s.message)&&void 0!==r?r:String(e)})},[t]),o=l(e=>function(e,n,t){return{answer:()=>{if(e)try{e.answer()}catch(e){n(e,"call_failed")}},reject:()=>{if(e)try{e.reject()}catch(e){n(e,"call_failed")}},hangup:()=>{if(e)try{e.hangup()}catch(e){n(e,"call_failed")}},toggleMute:()=>{if(e)try{e.isMuted?e.unmute():e.mute(),t()}catch(e){n(e,"call_failed")}},toggleHold:()=>{if(e)try{"held"===e.state?e.resume():e.hold()}catch(e){n(e,"call_failed")}},sendDtmf:t=>{if(t&&e)try{e.sendDtmf(t)}catch(e){n(e,"call_failed")}}}}(e,c,s),[c,s]),{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g}=o(e);return{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g,transfer:l(n=>{if(!e)return!1;const a=D(n,t,{silentWhenEmpty:!0});if(!a)return!1;try{return e.transfer(a),!0}catch(e){return c(e,"call_failed"),!1}},[e,c,t]),callActionsFor:o}}function U(e,n=500){const[,r]=a(0),s=null!=e&&E(e);return t(()=>{if(!s)return;const e=setInterval(()=>r(e=>e+1),n);return()=>clearInterval(e)},[s,n]),C(e?e.duration:0)}const R="Timed out confirming your location. Please try again.";function H(e,n){let t=!1;return new Promise((a,r)=>{const s=setTimeout(()=>{t=!0,r(new Error(R))},8e3);e.then(()=>{clearTimeout(s),t?n(null):a()},e=>{clearTimeout(s);const a=e instanceof Error?e:new Error(R);t?n(a):r(a)})})}function L(e){const[n,t]=a(null);return{lastError:n,handleError:l(n=>{t(n),null==e||e(n)},[e]),clearError:l(()=>t(null),[])}}function V(e){return{onType:l(n=>e(I(n)),[e]),onPasteText:l(n=>e(T(n,A)),[e])}}const F={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,radius:14},W={background:"#ffffff",surface:"rgba(0, 0, 0, 0.04)",surfaceActive:"rgba(0, 0, 0, 0.09)",text:"#1a1a1a",textSecondary:"rgba(0, 0, 0, 0.55)",border:"rgba(0, 0, 0, 0.1)",accent:"#6772e5",success:"#30a46c",danger:"#e5484d",warning:"#f5a623",onAccent:"#ffffff"},K={background:"#1a1a1a",surface:"rgba(255, 255, 255, 0.06)",surfaceActive:"rgba(255, 255, 255, 0.12)",text:"#ffffff",textSecondary:"rgba(255, 255, 255, 0.6)",border:"rgba(255, 255, 255, 0.12)",accent:"#828bf0",success:"#3dd68c",danger:"#ff6369",warning:"#f5a623",onAccent:"#ffffff"},q=[{digit:"1",letters:""},{digit:"2",letters:"ABC"},{digit:"3",letters:"DEF"},{digit:"4",letters:"GHI"},{digit:"5",letters:"JKL"},{digit:"6",letters:"MNO"},{digit:"7",letters:"PQRS"},{digit:"8",letters:"TUV"},{digit:"9",letters:"WXYZ"},{digit:"*",letters:""},{digit:"0",letters:"+"},{digit:"#",letters:""}];function G(e){var n,t,a,r,s,l,c,o,i,d;const u="dark"===(null==e?void 0:e.theme)?K:W;const p=null!==(n=null==e?void 0:e.variables)&&void 0!==n?n:{};return{background:null!==(t=p.colorBackground)&&void 0!==t?t:u.background,surface:null!==(a=p.colorSurfaceSubtle)&&void 0!==a?a:u.surface,surfaceActive:u.surfaceActive,text:null!==(r=p.colorText)&&void 0!==r?r:u.text,textSecondary:null!==(s=p.colorTextSecondary)&&void 0!==s?s:u.textSecondary,border:null!==(l=p.colorBorder)&&void 0!==l?l:u.border,accent:null!==(c=p.colorPrimary)&&void 0!==c?c:u.accent,success:null!==(o=p.colorSuccess)&&void 0!==o?o:u.success,danger:null!==(i=p.colorDanger)&&void 0!==i?i:u.danger,warning:null!==(d=p.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const Y=c(null),J=()=>Promise.reject(new Error("Phone not connected")),Q={listEmergencyAddresses:()=>u(J(),J),setEmergencyAddress:J,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:J,reconnectWithEmergency:J};function X({token:c,apiBaseUrl:o,onTokenExpiring:i,iceServers:d,storage:u,ringback:p,createSignalingSocket:m,onAppResume:f,emergencyAddressId:E,autoConnect:w=!0,appearance:k,locale:$=g,defaultCountry:C="US",onConnectionStateChange:S,onIncomingCall:I,onCallStarted:z,onCallEnded:O,onError:j,extra:M,children:R}){var V,F;const{lastError:W,handleError:K,clearError:q}=L(j),J=`${null!==(V=null==k?void 0:k.theme)&&void 0!==V?V:""}|${JSON.stringify(null!==(F=null==k?void 0:k.variables)&&void 0!==F?F:{})}`,X=s(()=>G(k),[J]),Z=e=>$.softphone[e],ee=e=>N(e,C),{phone:ne,connection:te}=v({token:c,apiBaseUrl:o,onTokenExpiring:i,iceServers:d,storage:u,ringback:p,createSignalingSocket:m,onAppResume:f,emergencyAddressId:E,autoConnect:w,onError:K}),{calls:ae,activeCall:re,incomingCalls:se,heldCalls:le,answerCall:ce,switchToCall:oe,placeCall:ie,consultCall:de,transferOriginal:ue,startAttendedTransfer:pe,completeAttendedTransfer:me,cancelAttendedTransfer:ge}=function(e,c,o={}){var i,d,u,p,m,g;const{onIncomingCall:f,onCallStarted:v,onCallActivated:x,onCallEnded:E,onError:w}=o,[k,$]=r(_,P),[C,N]=a(e);C!==e&&(N(e),k.calls.length>0&&$({type:"reset"}));const{calls:S}=k,I=null!==(i=S.find(e=>e.active))&&void 0!==i?i:null,z=null!==(d=null==I?void 0:I.call)&&void 0!==d?d:null,O=s(()=>S.filter(e=>!e.active&&y(e.call)).map(e=>e.call),[S]),j=s(()=>S.filter(e=>!e.active&&!y(e.call)).map(e=>e.call),[S]),M=null!==(p=null===(u=S.find(e=>"consult"===e.transferRole))||void 0===u?void 0:u.call)&&void 0!==p?p:null,B=null!==(g=null===(m=S.find(e=>"original"===e.transferRole))||void 0===m?void 0:m.call)&&void 0!==g?g:null,U=h(e),R=h(c),[,H]=a(0),L=l(()=>H(e=>e+1),[]),V=n(null);V.current=z;const F=h(M),W=h(B),K=n(!0);t(()=>(K.current=!0,()=>{K.current=!1}),[]);const q=h({onIncomingCall:f,onCallStarted:v,onCallActivated:x,onCallEnded:E,onError:w}),G=n(new Map),Y=n(new WeakSet),J=l(e=>{const n=G.current.get(e);n&&(n(),G.current.delete(e))},[]),Q=l(e=>{J(e);const n=()=>{L()},t=()=>{var n,t,a,r;"inbound"===e.direction&&(Y.current.add(e),null===(t=(n=q.current).onCallStarted)||void 0===t||t.call(n,{direction:"inbound",peer:e.from})),null===(r=(a=q.current).onCallActivated)||void 0===r||r.call(a,e),$({type:"answeredInPlace",call:e}),L()},a=n=>{var t,a;Y.current.has(e)&&(Y.current.delete(e),null===(a=(t=q.current).onCallEnded)||void 0===a||a.call(t,{reason:n})),$({type:"callEnded",call:e}),J(e)};e.on("trying",n),e.on("ringing",n),e.on("answered",t),e.on("held",n),e.on("resumed",n),e.on("ended",a),G.current.set(e,()=>{e.off("trying",n),e.off("ringing",n),e.off("answered",t),e.off("held",n),e.off("resumed",n),e.off("ended",a)})},[L,J,q]),X=l(e=>b(this,void 0,void 0,function*(){var n,t,a,r,s,l,c,o,i;const d=U.current,u=D(e,q.current.onError);if(!u)return;if(!d||"connected"!==R.current)return void(null===(t=(n=q.current).onError)||void 0===t||t.call(n,{code:"transport_closed",message:"The softphone is not connected"}));if(G.current.size>=4)return void(null===(r=(a=q.current).onError)||void 0===r||r.call(a,{code:"rate_limited",message:"Too many active calls"}));const p=V.current;try{null==p||p.hold();const e=yield d.call(u);$({type:"active",call:e}),Y.current.add(e),null===(l=(s=q.current).onCallStarted)||void 0===l||l.call(s,{direction:"outbound",peer:e.to}),Q(e)}catch(e){if(p&&"ended"!==p.state)try{p.resume()}catch(e){}const n=e;null===(o=(c=q.current).onError)||void 0===o||o.call(c,{code:null!==(i=n.code)&&void 0!==i?i:"call_failed",message:n.message})}}),[Q,R,q,U]),Z=l((e,n)=>{var t,a,r;const s=V.current;try{null==s||s.hold(),e(),$(n)}catch(e){if(s&&"ended"!==s.state)try{s.resume()}catch(e){}const n=e;null===(a=(t=q.current).onError)||void 0===a||a.call(t,{code:null!==(r=n.code)&&void 0!==r?r:"call_failed",message:n.message})}},[q]),ee=l(e=>{V.current!==e&&Z(()=>e.resume(),{type:"switchActive",call:e})},[Z]),ne=l(e=>{Z(()=>e.answer(),{type:"answered",call:e})},[Z]),te=l(e=>b(this,void 0,void 0,function*(){var n,t,a;const r=V.current,s=U.current,l=T(e,A);if(r&&!F.current&&l)try{const e=yield r.attendedTransfer(l);if(!K.current)return;if("ended"===r.state||U.current!==s)return void e.hangup();$({type:"consultStarted",call:e}),Q(e)}catch(e){const r=e;null===(t=(n=q.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}}),[Q,F,q,U]),ae=l(()=>{var e,n,t;const a=W.current,r=F.current;if(a&&r&&r.isConnected)try{a.completeTransfer()}catch(a){const r=a;null===(n=(e=q.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[F,q,W]),re=l(()=>{const e=F.current,n=W.current;e&&(e.hangup(),J(e),"held"===(null==n?void 0:n.state)&&n.resume(),$({type:"cancelConsult"}))},[J,F,W]);return t(()=>{if(!e)return;let n=!1;const t=G.current,a=e=>{var t,a;n||(G.current.size>=4?e.reject("busy"):($({type:"incomingAdded",call:e}),Y.current.add(e),null===(a=(t=q.current).onIncomingCall)||void 0===a||a.call(t,{from:e.from,fromName:e.fromName}),Q(e)))};return e.on("incoming",a),()=>{n=!0,e.off("incoming",a);for(const e of t.values())e();t.clear(),$({type:"reset"})}},[e,Q,q]),{calls:S,activeCall:z,incomingCalls:O,switchToCall:ee,answerCall:ne,placeCall:X,consultCall:M,heldCalls:j,transferOriginal:B,startAttendedTransfer:te,completeAttendedTransfer:ae,cancelAttendedTransfer:re}}(ne,te,{onIncomingCall:I,onCallStarted:z,onCallEnded:O,onError:K}),fe=function(e,r){const{disabled:s,connection:c,identityKey:o}=r,[i,d]=a(!s),[u,p]=a(!1),[m,g]=a(!1),[f,v]=a([]),[y,x]=a(!1),E=h(y),[w,k]=a(null),$=h(e),C=n(!1),N=n(0),S=n(o);t(()=>{S.current!==o&&(S.current=o,C.current=!1,p(!1),g(!1),v([]),k(null),d(!s))},[o,s]);const A=l(()=>{g(!0),p(!1)},[]);t(()=>{if(s)return;if("connected"!==c)return void("disconnected"!==c&&"error"!==c||d(!1));let e=!1;return(()=>{b(this,void 0,void 0,function*(){var n,t;try{const a=$.current,r=(yield a.listEmergencyAddresses()).data;if(e)return;v(r);const s=a.presentedEmergencyAddressId,l=null!==(t=null!==(n=r.find(e=>e.id===s))&&void 0!==n?n:r[0])&&void 0!==t?t:null;if(!l)return void p(!1);if(C.current||m)E.current||(p(!m),m||k(null));else{if(C.current=!0,null==s||s!==l.id||null==l.registered_ip)return void(yield H(a.reconnectWithEmergency(l.id),()=>{}).catch(()=>{}));p(!0),E.current||k(null)}}catch(n){e||p(!1)}finally{e||d(!1)}})})(),()=>{e=!0}},[s,c,m,$,E]);const I=l((e,n)=>b(this,void 0,void 0,function*(){const t=++N.current,a=n=>function(e){return"transport_closed"===(null==e?void 0:e.code)}(n)?"Connection interrupted. Please try again.":n instanceof Error?n.message:e,r=e=>{N.current===t&&k(e?a(e):null)};x(!0),k(null),g(!1),C.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield H(t,r)}catch(e){throw k(a(e)),e}finally{x(!1)}}),[$]);return{loading:i,bound:u,savedAddresses:f,submitting:y,error:w,onNetworkChanged:A,confirm:l(e=>I("Failed to confirm emergency address",()=>b(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[I,$]),create:l(e=>I("Failed to save emergency address",()=>b(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[I,$])}}(null!=ne?ne:Q,{disabled:!!E,connection:te,identityKey:c});t(()=>{if(!ne)return;const e=fe.onNetworkChanged;return ne.on("network.changed",e),()=>ne.off("network.changed",e)},[ne,fe.onNetworkChanged]);const he=B(re,{onError:K}),ve=function(e){const[n,r]=a(null),s=l(e=>{r(n=>n===e?null:e)},[]),c=l(()=>s("keypad"),[s]),o=l(()=>s("transfer"),[s]),i=l(()=>s("devices"),[s]),d=l(()=>r(e=>"transfer"===e?null:e),[]);return t(()=>{r(null)},[e]),{showKeypad:"keypad"===n,showTransfer:"transfer"===n,showDevices:"devices"===n,toggleKeypad:c,toggleTransfer:o,toggleDevices:i,closeTransfer:d}}(re),be=U(re),ye=s(()=>ae.map(e=>e.call),[ae]),xe=x(se),Ee=n(te);t(()=>{null==S||S({state:te}),"connected"===te&&"connected"!==Ee.current&&q(),Ee.current=te},[te,S,q]);const we=s(()=>Object.assign({connection:te,webrtcPhone:ne,calls:ye,activeCall:re,incomingCalls:se,incomingRinging:xe,heldCalls:le,answerCall:ce,switchToCall:oe,actions:he,overlays:ve,duration:be,consultCall:de,transferOriginal:ue,startAttendedTransfer:pe,completeAttendedTransfer:me,cancelAttendedTransfer:ge,placeCall:ie,emergency:fe,emergencyManagedByHost:!!E,lastError:W,clearError:q,t:Z,displayNumber:ee,palette:X},M),[te,ne,ye,re,se,xe,le,ce,oe,he,ve,be,de,ue,pe,me,ge,ie,fe,E,W,q,X,$,C,M]);return e.createElement(Y.Provider,{value:we},R)}function Z(){const e=o(Y);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const ee="dialstack.softphone.input_device_id",ne="dialstack.softphone.output_device_id",te=c(null),ae=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),re=({children:n})=>{var r,s,c;const{webrtcPhone:o,activeCall:i}=Z(),[d]=a(()=>"undefined"!=typeof HTMLMediaElement&&"function"==typeof HTMLMediaElement.prototype.setSinkId),[u]=a(()=>{var e;return"undefined"!=typeof navigator&&"function"==typeof(null===(e=navigator.mediaDevices)||void 0===e?void 0:e.enumerateDevices)}),[m,g]=a([]),[f,h]=a([]),[v,y]=a(!1),[x,E]=a(!1),[,w]=a(0),k=i?null!==(s=null!==(r=i.effectiveAudioInputDeviceId)&&void 0!==r?r:null==o?void 0:o.audioInputDeviceId)&&void 0!==s?s:null:null!==(c=null==o?void 0:o.audioInputDeviceId)&&void 0!==c?c:p.getItem(ee),[$,C]=a(()=>p.getItem(ne));t(()=>{if(!u)return;let e=!1;const n=()=>b(void 0,void 0,void 0,function*(){let n;try{n=yield navigator.mediaDevices.enumerateDevices()}catch(e){return}if(e)return;const t=n.filter(e=>"audioinput"===e.kind),a=n.filter(e=>"audiooutput"===e.kind);y(t.length>0&&t.every(e=>""===e.label)),g(ae(t)),h(d?ae(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,i]),t(()=>{o&&$&&o.setAudioOutputDevice($)},[o,$]),t(()=>{const e=p.getItem(ee);o&&e&&!o.audioInputDeviceId&&o.seedAudioInputDevice(e)},[o]),t(()=>{if(!i)return;const e=()=>E(!0),n=()=>w(e=>e+1);return i.on("audioInputLost",e),i.on("audioInputChanged",n),()=>{i.off("audioInputLost",e),i.off("audioInputChanged",n),E(!1)}},[i]);const N=l(e=>{const n=()=>w(e=>e+1);null==o||o.setAudioInputDevice(e).then(()=>{E(!1),e?p.setItem(ee,e):p.removeItem(ee),n()},n)},[o]),S=l(e=>{C(e),e?p.setItem(ne,e):p.removeItem(ne),null==o||o.setAudioOutputDevice(e)},[o]),A={inputs:m,outputs:f,inputDeviceId:k,outputDeviceId:$,selectInputDevice:N,selectOutputDevice:S,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:x};return e.createElement(te.Provider,{value:A},n)};function se(){const e=o(te);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const le=[440,480];class ce{constructor(){this.ctx=null,this.gain=null,this.oscillators=[],this.cadenceTimer=null,this.started=!1,this.nextCadenceTime=0,this.sinkId=null}get isPlaying(){return this.started}setSinkId(e){this.sinkId=e;const n=this.ctx;n&&"function"==typeof n.setSinkId&&Promise.resolve(n.setSinkId(null!=e?e:"")).catch(()=>{})}start(){if(this.started)return;const e=function(){var e,n;const t=globalThis;return null!==(n=null!==(e=t.AudioContext)&&void 0!==e?e:t.webkitAudioContext)&&void 0!==n?n:null}();if(!e)return;let n;try{n=new e(this.sinkId?{sinkId:this.sinkId}:void 0)}catch(t){this.sinkId=null;try{n=new e}catch(e){return}}this.ctx=n,"suspended"===n.state&&"function"==typeof n.resume&&Promise.resolve(n.resume()).catch(()=>{});try{const e=n.createGain();e.gain.value=0,e.connect(n.destination),this.gain=e;for(const t of le){const a=n.createOscillator();a.frequency.value=t,a.connect(e),a.start(),this.oscillators.push(a)}this.nextCadenceTime=n.currentTime,this.scheduleCadenceAhead(),this.cadenceTimer=setInterval(()=>this.scheduleCadenceAhead(),6e3),this.started=!0}catch(e){this.teardown()}}stop(){this.started&&(this.started=!1,this.teardown())}teardown(){this.cadenceTimer&&(clearInterval(this.cadenceTimer),this.cadenceTimer=null);for(const e of this.oscillators)try{e.stop(),e.disconnect()}catch(e){}if(this.oscillators=[],this.gain){try{this.gain.disconnect()}catch(e){}this.gain=null}const e=this.ctx;this.ctx=null,e&&"function"==typeof e.close&&Promise.resolve(e.close()).catch(()=>{})}scheduleCadenceAhead(){const e=this.ctx,n=this.gain;if(!e||!n)return;for(;this.nextCadenceTime+6<=e.currentTime;)this.nextCadenceTime+=6;const t=e.currentTime+12;for(;this.nextCadenceTime<t;)n.gain.setValueAtTime(.14,this.nextCadenceTime),n.gain.setValueAtTime(0,this.nextCadenceTime+2),this.nextCadenceTime+=6}}const oe=Y,ie=({token:n,apiBaseUrl:t,onTokenExpiring:r,iceServers:l,emergencyAddressId:c,autoConnect:d=!0,appearance:u,locale:p=g,formatting:m,onConnectionStateChange:h,onIncomingCall:v,onCallStarted:b,onCallEnded:y,onError:x,children:E})=>{var w,k,$;const C=`ds-softphone-${i().replace(/[:]/g,"")}`,N=s(()=>({scope:C}),[C]),S=o(f),[A,I]=a(()=>null==S?void 0:S.dialstack.getAppearance()),T=null!=u?u:A,z=`${null!==(w=null==T?void 0:T.theme)&&void 0!==w?w:""}|${JSON.stringify(null!==(k=null==T?void 0:T.variables)&&void 0!==k?k:{})}`,D=null!==($=null==m?void 0:m.defaultCountry)&&void 0!==$?$:"US",O=s(()=>function(e,n="ds-softphone"){const t=F;return`\n .${n} {\n --dsd-bg: ${e.background};\n --dsd-surface: ${e.surface};\n --dsd-surface-active: ${e.surfaceActive};\n --dsd-text: ${e.text};\n --dsd-text-secondary: ${e.textSecondary};\n --dsd-border: ${e.border};\n --dsd-accent: ${e.accent};\n --dsd-success: ${e.success};\n --dsd-danger: ${e.danger};\n --dsd-warning: ${e.warning};\n --dsd-on-accent: ${e.onAccent};\n font-family: var(--ds-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);\n background: var(--dsd-bg);\n color: var(--dsd-text);\n width: 100%;\n max-width: ${t.maxWidth}px;\n margin: 0 auto;\n border-radius: ${t.radius}px;\n padding: clamp(12px, 4vw, 24px);\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n .${n} * { box-sizing: border-box; }\n /* Every exported piece (DialPad, OngoingCall, IncomingCall, IncomingStack,\n IncomingCallCard, EmergencyBanner) self-wraps in its own \`.ds-softphone\`\n so it renders correctly standalone — a host can drop any one of them under\n the provider without hand-supplying scoped wrappers. When one such piece is\n composed INSIDE another (e.g. IncomingStack renders IncomingCallCards, or\n <Softphone> stacks several screens), the inner \`.ds-softphone\` would\n otherwise paint a second card box. Collapse any nested wrapper so only the\n outermost is the padded card. */\n .${n} .ds-softphone { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-screen { display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px); }\n\n .${n} .ds-chip {\n align-self: center;\n font-size: 12px;\n font-weight: 600;\n padding: 4px 12px;\n border-radius: 999px;\n letter-spacing: 0.02em;\n }\n .${n} .ds-chip-spacer { visibility: hidden; }\n .${n} .ds-chip-pending { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-off { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-error { background: color-mix(in srgb, var(--dsd-danger) 16%, transparent); color: var(--dsd-danger); }\n .${n} .ds-call-error {\n display: flex;\n align-items: center;\n gap: 8px;\n max-width: 100%;\n text-align: left;\n }\n .${n} .ds-call-error-dismiss {\n border: none;\n background: transparent;\n color: inherit;\n cursor: pointer;\n font-size: 12px;\n line-height: 1;\n padding: 0;\n }\n\n /* The number must center on the keypad's axis. The backspace flanks the input\n on the right, so an equal-width invisible spacer flanks it on the left — the\n input then centers between two 40px flanks and reads as truly centered (a\n lone backspace would optically pull the number left even when the box math\n centers). */\n .${n} .ds-display { display: flex; align-items: center; min-height: 56px; gap: 8px; }\n .${n} .ds-display-spacer { width: 40px; flex: none; }\n .${n} .ds-destination {\n flex: 1; min-width: 0;\n font-size: clamp(24px, 7vw, 32px);\n font-weight: 500;\n text-align: center;\n border: none; outline: none; background: transparent;\n color: var(--dsd-text);\n letter-spacing: 0.02em;\n }\n .${n} .ds-destination::placeholder { color: var(--dsd-text-secondary); opacity: 0.7; }\n .${n} .ds-backspace {\n flex: none;\n border: none; background: transparent; cursor: pointer;\n font-size: 22px; color: var(--dsd-text-secondary);\n width: 40px; height: 40px; border-radius: 999px;\n }\n .${n} .ds-backspace:hover { background: var(--dsd-surface); color: var(--dsd-text); }\n\n .${n} .ds-keypad {\n display: grid; grid-template-columns: repeat(3, 1fr);\n gap: ${t.keyGap}px;\n justify-items: center;\n }\n .${n} .ds-key {\n display: flex; flex-direction: column; align-items: center; justify-content: center;\n width: 100%; aspect-ratio: 1 / 1; max-width: 84px;\n border: none; border-radius: 999px;\n background: var(--dsd-surface); color: var(--dsd-text);\n cursor: pointer; gap: 2px;\n transition: background-color 0.12s ease, transform 0.06s ease;\n -webkit-tap-highlight-color: transparent;\n user-select: none;\n }\n .${n} .ds-key:hover { background: var(--dsd-surface-active); }\n .${n} .ds-key:active { transform: scale(0.94); }\n .${n} .ds-key-digit { font-size: clamp(22px, 6vw, 28px); font-weight: 500; line-height: 1; }\n .${n} .ds-key-letters {\n font-size: 10px; font-weight: 600; letter-spacing: 0.12em;\n color: var(--dsd-text-secondary); min-height: 12px;\n }\n .${n} .ds-keypad-dtmf .ds-key { aspect-ratio: auto; padding: 10px 0; max-width: 72px; }\n\n .${n} .ds-actions { display: flex; justify-content: center; gap: clamp(24px, 12vw, 72px); }\n .${n} .ds-actions-incoming { justify-content: space-evenly; }\n .${n} .ds-action {\n width: ${t.actionButtonSize}px; height: ${t.actionButtonSize}px;\n border: none; border-radius: 999px; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n color: var(--dsd-on-accent);\n transition: transform 0.06s ease, filter 0.12s ease;\n -webkit-tap-highlight-color: transparent;\n }\n .${n} .ds-action svg { width: 46%; height: 46%; }\n .${n} .ds-action:active { transform: scale(0.92); }\n .${n} .ds-action:disabled { opacity: 0.4; cursor: not-allowed; }\n .${n} .ds-call, .${n} .ds-answer { background: var(--dsd-success); }\n .${n} .ds-hangup, .${n} .ds-decline { background: var(--dsd-danger); }\n .${n} .ds-call:not(:disabled):hover, .${n} .ds-answer:hover,\n .${n} .ds-hangup:hover, .${n} .ds-decline:hover { filter: brightness(1.06); }\n\n .${n} .ds-peer { text-align: center; display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-peer-name { font-size: clamp(22px, 6vw, 28px); font-weight: 600; word-break: break-word; }\n .${n} .ds-peer-number { font-size: 15px; color: var(--dsd-text-secondary); }\n .${n} .ds-callstate { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }\n .${n} .ds-callstate-text { font-size: 14px; color: var(--dsd-text-secondary); }\n .${n} .ds-duration { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 500; }\n\n .${n} .ds-incoming-label {\n text-align: center; font-size: 13px; font-weight: 600;\n letter-spacing: 0.08em; text-transform: uppercase; color: var(--dsd-text-secondary);\n }\n .${n} .ds-incoming-pulse {\n width: 12px; height: 12px; border-radius: 999px; margin: 4px auto;\n background: var(--dsd-success);\n box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 60%, transparent);\n animation: ds-pulse 1.6s infinite;\n }\n @keyframes ds-pulse {\n 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 50%, transparent); }\n 70% { box-shadow: 0 0 0 16px transparent; }\n 100% { box-shadow: 0 0 0 0 transparent; }\n }\n\n .${n} .ds-controls {\n display: flex; flex-wrap: wrap; justify-content: center;\n gap: 8px 20px;\n max-width: ${3*(t.controlButtonSize+12)+40}px;\n margin: 0 auto;\n }\n .${n} .ds-controls > * { flex: 0 0 ${t.controlButtonSize+12}px; }\n .${n} .ds-control {\n display: flex; flex-direction: column; align-items: center; gap: 6px;\n border: none; background: transparent; cursor: pointer;\n color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-control-glyph {\n width: ${t.controlButtonSize}px; height: ${t.controlButtonSize}px;\n border-radius: 999px; background: var(--dsd-surface);\n display: flex; align-items: center; justify-content: center;\n transition: background-color 0.12s ease;\n }\n .${n} .ds-control-glyph svg { width: 42%; height: 42%; }\n .${n} .ds-control:hover:not(:disabled) .ds-control-glyph { background: var(--dsd-surface-active); }\n .${n} .ds-control-on .ds-control-glyph { background: var(--dsd-accent); color: var(--dsd-on-accent); }\n .${n} .ds-control-label { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-control-on .ds-control-label { color: var(--dsd-text); }\n .${n} .ds-control:disabled { cursor: not-allowed; opacity: 0.4; }\n\n .${n} .ds-dtmf { display: flex; flex-direction: column; gap: 10px; }\n .${n} .ds-dtmf-readout {\n text-align: center; font-size: 22px; min-height: 28px;\n font-variant-numeric: tabular-nums; letter-spacing: 0.08em;\n }\n .${n} .ds-transfer { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-transfer-input {\n flex: 1; min-width: 0; padding: 12px 14px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 16px; outline: none;\n }\n .${n} .ds-transfer-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-transfer-actions { display: flex; gap: 8px; }\n .${n} .ds-transfer-send {\n flex: 1; border: none; border-radius: ${t.radius}px; padding: 12px 18px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-transfer-send:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-transfer-send-secondary {\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+40}px; margin: 0 auto;\n }\n .${n} .ds-device-row { display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-device-label { font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-select {\n width: 100%; padding: 10px 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text);\n font-size: 14px; font-family: inherit; outline: none;\n }\n .${n} .ds-device-select:focus { border-color: var(--dsd-accent); }\n .${n} .ds-device-select:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-device-hint { margin: 0; font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-alert { font-size: 12px; color: var(--dsd-danger); }\n\n /* Attended-transfer banner (layered over the normal in-call view): the other\n transfer leg as a switch card + the Cancel/Complete actions. */\n .${n} .ds-transfer-banner { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-consult-held { opacity: 0.7; }\n .${n} .ds-consult-actions { display: flex; gap: 8px; }\n .${n} .ds-consult-actions .ds-e911-btn { flex: 1; }\n\n /* Multi-call + transfer: switchable held-call cards. Clickable (button reset)\n to switch focus to that call; the cursor + hover signal it's actionable. */\n .${n} .ds-held-calls { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-held-call {\n display: block; width: 100%; cursor: pointer; text-align: center;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 12px 14px;\n background: var(--dsd-surface); color: var(--dsd-text);\n font-family: inherit;\n }\n .${n} .ds-held-call:hover { opacity: 1; border-color: var(--dsd-accent); }\n\n /* Multi-call: composite layout — the in-call screen with the ringing\n call-waiting card(s) as a compact banner ABOVE it. The banner is in normal\n flow (not absolutely positioned) so it reserves its own space and never\n overlaps the in-call peer/controls below. (Idle inbound is a dedicated\n screen, not this banner.) */\n .${n}.ds-softphone-layout {\n display: flex; flex-direction: column; gap: 12px;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-softphone-layout > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-overlay { flex: none; }\n\n /* Batteries-included dial screen: the E911 banner above the dial pad, each in\n its own scope wrapper. This outer wrapper is the single padded card; the\n inner dial pad's own .ds-softphone must not add a second card box. The\n banner (a direct .ds-e911 child) carries its own spacing. */\n .${n}.ds-dial-screen {\n display: flex; flex-direction: column;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-dial-screen > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-stack { display: flex; flex-direction: column; gap: 8px; }\n\n /* One ringing call's card. Full-size inside the dedicated incoming screen;\n the compact variant (stacked / call-waiting overlay) shrinks it and puts\n the answer/decline buttons inline so it takes less space. */\n .${n} .ds-incoming-card {\n display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px);\n align-items: center; text-align: center;\n }\n .${n} .ds-incoming-card-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n .${n} .ds-incoming-card-compact {\n flex-direction: row; gap: 12px; align-items: center; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);\n }\n .${n} .ds-incoming-card-compact .ds-incoming-card-info { flex: 1; min-width: 0; }\n .${n} .ds-incoming-card-compact .ds-incoming-label { font-size: 11px; }\n /* Shrink the peer name/number in a compact card — otherwise they inherit the\n full-screen in-call sizes (clamp up to 28px) and overflow the small overlay\n card, colliding with the call behind it. Truncate rather than wrap. */\n .${n} .ds-incoming-card-compact .ds-peer-name {\n font-size: 15px; font-weight: 600; line-height: 1.2;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-peer-number {\n font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-actions-incoming { margin: 0; gap: 8px; flex: none; }\n .${n} .ds-incoming-card-compact .ds-action { width: 44px; height: 44px; }\n\n /* EmergencyBanner's self-wrap is only a scope carrier — never its own card\n box. The visible chrome is the .ds-e911 prompt inside; the wrapper stays\n transparent/paddingless in every context (standalone or composed), and its\n trailing margin comes from .ds-e911 itself. */\n .${n}.ds-e911-root { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-e911 {\n margin-bottom: 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n overflow: hidden; background: var(--dsd-surface);\n }\n .${n} .ds-e911-toggle {\n display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;\n padding: 10px 12px; border: none; cursor: pointer;\n background: color-mix(in srgb, var(--dsd-warning) 18%, transparent);\n color: color-mix(in srgb, var(--dsd-warning) 60%, var(--dsd-text));\n font-family: inherit; font-size: 13px;\n font-weight: 600; text-align: center;\n }\n .${n} .ds-e911-toggle svg { width: 16px; height: 16px; flex: none; }\n .${n} .ds-e911-label { flex: 0 1 auto; text-align: center; }\n .${n} .ds-e911-chevron { transition: transform 0.15s ease; }\n .${n} .ds-e911-open .ds-e911-chevron { transform: rotate(180deg); }\n .${n} .ds-e911-body {\n display: flex; flex-direction: column; gap: 8px;\n padding: 12px; border-top: 1px solid var(--dsd-border);\n }\n .${n} .ds-e911-hint { font-size: 12px; color: var(--dsd-text-secondary); margin: 0; }\n /* Saved-address choice buttons ("Are you here?") */\n .${n} .ds-e911-choice {\n display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); cursor: pointer;\n font-family: inherit; font-size: 13px;\n }\n .${n} .ds-e911-choice:hover { border-color: var(--dsd-accent); }\n .${n} .ds-e911-choice svg { width: 14px; height: 14px; flex: none; color: var(--dsd-success); }\n .${n} .ds-e911-choice-addr { flex: 1; min-width: 0; }\n .${n} .ds-e911-choice-cta { font-size: 12px; font-weight: 600; color: var(--dsd-accent); }\n .${n} .ds-e911-row { display: flex; gap: 8px; }\n .${n} .ds-e911-field { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }\n .${n} .ds-e911-field-sm { flex: none; width: 88px; }\n .${n} .ds-e911-field label { font-size: 11px; color: var(--dsd-text-secondary); }\n .${n} .ds-e911-input {\n padding: 8px 10px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 14px; outline: none;\n font-family: inherit; width: 100%;\n }\n .${n} .ds-e911-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-e911-error { font-size: 12px; color: var(--dsd-danger); margin: 0; }\n .${n} .ds-e911-actions { display: flex; gap: 8px; }\n .${n} .ds-e911-btn {\n flex: 1; border: none; border-radius: 8px; padding: 10px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-e911-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-e911-btn-secondary {\n flex: none; background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} button:focus-visible, .${n} input:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsd-accent) 45%, transparent);\n }\n `}(G(T),C),[z,C]);return e.createElement(X,{token:n,apiBaseUrl:t,onTokenExpiring:r,iceServers:l,emergencyAddressId:c,autoConnect:d,appearance:T,locale:p,defaultCountry:D,onConnectionStateChange:h,onIncomingCall:v,onCallStarted:b,onCallEnded:y,onError:x,extra:N},S&&e.createElement(pe,{dialstack:S.dialstack,onChange:I}),e.createElement("style",null,O),e.createElement(re,null,E,e.createElement(de,null),e.createElement(ue,{onError:x})))},de=()=>{const{incomingRinging:e}=me(),{outputDeviceId:a}=se(),r=n(null);return null===r.current&&(r.current=new ce),t(()=>{var e;null===(e=r.current)||void 0===e||e.setSinkId(a)},[a]),t(()=>{const n=r.current;if(n)return e?n.start():n.stop(),()=>n.stop()},[e]),null},ue=({onError:a})=>{const{activeCall:r}=me(),{outputDeviceId:s}=se(),l=n(null);return t(()=>{const e=l.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=s?s:"").catch(()=>{})},[s,r]),t(()=>{const e=l.current;if(!e)return;if(!r)return void(e.srcObject=null);e.srcObject=r.remoteMediaStream;const n=r;let t=!1;const s=n=>{e.play().then(()=>{t=!0},e=>{const r=null==e?void 0:e.name;n&&!t&&"AbortError"!==r&&(null==a||a({code:"audio_playback_blocked",message:"Could not play call audio — tap the call to enable sound."}))})};s("active"===n.state);const c=()=>s(!0);return n.on("answered",c),()=>{n.off("answered",c)}},[r,a]),e.createElement("audio",{ref:l,autoPlay:!0})},pe=({dialstack:e,onChange:n})=>{const r=function(e){const[n,r]=a(()=>e.getAppearance());return t(()=>{if("undefined"==typeof document)return;const n=document.createElement("div"),t=e=>{const n=e.detail;r(null==n?void 0:n.appearance)};return n.addEventListener("dialstack-appearance-update",t),e.addAppearanceTarget(n),()=>{e.removeAppearanceTarget(n),n.removeEventListener("dialstack-appearance-update",t)}},[e]),n}(e);return t(()=>{n(r)},[r,n]),null},me=()=>Z(),ge=()=>{const{activeCall:e,actions:n}=me();return{activeCall:e,actions:n}},fe=()=>{const{incomingCalls:e}=me();return function(e){var n;return null!==(n=e.find(y))&&void 0!==n?n:null}(e)},he={phone:{path:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},hangup:{path:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z",transform:"rotate(135 12 12)"},mic:{path:"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2z"},micOff:{path:"M19 11h-1.7a5.6 5.6 0 0 1-.34 1.6l1.22 1.22A7 7 0 0 0 19 11zM4.27 3 3 4.27 9 10.27V11a3 3 0 0 0 4.42 2.65l1.05 1.05A4.96 4.96 0 0 1 12 16a5 5 0 0 1-5-5H5a7 7 0 0 0 6 6.92V21h2v-3.08c.5-.07.98-.2 1.43-.39L19.73 21 21 19.73 4.27 3zM15 5a3 3 0 0 0-6-.09l6 6V5z"},pause:{path:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"},keypad:{path:"M5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 10a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 17a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4z"},transfer:{path:"M16 1l4 4-4 4V6H9V4h7V1zM8 23l-4-4 4-4v3h7v2H8v3z"},location:{path:"M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z"},chevronDown:{path:"M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"},speaker:{path:"M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05A4.47 4.47 0 0 0 16.5 12zM14 2.23v2.06a7.5 7.5 0 0 1 0 15.42v2.06a9.5 9.5 0 0 0 0-19.54z"}},ve=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),be=()=>{const{lastError:n,clearError:t,t:a}=me();return n?e.createElement("div",{className:"ds-chip ds-chip-error ds-call-error",role:"alert"},e.createElement("span",null,a(M(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null},ye=({autoFocusDestination:r=!1})=>{const{connection:s,placeCall:l,emergency:c,t:o,scope:i}=me(),[d,u]=a(""),{onType:p,onPasteText:m}=V(u),g=n(null);t(()=>{var e;r&&(null===(e=g.current)||void 0===e||e.focus())},[r]);const f=function(e,n,t){return"connected"===e&&n.length>0&&!t}(s,d,c.submitting);return e.createElement("div",{className:`${i} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(xe,null),e.createElement(be,null),e.createElement("div",{className:"ds-display"},d.length>0&&e.createElement("span",{className:"ds-display-spacer","aria-hidden":"true"}),e.createElement("input",{ref:g,className:"ds-destination",type:"tel",inputMode:"tel",value:d,placeholder:o("destinationPlaceholder"),"aria-label":o("destinationPlaceholder"),autoComplete:"off",onChange:e=>p(e.target.value),onPaste:e=>{e.preventDefault(),m(e.clipboardData.getData("text"))},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f&&l(d))}}),d.length>0&&e.createElement("button",{type:"button",className:"ds-backspace","aria-label":o("backspace"),onClick:()=>u(e=>e.slice(0,-1))},"⌫")),e.createElement("div",{className:"ds-keypad",role:"group","aria-label":o("title")},q.map(({digit:n,letters:t})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":`${n}${t?" "+t:""}`,onClick:()=>u(e=>e+n)},e.createElement("span",{className:"ds-key-digit"},n),e.createElement("span",{className:"ds-key-letters"},t||" ")))),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-call","aria-label":o("call"),disabled:!f,onClick:()=>{l(d)}},e.createElement(ve,{glyph:he.phone})))))},xe=()=>{const{connection:n,t:t}=me();switch(n){case"connecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("connecting"));case"reconnecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("reconnecting"));case"disconnected":return e.createElement("div",{className:"ds-chip ds-chip-off",role:"status"},t("disconnected"));case"error":return e.createElement("div",{className:"ds-chip ds-chip-error",role:"status"},t("connectionError"));default:return e.createElement("div",{className:"ds-chip ds-chip-spacer","aria-hidden":"true"})}},Ee={alabama:"AL",alaska:"AK",arizona:"AZ",arkansas:"AR",california:"CA",colorado:"CO",connecticut:"CT",delaware:"DE","district of columbia":"DC",florida:"FL",georgia:"GA",hawaii:"HI",idaho:"ID",illinois:"IL",indiana:"IN",iowa:"IA",kansas:"KS",kentucky:"KY",louisiana:"LA",maine:"ME",maryland:"MD",massachusetts:"MA",michigan:"MI",minnesota:"MN",mississippi:"MS",missouri:"MO",montana:"MT",nebraska:"NE",nevada:"NV","new hampshire":"NH","new jersey":"NJ","new mexico":"NM","new york":"NY","north carolina":"NC","north dakota":"ND",ohio:"OH",oklahoma:"OK",oregon:"OR",pennsylvania:"PA","rhode island":"RI","south carolina":"SC","south dakota":"SD",tennessee:"TN",texas:"TX",utah:"UT",vermont:"VT",virginia:"VA",washington:"WA","west virginia":"WV",wisconsin:"WI",wyoming:"WY","puerto rico":"PR",guam:"GU","u.s. virgin islands":"VI","american samoa":"AS","northern mariana islands":"MP",alberta:"AB","british columbia":"BC",manitoba:"MB","new brunswick":"NB","newfoundland and labrador":"NL","nova scotia":"NS","northwest territories":"NT",nunavut:"NU",ontario:"ON","prince edward island":"PE",quebec:"QC",saskatchewan:"SK",yukon:"YT"};function we(e){const n=e.trim(),t=Ee[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const ke={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},$e=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:r,t:s,scope:l}=me(),[c,o]=a(!1),[i,d]=a(!1),[u,p]=a(ke);if(t||n.loading||n.bound||r)return null;const m=e=>n=>p(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${l} ds-softphone ds-e911-root`},e.createElement("div",{className:"ds-e911 "+(c?"ds-e911-open":"")},e.createElement("button",{type:"button",className:"ds-e911-toggle","aria-expanded":c,onClick:()=>o(e=>!e)},e.createElement("span",null,e.createElement(ve,{glyph:he.location})),e.createElement("span",{className:"ds-e911-label"},s("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(ve,{glyph:he.chevronDown}))),c&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},s("emergencyHint")),!i&&n.savedAddresses.map(t=>e.createElement("button",{key:t.id,type:"button",className:"ds-e911-choice",disabled:n.submitting,onClick:()=>{return e=t.id,void n.confirm(e).then(()=>o(!1)).catch(()=>{});var e}},e.createElement(ve,{glyph:he.location}),e.createElement("span",{className:"ds-e911-choice-addr"},[t.address.address_number,t.address.street,t.address.city,t.address.state,t.address.postal_code].filter(Boolean).join(" ")),e.createElement("span",{className:"ds-e911-choice-cta"},s("emergencyConfirm")))),!i&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!0)},s("emergencyNewLocation")),i&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),n.create(Object.assign(Object.assign({},u),{state:we(u.state),unit:u.unit||void 0})).then(()=>{o(!1),d(!1)}).catch(()=>{})}},e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${l}-ea-num`},s("emergencyNumber")),e.createElement("input",{id:`${l}-ea-num`,className:"ds-e911-input",value:u.address_number,onChange:m("address_number")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${l}-ea-street`},s("emergencyStreet")),e.createElement("input",{id:`${l}-ea-street`,className:"ds-e911-input",value:u.street,onChange:m("street"),required:!0}))),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${l}-ea-unit`},s("emergencyUnit")),e.createElement("input",{id:`${l}-ea-unit`,className:"ds-e911-input",value:u.unit,onChange:m("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${l}-ea-city`},s("emergencyCity")),e.createElement("input",{id:`${l}-ea-city`,className:"ds-e911-input",value:u.city,onChange:m("city"),required:!0})),e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${l}-ea-state`},s("emergencyState")),e.createElement("input",{id:`${l}-ea-state`,className:"ds-e911-input",value:u.state,onChange:m("state"),required:!0})),e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${l}-ea-zip`},s("emergencyPostalCode")),e.createElement("input",{id:`${l}-ea-zip`,className:"ds-e911-input",value:u.postal_code,onChange:m("postal_code"),required:!0}))),n.error&&e.createElement("p",{className:"ds-e911-error"},n.error),e.createElement("div",{className:"ds-e911-actions"},n.savedAddresses.length>0&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!1)},s("emergencyBack")),e.createElement("button",{type:"submit",className:"ds-e911-btn",disabled:n.submitting},n.submitting?s("emergencySaving"):s("emergencySave")))))))},Ce=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:s,displayNumber:l}=me(),c=k(n),o=$(n)||l(c)||s("unknownCaller");return e.createElement("div",{className:"ds-incoming-card "+(t?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-incoming-card-info"},e.createElement("div",{className:"ds-incoming-label"},s("incomingCall")),e.createElement("div",{className:"ds-peer-name"},o),$(n)&&e.createElement("div",{className:"ds-peer-number"},l(c))),e.createElement("div",{className:"ds-actions ds-actions-incoming"},e.createElement("button",{type:"button",className:"ds-action ds-decline","aria-label":s("decline"),onClick:()=>r.callActionsFor(n).reject()},e.createElement(ve,{glyph:he.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":s("answer"),onClick:()=>a(n)},e.createElement(ve,{glyph:he.phone}))))},Ne=()=>{const{incomingCalls:n,scope:t}=me(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(Ce,{call:a}))):null},Se=({compact:n})=>{const{incomingCalls:t,scope:a}=me();if(0===t.length)return null;const r=null!=n?n:t.length>1;return e.createElement("div",{className:`${a} ds-softphone`},e.createElement("div",{className:"ds-incoming-stack"},t.map(n=>e.createElement(Ce,{key:n.id,call:n,compact:r}))))},Ae=()=>{const{t:n}=me(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:s,selectInputDevice:l,selectOutputDevice:c,outputSelectionSupported:o,enumerationSupported:i,labelsHidden:d,inputLost:u}=se();return e.createElement("div",{className:"ds-devices",role:"group"},u&&e.createElement("div",{className:"ds-device-alert",role:"alert"},n("audioMicrophoneLost")),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioMicrophone")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioMicrophone"),value:null!=r?r:"",onChange:e=>l(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),t.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioSpeaker")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioSpeaker"),value:null!=s?s:"",disabled:!o,onChange:e=>c(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),a.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),!i&&e.createElement("p",{className:"ds-device-hint"},n("audioDevicesUnsupported")),!o&&e.createElement("p",{className:"ds-device-hint"},n("audioSpeakerUnsupported")),d&&e.createElement("p",{className:"ds-device-hint"},n("audioLabelsHidden")))},Ie=()=>{var n;const{activeCall:r,actions:s,overlays:l,duration:c,consultCall:o,transferOriginal:i,heldCalls:d,incomingCalls:u,switchToCall:p,startAttendedTransfer:m,completeAttendedTransfer:g,cancelAttendedTransfer:f,t:h,displayNumber:v,scope:b}=me(),{showKeypad:y,showTransfer:x,showDevices:w}=l,[C,N]=a(""),[S,A]=a(""),{onType:I,onPasteText:T}=V(A),z=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{N(""),A("")},[z]),!r)return null;const D=k(r),j=$(r),M=E(r),P=j||v(D)||h("unknownCaller"),_=r.canSendDtmf,B=null!==o&&null!==i,U=B&&(r===o||r===i),R=U?r===o?i:o:null,H=U&&null!==o&&o.isConnected,L=d.filter(e=>e!==R),F=d.length+u.length,W=!B&&0===F;return e.createElement("div",{className:`${b} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall"},U&&R&&e.createElement("div",{className:"ds-transfer-banner"},(()=>{const n=k(R),t=$(R)||v(n)||h("unknownCaller");return e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${h("switchToCall")}: ${t}`,onClick:()=>p(R)},e.createElement("div",{className:"ds-peer-name"},t),e.createElement("div",{className:"ds-callstate-text"},h("transferOriginalOnHold")))})(),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:f},h("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!H,onClick:g},h("transferComplete")))),L.length>0&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":h("heldCallsLabel")},L.map(n=>{const t=k(n),a=$(n)||v(t)||h("unknownCaller");return e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${h("switchToCall")}: ${a}`,onClick:()=>p(n)},e.createElement("div",{className:"ds-peer-name"},a),e.createElement("div",{className:"ds-callstate-text"},h("heldCallsLabel")))})),e.createElement("div",{className:"ds-peer"},e.createElement("div",{className:"ds-peer-name"},P),j&&e.createElement("div",{className:"ds-peer-number"},v(D)),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-callstate-text"},h(O(r.state))),"active"===r.state&&e.createElement("span",{className:"ds-duration"},c))),e.createElement(be,null),M&&y&&_&&e.createElement("div",{className:"ds-dtmf"},e.createElement("div",{className:"ds-dtmf-readout"},C||" "),e.createElement("div",{className:"ds-keypad ds-keypad-dtmf",role:"group","aria-label":h("keypad")},q.map(({digit:n})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":n,onClick:()=>(e=>{s.sendDtmf(e),N(n=>n+e)})(n)},e.createElement("span",{className:"ds-key-digit"},n))))),M&&x&&W&&e.createElement("div",{className:"ds-transfer"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:S,placeholder:h("transferPlaceholder"),"aria-label":h("transferPlaceholder"),autoComplete:"off",onChange:e=>I(e.target.value),onPaste:e=>{e.preventDefault(),T(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!S.trim(),onClick:()=>{s.transfer(S)&&(A(""),l.closeTransfer())}},h("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!S.trim(),onClick:()=>{m(S)}},h("transferConsult")))),M&&w&&e.createElement(Ae,null),M&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement("button",{type:"button",className:"ds-control "+(r.isMuted?"ds-control-on":""),"aria-pressed":r.isMuted,"aria-label":r.isMuted?h("unmute"):h("mute"),onClick:s.toggleMute},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ve,{glyph:r.isMuted?he.micOff:he.mic})),e.createElement("span",{className:"ds-control-label"},r.isMuted?h("unmute"):h("mute"))),e.createElement("button",{type:"button",className:"ds-control "+("held"===r.state?"ds-control-on":""),"aria-pressed":"held"===r.state,"aria-label":"held"===r.state?h("resume"):h("hold"),onClick:s.toggleHold},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ve,{glyph:he.pause})),e.createElement("span",{className:"ds-control-label"},"held"===r.state?h("resume"):h("hold"))),_&&e.createElement("button",{type:"button",className:"ds-control "+(y?"ds-control-on":""),"aria-pressed":y,"aria-label":h("keypad"),onClick:l.toggleKeypad},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ve,{glyph:he.keypad})),e.createElement("span",{className:"ds-control-label"},h("keypad"))),e.createElement("button",{type:"button",className:"ds-control "+(x?"ds-control-on":""),"aria-pressed":x,"aria-label":h("transfer"),disabled:!W,onClick:l.toggleTransfer},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ve,{glyph:he.transfer})),e.createElement("span",{className:"ds-control-label"},h("transfer"))),e.createElement("button",{type:"button",className:"ds-control "+(w?"ds-control-on":""),"aria-pressed":w,"aria-label":h("audioDevices"),onClick:l.toggleDevices},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ve,{glyph:he.speaker})),e.createElement("span",{className:"ds-control-label"},h("audioDevices")))),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":h("hangUp"),onClick:s.hangup},e.createElement(ve,{glyph:he.hangup})))))},Te=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=me(),s=function(e,n=null){const t=e.filter(e=>e!==n&&y(e)),a=e.some(e=>e===n||!y(e));return{base:a?"in-call":"dial",incoming:t,overlay:a&&t.length>0,compact:a?t.length>0:t.length>1}}(t,a);if("dial"===s.base&&s.incoming.length>0)return 1===s.incoming.length?e.createElement(Ne,null):e.createElement(Se,{compact:s.compact});const l="in-call"===s.base?e.createElement(Ie,null):e.createElement(ze,{autoFocusDestination:n});return 0===s.incoming.length?l:e.createElement("div",{className:`${r} ds-softphone-layout`},e.createElement("div",{className:"ds-incoming-overlay"},e.createElement(Se,{compact:s.compact})),l)},ze=({autoFocusDestination:n})=>{const{scope:t}=me();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement($e,null),e.createElement(ye,{autoFocusDestination:n}))},De=({autoFocusDestination:n})=>{if(null===o(oe))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdk/react.");return e.createElement(Te,{autoFocusDestination:n})};export{A as DIAL_COUNTRY,ye as DialPad,$e as EmergencyBanner,Ne as IncomingCall,Se as IncomingStack,Ie as OngoingCall,De as Softphone,ie as SoftphoneProvider,$ as callPeerName,k as callPeerNumber,O as callStateLabelKey,M as errorMessageKey,C as formatCallDuration,N as formatDisplayNumber,E as isCallActive,y as isIncomingRinging,T as sanitizeDestination,w as selectScreen,x as shouldRingIncoming,I as stripToDialString,ge as useActiveCall,B as useCallActions,U as useCallDuration,V as useDialInput,fe as useIncomingCall,L as useLastError,me as useSoftphone};
|
|
1
|
+
import e,{useRef as n,useEffect as t,useState as a,useReducer as r,useMemo as l,useCallback as s,createContext as c,useContext as o,useId as i}from"react";import{DialStackPhone as d,supportsConference as u,LocalConference as p,createPaginatedList as m,storage as g}from"@dialstack/sdk-webrtc";import{parsePhoneNumber as f}from"libphonenumber-js";import{defaultLocale as h}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as v}from"@dialstack/sdk-react";function b(e){const a=n(e);return t(()=>{a.current=e},[e]),a}function y(e){const{autoConnect:n=!0,onError:r,existingPhone:l}=e,[s,c]=a(null!=l?l:null),[o,i]=a(l?l.isConnected?"connected":l.isConnecting||n?"connecting":"idle":n&&e.token?"connecting":"idle"),u=b({onError:r}),p=b(e.emergencyAddressId),m=b(e.iceServers),g=b(e.storage),f=b(e.ringback),h=b(e.createSignalingSocket),v=b(e.onAppResume),y=b(e.onTokenExpiring),{token:x,apiBaseUrl:E,signalingBaseUrl:w,autoReconnect:C}=e;t(()=>{if(l){let e=!1;const t=n=>()=>{e||n()},a=t(()=>i("connected")),r=t(()=>i("reconnecting")),s=t(()=>i("disconnected")),c=n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))};return l.on("connected",a),l.on("reconnected",a),l.on("reconnecting",r),l.on("disconnected",s),l.on("error",c),!n||l.isConnected||l.isConnecting||l.connect().catch(n=>{var t,a,r,l;if(e)return;const s=n;null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==s?void 0:s.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==s?void 0:s.message)&&void 0!==l?l:String(n)}),i("error")}),()=>{e=!0,l.off("connected",a),l.off("reconnected",a),l.off("reconnecting",r),l.off("disconnected",s),l.off("error",c)}}if(!x)return;let e=!1;const t=(a={token:x,apiBaseUrl:E,signalingBaseUrl:w,emergencyAddressId:p.current,iceServers:m.current,storage:g.current,ringback:f.current,createSignalingSocket:h.current,onAppResume:v.current,autoReconnect:C,onTokenExpiring:y.current?()=>{const e=y.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new d(a));var a;c(t);const r=n=>()=>{e||n()};return t.on("connected",r(()=>i("connected"))),t.on("reconnected",r(()=>i("connected"))),t.on("reconnecting",r(()=>i("reconnecting"))),t.on("disconnected",r(()=>i("disconnected"))),t.on("error",n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))}),n&&(i("connecting"),t.connect().catch(n=>{var t,a,r,l;"transport_closed"!==(null==n?void 0:n.code)&&(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==n?void 0:n.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==n?void 0:n.message)&&void 0!==l?l:String(n)}),e||i("error"))})),()=>{e=!0,t.disconnect(),c(null),i("idle")}},[l,x,E,w,C,n,u,p,m,g,f,h,v,y]);const k=!l||"idle"!==o&&"connecting"!==o?o:l.isConnected?"connected":l.isConnecting?"connecting":o;return{phone:null!=l?l:s,connection:k}}function x(e,n,t,a){return new(t||(t=Promise))(function(r,l){function s(e){try{o(a.next(e))}catch(e){l(e)}}function c(e){try{o(a.throw(e))}catch(e){l(e)}}function o(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,c)}o((a=a.apply(e,n||[])).next())})}function E(e){return"inbound"===e.direction&&("ringing"===e.state||"trying"===e.state)}function w(e){return!!e&&(Array.isArray(e)?e.some(E):E(e))}function C(e){return e.isConnected}function k(e){return e?E(e)?"incoming":"in-call":"dial"}function $(e){return"inbound"===e.direction?e.from:e.to}function N(e){return"inbound"===e.direction?e.fromName:null}function A(e){const n=Math.max(0,Math.floor(e));return`${Math.floor(n/60)}:${(n%60).toString().padStart(2,"0")}`}function S(e,n="US"){if(!e)return"";try{const t=f(e,n);if(t){return"US"===t.country||"1"===t.countryCallingCode?t.formatNational():t.formatInternational()}}catch(e){}return e}"function"==typeof SuppressedError&&SuppressedError;const I=/[^+*#0-9A-Da-d]/g,T="US";function z(e){return e.replace(I,"").slice(0,32).toUpperCase()}function O(e,n="US"){const t=z(e);if(!t)return"";if(!/[*#]/.test(t)&&/^\+?[0-9]+$/.test(t))try{const e=f(t,n);if(null==e?void 0:e.isValid())return e.number}catch(e){}return t}const D={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function M(e,n,{silentWhenEmpty:t=!1}={}){const a=O(e,T);return a||(t&&!e.trim()||null==n||n(Object.assign({},D)),"")}function j(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const P=new Set(["auth_failed","auth_expired","session_limit","session_revoked","going_away","idle_timeout","slow_consumer","transport_closed","ice_fetch_failed"]);function _(e){return"mic_permission_denied"===e?"micPermissionError":P.has(e)?"connectionError":"callError"}const B={calls:[],conferenceAudio:null};function H(e,n){const t=function(e,n){var t,a;switch(n.type){case"active":{const t=e.calls.find(e=>e.call===n.call),a=e.calls.filter(e=>e.call!==n.call).map(e=>Object.assign(Object.assign({},e),{active:!1})),r=t?Object.assign(Object.assign({},t),{active:!0}):{call:n.call,active:!0,transferPeer:null,transferRole:null,merged:!1};return Object.assign(Object.assign({},e),{calls:[...a,r]})}case"incomingAdded":return e.calls.some(e=>e.call===n.call)?e:Object.assign(Object.assign({},e),{calls:[...e.calls,{call:n.call,active:!1,transferPeer:null,transferRole:null,merged:!1}]});case"answered":case"switchActive":return e.calls.some(e=>e.call===n.call)?Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"answeredInPlace":return e.calls.find(e=>e.call===n.call)?e.calls.some(e=>e.active)?e:Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"consultStarted":{const r=null!==(a=null===(t=e.calls.find(e=>e.active))||void 0===t?void 0:t.call)&&void 0!==a?a:null,l=e.calls.filter(e=>e.call!==r).map(e=>Object.assign(Object.assign({},e),{active:!1})),s=r?[{call:r,active:!1,transferPeer:n.call,transferRole:"original",merged:!1}]:[];return Object.assign(Object.assign({},e),{calls:[...l,...s,{call:n.call,active:!0,transferPeer:r,transferRole:"consult",merged:!1}]})}case"cancelConsult":{const n=e.calls.find(e=>"consult"===e.transferRole),t=e.calls.find(e=>"original"===e.transferRole);if(!n||!t)return e;const a=e.calls.filter(e=>e.call!==n.call&&e.call!==t.call);return Object.assign(Object.assign({},e),{calls:[...a,{call:t.call,active:!0,transferPeer:null,transferRole:null,merged:!1}]})}case"callEnded":{const t=e.calls.find(e=>e.call===n.call);if(!t)return e;let a=e.calls.filter(e=>e.call!==n.call);return t.transferPeer&&(a=a.map(e=>e.call===t.transferPeer?{call:e.call,active:!0,transferPeer:null,transferRole:null,merged:!1}:e)),Object.assign(Object.assign({},e),{calls:a})}case"merged":{const[t]=n.calls;if(!t)return e;const a=new Set(n.calls);return Object.assign(Object.assign({},e),{conferenceAudio:n.audio,calls:e.calls.map(e=>a.has(e.call)?Object.assign(Object.assign({},e),{merged:!0,active:e.call===t}):Object.assign(Object.assign({},e),{active:!1}))})}case"unmerged":return e.calls.some(e=>e.merged)?Object.assign(Object.assign({},e),{conferenceAudio:null,calls:e.calls.map(e=>e.merged?Object.assign(Object.assign({},e),{merged:!1}):e)}):e;case"reset":return 0===e.calls.length?e:B}}(e,n);if(t===e)return e;const a=function(e){const n=e.filter(e=>e.active).length;if(0===n){const n=[...e].reverse().find(e=>!E(e.call));return n?e.map(e=>e.call===n.call?Object.assign(Object.assign({},e),{active:!0}):e):e}if(1===n)return e;let t=!1;return[...e].reverse().map(e=>e.active?t?Object.assign(Object.assign({},e),{active:!1}):(t=!0,e):e).reverse()}(t.calls);return a===t.calls?t:Object.assign(Object.assign({},t),{calls:a})}function R(e,n={}){const{onError:t}=n,[,r]=a(0),l=s(()=>r(e=>e+1),[]),c=s((e,n)=>{var a,r;const l=e;null==t||t({code:null!==(a=null==l?void 0:l.code)&&void 0!==a?a:n,message:null!==(r=null==l?void 0:l.message)&&void 0!==r?r:String(e)})},[t]),o=s(e=>function(e,n,t){return{answer:()=>{if(e)try{e.answer()}catch(e){n(e,"call_failed")}},reject:()=>{if(e)try{e.reject()}catch(e){n(e,"call_failed")}},hangup:()=>{if(e)try{e.hangup()}catch(e){n(e,"call_failed")}},toggleMute:()=>{if(e)try{e.isMuted?e.unmute():e.mute(),t()}catch(e){n(e,"call_failed")}},toggleHold:()=>{if(e)try{"held"===e.state?e.resume():e.hold()}catch(e){n(e,"call_failed")}},sendDtmf:t=>{if(t&&e)try{e.sendDtmf(t)}catch(e){n(e,"call_failed")}}}}(e,c,l),[c,l]),{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g}=o(e);return{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g,transfer:s(n=>{if(!e)return!1;const a=M(n,t,{silentWhenEmpty:!0});if(!a)return!1;try{return e.transfer(a),!0}catch(e){return c(e,"call_failed"),!1}},[e,c,t]),callActionsFor:o}}function L(e,n=500){const[,r]=a(0),l=null!=e&&C(e);return t(()=>{if(!l)return;const e=setInterval(()=>r(e=>e+1),n);return()=>clearInterval(e)},[l,n]),A(e?e.duration:0)}const U="Timed out confirming your location. Please try again.";function V(e,n){let t=!1;return new Promise((a,r)=>{const l=setTimeout(()=>{t=!0,r(new Error(U))},8e3);e.then(()=>{clearTimeout(l),t?n(null):a()},e=>{clearTimeout(l);const a=e instanceof Error?e:new Error(U);t?n(a):r(a)})})}function F(e){const[n,t]=a(null);return{lastError:n,handleError:s(n=>{t(n),null==e||e(n)},[e]),clearError:s(()=>t(null),[])}}function W(e){return{onType:s(n=>e(z(n)),[e]),onPasteText:s(n=>e(O(n,T)),[e])}}const K={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,radius:14},q={background:"#ffffff",surface:"rgba(0, 0, 0, 0.04)",surfaceActive:"rgba(0, 0, 0, 0.09)",text:"#1a1a1a",textSecondary:"rgba(0, 0, 0, 0.55)",border:"rgba(0, 0, 0, 0.1)",accent:"#6772e5",success:"#30a46c",danger:"#e5484d",warning:"#f5a623",onAccent:"#ffffff"},G={background:"#1a1a1a",surface:"rgba(255, 255, 255, 0.06)",surfaceActive:"rgba(255, 255, 255, 0.12)",text:"#ffffff",textSecondary:"rgba(255, 255, 255, 0.6)",border:"rgba(255, 255, 255, 0.12)",accent:"#828bf0",success:"#3dd68c",danger:"#ff6369",warning:"#f5a623",onAccent:"#ffffff"},Y=[{digit:"1",letters:""},{digit:"2",letters:"ABC"},{digit:"3",letters:"DEF"},{digit:"4",letters:"GHI"},{digit:"5",letters:"JKL"},{digit:"6",letters:"MNO"},{digit:"7",letters:"PQRS"},{digit:"8",letters:"TUV"},{digit:"9",letters:"WXYZ"},{digit:"*",letters:""},{digit:"0",letters:"+"},{digit:"#",letters:""}];function J(e){var n,t,a,r,l,s,c,o,i,d;const u="dark"===(null==e?void 0:e.theme)?G:q;const p=null!==(n=null==e?void 0:e.variables)&&void 0!==n?n:{};return{background:null!==(t=p.colorBackground)&&void 0!==t?t:u.background,surface:null!==(a=p.colorSurfaceSubtle)&&void 0!==a?a:u.surface,surfaceActive:u.surfaceActive,text:null!==(r=p.colorText)&&void 0!==r?r:u.text,textSecondary:null!==(l=p.colorTextSecondary)&&void 0!==l?l:u.textSecondary,border:null!==(s=p.colorBorder)&&void 0!==s?s:u.border,accent:null!==(c=p.colorPrimary)&&void 0!==c?c:u.accent,success:null!==(o=p.colorSuccess)&&void 0!==o?o:u.success,danger:null!==(i=p.colorDanger)&&void 0!==i?i:u.danger,warning:null!==(d=p.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const Q=c(null),X=()=>Promise.reject(new Error("Phone not connected")),Z={listEmergencyAddresses:()=>m(X(),X),setEmergencyAddress:X,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:X,reconnectWithEmergency:X};function ee({token:c,existingPhone:o,apiBaseUrl:i,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,onAppResume:C,emergencyAddressId:k,autoConnect:$=!0,appearance:N,locale:A=h,defaultCountry:I="US",onConnectionStateChange:z,onIncomingCall:D,onCallStarted:j,onCallEnded:P,onError:_,placeOutbound:U,extra:W,children:K}){var q,G;const{lastError:Y,handleError:X,clearError:ee}=F(_),ne=`${null!==(q=null==N?void 0:N.theme)&&void 0!==q?q:""}|${JSON.stringify(null!==(G=null==N?void 0:N.variables)&&void 0!==G?G:{})}`,te=l(()=>J(N),[ne]),ae=e=>A.softphone[e],re=e=>S(e,I),{phone:le,connection:se}=y({existingPhone:o,token:c,apiBaseUrl:i,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,onAppResume:C,emergencyAddressId:k,autoConnect:$,onError:X}),{calls:ce,activeCall:oe,incomingCalls:ie,heldCalls:de,answerCall:ue,switchToCall:pe,placeCall:me,consultCall:ge,transferOriginal:fe,startAttendedTransfer:he,completeAttendedTransfer:ve,cancelAttendedTransfer:be,mergedCalls:ye,isMerged:xe,conferenceAudio:Ee,canMerge:we,mergeCalls:Ce,splitMerge:ke,hangupConference:$e,holdConference:Ne}=function(e,c,o={}){var i,d,m,g,f,h;const{onIncomingCall:v,onCallStarted:y,onCallActivated:w,onCallEnded:C,onError:k,placeOutbound:$}=o,[N,A]=r(H,B),[S,I]=a(e);S!==e&&(I(e),N.calls.length>0&&A({type:"reset"}));const{calls:z,conferenceAudio:D}=N,j=null!==(i=z.find(e=>e.active))&&void 0!==i?i:null,P=null!==(d=null==j?void 0:j.call)&&void 0!==d?d:null,_=l(()=>z.filter(e=>!e.active&&E(e.call)).map(e=>e.call),[z]),R=l(()=>z.filter(e=>!e.active&&!E(e.call)).map(e=>e.call),[z]),L=null!==(g=null===(m=z.find(e=>"consult"===e.transferRole))||void 0===m?void 0:m.call)&&void 0!==g?g:null,U=null!==(h=null===(f=z.find(e=>"original"===e.transferRole))||void 0===f?void 0:f.call)&&void 0!==h?h:null,V=l(()=>z.filter(e=>e.merged).map(e=>e.call),[z]),F=V.length>0,W=b(e),K=b(c),[,q]=a(0),G=s(()=>q(e=>e+1),[]),Y=n(null);Y.current=P;const J=b(L),Q=n(null),X=b(z),Z=b(U),ee=n(!0);t(()=>(ee.current=!0,()=>{ee.current=!1}),[]);const ne=b({onIncomingCall:v,onCallStarted:y,onCallActivated:w,onCallEnded:C,onError:k,placeOutbound:$}),te=n(new Map),ae=n(new WeakSet),re=s(e=>{const n=te.current.get(e);n&&(n(),te.current.delete(e))},[]),le=s(e=>{re(e);const n=()=>{G()},t=()=>{var n,t,a,r;"inbound"===e.direction&&(ae.current.add(e),null===(t=(n=ne.current).onCallStarted)||void 0===t||t.call(n,{direction:"inbound",peer:e.from})),null===(r=(a=ne.current).onCallActivated)||void 0===r||r.call(a,e),A({type:"answeredInPlace",call:e}),G()},a=n=>{var t,a;ae.current.has(e)&&(ae.current.delete(e),null===(a=(t=ne.current).onCallEnded)||void 0===a||a.call(t,{reason:n}));const r=Q.current;(null==r?void 0:r.has(e))&&(r.remove(e),r.calls.length<2&&(r.dispose(),Q.current=null,A({type:"unmerged"}))),A({type:"callEnded",call:e}),re(e)};e.on("trying",n),e.on("ringing",n),e.on("answered",t),e.on("held",n),e.on("resumed",n),e.on("ended",a),te.current.set(e,()=>{e.off("trying",n),e.off("ringing",n),e.off("answered",t),e.off("held",n),e.off("resumed",n),e.off("ended",a)})},[G,re,ne]),se=s(e=>x(this,void 0,void 0,function*(){var n,t,a,r,l,s,c,o,i,d,u,p;const m=W.current,g=M(e,ne.current.onError);if(!g)return;if(!m||"connected"!==K.current)return void(null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:"transport_closed",message:"The softphone is not connected"}));if(te.current.size>=4)return void(null===(r=(a=ne.current).onError)||void 0===r||r.call(a,{code:"rate_limited",message:"Too many active calls"}));const f=Y.current;try{null==f||f.hold();const e=yield null!==(c=null===(s=(l=ne.current).placeOutbound)||void 0===s?void 0:s.call(l,g))&&void 0!==c?c:m.call(g);A({type:"active",call:e}),ae.current.add(e),null===(i=(o=ne.current).onCallStarted)||void 0===i||i.call(o,{direction:"outbound",peer:e.to}),le(e)}catch(e){if(f&&"ended"!==f.state)try{f.resume()}catch(e){}const n=e;null===(u=(d=ne.current).onError)||void 0===u||u.call(d,{code:null!==(p=n.code)&&void 0!==p?p:"call_failed",message:n.message})}}),[le,K,ne,W]),ce=s((e,n)=>{var t,a,r;const l=Y.current;try{null==l||l.hold(),e(),A(n)}catch(e){if(l&&"ended"!==l.state)try{l.resume()}catch(e){}const n=e;null===(a=(t=ne.current).onError)||void 0===a||a.call(t,{code:null!==(r=n.code)&&void 0!==r?r:"call_failed",message:n.message})}},[ne]),oe=s(e=>{Y.current!==e&&ce(()=>e.resume(),{type:"switchActive",call:e})},[ce]),ie=s(e=>{ce(()=>e.answer(),{type:"answered",call:e})},[ce]),de=s(()=>{var e,n,t;if(Q.current)return;const a=X.current;if(2!==a.length)return;if(!a.every(e=>e.call.isConnected)||!u())return;const r=a.map(e=>e.call);if(X.current.some(e=>null!==e.transferRole))return;const l=[];for(const e of r)if("held"===e.state)try{e.resume(),l.push(e)}catch(e){}try{const e=p.merge(r,r[0].localMediaStream,e=>{var n,t,a;return null===(t=(n=ne.current).onError)||void 0===t?void 0:t.call(n,{code:null!==(a=e.code)&&void 0!==a?a:"call_failed",message:e.message})});Q.current=e,A({type:"merged",calls:r,audio:e.localMediaStream}),G()}catch(a){for(const e of l)try{e.holdAfterResume()}catch(e){}const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[X,Q,ne,G]),ue=s(()=>{const e=Q.current;if(e){e.dispose(),Q.current=null;for(const e of X.current)if(e.merged&&!e.active)try{e.call.hold()}catch(e){}A({type:"unmerged"}),G()}},[X,Q,G]),pe=s(e=>{var n,t,a;const r=Q.current;if(r){for(const l of r.calls)try{l.setConferenceHold(e)}catch(e){const r=e;null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}G()}},[Q,ne,G]),me=s(()=>{var e,n,t;const a=Q.current;if(!a)return;const r=a.calls;a.dispose(),Q.current=null,A({type:"unmerged"});for(const a of r)try{a.hangup()}catch(a){const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[Q,ne]),ge=s(e=>x(this,void 0,void 0,function*(){var n,t,a;const r=Y.current,l=W.current,s=O(e,T);if(r&&!J.current&&s&&!Q.current)try{const e=yield r.attendedTransfer(s);if(!ee.current)return;if("ended"===r.state||W.current!==l)return void e.hangup();A({type:"consultStarted",call:e}),le(e)}catch(e){const r=e;null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}}),[le,J,ne,W]),fe=s(()=>{var e,n,t;const a=Z.current,r=J.current;if(a&&r&&r.isConnected)try{a.completeTransfer()}catch(a){const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[J,ne,Z]),he=s(()=>{const e=J.current,n=Z.current;e&&(e.hangup(),re(e),"held"===(null==n?void 0:n.state)&&n.resume(),A({type:"cancelConsult"}))},[re,J,Z]);t(()=>{var n;if(!e)return;let t=!1;const a=te.current,r=(e,n)=>{var a,r,l;if(t)return;const s=null===(a=null==n?void 0:n.notifyHost)||void 0===a||a;Q.current||te.current.size>=4?e.reject("busy"):(A({type:"incomingAdded",call:e}),s&&(ae.current.add(e),null===(l=(r=ne.current).onIncomingCall)||void 0===l||l.call(r,{callId:e.id,from:e.from,fromName:e.fromName})),le(e))};e.on("incoming",r);for(const t of null!==(n=e.activeCalls)&&void 0!==n?n:[])te.current.has(t)||"inbound"===t.direction&&(r(t,{notifyHost:!t.isConnected}),t.isConnected&&(ae.current.add(t),A({type:"answeredInPlace",call:t})));return()=>{t=!0,e.off("incoming",r);const n=Q.current;n&&(n.dispose(),Q.current=null);for(const e of a.values())e();a.clear(),A({type:"reset"})}},[e,le,ne]);const ve=!F&&2===z.length&&z.every(e=>e.call.isConnected)&&!z.some(e=>null!==e.transferRole)&&u();return{calls:z,activeCall:P,incomingCalls:_,switchToCall:oe,answerCall:ie,placeCall:se,consultCall:L,heldCalls:R,transferOriginal:U,startAttendedTransfer:ge,completeAttendedTransfer:fe,cancelAttendedTransfer:he,mergedCalls:V,isMerged:F,conferenceAudio:D,canMerge:ve,mergeCalls:de,splitMerge:ue,hangupConference:me,holdConference:pe}}(le,se,{onIncomingCall:D,onCallStarted:j,onCallEnded:P,onError:X,placeOutbound:U}),Ae=function(e,r){const{disabled:l,connection:c,identityKey:o,liveCallCount:i=0}=r,[d,u]=a(!l),[p,m]=a(!1),[g,f]=a(!1),[h,v]=a([]),[y,E]=a(!1),w=b(y),[C,k]=a(null),$=b(e),N=n(!1),A=n(0),S=n(o);t(()=>{S.current!==o&&(S.current=o,N.current=!1,m(!1),f(!1),v([]),k(null),u(!l))},[o,l]);const I=s(()=>{f(!0),m(!1)},[]);t(()=>{if(l)return;if("connected"!==c)return void("disconnected"!==c&&"error"!==c||u(!1));let e=!1;return(()=>{x(this,void 0,void 0,function*(){var n,t;try{const a=$.current,r=(yield a.listEmergencyAddresses()).data;if(e)return;v(r);const l=a.presentedEmergencyAddressId,s=null!==(t=null!==(n=r.find(e=>e.id===l))&&void 0!==n?n:r[0])&&void 0!==t?t:null;if(!s)return void m(!1);if(i>0)return void u(!1);if(N.current||g)w.current||(m(!g),g||k(null));else{if(N.current=!0,null==l||l!==s.id||null==s.registered_ip)return void(yield V(a.reconnectWithEmergency(s.id),()=>{}).catch(()=>{}));m(!0),w.current||k(null)}}catch(n){e||m(!1)}finally{e||u(!1)}})})(),()=>{e=!0}},[l,c,g,$,w,i]);const T=s((e,n)=>x(this,void 0,void 0,function*(){const t=++A.current,a=n=>function(e){return"transport_closed"===(null==e?void 0:e.code)}(n)?"Connection interrupted. Please try again.":n instanceof Error?n.message:e,r=e=>{A.current===t&&k(e?a(e):null)};E(!0),k(null),f(!1),N.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield V(t,r)}catch(e){throw k(a(e)),e}finally{E(!1)}}),[$]);return{loading:d,bound:p,savedAddresses:h,submitting:y,error:C,onNetworkChanged:I,confirm:s(e=>T("Failed to confirm emergency address",()=>x(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[T,$]),create:s(e=>T("Failed to save emergency address",()=>x(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[T,$])}}(null!=le?le:Z,{disabled:!!k,connection:se,identityKey:c,liveCallCount:ce.length});t(()=>{if(!le)return;const e=Ae.onNetworkChanged;return le.on("network.changed",e),()=>le.off("network.changed",e)},[le,Ae.onNetworkChanged]);const Se=R(oe,{onError:X}),Ie=function(e,n=!0){const[r,l]=a(null);n||"addcall"!==r||l(null);const c=s(e=>{l(n=>n===e?null:e)},[]),o=s(()=>c("keypad"),[c]),i=s(()=>c("transfer"),[c]),d=s(()=>c("devices"),[c]),u=s(()=>c("addcall"),[c]),p=s(()=>l(e=>"transfer"===e?null:e),[]),m=s(()=>l(e=>"addcall"===e?null:e),[]);return t(()=>{l(null)},[e]),{showKeypad:"keypad"===r,showTransfer:"transfer"===r,showDevices:"devices"===r,showAddCall:"addcall"===r,toggleKeypad:o,toggleTransfer:i,toggleDevices:d,toggleAddCall:u,closeTransfer:p,closeAddCall:m}}(oe,ce.length<4),Te=L(oe),ze=l(()=>ce.map(e=>e.call),[ce]),Oe=w(ie),De=n(se);t(()=>{null==z||z({state:se}),"connected"===se&&"connected"!==De.current&&ee(),De.current=se},[se,z,ee]);const Me=l(()=>Object.assign({connection:se,webrtcPhone:le,calls:ze,activeCall:oe,incomingCalls:ie,incomingRinging:Oe,heldCalls:de,answerCall:ue,switchToCall:pe,actions:Se,overlays:Ie,duration:Te,consultCall:ge,transferOriginal:fe,startAttendedTransfer:he,completeAttendedTransfer:ve,cancelAttendedTransfer:be,placeCall:me,mergedCalls:ye,isMerged:xe,conferenceAudio:Ee,canMerge:we,mergeCalls:Ce,splitMerge:ke,hangupConference:$e,holdConference:Ne,emergency:Ae,emergencyManagedByHost:!!k,lastError:Y,clearError:ee,t:ae,displayNumber:re,palette:te},W),[se,le,ze,oe,ie,Oe,de,ue,pe,Se,Ie,Te,ge,fe,he,ve,be,me,ye,xe,Ee,we,Ce,ke,$e,Ne,Ae,k,Y,ee,te,A,I,W]);return e.createElement(Q.Provider,{value:Me},K)}function ne(){const e=o(Q);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const te="dialstack.softphone.input_device_id",ae="dialstack.softphone.output_device_id",re=c(null),le=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),se=({children:n})=>{var r,l,c;const{webrtcPhone:o,activeCall:i}=ne(),[d]=a(()=>"undefined"!=typeof HTMLMediaElement&&"function"==typeof HTMLMediaElement.prototype.setSinkId),[u]=a(()=>{var e;return"undefined"!=typeof navigator&&"function"==typeof(null===(e=navigator.mediaDevices)||void 0===e?void 0:e.enumerateDevices)}),[p,m]=a([]),[f,h]=a([]),[v,b]=a(!1),[y,E]=a(!1),[,w]=a(0),C=i?null!==(l=null!==(r=i.effectiveAudioInputDeviceId)&&void 0!==r?r:null==o?void 0:o.audioInputDeviceId)&&void 0!==l?l:null:null!==(c=null==o?void 0:o.audioInputDeviceId)&&void 0!==c?c:g.getItem(te),[k,$]=a(()=>g.getItem(ae));t(()=>{if(!u)return;let e=!1;const n=()=>x(void 0,void 0,void 0,function*(){let n;try{n=yield navigator.mediaDevices.enumerateDevices()}catch(e){return}if(e)return;const t=n.filter(e=>"audioinput"===e.kind),a=n.filter(e=>"audiooutput"===e.kind);b(t.length>0&&t.every(e=>""===e.label)),m(le(t)),h(d?le(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,i]),t(()=>{o&&k&&o.setAudioOutputDevice(k)},[o,k]),t(()=>{const e=g.getItem(te);o&&e&&!o.audioInputDeviceId&&o.seedAudioInputDevice(e)},[o]),t(()=>{if(!i)return;const e=()=>E(!0),n=()=>w(e=>e+1);return i.on("audioInputLost",e),i.on("audioInputChanged",n),()=>{i.off("audioInputLost",e),i.off("audioInputChanged",n),E(!1)}},[i]);const N=s(e=>{const n=()=>w(e=>e+1);null==o||o.setAudioInputDevice(e).then(()=>{E(!1),e?g.setItem(te,e):g.removeItem(te),n()},n)},[o]),A=s(e=>{$(e),e?g.setItem(ae,e):g.removeItem(ae),null==o||o.setAudioOutputDevice(e)},[o]),S={inputs:p,outputs:f,inputDeviceId:C,outputDeviceId:k,selectInputDevice:N,selectOutputDevice:A,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:y};return e.createElement(re.Provider,{value:S},n)};function ce(){const e=o(re);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const oe=[440,480];class ie{constructor(){this.ctx=null,this.gain=null,this.oscillators=[],this.cadenceTimer=null,this.started=!1,this.nextCadenceTime=0,this.sinkId=null}get isPlaying(){return this.started}setSinkId(e){this.sinkId=e;const n=this.ctx;n&&"function"==typeof n.setSinkId&&Promise.resolve(n.setSinkId(null!=e?e:"")).catch(()=>{})}start(){if(this.started)return;const e=function(){var e,n;const t=globalThis;return null!==(n=null!==(e=t.AudioContext)&&void 0!==e?e:t.webkitAudioContext)&&void 0!==n?n:null}();if(!e)return;let n;try{n=new e(this.sinkId?{sinkId:this.sinkId}:void 0)}catch(t){this.sinkId=null;try{n=new e}catch(e){return}}this.ctx=n,"suspended"===n.state&&"function"==typeof n.resume&&Promise.resolve(n.resume()).catch(()=>{});try{const e=n.createGain();e.gain.value=0,e.connect(n.destination),this.gain=e;for(const t of oe){const a=n.createOscillator();a.frequency.value=t,a.connect(e),a.start(),this.oscillators.push(a)}this.nextCadenceTime=n.currentTime,this.scheduleCadenceAhead(),this.cadenceTimer=setInterval(()=>this.scheduleCadenceAhead(),6e3),this.started=!0}catch(e){this.teardown()}}stop(){this.started&&(this.started=!1,this.teardown())}teardown(){this.cadenceTimer&&(clearInterval(this.cadenceTimer),this.cadenceTimer=null);for(const e of this.oscillators)try{e.stop(),e.disconnect()}catch(e){}if(this.oscillators=[],this.gain){try{this.gain.disconnect()}catch(e){}this.gain=null}const e=this.ctx;this.ctx=null,e&&"function"==typeof e.close&&Promise.resolve(e.close()).catch(()=>{})}scheduleCadenceAhead(){const e=this.ctx,n=this.gain;if(!e||!n)return;for(;this.nextCadenceTime+6<=e.currentTime;)this.nextCadenceTime+=6;const t=e.currentTime+12;for(;this.nextCadenceTime<t;)n.gain.setValueAtTime(.14,this.nextCadenceTime),n.gain.setValueAtTime(0,this.nextCadenceTime+2),this.nextCadenceTime+=6}}const de=Q,ue=({existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:c,emergencyAddressId:d,autoConnect:u=!0,appearance:p,locale:m=h,formatting:g,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:x,onError:E,children:w})=>{var C,k,$;const N=`ds-softphone-${i().replace(/[:]/g,"")}`,A=l(()=>({scope:N}),[N]),S=o(v),[I,T]=a(()=>null==S?void 0:S.dialstack.getAppearance()),z=null!=p?p:I,O=`${null!==(C=null==z?void 0:z.theme)&&void 0!==C?C:""}|${JSON.stringify(null!==(k=null==z?void 0:z.variables)&&void 0!==k?k:{})}`,D=null!==($=null==g?void 0:g.defaultCountry)&&void 0!==$?$:"US",M=l(()=>function(e,n="ds-softphone"){const t=K;return`\n .${n} {\n --dsd-bg: ${e.background};\n --dsd-surface: ${e.surface};\n --dsd-surface-active: ${e.surfaceActive};\n --dsd-text: ${e.text};\n --dsd-text-secondary: ${e.textSecondary};\n --dsd-border: ${e.border};\n --dsd-accent: ${e.accent};\n --dsd-success: ${e.success};\n --dsd-danger: ${e.danger};\n --dsd-warning: ${e.warning};\n --dsd-on-accent: ${e.onAccent};\n font-family: var(--ds-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);\n background: var(--dsd-bg);\n color: var(--dsd-text);\n width: 100%;\n max-width: ${t.maxWidth}px;\n margin: 0 auto;\n border-radius: ${t.radius}px;\n padding: clamp(12px, 4vw, 24px);\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n .${n} * { box-sizing: border-box; }\n /* Every exported piece (DialPad, OngoingCall, IncomingCall, IncomingStack,\n IncomingCallCard, EmergencyBanner) self-wraps in its own \`.ds-softphone\`\n so it renders correctly standalone — a host can drop any one of them under\n the provider without hand-supplying scoped wrappers. When one such piece is\n composed INSIDE another (e.g. IncomingStack renders IncomingCallCards, or\n <Softphone> stacks several screens), the inner \`.ds-softphone\` would\n otherwise paint a second card box. Collapse any nested wrapper so only the\n outermost is the padded card. */\n .${n} .ds-softphone { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-screen { display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px); }\n\n .${n} .ds-chip {\n align-self: center;\n font-size: 12px;\n font-weight: 600;\n padding: 4px 12px;\n border-radius: 999px;\n letter-spacing: 0.02em;\n }\n .${n} .ds-chip-spacer { visibility: hidden; }\n .${n} .ds-chip-pending { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-off { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-error { background: color-mix(in srgb, var(--dsd-danger) 16%, transparent); color: var(--dsd-danger); }\n .${n} .ds-call-error {\n display: flex;\n align-items: center;\n gap: 8px;\n max-width: 100%;\n text-align: left;\n }\n .${n} .ds-call-error-dismiss {\n border: none;\n background: transparent;\n color: inherit;\n cursor: pointer;\n font-size: 12px;\n line-height: 1;\n padding: 0;\n }\n\n /* The number must center on the keypad's axis. The backspace flanks the input\n on the right, so an equal-width invisible spacer flanks it on the left — the\n input then centers between two 40px flanks and reads as truly centered (a\n lone backspace would optically pull the number left even when the box math\n centers). */\n .${n} .ds-display { display: flex; align-items: center; min-height: 56px; gap: 8px; }\n .${n} .ds-display-spacer { width: 40px; flex: none; }\n .${n} .ds-destination {\n flex: 1; min-width: 0;\n font-size: clamp(24px, 7vw, 32px);\n font-weight: 500;\n text-align: center;\n border: none; outline: none; background: transparent;\n color: var(--dsd-text);\n letter-spacing: 0.02em;\n }\n .${n} .ds-destination::placeholder { color: var(--dsd-text-secondary); opacity: 0.7; }\n .${n} .ds-backspace {\n flex: none;\n border: none; background: transparent; cursor: pointer;\n font-size: 22px; color: var(--dsd-text-secondary);\n width: 40px; height: 40px; border-radius: 999px;\n }\n .${n} .ds-backspace:hover { background: var(--dsd-surface); color: var(--dsd-text); }\n\n .${n} .ds-keypad {\n display: grid; grid-template-columns: repeat(3, 1fr);\n gap: ${t.keyGap}px;\n justify-items: center;\n }\n .${n} .ds-key {\n display: flex; flex-direction: column; align-items: center; justify-content: center;\n width: 100%; aspect-ratio: 1 / 1; max-width: 84px;\n border: none; border-radius: 999px;\n background: var(--dsd-surface); color: var(--dsd-text);\n cursor: pointer; gap: 2px;\n transition: background-color 0.12s ease, transform 0.06s ease;\n -webkit-tap-highlight-color: transparent;\n user-select: none;\n }\n .${n} .ds-key:hover { background: var(--dsd-surface-active); }\n .${n} .ds-key:active { transform: scale(0.94); }\n .${n} .ds-key-digit { font-size: clamp(22px, 6vw, 28px); font-weight: 500; line-height: 1; }\n .${n} .ds-key-letters {\n font-size: 10px; font-weight: 600; letter-spacing: 0.12em;\n color: var(--dsd-text-secondary); min-height: 12px;\n }\n .${n} .ds-keypad-dtmf .ds-key { aspect-ratio: auto; padding: 10px 0; max-width: 72px; }\n\n .${n} .ds-actions { display: flex; justify-content: center; gap: clamp(24px, 12vw, 72px); }\n .${n} .ds-actions-incoming { justify-content: space-evenly; }\n .${n} .ds-action {\n width: ${t.actionButtonSize}px; height: ${t.actionButtonSize}px;\n border: none; border-radius: 999px; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n color: var(--dsd-on-accent);\n transition: transform 0.06s ease, filter 0.12s ease;\n -webkit-tap-highlight-color: transparent;\n }\n .${n} .ds-action svg { width: 46%; height: 46%; }\n .${n} .ds-action:active { transform: scale(0.92); }\n .${n} .ds-action:disabled { opacity: 0.4; cursor: not-allowed; }\n .${n} .ds-call, .${n} .ds-answer { background: var(--dsd-success); }\n .${n} .ds-hangup, .${n} .ds-decline { background: var(--dsd-danger); }\n .${n} .ds-call:not(:disabled):hover, .${n} .ds-answer:hover,\n .${n} .ds-hangup:hover, .${n} .ds-decline:hover { filter: brightness(1.06); }\n\n .${n} .ds-peer { text-align: center; display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-peer-name { font-size: clamp(22px, 6vw, 28px); font-weight: 600; word-break: break-word; }\n .${n} .ds-peer-number { font-size: 15px; color: var(--dsd-text-secondary); }\n .${n} .ds-callstate { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }\n .${n} .ds-callstate-text { font-size: 14px; color: var(--dsd-text-secondary); }\n .${n} .ds-duration { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 500; }\n\n .${n} .ds-incoming-label {\n text-align: center; font-size: 13px; font-weight: 600;\n letter-spacing: 0.08em; text-transform: uppercase; color: var(--dsd-text-secondary);\n }\n .${n} .ds-incoming-pulse {\n width: 12px; height: 12px; border-radius: 999px; margin: 4px auto;\n background: var(--dsd-success);\n box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 60%, transparent);\n animation: ds-pulse 1.6s infinite;\n }\n @keyframes ds-pulse {\n 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 50%, transparent); }\n 70% { box-shadow: 0 0 0 16px transparent; }\n 100% { box-shadow: 0 0 0 0 transparent; }\n }\n\n .${n} .ds-controls {\n display: flex; flex-wrap: wrap; justify-content: center;\n gap: 8px 20px;\n max-width: ${3*(t.controlButtonSize+12)+40}px;\n margin: 0 auto;\n }\n .${n} .ds-controls > * { flex: 0 0 ${t.controlButtonSize+12}px; }\n .${n} .ds-control {\n display: flex; flex-direction: column; align-items: center; gap: 6px;\n border: none; background: transparent; cursor: pointer;\n color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-control-glyph {\n width: ${t.controlButtonSize}px; height: ${t.controlButtonSize}px;\n border-radius: 999px; background: var(--dsd-surface);\n display: flex; align-items: center; justify-content: center;\n transition: background-color 0.12s ease;\n }\n .${n} .ds-control-glyph svg { width: 42%; height: 42%; }\n .${n} .ds-control:hover:not(:disabled) .ds-control-glyph { background: var(--dsd-surface-active); }\n .${n} .ds-control-on .ds-control-glyph { background: var(--dsd-accent); color: var(--dsd-on-accent); }\n .${n} .ds-control-label { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-control-on .ds-control-label { color: var(--dsd-text); }\n .${n} .ds-control:disabled { cursor: not-allowed; opacity: 0.4; }\n\n .${n} .ds-dtmf { display: flex; flex-direction: column; gap: 10px; }\n .${n} .ds-dtmf-readout {\n text-align: center; font-size: 22px; min-height: 28px;\n font-variant-numeric: tabular-nums; letter-spacing: 0.08em;\n }\n .${n} .ds-transfer { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-transfer-input {\n flex: 1; min-width: 0; padding: 12px 14px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 16px; outline: none;\n }\n .${n} .ds-transfer-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-transfer-actions { display: flex; gap: 8px; }\n .${n} .ds-transfer-send {\n flex: 1; border: none; border-radius: ${t.radius}px; padding: 12px 18px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-transfer-send:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-transfer-send-secondary {\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+40}px; margin: 0 auto;\n }\n .${n} .ds-device-row { display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-device-label { font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-select {\n width: 100%; padding: 10px 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text);\n font-size: 14px; font-family: inherit; outline: none;\n }\n .${n} .ds-device-select:focus { border-color: var(--dsd-accent); }\n .${n} .ds-device-select:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-device-hint { margin: 0; font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-alert { font-size: 12px; color: var(--dsd-danger); }\n\n /* Attended-transfer banner (layered over the normal in-call view): the other\n transfer leg as a switch card + the Cancel/Complete actions. */\n .${n} .ds-transfer-banner { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-consult-held { opacity: 0.7; }\n .${n} .ds-consult-actions { display: flex; gap: 8px; }\n .${n} .ds-consult-actions .ds-e911-btn { flex: 1; }\n\n /* Multi-call + transfer: switchable held-call cards. Clickable (button reset)\n to switch focus to that call; the cursor + hover signal it's actionable. */\n .${n} .ds-held-calls { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-held-call {\n display: block; width: 100%; cursor: pointer; text-align: center;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 12px 14px;\n background: var(--dsd-surface); color: var(--dsd-text);\n font-family: inherit;\n }\n .${n} .ds-held-call:hover { opacity: 1; border-color: var(--dsd-accent); }\n /* A conference is ONE conversation with two people. The participants sit in a\n single bordered block under one heading and one timer, so they read as\n joined rather than as an active call with another stacked above it. */\n .${n} .ds-conference-parties {\n display: flex; flex-direction: column; align-items: center; gap: 2px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 10px 14px; margin: 6px 0;\n background: var(--dsd-surface);\n }\n\n /* Multi-call: composite layout — the in-call screen with the ringing\n call-waiting card(s) as a compact banner ABOVE it. The banner is in normal\n flow (not absolutely positioned) so it reserves its own space and never\n overlaps the in-call peer/controls below. (Idle inbound is a dedicated\n screen, not this banner.) */\n .${n}.ds-softphone-layout {\n display: flex; flex-direction: column; gap: 12px;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-softphone-layout > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-overlay { flex: none; }\n\n /* Batteries-included dial screen: the E911 banner above the dial pad, each in\n its own scope wrapper. This outer wrapper is the single padded card; the\n inner dial pad's own .ds-softphone must not add a second card box. The\n banner (a direct .ds-e911 child) carries its own spacing. */\n .${n}.ds-dial-screen {\n display: flex; flex-direction: column;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-dial-screen > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-stack { display: flex; flex-direction: column; gap: 8px; }\n\n /* One ringing call's card. Full-size inside the dedicated incoming screen;\n the compact variant (stacked / call-waiting overlay) shrinks it and puts\n the answer/decline buttons inline so it takes less space. */\n .${n} .ds-incoming-card {\n display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px);\n align-items: center; text-align: center;\n }\n .${n} .ds-incoming-card-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n .${n} .ds-incoming-card-compact {\n flex-direction: row; gap: 12px; align-items: center; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);\n }\n .${n} .ds-incoming-card-compact .ds-incoming-card-info { flex: 1; min-width: 0; }\n .${n} .ds-incoming-card-compact .ds-incoming-label { font-size: 11px; }\n /* Shrink the peer name/number in a compact card — otherwise they inherit the\n full-screen in-call sizes (clamp up to 28px) and overflow the small overlay\n card, colliding with the call behind it. Truncate rather than wrap. */\n .${n} .ds-incoming-card-compact .ds-peer-name {\n font-size: 15px; font-weight: 600; line-height: 1.2;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-peer-number {\n font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-actions-incoming { margin: 0; gap: 8px; flex: none; }\n .${n} .ds-incoming-card-compact .ds-action { width: 44px; height: 44px; }\n\n /* EmergencyBanner's self-wrap is only a scope carrier — never its own card\n box. The visible chrome is the .ds-e911 prompt inside; the wrapper stays\n transparent/paddingless in every context (standalone or composed), and its\n trailing margin comes from .ds-e911 itself. */\n .${n}.ds-e911-root { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-e911 {\n margin-bottom: 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n overflow: hidden; background: var(--dsd-surface);\n }\n .${n} .ds-e911-toggle {\n display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;\n padding: 10px 12px; border: none; cursor: pointer;\n background: color-mix(in srgb, var(--dsd-warning) 18%, transparent);\n color: color-mix(in srgb, var(--dsd-warning) 60%, var(--dsd-text));\n font-family: inherit; font-size: 13px;\n font-weight: 600; text-align: center;\n }\n .${n} .ds-e911-toggle svg { width: 16px; height: 16px; flex: none; }\n .${n} .ds-e911-label { flex: 0 1 auto; text-align: center; }\n .${n} .ds-e911-chevron { transition: transform 0.15s ease; }\n .${n} .ds-e911-open .ds-e911-chevron { transform: rotate(180deg); }\n .${n} .ds-e911-body {\n display: flex; flex-direction: column; gap: 8px;\n padding: 12px; border-top: 1px solid var(--dsd-border);\n }\n .${n} .ds-e911-hint { font-size: 12px; color: var(--dsd-text-secondary); margin: 0; }\n /* Saved-address choice buttons ("Are you here?") */\n .${n} .ds-e911-choice {\n display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); cursor: pointer;\n font-family: inherit; font-size: 13px;\n }\n .${n} .ds-e911-choice:hover { border-color: var(--dsd-accent); }\n .${n} .ds-e911-choice svg { width: 14px; height: 14px; flex: none; color: var(--dsd-success); }\n .${n} .ds-e911-choice-addr { flex: 1; min-width: 0; }\n .${n} .ds-e911-choice-cta { font-size: 12px; font-weight: 600; color: var(--dsd-accent); }\n .${n} .ds-e911-row { display: flex; gap: 8px; }\n .${n} .ds-e911-field { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }\n .${n} .ds-e911-field-sm { flex: none; width: 88px; }\n .${n} .ds-e911-field label { font-size: 11px; color: var(--dsd-text-secondary); }\n .${n} .ds-e911-input {\n padding: 8px 10px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 14px; outline: none;\n font-family: inherit; width: 100%;\n }\n .${n} .ds-e911-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-e911-error { font-size: 12px; color: var(--dsd-danger); margin: 0; }\n .${n} .ds-e911-actions { display: flex; gap: 8px; }\n .${n} .ds-e911-btn {\n flex: 1; border: none; border-radius: 8px; padding: 10px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-e911-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-e911-btn-secondary {\n flex: none; background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} button:focus-visible, .${n} input:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsd-accent) 45%, transparent);\n }\n `}(J(z),N),[O,N]);return e.createElement(ee,{existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:c,emergencyAddressId:d,autoConnect:u,appearance:z,locale:m,defaultCountry:D,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:x,onError:E,extra:A},S&&e.createElement(ge,{dialstack:S.dialstack,onChange:T}),e.createElement("style",null,M),e.createElement(se,null,w,e.createElement(pe,null),e.createElement(me,{onError:E})))},pe=()=>{const{incomingRinging:e}=fe(),{outputDeviceId:a}=ce(),r=n(null);return null===r.current&&(r.current=new ie),t(()=>{var e;null===(e=r.current)||void 0===e||e.setSinkId(a)},[a]),t(()=>{const n=r.current;if(n)return e?n.start():n.stop(),()=>n.stop()},[e]),null},me=({onError:a})=>{const{activeCall:r,conferenceAudio:l}=fe(),{outputDeviceId:s}=ce(),c=n(null);return t(()=>{const e=c.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=s?s:"").catch(()=>{})},[s,r]),t(()=>{const e=c.current;if(!e)return;if(!r)return void(e.srcObject=null);e.srcObject=null!=l?l:r.remoteMediaStream;const n=r;let t=!1;const s=n=>{e.play().then(()=>{t=!0},e=>{const r=null==e?void 0:e.name;n&&!t&&"AbortError"!==r&&(null==a||a({code:"audio_playback_blocked",message:"Could not play call audio — tap the call to enable sound."}))})};s("active"===n.state);const o=()=>s(!0);return n.on("answered",o),()=>{n.off("answered",o)}},[r,l,a]),e.createElement("audio",{ref:c,autoPlay:!0})},ge=({dialstack:e,onChange:n})=>{const r=function(e){const[n,r]=a(()=>e.getAppearance());return t(()=>{if("undefined"==typeof document)return;const n=document.createElement("div"),t=e=>{const n=e.detail;r(null==n?void 0:n.appearance)};return n.addEventListener("dialstack-appearance-update",t),e.addAppearanceTarget(n),()=>{e.removeAppearanceTarget(n),n.removeEventListener("dialstack-appearance-update",t)}},[e]),n}(e);return t(()=>{n(r)},[r,n]),null},fe=()=>ne(),he=()=>{const{activeCall:e,actions:n}=fe();return{activeCall:e,actions:n}},ve=()=>{const{incomingCalls:e}=fe();return function(e){var n;return null!==(n=e.find(E))&&void 0!==n?n:null}(e)},be={phone:{path:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},hangup:{path:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z",transform:"rotate(135 12 12)"},mic:{path:"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2z"},micOff:{path:"M19 11h-1.7a5.6 5.6 0 0 1-.34 1.6l1.22 1.22A7 7 0 0 0 19 11zM4.27 3 3 4.27 9 10.27V11a3 3 0 0 0 4.42 2.65l1.05 1.05A4.96 4.96 0 0 1 12 16a5 5 0 0 1-5-5H5a7 7 0 0 0 6 6.92V21h2v-3.08c.5-.07.98-.2 1.43-.39L19.73 21 21 19.73 4.27 3zM15 5a3 3 0 0 0-6-.09l6 6V5z"},pause:{path:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"},keypad:{path:"M5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 10a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 17a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4z"},transfer:{path:"M16 1l4 4-4 4V6H9V4h7V1zM8 23l-4-4 4-4v3h7v2H8v3z"},location:{path:"M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z"},chevronDown:{path:"M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"},speaker:{path:"M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05A4.47 4.47 0 0 0 16.5 12zM14 2.23v2.06a7.5 7.5 0 0 1 0 15.42v2.06a9.5 9.5 0 0 0 0-19.54z"},addCall:{path:"M15 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zM6 8V5H4v3H1v2h3v3h2v-3h3V8H6z"},merge:{path:"M17 20.41 18.41 19 15 15.59 13.59 17 17 20.41zM7.5 8H11v5.59L5.59 19 7 20.41l6-6V8h3.5L12 3.5 7.5 8z"}},ye=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),xe=()=>{const{lastError:n,clearError:t,t:a}=fe();return n?e.createElement("div",{className:"ds-chip ds-chip-error ds-call-error",role:"alert"},e.createElement("span",null,a(_(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null},Ee=({autoFocusDestination:r=!1})=>{const{connection:l,placeCall:s,emergency:c,t:o,scope:i}=fe(),[d,u]=a(""),{onType:p,onPasteText:m}=W(u),g=n(null);t(()=>{var e;r&&(null===(e=g.current)||void 0===e||e.focus())},[r]);const f=function(e,n,t){return"connected"===e&&n.length>0&&!t}(l,d,c.submitting);return e.createElement("div",{className:`${i} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(we,null),e.createElement(xe,null),e.createElement("div",{className:"ds-display"},d.length>0&&e.createElement("span",{className:"ds-display-spacer","aria-hidden":"true"}),e.createElement("input",{ref:g,className:"ds-destination",type:"tel",inputMode:"tel",value:d,placeholder:o("destinationPlaceholder"),"aria-label":o("destinationPlaceholder"),autoComplete:"off",onChange:e=>p(e.target.value),onPaste:e=>{e.preventDefault(),m(e.clipboardData.getData("text"))},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f&&s(d))}}),d.length>0&&e.createElement("button",{type:"button",className:"ds-backspace","aria-label":o("backspace"),onClick:()=>u(e=>e.slice(0,-1))},"⌫")),e.createElement("div",{className:"ds-keypad",role:"group","aria-label":o("title")},Y.map(({digit:n,letters:t})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":`${n}${t?" "+t:""}`,onClick:()=>u(e=>e+n)},e.createElement("span",{className:"ds-key-digit"},n),e.createElement("span",{className:"ds-key-letters"},t||" ")))),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-call","aria-label":o("call"),disabled:!f,onClick:()=>{s(d)}},e.createElement(ye,{glyph:be.phone})))))},we=()=>{const{connection:n,t:t}=fe();switch(n){case"connecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("connecting"));case"reconnecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("reconnecting"));case"disconnected":return e.createElement("div",{className:"ds-chip ds-chip-off",role:"status"},t("disconnected"));case"error":return e.createElement("div",{className:"ds-chip ds-chip-error",role:"status"},t("connectionError"));default:return e.createElement("div",{className:"ds-chip ds-chip-spacer","aria-hidden":"true"})}},Ce={alabama:"AL",alaska:"AK",arizona:"AZ",arkansas:"AR",california:"CA",colorado:"CO",connecticut:"CT",delaware:"DE","district of columbia":"DC",florida:"FL",georgia:"GA",hawaii:"HI",idaho:"ID",illinois:"IL",indiana:"IN",iowa:"IA",kansas:"KS",kentucky:"KY",louisiana:"LA",maine:"ME",maryland:"MD",massachusetts:"MA",michigan:"MI",minnesota:"MN",mississippi:"MS",missouri:"MO",montana:"MT",nebraska:"NE",nevada:"NV","new hampshire":"NH","new jersey":"NJ","new mexico":"NM","new york":"NY","north carolina":"NC","north dakota":"ND",ohio:"OH",oklahoma:"OK",oregon:"OR",pennsylvania:"PA","rhode island":"RI","south carolina":"SC","south dakota":"SD",tennessee:"TN",texas:"TX",utah:"UT",vermont:"VT",virginia:"VA",washington:"WA","west virginia":"WV",wisconsin:"WI",wyoming:"WY","puerto rico":"PR",guam:"GU","u.s. virgin islands":"VI","american samoa":"AS","northern mariana islands":"MP",alberta:"AB","british columbia":"BC",manitoba:"MB","new brunswick":"NB","newfoundland and labrador":"NL","nova scotia":"NS","northwest territories":"NT",nunavut:"NU",ontario:"ON","prince edward island":"PE",quebec:"QC",saskatchewan:"SK",yukon:"YT"};function ke(e){const n=e.trim(),t=Ce[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const $e={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},Ne=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:r,t:l,scope:s}=fe(),[c,o]=a(!1),[i,d]=a(!1),[u,p]=a($e);if(t||n.loading||n.bound||r)return null;const m=e=>n=>p(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${s} ds-softphone ds-e911-root`},e.createElement("div",{className:"ds-e911 "+(c?"ds-e911-open":"")},e.createElement("button",{type:"button",className:"ds-e911-toggle","aria-expanded":c,onClick:()=>o(e=>!e)},e.createElement("span",null,e.createElement(ye,{glyph:be.location})),e.createElement("span",{className:"ds-e911-label"},l("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(ye,{glyph:be.chevronDown}))),c&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},l("emergencyHint")),!i&&n.savedAddresses.map(t=>e.createElement("button",{key:t.id,type:"button",className:"ds-e911-choice",disabled:n.submitting,onClick:()=>{return e=t.id,void n.confirm(e).then(()=>o(!1)).catch(()=>{});var e}},e.createElement(ye,{glyph:be.location}),e.createElement("span",{className:"ds-e911-choice-addr"},[t.address.address_number,t.address.street,t.address.city,t.address.state,t.address.postal_code].filter(Boolean).join(" ")),e.createElement("span",{className:"ds-e911-choice-cta"},l("emergencyConfirm")))),!i&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!0)},l("emergencyNewLocation")),i&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),n.create(Object.assign(Object.assign({},u),{state:ke(u.state),unit:u.unit||void 0})).then(()=>{o(!1),d(!1)}).catch(()=>{})}},e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${s}-ea-num`},l("emergencyNumber")),e.createElement("input",{id:`${s}-ea-num`,className:"ds-e911-input",value:u.address_number,onChange:m("address_number")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-street`},l("emergencyStreet")),e.createElement("input",{id:`${s}-ea-street`,className:"ds-e911-input",value:u.street,onChange:m("street"),required:!0}))),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-unit`},l("emergencyUnit")),e.createElement("input",{id:`${s}-ea-unit`,className:"ds-e911-input",value:u.unit,onChange:m("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-city`},l("emergencyCity")),e.createElement("input",{id:`${s}-ea-city`,className:"ds-e911-input",value:u.city,onChange:m("city"),required:!0})),e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-state`},l("emergencyState")),e.createElement("input",{id:`${s}-ea-state`,className:"ds-e911-input",value:u.state,onChange:m("state"),required:!0})),e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${s}-ea-zip`},l("emergencyPostalCode")),e.createElement("input",{id:`${s}-ea-zip`,className:"ds-e911-input",value:u.postal_code,onChange:m("postal_code"),required:!0}))),n.error&&e.createElement("p",{className:"ds-e911-error"},n.error),e.createElement("div",{className:"ds-e911-actions"},n.savedAddresses.length>0&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!1)},l("emergencyBack")),e.createElement("button",{type:"submit",className:"ds-e911-btn",disabled:n.submitting},n.submitting?l("emergencySaving"):l("emergencySave")))))))},Ae=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:l,displayNumber:s}=fe(),c=$(n),o=N(n)||s(c)||l("unknownCaller");return e.createElement("div",{className:"ds-incoming-card "+(t?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-incoming-card-info"},e.createElement("div",{className:"ds-incoming-label"},l("incomingCall")),e.createElement("div",{className:"ds-peer-name"},o),N(n)&&e.createElement("div",{className:"ds-peer-number"},s(c))),e.createElement("div",{className:"ds-actions ds-actions-incoming"},e.createElement("button",{type:"button",className:"ds-action ds-decline","aria-label":l("decline"),onClick:()=>r.callActionsFor(n).reject()},e.createElement(ye,{glyph:be.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":l("answer"),onClick:()=>a(n)},e.createElement(ye,{glyph:be.phone}))))},Se=()=>{const{incomingCalls:n,scope:t}=fe(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(Ae,{call:a}))):null},Ie=({compact:n})=>{const{incomingCalls:t,scope:a}=fe();if(0===t.length)return null;const r=null!=n?n:t.length>1;return e.createElement("div",{className:`${a} ds-softphone`},e.createElement("div",{className:"ds-incoming-stack"},t.map(n=>e.createElement(Ae,{key:n.id,call:n,compact:r}))))},Te=({label:n,glyph:t,on:a=!1,disabled:r=!1,onClick:l})=>e.createElement("button",{type:"button",className:"ds-control "+(a?"ds-control-on":""),"aria-pressed":a,"aria-label":n,disabled:r,onClick:l},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ye,{glyph:t})),e.createElement("span",{className:"ds-control-label"},n)),ze=()=>{const{t:n}=fe(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,selectInputDevice:s,selectOutputDevice:c,outputSelectionSupported:o,enumerationSupported:i,labelsHidden:d,inputLost:u}=ce();return e.createElement("div",{className:"ds-devices",role:"group"},u&&e.createElement("div",{className:"ds-device-alert",role:"alert"},n("audioMicrophoneLost")),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioMicrophone")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioMicrophone"),value:null!=r?r:"",onChange:e=>s(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),t.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioSpeaker")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioSpeaker"),value:null!=l?l:"",disabled:!o,onChange:e=>c(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),a.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),!i&&e.createElement("p",{className:"ds-device-hint"},n("audioDevicesUnsupported")),!o&&e.createElement("p",{className:"ds-device-hint"},n("audioSpeakerUnsupported")),d&&e.createElement("p",{className:"ds-device-hint"},n("audioLabelsHidden")))},Oe=()=>{var n;const{activeCall:r,actions:l,overlays:s,duration:c,consultCall:o,transferOriginal:i,heldCalls:d,incomingCalls:u,switchToCall:p,startAttendedTransfer:m,completeAttendedTransfer:g,cancelAttendedTransfer:f,placeCall:h,calls:v,mergedCalls:b,isMerged:y,canMerge:x,mergeCalls:E,splitMerge:w,hangupConference:k,holdConference:A,t:S,displayNumber:I,scope:T}=fe(),{showKeypad:z,showTransfer:O,showDevices:D,showAddCall:M}=s,[P,_]=a(""),[B,H]=a(""),[R,L]=a(""),{onType:U,onPasteText:V}=W(H),{onType:F,onPasteText:K}=W(L),q=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{_(""),H(""),L("")},[q]),!r)return null;const G=$(r),J=N(r),Q=C(r),X=J||I(G)||S("unknownCaller"),Z=r.canSendDtmf,ee=null!==o&&null!==i,ne=ee&&(r===o||r===i),te=ne?r===o?i:o:null,ae=ne&&null!==o&&o.isConnected,re=d.filter(e=>e!==te&&!b.includes(e)),le=d.length+u.length,se=!ee&&!y&&0===le,ce=y&&b.some(e=>"held"===e.state),oe=v.length<4,ie=oe?R:"";return e.createElement("div",{className:`${T} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall"},ne&&te&&e.createElement("div",{className:"ds-transfer-banner"},(()=>{const n=$(te),t=N(te)||I(n)||S("unknownCaller");return e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${S("switchToCall")}: ${t}`,onClick:()=>p(te)},e.createElement("div",{className:"ds-peer-name"},t),e.createElement("div",{className:"ds-callstate-text"},S("transferOriginalOnHold")))})(),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:f},S("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!ae,onClick:g},S("transferComplete")))),re.length>0&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":S("heldCallsLabel")},re.map(n=>{const t=$(n),a=N(n)||I(t)||S("unknownCaller");return e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${S("switchToCall")}: ${a}`,onClick:()=>p(n)},e.createElement("div",{className:"ds-peer-name"},a),e.createElement("div",{className:"ds-callstate-text"},S("heldCallsLabel")))})),y?e.createElement("div",{className:"ds-peer ds-peer-conference"},e.createElement("div",{className:"ds-callstate-text"},S("conferenceLabel")),e.createElement("div",{className:"ds-conference-parties"},b.map(n=>e.createElement("div",{key:n.id,className:"ds-peer-name"},N(n)||I($(n))||S("unknownCaller")))),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-duration"},c))):e.createElement("div",{className:"ds-peer"},e.createElement("div",{className:"ds-peer-name"},X),J&&e.createElement("div",{className:"ds-peer-number"},I(G)),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-callstate-text"},S(j(r.state))),"active"===r.state&&e.createElement("span",{className:"ds-duration"},c))),e.createElement(xe,null),Q&&z&&Z&&e.createElement("div",{className:"ds-dtmf"},e.createElement("div",{className:"ds-dtmf-readout"},P||" "),e.createElement("div",{className:"ds-keypad ds-keypad-dtmf",role:"group","aria-label":S("keypad")},Y.map(({digit:n})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":n,onClick:()=>(e=>{l.sendDtmf(e),_(n=>n+e)})(n)},e.createElement("span",{className:"ds-key-digit"},n))))),Q&&O&&se&&e.createElement("div",{className:"ds-transfer"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:B,placeholder:S("transferPlaceholder"),"aria-label":S("transferPlaceholder"),autoComplete:"off",onChange:e=>U(e.target.value),onPaste:e=>{e.preventDefault(),V(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!B.trim(),onClick:()=>{l.transfer(B)&&(H(""),s.closeTransfer())}},S("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!B.trim(),onClick:()=>{m(B)}},S("transferConsult")))),Q&&M&&oe&&e.createElement("div",{className:"ds-transfer ds-addcall"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:ie,placeholder:S("addCallPlaceholder"),"aria-label":S("addCallPlaceholder"),autoComplete:"off",onChange:e=>F(e.target.value),onPaste:e=>{e.preventDefault(),K(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!ie.trim(),onClick:()=>{const e=ie.trim();e&&(h(e),L(""),s.closeAddCall())}},S("addCallSend")))),Q&&D&&e.createElement(ze,null),Q&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement(Te,{label:r.isMuted?S("unmute"):S("mute"),glyph:r.isMuted?be.micOff:be.mic,on:r.isMuted,onClick:l.toggleMute}),e.createElement(Te,{label:ce||"held"===r.state?S("resume"):S("hold"),glyph:be.pause,on:ce||"held"===r.state,onClick:y?()=>A(!ce):l.toggleHold}),Z&&e.createElement(Te,{label:S("keypad"),glyph:be.keypad,on:z,onClick:s.toggleKeypad}),e.createElement(Te,{label:S("addCall"),glyph:be.addCall,on:M,disabled:!oe||y,onClick:s.toggleAddCall}),x||y?e.createElement(Te,{label:S(y?"split":"merge"),glyph:be.merge,on:y,onClick:y?w:E}):e.createElement(Te,{label:S("transfer"),glyph:be.transfer,on:O,disabled:!se,onClick:s.toggleTransfer}),e.createElement(Te,{label:S("audioDevices"),glyph:be.speaker,on:D,onClick:s.toggleDevices})),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":S("hangUp"),onClick:y?k:l.hangup},e.createElement(ye,{glyph:be.hangup})))))},De=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=fe(),l=function(e,n=null){const t=e.filter(e=>e!==n&&E(e)),a=e.some(e=>e===n||!E(e));return{base:a?"in-call":"dial",incoming:t,overlay:a&&t.length>0,compact:a?t.length>0:t.length>1}}(t,a);if("dial"===l.base&&l.incoming.length>0)return 1===l.incoming.length?e.createElement(Se,null):e.createElement(Ie,{compact:l.compact});const s="in-call"===l.base?e.createElement(Oe,null):e.createElement(Me,{autoFocusDestination:n});return 0===l.incoming.length?s:e.createElement("div",{className:`${r} ds-softphone-layout`},e.createElement("div",{className:"ds-incoming-overlay"},e.createElement(Ie,{compact:l.compact})),s)},Me=({autoFocusDestination:n})=>{const{scope:t}=fe();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement(Ne,null),e.createElement(Ee,{autoFocusDestination:n}))},je=({autoFocusDestination:n})=>{if(null===o(de))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdk/react.");return e.createElement(De,{autoFocusDestination:n})};export{T as DIAL_COUNTRY,Ee as DialPad,Ne as EmergencyBanner,Se as IncomingCall,Ie as IncomingStack,Oe as OngoingCall,je as Softphone,ue as SoftphoneProvider,N as callPeerName,$ as callPeerNumber,j as callStateLabelKey,_ as errorMessageKey,A as formatCallDuration,S as formatDisplayNumber,C as isCallActive,E as isIncomingRinging,O as sanitizeDestination,k as selectScreen,w as shouldRingIncoming,z as stripToDialString,he as useActiveCall,R as useCallActions,L as useCallDuration,W as useDialInput,ve as useIncomingCall,F as useLastError,fe as useSoftphone};
|
|
2
2
|
//# sourceMappingURL=softphone.mjs.map
|