PageSourceSearch

https://magpipe.ai/assets/sipClient-C3SChj3J.js

js magpipe.ai collected 2026-10-05 13:36:27 UTC 6,762 bytes, 1 lines download raw bytes

1import{J as g}from"./jssip-BqIs6aTJ.js";import"./supabase-DopYWMZw.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};l.SENTRY_RELEASE={id:"280815f9a48432bd"};var e=new l.Error().stack;e&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[e]="affdee00-334d-4674-ab70-fdb564e6b7ce",l._sentryDebugIdIdentifier="sentry-dbid-affdee00-334d-4674-ab70-fdb564e6b7ce")}catch{}})();class h{constructor(){this.userAgent=null,this.currentSession=null,this.isRegistered=!1,this.remoteAudio=null,this.sipDomain=null}async initialize(e){var r;try{console.log("🔧 Initializing SIP client with config:",{sipUri:e.sipUri,wsServer:e.wsServer,displayName:e.displayName,passwordLength:(r=e.sipPassword)==null?void 0:r.length});const o=e.sipUri.match(/@(.+)$/);this.sipDomain=o?o[1]:"erik.signalwire.com",console.log("📡 SIP Domain for caller ID:",this.sipDomain),g.debug.enable("JsSIP:*");const i=new g.WebSocketInterface(e.wsServer);console.log("🔄 Creating WebSocket to:",e.wsServer);const t={sockets:[i],uri:e.sipUri,password:e.sipPassword,display_name:e.displayName||"Web Caller",session_timers:!1,register:!0,register_expires:3600};return console.log("🔧 JsSIP UA configuration:",{...t,password:"***REDACTED***"}),this.userAgent=new g.UA(t),this.setupEventHandlers(),this.userAgent.start(),new Promise((a,s)=>{const d=setTimeout(()=>{s(new Error("SIP registration timeout"))},1e4);this.userAgent.on("registered",()=>{clearTimeout(d),this.isRegistered=!0,console.log("✅ SIP registered successfully"),a()}),this.userAgent.on("registrationFailed",u=>{clearTimeout(d),console.error("❌ SIP registration failed:",u),s(new Error(`Registration failed: ${u.cause}`))})})}catch(o){throw console.error("Failed to initialize SIP client:",o),o}}setupEventHandlers(){this.userAgent.on("connecting",e=>{console.log("🔄 WebSocket connecting...",e)}),this.userAgent.on("connected",()=>{console.log("🔌 WebSocket connected successfully")}),this.userAgent.on("disconnected",e=>{console.log("🔌 WebSocket disconnected:",e),this.isRegistered=!1}),this.userAgent.on("newRTCSession",e=>{const r=e.session;r.direction==="incoming"&&(console.log("📞 Incoming call from:",r.remote_identity.uri.user),this.handleIncomingCall(r))}),this.userAgent.on("registrationExpiring",()=>{console.log("⏰ SIP registration expiring, will re-register")}),this.userAgent.on("unregistered",e=>{console.log("❌ SIP unregistered:",e),this.isRegistered=!1}),this.userAgent.on("sipEvent",e=>{console.log("📡 SIP Event:",e)}),this.userAgent.on("newMessage",e=>{console.log("💬 SIP Message:",e)})}async makeCall(e,r,o,i={}){const t=i.onProgress?i:{},a=i.callRecordId||null;if(!this.isRegistered)throw new Error("SIP client not registered");if(this.currentSession)throw new Error("Call already in progress");try{const s=e.replace(/[^\d+]/g,""),u={eventHandlers:{progress:c=>{var n;console.log("📞 Call in progress..."),(n=t.onProgress)==null||n.call(t)},failed:c=>{var n;console.log("❌ Call failed:",c.cause),this.currentSession=null,(n=t.onFailed)==null||n.call(t,c.cause)},ended:c=>{var n;console.log("📞 Call ended"),this.currentSession=null,(n=t.onEnded)==null||n.call(t)},confirmed:c=>{var n;console.log("✅ Call confirmed"),(n=t.onConfirmed)==null||n.call(t)},peerconnection:c=>{c.peerconnection.addEventListener("track",n=>{n.streams&&n.streams[0]&&this.playRemoteAudio(n.streams[0])})}},mediaConstraints:{audio:!0,video:!1},rtcOfferConstraints:{offerToReceiveAudio:!0,offerToReceiveVideo:!1},pcConfig:{iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"}]},extraHeaders:[`X-From-Number: ${r}`,`P-Asserted-Identity: <sip:${r}@${this.sipDomain}>`,`Remote-Party-ID: "${o}" <sip:${r}@${this.sipDomain}>;party=calling;privacy=off;screen=no`,...a?[`X-Call-Record-Id: ${a}`]:[]]};return o&&(u.fromDisplayName=o),this.currentSession=this.userAgent.call(s,u),this.currentSession}catch(s){throw console.error("Failed to make call:",s),s}}handleIncomingCall(e){this.currentSession=e,e.on("confirmed",()=>{console.log("✅ Incoming call answered")}),e.on("ended",()=>{console.log("📞 Incoming call ended"),this.currentSession=null}),e.on("failed",()=>{console.log("❌ Incoming call failed"),this.currentSession=null}),e.on("peerconnection",o=>{o.peerconnection.addEventListener("track",i=>{i.streams&&i.streams[0]&&this.playRemoteAudio(i.streams[0])})}),console.log("📞 Auto-answering incoming call...");const r={mediaConstraints:{audio:!0,video:!1},rtcAnswerConstraints:{offerToReceiveAudio:!0,offerToReceiveVideo:!1},pcConfig:{iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"}]}};e.answer(r)}playRemoteAudio(e){this.remoteAudio||(this.remoteAudio=document.createElement("audio"),this.remoteAudio.autoplay=!0,document.body.appendChild(this.remoteAudio)
1),this.remoteAudio.srcObject=e}hangup(){this.currentSession&&(this.currentSession.terminate(),this.currentSession=null)}sendDTMF(e){this.currentSession&&this.currentSession.isEstablished()&&(this.currentSession.sendDTMF(e),console.log("📱 Sent DTMF:",e))}setMute(e){this.currentSession&&(e?this.currentSession.mute():this.currentSession.unmute())}disconnect(){this.currentSession&&this.hangup(),this.userAgent&&(this.userAgent.stop(),this.isRegistered=!1),this.remoteAudio&&(this.remoteAudio.remove(),this.remoteAudio=null)}isInCall(){return this.currentSession!==null}isCallActive(){return this.currentSession!==null&&this.currentSession.isEstablished()}getCallStatus(){return this.currentSession?this.currentSession.isInProgress()?"connecting":this.currentSession.isEstablished()?"active":"idle":"idle"}async transfer(e){if(!this.currentSession||!this.currentSession.isEstablished())return console.error("No active call to transfer"),!1;try{const r=e.replace(/[^\d+]/g,"");console.log("📞 Initiating SIP REFER transfer to:",r);const o=r.startsWith("+")?`sip:${r}@${this.sipDomain}`:`sip:+${r}@${this.sipDomain}`;return new Promise((i,t)=>{const a={requestSucceeded:s=>{console.log("✅ REFER request accepted"),i(!0)},requestFailed:s=>{console.error("❌ REFER request failed:",s.cause),t(new Error(s.cause||"REFER failed"))},trying:s=>{console.log("📞 REFER trying...")},progress:s=>{console.log("📞 REFER progress:",s.status_code)},accepted:s=>{console.log("✅ REFER accepted by remote party")},failed:s=>{console.error("❌ REFER failed:",s.cause),t(new Error(s.cause||"Transfer failed"))}};try{this.currentSession.refer(o,{eventHandlers:a,extraHeaders:["Referred-By: <"+this.userAgent.configuration.uri+">"]})}catch(s){console.error("Error calling refer:",s),t(s)}})}catch(r){return console.error("Transfer error:",r),!1}}}const p=new h;export{p as sipClient};

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.