1import{r as n,j as e,U as J,O as Q,a7 as X}from"./index-DYMIpwuw.js";import{A as Z}from"./arrow-left-hGJ4GYgW.js";import{W as ee}from"./wifi-ehCNRDYT.js";import{V as te,S as se}from"./video-BYANPfoF.js";import{S as R}from"./server-cog-BJDtdEzS.js";import{P as ae}from"./play-pqpZOylZ.js";import{P as ie}from"./phone-B0y2I-gP.js";import{U as N,R as ne,I as ce,S as W}from"./user-agent-4Y3xBvje.js";const oe="wss://sip.webtechnicom.net:8089/ws",re="sip.webtechnicom.net";function le({status:d}){return d==="running"?e.jsx(J,{"data-loc":"client/src/pages/SipDiagnostics.tsx:13",className:"animate-spin text-violet-500",size:18}):d==="pass"?e.jsx(Q,{"data-loc":"client/src/pages/SipDiagnostics.tsx:14",className:"text-emerald-500",size:18}):d==="fail"?e.jsx(X,{"data-loc":"client/src/pages/SipDiagnostics.tsx:15",className:"text-rose-500",size:18}):e.jsx("span",{"data-loc":"client/src/pages/SipDiagnostics.tsx:16",className:"h-[18px] w-[18px] rounded-full border border-slate-200"})}function be(){const[d,A]=n.useState(oe),[h,U]=n.useState(re),[m,M]=n.useState(""),[v,$]=n.useState(""),[I,L]=n.useState("1002"),[O,C]=n.useState("idle"),[_,w]=n.useState("idle"),[z,D]=n.useState("idle"),[y,b]=n.useState("idle"),[V,u]=n.useState("idle"),[H,r]=n.useState("Run the checks in order. Credentials are never written to the log."),[k,T]=n.useState([]),x=n.useRef(null),S=n.useRef(null),f=n.useRef(null),g=n.useRef(null),c=(t,a)=>T(s=>[...s.slice(-99),{id:crypto.randomUUID(),at:new Date().toLocaleTimeString(),source:t,message:a}]),B=async()=>{C("running"),c("TEST",`Opening SIP WebSocket ${d}.`),await new Promise(t=>{let a=!1;const s=(p,o)=>{a||(a=!0,window.clearTimeout(l),C(p),c(p==="pass"?"SIP":"TEST",o),t())},i=new WebSocket(d,"sip"),l=window.setTimeout(()=>{i.close(),s("fail","WSS probe timed out after 6 seconds.")},6e3);i.onopen=()=>{i.close(),s("pass","WSS endpoint accepted a WebSocket connection.")},i.onerror=()=>s("fail","WSS endpoint could not be opened from this browser.")})},G=async()=>{w("running");try{if(!navigator.mediaDevices?.getUserMedia)throw new Error("getUserMedia is unavailable in this browser.");const t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),a=t.getAudioTracks().length,s=t.getVideoTracks().length;if(t.getTracks().forEach(i=>i.stop()),!a||!s)throw new Error(`Media incomplete: ${a} audio track(s), ${s} video track(s).`);w("pass"),c("MEDIA",`Camera and microphone permission granted (${a} audio, ${s} video).`),r("Camera and microphone are available for a WebRTC call.")}catch(t){const a=t instanceof Error?t.message:"Camera or microphone check failed.";w("fail"),c("MEDIA",a),r("Media check failed. Review browser permissions and device availability.")}},F=async()=>{D("running");let t=null;const a=new RTCPeerConnection,s=new RTCPeerConnection;try{t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0});let i=0;s.ontrack=()=>{i+=1},a.onicecandidate=o=>{o.candidate&&s.addIceCandidate(o.candidate)},s.onicecandidate=o=>{o.candidate&&a.addIceCandidate(o.candidate)},t.getTracks().forEach(o=>a.addTrack(o,t));const l=await a.createOffer();await a.setLocalDescription(l),await s.setRemoteDescription(l);const p=await s.createAnswer();if(await s.setLocalDescription(p),await a.setRemoteDescription(p),await new Promise(o=>window.setTimeout(o,700)),i<2)throw new Error(`PeerConnection loopback received ${i}/2 media tracks.`);D("pass"),c("WebRTC","Audio/video PeerConnection loopback negotiated successfully."),r("WebRTC media negotiation passed locally.")}catch(i){const l=i instanceof Error?i.message:"PeerConnection test failed.";D("fail"),c("WebRTC",l),r("WebRTC loopback failed. Check permissions, device and browser support.")}finally{t?.getTracks().forEach(i=>i.stop()),a.close(),s.close()}},j=async()=>{if(b("running"),!m.trim()||!v)return b("fail"),c("SIP","Registration blocked: SIP username and password are required."),r("Enter the credentials for a non-owner SIP test account."),!1;try{const t=N.makeURI(`sip:${m.trim()}@${h}`);
1if(!t)throw new Error("SIP identity is invalid.");const a=new N({uri:t,transportOptions:{server:d},authorizationUsername:m.trim(),authorizationPassword:v,sessionDescriptionHandlerFactoryOptions:{peerConnectionOptions:{rtcConfiguration:{iceServers:[]}}}});await a.start();const s=new ne(a);return await s.register(),x.current=a,S.current=s,b("pass"),c("SIP",`REGISTER accepted for ${m.trim()}@${h}.`),r("SIP registration passed. You can now run the internal call test."),!0}catch(t){const a=t instanceof Error?t.message:"SIP registration failed.";return b("fail"),c("SIP",a),r("SIP registration failed. Check WSS, credentials and endpoint provisioning."),!1}},Y=async()=>{u("running");const t=I.trim().replace(/[^0-9*#]/g,"");if(!t||t==="1001"){u("fail"),c("TEST","Internal call blocked: 1001 is reserved and cannot be used as a test target."),r("Choose a non-owner internal extension, such as the provisioned test endpoint.");return}if(!(x.current&&S.current?!0:await j())||!x.current){u("fail");return}try{const s=N.makeURI(`sip:${t}@${h}`);if(!s)throw new Error("Internal target is invalid.");const i=new ce(x.current,s,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!0}}});f.current=i,i.stateChange.addListener(l=>{if(l===W.Established){u("pass"),c("SIP",`Internal call established to ${t}; audio/video session is active.`);const o=i.sessionDescriptionHandler.peerConnection;if(o&&g.current){const P=new MediaStream;o.getReceivers().forEach(E=>{E.track&&P.addTrack(E.track)}),g.current.srcObject=P,g.current.play().catch(()=>{})}}l===W.Terminated&&c("SIP","Internal call session terminated.")}),c("SIP",`Sending internal INVITE to ${t}.`),await i.invite(),r(`Internal call test started to ${t}.`)}catch(s){const i=s instanceof Error?s.message:"Internal call failed.";u("fail"),c("SIP",i),r("Internal call failed. Confirm that the target endpoint is provisioned and registered.")}},q=async()=>{await f.current?.cancel().catch(()=>{}),await S.current?.unregister().catch(()=>{}),await x.current?.stop().catch(()=>{}),f.current=null,S.current=null,x.current=null,g.current&&(g.current.srcObject=null),c("SIP","Diagnostic SIP session disconnected."),r("Diagnostic session disconnected.")};n.useEffect(()=>()=>{f.current?.cancel().catch(()=>{}),S.current?.unregister().catch(()=>{}),x.current?.stop().catch(()=>{})},[]);const K=[{label:"WSS endpoint",detail:"TLS WebSocket reachability",status:O,action:B,icon:ee},{label:"Camera + microphone",detail:"Browser permission and devices",status:_,action:G,icon:te},{label:"WebRTC loopback",detail:"Local audio/video negotiation",status:z,action:F,icon:se},{label:"SIP registration",detail:"REGISTER against Asterisk",status:y,action:j,icon:R}];return e.jsxs("main",{"data-loc":"client/src/pages/SipDiagnostics.tsx:213",className:"min-h-screen bg-[#fbfbfe] px-5 py-8 text-slate-800 sm:px-8",children:[e.jsx("audio",{"data-loc":"client/src/pages/SipDiagnostics.tsx:214",ref:g,autoPlay:!0,"aria-label":"Diagnostic remote audio"}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:215",className:"mx-auto max-w-6xl",children:[e.jsxs("a",{"data-loc":"client/src/pages/SipDiagnostics.tsx:216",href:"/connect/softphone",className:"mb-8 inline-flex items-center gap-2 text-xs font-semibold text-violet-600",children:[e.jsx(Z,{"data-loc":"client/src/pages/SipDiagnostics.tsx:216",size:15}),"Back to CONNECT Softphone"]}),e.jsxs("header",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",className:"mb-8 flex flex-col justify-between gap-4 md:flex-row md:items-end",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",children:[e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",className:"mb-2 text-[10px] font-bold uppercase tracking-[.2em] text-violet-500",children:"WEBTECHNICOM / DIAGNOSTICS"}),e.jsx("h1",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",className:"text-4xl font-semibold tracking-[-.04em] text-slate-900",children:"WebRTC / SIP test bench"}),e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",className:"mt-3 max-w-2xl text-sm leading-6 text-slate-500",children:"Validate WSS reachability, browser media, local WebRTC negotiation, SIP registration and a controlled internal
1call without using owner account 1001 or an external number."})]}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",className:"rounded-2xl border border-violet-100 bg-violet-50 px-4 py-3 text-xs text-violet-700",children:[e.jsx("strong",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217",children:"Safe test mode"}),e.jsx("br",{"data-loc":"client/src/pages/SipDiagnostics.tsx:217"}),"No DID purchase · no external dialling"]})]}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:218",className:"grid gap-6 lg:grid-cols-[1.05fr_.95fr]",children:[e.jsxs("section",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"rounded-3xl border border-slate-200 bg-white p-5 shadow-[0_18px_50px_rgba(47,34,110,.08)] sm:p-7",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"mb-5 flex items-center justify-between",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",children:[e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"text-[10px] font-bold uppercase tracking-[.18em] text-slate-400",children:"STEP-BY-STEP CHECKS"}),e.jsx("h2",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"mt-1 text-xl font-semibold text-slate-900",children:"Run the connection path"})]}),e.jsx("button",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",type:"button",onClick:()=>T([]),className:"text-xs font-semibold text-slate-400 hover:text-violet-600",children:"Clear logs"})]}),e.jsx("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"space-y-3",children:K.map(({label:t,detail:a,status:s,action:i,icon:l},p)=>e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"flex items-center gap-4 roun
1ded-2xl border border-slate-100 bg-slate-50/70 p-4",children:[e.jsx("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-violet-50 text-violet-600",children:e.jsx(l,{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",size:17})}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"min-w-0 flex-1",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"flex items-center gap-2",children:[e.jsxs("span",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"text-[10px] font-bold text-slate-400",children:["0",p+1]}),e.jsx("strong",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"text-sm text-slate-800",children:t})]}),e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",className:"mt-1 text-xs text-slate-500",children:a})]}),e.jsx(le,{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",status:s}),e.jsxs("button",{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",type:"button",onClick:()=>void i(),disabled:s==="running",className:"rounded-xl bg-white px-3 py-2 text-xs font-bold text-violet-600 shadow-sm ring-1 ring-slate-200 hover:bg-violet-50 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(ae,{"data-loc":"client/src/pages/SipDiagnostics.tsx:219",size:13,className:"mr-1 inline"}),"Run"]})]},t))})]}),e.jsxs("section",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"rounded-3xl border border-slate-200 bg-white p-5 shadow-[0_18px_50px_rgba(47,34,110,.08)] sm:p-7",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"mb-5",children:[e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-[10px] font-bold uppercase tracking-[.18em] text-slate-400",children:"SIP TEST IDENTITY"}),e.jsx("h2",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"mt-1 text-xl font-semibold text-slate-900",children:"Use a non-owner endpoint"}),e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"mt-2 text-xs leading-5 text-slate-500",children:"Enter credentials from the secure SIP provisioning flow. Passwords are kept in memory only and are never copied into logs."})]}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-xs font-semibold text-slate-600",children:["SIP username",e.jsx("input",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",value:m,onChange:t=>M(t.target.value),autoComplete:"username",className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm outline-none focus:border-violet-400",placeholder:"client-test"})]}),e.jsxs("label",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-xs font-semibold text-slate-600",children:["Private password",e.jsx("input",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",type:"password",value:v,onChange:t=>$(t.target.value),autoComplete:"current-password",className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm outline-none focus:border-violet-400",placeholder:"Secure password"})]}),e.jsxs("label",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-xs font-semibold text-slate-600 sm:col-span-2",children:["WSS server",e.jsx("input",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",value:d,onChange:t=>A(t.target.value),className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm outline-none focus:border-violet-400"})]}),e.jsxs("label",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-xs font-semibold text-slate-600",children:["SIP domain",e.jsx("input",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",value:h,onChange:t=>U(t.target.value),className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm outline-none focus:border-violet-400"})]}),e.jsxs("label",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"text-xs font-semibold text-slate-600",children:["Internal test target",e.jsx("input",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",value:I,onChange:t=>L(t.target.value),inputMode:"numeric",className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm outline-none focus:border-violet-400",placeholder:"1002"})]})]}),e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"mt-5 flex flex-wrap gap-2",children:[e.jsxs("button",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",type:"button",onClick:()=>void j(),disabled:y==="running",className:"inline-flex items-center gap-2 rounded-xl bg-violet-600 px-4 py-2.5 text-xs font-bold text-white shadow-lg shadow-violet-200 disabled:opacity-50",children:[e.jsx(R,{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",size:15}),"Register test SIP"]}),e.jsxs("button",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",type:"button",onClick:()=>void Y(),disabled:V==="running",className:"inline-flex items-center gap-2 rounded-xl border border-violet-200 bg-vi
1olet-50 px-4 py-2.5 text-xs font-bold text-violet-700 disabled:opacity-50",children:[e.jsx(ie,{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",size:15}),"Run internal call"]}),e.jsx("button",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",type:"button",onClick:()=>void q(),className:"rounded-xl px-4 py-2.5 text-xs font-bold text-slate-500 hover:bg-slate-50",children:"Disconnect"})]}),e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:220",className:"mt-4 rounded-xl bg-slate-50 px-3 py-2 text-xs text-slate-500",role:"status",children:H})]})]}),e.jsxs("section",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"mt-6 rounded-3xl border border-slate-200 bg-[#151322] p-5 text-slate-100 shadow-[0_18px_50px_rgba(47,34,110,.12)] sm:p-7",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"mb-4 flex items-center justify-between",children:[e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",children:[e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"text-[10px] font-bold uppercase tracking-[.18em] text-violet-300",children:"LIVE DIAGNOSTICS"}),e.jsx("h2",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"mt-1 text-xl font-semibold",children:"SIP / WebRTC event stream"})]}),e.jsxs("span",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"inline-flex items-center gap-2 rounded-full bg-emerald-400/10 px-3 py-1 text-[10px] font-bold uppercase tracking-[.12em] text-emerald-300",children:[e.jsx("i",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"h-1.5 w-1.5 rounded-full bg-emerald-300"}),"Local panel"]})]}),e.jsx("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"max-h-72 min-h-36 overflow-auto rounded-2xl border border-white/10 bg-black/20 p-4 font-mono text-[11px] leading-6",children:k.length===0?e.jsx("p",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"text-slate-500",children:"No events yet. Run a step to start the diagnostic stream."}):k.map(t=>e.jsxs("div",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"grid grid-cols-[auto_auto_1fr] gap-3",children:[e.jsx("time",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"text-slate-500",children:t.at}),e.jsx("b",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:t.source==="SIP"?"text-violet-300":t.source==="WebRTC"?"text-emerald-300":t.source==="MEDIA"?"text-amber-300":"text-sky-300",children:t.source}),e.jsx("span",{"data-loc":"client/src/pages/SipDiagnostics.tsx:222",className:"text-slate-300",children:t.message})]},t.id))})]})]})]})}export{be as default};
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.