1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5866],{3485:(e,t,n)=>{n.d(t,{G:()=>s,I:()=>d});var a=n(54568),r=n(7620),c=n(90008),l=n(74731);let u=(0,r.createContext)(null),s=()=>(0,r.useContext)(u),i={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun2.l.google.com:19302"]},{urls:"stun:stun.cloudflare.com:3478"}]},o=(e,t)=>c.supabase.schema("consumer").from("calls").update(t).eq("id",e).then(e=>{let{error:t}=e;t&&console.error("Call status update failed:",t)}),d=e=>{let{user:t,children:n}=e,[s,d]=(0,r.useState)("idle"),g=(0,r.useRef)("idle"),f=e=>{g.current=e,d(e)},[p,b]=(0,r.useState)(null),[m,v]=(0,r.useState)(!1),[h,w]=(0,r.useState)(0),[y,S]=(0,r.useState)(null),_=(0,r.useRef)(null),C=(0,r.useRef)(null),k=(0,r.useRef)(null),I=(0,r.useRef)(null),T=(0,r.useRef)(null),D=(0,r.useRef)(null),R=(0,r.useRef)(null),E=(0,r.useRef)(null),q=(0,r.useCallback)(()=>{var e,t;null==(e=_.current)||e.close(),_.current=null,null==(t=C.current)||t.getTracks().forEach(e=>e.stop()),C.current=null,I.current&&(c.supabase.removeChannel(I.current),I.current=null),R.current&&(clearInterval(R.current),R.current=null),E.current&&(clearTimeout(E.current),E.current=null),T.current=null,D.current=null,f("idle"),b(null),v(!1),w(0),S(null)},[]),O=(0,r.useCallback)(function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"ended",n=T.current;null==(e=I.current)||e.send({type:"broadcast",event:"hangup",payload:{}}),n&&o(n,{status:t,ended_at:new Date().toISOString()}),q()},[q]),P=(0,r.useCallback)(()=>{var e;let t=new RTCPeerConnection(i);return _.current=t,t.onicecandidate=e=>{if(e.candidate){var t;null==(t=I.current)||t.send({type:"broadcast",event:"ice-candidate",payload:{candidate:e.candidate}})}},t.ontrack=e=>{k.current&&(k.current.srcObject=e.streams[0],k.current.play().catch(()=>{}))},t.onconnectionstatechange=()=>{"connected"===t.connectionState?(E.current&&(clearTimeout(E.current),E.current=null),f("connected"),R.current||(R.current=setInterval(()=>w(e=>e+1),1e3))):"failed"===t.connectionState?(alert("The call couldn't connect on this network."),O("ended")):("disconnected"===t.connectionState||"closed"===t.connectionState)&&O("ended")},null==(e=C.current)||e.getTracks().forEach(e=>t.addTrack(e,C.current)),t},[O]),j=(0,r.useCallback)((e,t)=>{let n=c.supabase.channel("call:".concat(e));return I.current=n,n.on("broadcast",{event:"accept"},async()=>{if("caller"!==t||!_.current)return;let e=await _.current.createOffer();await _.current.setLocalDescription(e),n.send({type:"broadcast",event:"offer",payload:{sdp:e}})}).on("broadcast",{event:"offer"},async e=>{let{payload:a}=e;if("callee"!==t||!_.current)return;await _.current.setRemoteDescription(new RTCSessionDescription(a.sdp));let r=await _.current.createAnswer();await _.current.setLocalDescription(r),n.send({type:"broadcast",event:"answer",payload:{sdp:r}})}).on("broadcast",{event:"answer"},async e=>{let{payload:n}=e;"caller"===t&&_.current&&await _.current.setRemoteDescription(new RTCSessionDescription(n.sdp))}).on("broadcast",{event:"ice-candidate"},async e=>{let{payload:t}=e;if(_.current)try{await _.current.addIceCandidate(new RTCIceCandidate(t.candidate))}catch(e){}}).on("broadcast",{event:"hangup"},()=>q()).subscribe(),n},[q]),x=(0,r.useCallback)(async(e,n)=>{if(!(null==t?void 0:t.id)||"idle"!==g.current)return;try{C.current=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){alert("Microphone access is required to make a call.");return}let{data:a,error:r}=await c.supabase.schema("consumer").from("calls").insert({caller_id:t.id,callee_id:e}).select("id").single();if(r||!a){var u;null==(u=C.current)||u.getTracks().forEach(e=>e.stop()),C.current=null,alert((null==r?void 0:r.code)==="42501"?"".concat(n," can't receive calls from you."):"The call couldn't be started.");return}let s=a.id;T.current=s,D.current=e,b(n),f("outgoing"),P(),j(s,"caller"),(0,l.s)({category:"calls",recipientId:e,title:"Incoming call",body:"",url:"/",tag:"call-".concat(s)}),E.current=setTimeout(()=>{T.current===s&&"outgoing"===g.current&&(alert("".concat(n," didn't answer.")),O("missed"))},3e4)},[t,P,j,O]),A=(0,r.useCallback)(async()=>
1{if(!y)return;let{callId:e,callerId:t,callerName:n}=y;try{C.current=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(t){alert("Microphone access is required to answer the call."),o(e,{status:"declined",ended_at:new Date().toISOString()}),S(null),f("idle");return}T.current=e,D.current=t,b(n),S(null),o(e,{status:"accepted",answered_at:new Date().toISOString()}),P();let a=j(e,"callee");await new Promise(e=>{let t=setInterval(()=>{"joined"===a.state&&(clearInterval(t),e())},50);setTimeout(()=>{clearInterval(t),e()},3e3)}),a.send({type:"broadcast",event:"accept",payload:{}}),f("outgoing")},[y,P,j]),M=(0,r.useCallback)(()=>{y&&(o(y.callId,{status:"declined",ended_at:new Date().toISOString()}),S(null),b(null),f("idle"))},[y]),U=(0,r.useCallback)(()=>{O("connected"===g.current?"ended":"cancelled")},[O]),N=(0,r.useCallback)(()=>{if(!C.current)return;let e=!m;C.current.getAudioTracks().forEach(t=>t.enabled=!e),v(e)},[m]),L=(0,r.useRef)(null);return(0,r.useEffect)(()=>{L.current=p},[p]),(0,r.useEffect)(()=>{if(!(null==t?void 0:t.id))return;let e=async e=>{if("idle"!==g.current)return void o(e.id,{status:"busy",ended_at:new Date().toISOString()});let{data:t}=await c.supabase.from("profiles").select("name").eq("id",e.caller_id).maybeSingle(),n=(null==t?void 0:t.name)||"SETX 360 member";S({callId:e.id,callerId:e.caller_id,callerName:n}),b(n),f("incoming")},n=c.supabase.channel("calls-".concat(t.id)).on("postgres_changes",{event:"INSERT",schema:"consumer",table:"calls",filter:"callee_id=eq.".concat(t.id)},t=>{let{new:n}=t;"ringing"===n.status&&e(n)}).on("postgres_changes",{event:"UPDATE",schema:"consumer",table:"calls",filter:"callee_id=eq.".concat(t.id)},e=>{let{new:t}=e;"ringing"!==t.status&&"accepted"!==t.status&&S(e=>(null==e?void 0:e.callId)===t.id?(f("idle"),b(null),null):e)}).on("postgres_changes",{event:"UPDATE",schema:"consumer",table:"calls",filter:"caller_id=eq.".concat(t.id)},e=>{let{new:t}=e;if(t.id===T.current&&"outgoing"===g.current&&("declined"===t.status||"busy"===t.status)){let e=L.current||"They";q(),alert("busy"===t.status?"".concat(e," is on another call."):"".concat(e," declined the call."))}}).subscribe();return c.supabase.schema("consumer").from("calls").select("id, caller_id, status, created_at").eq("callee_id",t.id).eq("status","ringing").gte("created_at",new Date(Date.now()-3e4).toISOString()).order("created_at",{ascending:!1}).limit(1).then(t=>{let{data:n}=t;(null==n?void 0:n[0])&&e(n[0])}),()=>{c.supabase.removeChannel(n)}},[null==t?void 0:t.id]),(0,a.jsxs)(u.Provider,{value:{callState:s,remoteName:p,isMuted:m,callDurationSec:h,startCall:x,acceptCall:A,declineCall:M,hangUp:U,toggleMute:N},children:[n,(0,a.jsx)("audio",{ref:k,autoPlay:!0,style:{display:"none"}})]})}}}]);
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.