1import{r as a,j as e}from"./jsx-runtime-DHesG5eV.js";import{u as ee,r as te,c as u,s as z,t as se,P as ae,C as le,a as ne}from"./callHelpers-9dRvVn3s.js";import{P as re,M as ce,a as ie,L as oe}from"./leaveCallUi-DXPtDH8_.js";import{q as de,L as m}from"./index-CFbNN_S_.js";import{c as j}from"./index-mMvBXwGX.js";import{u as ue,a as fe,p as me}from"./index-Cv9WPQe9.js";import{u as he}from"./index-BvOfzxDr.js";import{u as xe,a as pe}from"./components-DUaCEilp.js";import{U as ve}from"./user-Jq_vEbyw.js";import{P as M}from"./phone-DWHfR47p.js";import{X as je}from"./x-BXJvlIaq.js";function Re(T){const{callerRole:h}=T,U=ue(),g=fe(),[$]=he(),t=U.state,[x,S]=a.useState(!0),[B,b]=a.useState("Calling..."),[C,k]=a.useState(!1),[n,I]=a.useState(!1),[y,L]=a.useState(1),[R,w]=a.useState(!1),[c,o]=a.useState(!0),[N,O]=a.useState(!1),[D,_]=a.useState(t==null?void 0:t.token),[q,F]=a.useState(t==null?void 0:t.url),[A,d]=a.useState(!1),{data:E}=xe(),G=E==null?void 0:E.carrierUserId,i=pe(),p=a.useRef(c);a.useEffect(()=>{p.current=c},[c]);const K=h==="carrier",V=ee(n);a.useEffect(()=>{te().then(s=>{s||(O(!0),o(!1),d(!0))})},[]),a.useEffect(()=>{const s=l=>{l.preventDefault(),l.returnValue=""};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[]);const r=me(({currentLocation:s,nextLocation:l})=>s.pathname!==l.pathname&&c);a.useEffect(()=>{r.state==="blocked"&&c&&w(!0)},[r.state]),a.useEffect(()=>{const s=setTimeout(async()=>{n||!p.current||(y<=3&&(b("No Answer"),k(!0),i.submit({type:"update_missed_call",calleeId:t==null?void 0:t.calleeId,indentId:t==null?void 0:t.indentId,callerRole:h},{method:"post",encType:"application/json"})),y>3&&(o(!1),d(!0),u.noAnswer()))},4e4);return()=>clearTimeout(s)},[n,y]),a.useEffect(()=>{var l,P;if(!i.data)return;const s=(l=i.data)==null?void 0:l.data;s!=null&&s.token?(_(s.token),s.url&&F(s.url)):(P=i.data)!=null&&P.description&&u.callFailed(i.data.description)},[i.data]),a.useEffect(()=>{!c&&A&&X()},[c,A]);const X=()=>{const s=(t==null?void 0:t.indentId)??$.get("indent");if(!s){g(h==="employee"?j.employee.indent:j.carrier.indent,{replace:!0});return}h==="employee"?g(`${j.employee.indent}/${s}`,{replace:!0}):g(`${j.carrier.indent}/${s}`,{replace:!0})},f=a.useCallback(()=>{o(!1),d(!0),u.callEndedBySelf()},[]),H=a.useCallback(()=>{o(!1),d(!0),u.callEndedByOther()},[]),v=a.useCallback(()=>{o(!1),d(!0),u.callDeclined()},[]),J=a.useCallback(s=>{if(p.current){if(!n){v();return}u.connectionError(s.message)}},[n,v]),Q=a.useCallback(()=>{S(!0),z()},[]),W=a.useCallback(()=>{if(z(),!!p.current){if(!n){v();return}f()}},[n,v,f]),Y=a.useCallback(()=>{I(!0),b("Connected"),L(0)},[]),Z=()=>{L(l=>l+1),I(!1),b("Calling..."),k(!1);const s=K?`${G} - ${t==null?void 0:t.calleeId}`:t==null?void 0:t.calleeId;i.submit({type:"generate_token",roomName:s,calleeName:t==null?void 0:t.calleeName,userType:t==null?void 0:t.callerRole,calleeId:t==null?void 0:t.calleeId,indentId:t==null?void 0:t.indentId},{method:"post",encType:"application/json"})};return!D||N?e.jsx("div",{className:"w-full h-screen flex items-center justify-center bg-neutral-900",children:e.jsxs(de,{className:"p-6 max-w-sm text-center",children:[e.jsx("h2",{className:"text-xl font-semibold mb-2",children:N?"Microphone Required":"Invalid Call Data"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:N?"Microphone access is needed to place a call.":"Unable to initiate the call."}),e.jsx(m,{onClick:()=>{o(!1),d(!0)},children:"Go Back"})]})}):e.jsxs("div",{className:"fixed inset-0 bg-neutral-900 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"w-full h-full bg-gray-900 flex items-center justify-center overflow-hidden",children:e.jsxs(se,{video:!1,audio:!0,token:D,serverUrl:q,onError:J,onConnected:Q,onDisconnected:W,connectOptions:{autoSubscribe:!0},children:[e.jsx(ae,{onParticipantConnected:Y}),e.jsx(re,{}),e.jsx(le,{audioEnabled:x}),e.jsx(ne,{onCallEnded:H}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"pt-20 text-5xl font-medium text-white",children:t.calleeName}),e.jsx("p",{className:"text-base mt-1 text-white",children:n?V:B})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"relative mb-10 w-40 h-40",children:[!C&&e.jsx("div",{className:"absolute inset-0 rounded-full bg-green-500/20 animate-ping"}),e.jsx("div",{className:"relative w-40 h-40 rounded-full bg-gradient-to-br from-gray-700 to-gray-800 flex items-center justify-center shadow-2xl border border-gray-600",children:e.jsx(ve,{size:80,className:"text-white"})})]})})]})]})}),!C&&e.jsx("div",{className:"bg-neutral-800 border-t border-neutral-700 px-10 py-6",children:e.jsxs("div",{className:"w-full flex items-center justify-center gap-10",children:[e.jsx(m,{variant:x?"default":"destructive",size:"lg",className:"rounded-full w-14 h-14 p-0",onClick:()=>S(!x),children:x?e.jsx(ce,{size:20}):e.jsx(ie,{size:20})}),e.jsx(m,{variant:"destructive",size:"lg",className:"rounded-full w-14 h-14 p-0",onClick:f,children:e.jsx(M,{size:20})})]})}),C&&e.jsx("div",{className:"bg-neutral-800 border-t border-neutral-700 px-10 py-6",children:e.jsxs("div",{className:"w-full flex items-center justify-center gap-10",children:[e.jsx(m,{size:"lg",className:"rounded-full w-14 h-14 p-0 bg-white",onClick:f,children:e.jsx(je,{size:25,color:"grey"})}),e.jsx(m,{size:"lg",className:"rounded-full w-14 h-14 p-0 bg-green-500 hover:bg-green-600",onClick:Z,children:e.jsx(M,{size:20})})]})}),R&&e.jsx(oe,{open:R,onOpenChange:s=>{var l;s||(l=r.reset)==null||l.call(r),w(s)},onLeave:f,onStay:()=>{var s;w(!1),(s=r.reset)==null||s.call(r)}})]})}export{Re as L}; 2//# sourceMappingURL=livekit-caller-BP__V9y_.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.