PageSourceSearch

https://snestico.ai/assets/js/VideoCallModal-DdgQRRxf.js

js snestico.ai collected 2026-10-05 15:08:31 UTC 12,879 bytes, 1 lines download raw bytes

1import{r as n,j as e,a as K}from"./vendor-BOadm9Gy.js";import{H as q,O as J,K as Q,d as ee,C as R,W as te,a as D,T as se}from"./vendor-livekit-DglilFg9.js";import{u as P}from"./vendor-toast-D6B0hGGw.js";import{u as ne,A as ae,aZ as le,c as re}from"./index-DcN63-UG.js";import{u as ce,c as _,R as ie}from"./calls-D_YBXu01.js";import{u as oe}from"./useIsPhone-_GM7JVgE.js";import{V as Be,i as Ie}from"./videoCallInvite-CJW20aQp.js";import{b2 as ue,b1 as de,V as me,cV as fe,cW as he,cm as z,cX as xe,cb as pe,cY as ge,cZ as be,cL as we,X as je,ag as ve,ak as ye,as as ke}from"./vendor-icons-kUGsRs8M.js";import"./vendor-ui-CeWyqG0w.js";import"./vendor-classnames-CSqCgoPn.js";import"./vendor-motion-DwikGbVM.js";function ze({conversationId:v,otherName:h,onClose:b,call:a}){const{user:x,getToken:d}=ne(),r=ce(),[c,o]=n.useState({status:"connecting"}),[S,$]=n.useState(0),[i,y]=n.useState(a?.status??null),k=n.useRef(!1),m=n.useCallback(()=>{k.current||(k.current=!0,a&&!_(i||a.status)&&r.act(a.id,"end").catch(()=>{}),b())},[a,i,r,b]);n.useEffect(()=>{if(!a)return;let t=!1;const l=new Date(a.createdAt).getTime(),f=async()=>{try{const u=await r.get(a.id);if(t)return;if(u.status==="ringing"&&a.role==="caller"&&Date.now()-l>ie){const G=await r.act(a.id,"missed").catch(()=>null);t||y(G?.status||"missed");return}y(u.status)}catch{}};f();const g=window.setInterval(f,2500);return()=>{t=!0,window.clearInterval(g)}},[a,r]),n.useEffect(()=>{if(!a||!i||!_(i))return;k.current=!0;const t=window.setTimeout(b,3500);return()=>window.clearTimeout(t)},[a,i,b]),n.useEffect(()=>{let t=!1;return o({status:"connecting"}),(async()=>{try{const l={"Content-Type":"application/json"};x?.id&&(l["x-clerk-user-id"]=String(x.id));const f=await d();f&&(l.Authorization=`Bearer ${f}`);const g=await fetch(`${ae}/messaging/livekit/token`,{method:"POST",headers:l,body:JSON.stringify({conversationId:v,purpose:"call"})}),u=await g.json().catch(()=>null);if(t)return;if(!g.ok||!u?.data?.token||!u?.data?.url){o({status:"error",message:u?.message||`Couldn't start the call (${g.status}).`});return}if(!String(u.data.room||"").startsWith("call_")){o({status:"error",message:"Video calling needs the latest backend deploy."});return}o({status:"ready",token:u.data.token,serverUrl:u.data.url})}catch{t||o({status:"error",message:"Couldn't reach the server to start the call."})}})(),()=>{t=!0}},[v,x?.id,d,S]);const[p,N]=n.useState(!1),C=n.useRef(!1);n.useEffect(()=>{if(c.status!=="ready"||p)return;const t=window.setTimeout(()=>o({status:"error",message:"The call couldn't connect on this network. Try again, or use the backup call."}),25e3);return()=>window.clearTimeout(t)},[c.status,p]);const[s,L]=n.useState(!1),[w,V]=n.useState(null),j=n.useRef(null),E=n.useRef(null),[A,O]=n.useState(!1),U=typeof document<"u"&&!!document.fullscreenEnabled;n.useEffect(()=>{if(s)return;const t=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=t}},[s]),n.useEffect(()=>{const t=()=>O(!!document.fullscreenElement&&document.fullscreenElement===j.current);return document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t),document.fullscreenElement===j.current&&document.exitFullscreen().catch(()=>{})}},[]);const H=n.useCallback(()=>{document.fullscreenElement?document.exitFullscreen().catch(()=>{}):j.current?.requestFullscreen().catch(()=>{})},[]),W=n.useCallback(()=>{document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),L(!0)},[]),F=n.useCallback((t,l)=>{const f=j.current,g=f?.offsetWidth||0,u=f?.offsetHeight||0;return{x:Math.min(Math.max(8,t),window.innerWidth-g-8),y:Math.min(Math.max(8,l),window.innerHeight-u-8)}},[]);n.useEffect(()=>{if(!s||!w)return;const t=()=>V(l=>l&&F(l.x,l.y));return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[s,w,F]);const X=t=>{if(!s||t.target.closest("button"))return;const l=j.current?.getBoundingClientRect();l&&(E.current={dx:t.clientX-l.left,dy:t.clientY-l.top},t.currentTarget.setPointerCapture(t.pointerId))},Y=t=>{E.current&&V(F(t.clientX-E.current.dx,t.clientY-E.current.dy))},B=()=>{E.current=null},I=n.useCallback(()=>{P.error("Allow camera and microphone access in your browser to be seen and heard.")},[]),T=oe(),Z=`${le}
1/Snestico-${String(v).replace(/[^a-zA-Z0-9-]/g,"")}`,M="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-white/10 hover:bg-white/20";return K.createPortal(e.jsxs("div",{"data-keep-colors":!0,className:s?"pointer-events-none fixed inset-0 z-[10001]":"fixed inset-0 z-[10001] flex items-center justify-center bg-black/85 md:p-3",role:s?"region":"dialog","aria-modal":s?void 0:!0,"aria-label":"Video call",children:[(s||T)&&e.jsx("style",{children:".sn-call-mini .lk-control-bar,.sn-call-mini .lk-chat,.sn-call-phone .lk-control-bar{display:none!important}"}),e.jsxs("div",{ref:j,style:s&&w?{left:w.x,top:w.y}:void 0,className:s?`sn-call-mini pointer-events-auto absolute flex h-64 w-48 flex-col overflow-hidden rounded-2xl bg-[#111] shadow-2xl ring-1 ring-white/15 sm:h-52 sm:w-80 ${w?"":"bottom-24 right-4 md:bottom-6 md:right-6"}`:"flex h-[100dvh] w-full flex-col overflow-hidden bg-[#111] pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] md:h-full md:rounded-2xl md:pb-0 md:pt-0 md:shadow-2xl",children:[e.jsxs("div",{onPointerDown:X,onPointerMove:Y,onPointerUp:B,onPointerCancel:B,className:`flex flex-shrink-0 items-center justify-between gap-2 bg-[#0C1A2B] text-white ${s?"cursor-grab touch-none select-none px-2 py-1.5 active:cursor-grabbing":"px-4 py-2.5"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate text-sm font-semibold",children:[s&&e.jsx(xe,{className:"h-4 w-4 flex-shrink-0 text-white/50","aria-hidden":!0}),e.jsx("span",{className:s?"hidden truncate sm:inline":"truncate",children:s?h:`Video call with ${h}`})]}),e.jsx("div",{className:"flex flex-shrink-0 items-center gap-1.5",children:s?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>L(!1),"aria-label":"Expand call",title:"Expand",className:M,children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:m,"aria-label":"Hang up",title:"Hang up",className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-red-600 hover:bg-red-700",children:e.jsx(z,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:W,"aria-label":"Minimize call",title:"Minimize",className:M,children:e.jsx(ge,{className:"h-4 w-4"})}),U&&e.jsx("button",{type:"button",onClick:H,"aria-label":A?"Exit full screen":"Full screen",title:A?"Exit full screen":"Full screen",className:`hidden md:flex ${M}`,children:A?e.jsx(be,{className:"h-4 w-4"}):e.jsx(we,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:m,"aria-label":"Close call",title:"End call",className:M,children:e.jsx(je,{className:"h-4 w-4"})})]})})]}),e.jsxs("div",{className:`relative min-h-0 flex-1 ${T&&!s?"sn-call-phone flex flex-col":""}`,children:[a&&i&&i!=="accepted"&&e.jsx("div",{className:`pointer-events-none absolute inset-x-0 z-10 flex justify-center ${s?"top-2 px-2":"top-4 px-4"}`,role:"status","aria-live":"polite",children:e.jsx("div",{className:`flex items-center rounded-full bg-black/70 font-medium text-white shadow-lg backdrop-blur ${s?"gap-1.5 px-2.5 py-1 text-[11px]":"gap-2.5 px-4 py-2 text-sm"}`,children:i==="ringing"?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-emerald-400"})]}),s?a.role==="caller"?"Ringing…":"Connecting…":a.role==="caller"?`Ringing ${h}… they'll get a notification and an email`:"Connecting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"h-4 w-4 text-red-300"}),i==="declined"?a.role==="caller"?`${h} can't take the call right now`:"Call declined":i==="missed"?a.role==="caller"?`No answer. We've let ${h} know you called.`:"Missed call":i==="cancelled"?"The call was cancelled":"The call has ended"]})})}),c.status==="connecting"&&e.jsx(re,{label:"Starting call",tone:"dark",className:"h-full"}),c.status==="error"&&e.jsxs("div",{className:`flex h-full flex-col items-center justify-center text-center text-white ${s?"gap-2 px-3":"gap-4 px-6"}`,children:[e.jsx(ve,{className:s?"h-6 w-6 text-red-400":"h-10 w-10 text-red-400"}),e.jsx("p",{className:`max-w-sm text-white/80 ${s?"line-clamp-2 text-xs":"text-sm"}`,children:c.message}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>$(t=>t+1),className:"flex items-center gap-1.5 rounded-full bg-white px-4 py-2 text-sm font-semibold text-[#0C1A2B] hover:bg-white/90",children:[e.jsx(ye,{className:"h-4 w-4"})," Try again"]}),!s&&e.jsxs("a",{href:Z,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 rounded-full bg-white/10 px-4 py-2 text-sm font-medium hover:bg-white/20",children:[e.jsx(ke,{className:"h-4 w-4"})," Use backup call (new tab)"]})]})]}),c.status==="ready"&&e.jsx(te,{serverUrl:c.serverUrl,token:c.token,connect:!0,video:!0,audio:!0,"data-lk-theme":"default",className:T&&!s?"flex h-full flex-col":"h-full",onConnected:()=>{C.current=!0,N(!0)},onDisconnected:()=>{C.current&&m()},onMediaDeviceFailure:I,onError:t=>o({status:"error",message:/signal|websocket|connect|network|timeout/i.test(t.message||"")?"The call couldn't connect on this network. Check your connection and try again, or use the backup call.":"The call disconnected. Try again to rejoin."}),children:T&&!s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"relative min-h-0 flex-1",children:e.jsx(D,{})}),e.jsx(Ne,{onHangUp:m,onMediaFailure:I})]}):e.jsx(D,{})})]})]})]}),document.body)}function Ne({onHangUp:v,onMediaFailure:h}){const b=q(),a=J(),{localParticipant:x,isMicrophoneEnabled:d,isCameraEnabled:r}=Q(),[c,o]=n.useState(null),[S,$]=n.useState("user"),i=a===R.Connected,y=async N=>{if(!c){if(!i){P.message(a===R.Reconnecting?"Reconnecting the call…":"Still connecting the call…");return}o(N);try{N==="mic"?await x.setMicrophoneEnabled(!d):await x.setCameraEnabled(!r,{facingMode:S})}catch{h()}finally{o(null)}}},k=async()=>
1{if(c||!r)return;const C=x.getTrackPublication(se.Source.Camera)?.track;if(!C)return;const s=S==="user"?"environment":"user";o("flip");try{await C.restartTrack({facingMode:s}),$(s)}catch{P.error("This phone couldn't switch cameras.")}finally{o(null)}},m="flex h-14 w-14 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50",p="mt-1.5 text-[11px] font-medium text-white/75";return e.jsxs("div",{className:"relative flex-shrink-0 bg-[#0C1A2B] px-4 pb-[max(1rem,env(safe-area-inset-bottom))] pt-3 text-white",children:[b&&e.jsx(ee,{label:"Tap to hear the call",className:"mx-auto mb-3 flex items-center gap-2 rounded-full bg-white px-4 py-2 text-sm font-semibold text-[#0C1A2B]"}),!i&&e.jsxs("p",{className:"mb-2 flex items-center justify-center gap-2 text-xs text-white/70",role:"status",children:[e.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-amber-300"}),a===R.Reconnecting?"Reconnecting…":"Connecting the call…"]}),e.jsxs("div",{className:"mx-auto flex max-w-sm items-start justify-around",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{type:"button",onClick:()=>void y("mic"),disabled:c==="mic","aria-pressed":d,"aria-label":d?"Mute microphone":"Turn microphone on",className:`${m} ${d?"bg-white/15":"bg-white text-[#0C1A2B]"}`,children:d?e.jsx(ue,{className:"h-6 w-6"}):e.jsx(de,{className:"h-6 w-6"})}),e.jsx("span",{className:p,children:d?"Mute":"Unmute"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{type:"button",onClick:()=>void y("cam"),disabled:c==="cam","aria-pressed":r,"aria-label":r?"Turn camera off":"Turn camera on",className:`${m} ${r?"bg-white/15":"bg-white text-[#0C1A2B]"}`,children:r?e.jsx(me,{className:"h-6 w-6"}):e.jsx(fe,{className:"h-6 w-6"})}),e.jsx("span",{className:p,children:r?"Camera":"Camera off"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{type:"button",onClick:()=>void k(),disabled:!r||c==="flip","aria-label":"Switch camera",className:`${m} bg-white/15`,children:e.jsx(he,{className:"h-6 w-6"})}),e.jsx("span",{className:p,children:"Flip"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{type:"button",onClick:v,"aria-label":"Hang up",className:`${m} bg-red-600 hover:bg-red-700`,children:e.jsx(z,{className:"h-6 w-6"})}),e.jsx("span",{className:p,children:"End"})]})]})]})}export{Ne as PhoneCallControls,Be as VIDEO_CALL_INVITE_PREFIX,ze as VideoCallModal,Ie as isVideoCallInvite};

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.