voxnix 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/voxnix.iife.js +1 -1
- package/dist/voxnix.js +8 -2
- package/dist/voxnix.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/voxnix.iife.js
CHANGED
|
@@ -426,4 +426,4 @@ Arguments: `+Array.prototype.slice.call(l).join("")+`
|
|
|
426
426
|
Ve.version="2.30.1",S8(Gr),Ve.fn=Me,Ve.min=c6,Ve.max=f6,Ve.now=d6,Ve.utc=wo,Ve.unix=LA,Ve.months=jA,Ve.isDate=n0,Ve.locale=Cu,Ve.invalid=kv,Ve.duration=zs,Ve.isMoment=Us,Ve.weekdays=qA,Ve.parseZone=UA,Ve.localeData=xl,Ve.isDuration=qv,Ve.monthsShort=zA,Ve.weekdaysMin=VA,Ve.defineLocale=o1,Ve.updateLocale=U4,Ve.locales=j4,Ve.weekdaysShort=YA,Ve.normalizeUnits=os,Ve.relativeTimeRounding=xk,Ve.relativeTimeThreshold=Ek,Ve.calendarFormat=I6,Ve.prototype=Me,Ve.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"GGGG-[W]WW",MONTH:"YYYY-MM"};let Xv=null,on=null,eb=null,To=null;function Sk(o,r){if(!o||!o.sessionDescriptionHandler)return;const i=o.sessionDescriptionHandler.peerConnection;i&&i.getSenders().forEach(l=>{l.track&&l.track.kind==="audio"&&(l.track.enabled=r)})}function tb(o){To||(To=document.createElement("audio"),To.id="voxnix-remote-audio",To.autoplay=!0,document.body.appendChild(To));const r=new MediaStream;if(o.sessionDescriptionHandler&&o.sessionDescriptionHandler.peerConnection){o.sessionDescriptionHandler.peerConnection.getReceivers().forEach(l=>{l.track&&r.addTrack(l.track)});const i=o.sessionDescriptionHandler.peerConnection;if(!i._isSetRemoteDescPatched){const l=i.setRemoteDescription.bind(i);i.setRemoteDescription=function(f){if(f&&f.sdp&&f.type==="answer"){const v=(((i.localDescription||{}).sdp||"").match(/^m=/gm)||[]).length,S=(f.sdp.match(/^m=/gm)||[]).length;if(console.log("[RTC Patch] local offer m-lines:",v,"| remote answer m-lines:",S),v>0&&S>v){const w=f.sdp.split(/\r?\n/);let C=0,b=!1;const R=[];for(const H of w)H.startsWith("m=")&&(C++,b=C>v),b||R.push(H);let T=R.join(`\r
|
|
427
427
|
`);T.endsWith(`\r
|
|
428
428
|
`)||(T+=`\r
|
|
429
|
-
`),console.log("[RTC Patch] filtered to",(T.match(/^m=/gm)||[]).length,"m-lines. Applying to Chrome."),f={type:"answer",sdp:T}}}return l(f)},i._isSetRemoteDescPatched=!0}}To.srcObject=r,To.play().catch(i=>console.error("Error playing media:",i))}function rb(){To&&(To.srcObject=null,To.pause())}const wk=()=>{tt.on("incoming_call",()=>{Ni.pushSound()}),tt.on("local_dial",({number:o})=>{if(Xv){const r=Tc.makeURI(`sip:${o}@${Xv.configuration.uri.domain}`),i=new W2(Xv,r);i.stateChange.addListener(l=>{l===xe.Establishing?tt.emitLocal("call_status","Calling..."):l===xe.Established?(tb(i),on=i,tt.emitLocal("call_status","InCall")):l===xe.Terminated&&(rb(),tt.emitLocal("call_status","Idle"),on=null)}),i.invite()}}),tt.on("local_hangup",()=>{Ni.stopSound(),on&&(on.state===xe.Established?on.bye():typeof on.reject=="function"?on.reject():on.cancel()),tt.emitLocal("call_status","Idle"),tt.emitLocal("call_duration","00:00"),tt.emitToParent("sync_call_ended")}),tt.on("local_reject",()=>{Ni.stopSound(),on&&(typeof on.reject=="function"?on.reject():on.cancel()),tt.emitLocal("call_status","Idle"),tt.emitLocal("call_duration","00:00"),tt.emitToParent("sync_call_ended")}),tt.on("local_answer",()=>{Ni.stopSound();const o={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};on&&on.accept(o)}),tt.on("local_toggle_mute",({muted:o})=>{on&&Sk(on,!o)}),tt.on("local_toggle_hold",({isOnHold:o,setIsOnHold:r})=>{if(on)try{const i=!o,l={sessionDescriptionHandlerOptions:{hold:i}};on.invite(l).then(()=>{r(i),console.log(i?"Call successfully put on hold":"Call successfully resumed")}).catch(f=>{console.error("Hold/Unhold failed",f)})}catch(i){console.error("Gagal mengubah status hold:",i)}}),tt.on("local_dtmf",({key:o})=>{on&&on.sessionDescriptionHandler&&on.sessionDescriptionHandler.sendDtmf(o)})},bk=async o=>{var v,S;window.__sipjsEventsBound||(wk(),window.__sipjsEventsBound=!0);const{auth:r}=o;if(!r)return;const i=r.user_pbx||r.username,l=r.pwd_pbx||r.secret,f=((S=(v=r.pabx_host)==null?void 0:v.replace("http://",""))==null?void 0:S.replace("https://",""))||r.pbxurl,p=r.port||8089;if(!(!i||!f))try{const w=Tc.makeURI(`sip:${i}@${f}`);if(!w)throw new Error("Failed to create SIP URI");const C=`wss://sip.omnix.co.id:${p}`,b=new Tc({uri:w,transportOptions:{server:C,useSSL:!0},authorizationUsername:i,authorizationPassword:l,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn",contactParams:{transport:"tls"}});Xv=b;const R=new Co(b);R.stateChange.addListener(async T=>{var H;if(console.log("NEW STATE",T),T===Cr.Registered)if(((H=Ni.getConfig())==null?void 0:H.autoReady)!==!1)await Ni.updateExtensionStatus(i,"Ready","ready")?(tt.emitLocal("register_status","REGISTERED"),tt.emitLocal("agent_status","READY")):tt.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"});else{const j=await Ni.fetchExtensionStatus(i),z=j==null?void 0:j.extension_status;let O="NOT_READY";z==="Ready"?O="READY":typeof z=="string"&&z.toLowerCase().startsWith("aux")&&(O="AUX"),tt.emitLocal("register_status","SIP_CONNECTED"),tt.emitLocal("agent_status",O)}else(T===Cr.Unregistered||T===Cr.Terminated)&&tt.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),b.delegate={onInvite(T){let H=!1;on=T,tt.emitLocal("sipjsSession",T),Ni.pushSound(),Ni.pushNotification(`New incoming call from ${T.remoteIdentity.uri.user}`),tt.emitLocal("incoming_call",T),tt.emitToParent("sync_incoming_call",T),T.stateChange.addListener(P=>{if(P===xe.Established){tb(T),H=!0,tt.emitLocal("call_status","InCall"),tt.emitToParent("sync_call_answered",T);const j=Ve();eb=setInterval(()=>{const z=Ve.duration(Ve().diff(j));tt.emitLocal("call_duration",Ni.toHHMMSS(z.asSeconds()))},1e3)}else P===xe.Terminated&&(rb(),clearInterval(eb),Ni.stopSound(),tt.emitLocal("call_duration","00:00"),tt.emitLocal("call_status","Idle"),H?tt.emitToParent("sync_call_ended",T):tt.emitToParent("sync_call_unanswered"),on=null)})}},await b.start(),await R.register()}catch(w){console.error("SipJS init error:",w),tt.emitLocal("register_status",{status:"FAILED",reason:w.message||"Failed to connect to SIP server"})}},nb={"bottom-left":"bottom-6 left-3 items-start","bottom-right":"bottom-6 right-3 items-end","top-left":"top-6 left-3 items-start","top-right":"top-6 right-3 items-end"};function _k({config:o,placement:r="bottom-left",offset:i,onIncomingCall:l,onCallAnswered:f,onCallEnded:p,onCallUnanswered:v,onRegisterStatus:S,onAgentStatus:w}){const[C,b]=qt.useState(!1),[R,T]=qt.useState("CONNECTING"),[H,P]=qt.useState("NOT_READY"),[j,z]=qt.useState(!1),O=qt.useRef(!1),B=qt.useRef({}),U=(o==null?void 0:o.autoReady)!==!1,q=(o==null?void 0:o.showAuxButton)===!0,K=(o==null?void 0:o.auxOptions)||[];qt.useEffect(()=>{B.current={onIncomingCall:l,onCallAnswered:f,onCallEnded:p,onCallUnanswered:v,onRegisterStatus:S,onAgentStatus:w}}),qt.useEffect(()=>{var F;o&&Ni.setConfig(o);const X=(o==null?void 0:o.auth)||((F=o==null?void 0:o.pabxConfig)==null?void 0:F.auth)||{};!O.current&&(X.username||X.user_pbx)&&(X.pwd_pbx||X.secret)&&(X.pabx_host||X.pbxurl||X.host)&&(O.current=!0,bk({auth:X}))},[o]),qt.useEffect(()=>{const X=[tt.on("register_status",F=>{var M,_e;const L=typeof F=="string"?F:(F==null?void 0:F.status)??"FAILED";T(L),(L==="REGISTERED"||L==="SIP_CONNECTED")&&b(!0),L!=="SIP_CONNECTED"&&((_e=(M=B.current).onRegisterStatus)==null||_e.call(M,L==="FAILED"?F:L))}),tt.on("agent_status",F=>{var L,M;P(F),(M=(L=B.current).onAgentStatus)==null||M.call(L,F)}),tt.on("sync_incoming_call",F=>{var L,M;z(!0),b(!0),(M=(L=B.current).onIncomingCall)==null||M.call(L,F)}),tt.on("sync_call_answered",F=>{var L,M;z(!1),(M=(L=B.current).onCallAnswered)==null||M.call(L,F)}),tt.on("sync_call_ended",F=>{var L,M;z(!1),(M=(L=B.current).onCallEnded)==null||M.call(L,F)}),tt.on("sync_call_unanswered",F=>{var L,M;z(!1),(M=(L=B.current).onCallUnanswered)==null||M.call(L,F)})];return()=>X.forEach(F=>F())},[]);const Z=nb[r]||nb["bottom-left"],ee=R!=="REGISTERED"?R==="FAILED"?"bg-red-500":"bg-blue-400":H==="READY"?"bg-green-500":H==="AUX"?"bg-amber-400":"bg-gray-400",A=i?{position:"fixed",zIndex:9999,...i}:void 0,Ce=r!=null&&r.includes("right")?"origin-bottom-right":"origin-bottom-left";return ie.jsxs("div",{className:i?void 0:`fixed ${Z} z-[9999] flex flex-col gap-3`,style:A,children:[ie.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${Ce} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${C?"animate-slideUp":"hidden"}`,children:[ie.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[ie.jsx("div",{className:"flex items-center gap-2.5",children:ie.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),ie.jsx("button",{onClick:()=>b(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:ie.jsx(XT,{className:"w-4 h-4"})})]}),ie.jsx(HR,{initialRegisterStatus:R,autoReady:U,showAuxButton:q,auxOptions:K})]}),ie.jsxs("button",{onClick:()=>b(X=>!X),className:"w-12 h-12 rounded-full bg-primary hover:bg-primary-hover text-white shadow-lg shadow-primary/30 flex items-center justify-center transition-all active:scale-95 relative",title:"Voice Widget",children:[ie.jsx(Xh,{className:"w-5 h-5"}),j&&ie.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),ie.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white ${ee}`})]})]})}let wu=null,us=null;function Dk(o,r){if(Gh.createRoot){const i=Gh.createRoot(r);return i.render(o),{render:l=>i.render(l),unmount:()=>i.unmount()}}return Gh.render(o,r),{render:i=>Gh.render(i,r),unmount:()=>Gh.unmountComponentAtNode(r)}}const Tk={init(o={}){const{container:r,placement:i="bottom-left",offset:l,platform:f="sipjs",auth:p,pabxConfig:v,autoReady:S=!0,showAuxButton:w=!1,auxOptions:C=[],onIncomingCall:b,onCallAnswered:R,onCallEnded:T,onCallUnanswered:H,onRegisterStatus:P,onAgentStatus:j,...z}=o;typeof r=="string"?us=document.querySelector(r):r instanceof HTMLElement&&(us=r),us||(us=document.createElement("div"),us.id="omnix-widget-root",document.body.appendChild(us)),wu&&(wu.unmount(),wu=null);const O=UT.createElement(_k,{config:{platform:f,auth:p,pabxConfig:v,autoReady:S,showAuxButton:w,auxOptions:C,...z},placement:i,offset:l,onIncomingCall:b,onCallAnswered:R,onCallEnded:T,onCallUnanswered:H,onRegisterStatus:P,onAgentStatus:j});return wu=Dk(O,us),{answer:()=>tt.emitLocal("local_answer"),hangup:()=>tt.emitLocal("local_hangup"),reject:()=>tt.emitLocal("local_reject"),mute:B=>tt.emitLocal("local_toggle_mute",{muted:B}),hold:B=>tt.emitLocal("local_toggle_hold",{isOnHold:B,setIsOnHold:()=>{}}),dial:B=>tt.emitLocal("local_dial",{number:B}),destroy:()=>{wu==null||wu.unmount(),wu=null,(us==null?void 0:us.id)==="omnix-widget-root"&&us.remove(),us=null}}}};return zy.OmnixWidget=Tk,Object.defineProperty(zy,Symbol.toStringTag,{value:"Module"}),zy}({});
|
|
429
|
+
`),console.log("[RTC Patch] filtered to",(T.match(/^m=/gm)||[]).length,"m-lines. Applying to Chrome."),f={type:"answer",sdp:T}}}return l(f)},i._isSetRemoteDescPatched=!0}}To.srcObject=r,To.play().catch(i=>console.error("Error playing media:",i))}function rb(){To&&(To.srcObject=null,To.pause())}const wk=()=>{tt.on("incoming_call",()=>{Ni.pushSound()}),tt.on("local_dial",({number:o})=>{if(Xv){const r=Tc.makeURI(`sip:${o}@${Xv.configuration.uri.domain}`),i=new W2(Xv,r);i.stateChange.addListener(l=>{l===xe.Establishing?tt.emitLocal("call_status","Calling..."):l===xe.Established?(tb(i),on=i,tt.emitLocal("call_status","InCall")):l===xe.Terminated&&(rb(),tt.emitLocal("call_status","Idle"),on=null)}),i.invite()}}),tt.on("local_hangup",()=>{Ni.stopSound(),on&&(on.state===xe.Established?on.bye():typeof on.reject=="function"?on.reject():on.cancel()),tt.emitLocal("call_status","Idle"),tt.emitLocal("call_duration","00:00"),tt.emitToParent("sync_call_ended")}),tt.on("local_reject",()=>{Ni.stopSound(),on&&(typeof on.reject=="function"?on.reject():on.cancel()),tt.emitLocal("call_status","Idle"),tt.emitLocal("call_duration","00:00"),tt.emitToParent("sync_call_ended")}),tt.on("local_answer",()=>{Ni.stopSound();const o={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};on&&on.accept(o)}),tt.on("local_toggle_mute",({muted:o})=>{on&&Sk(on,!o)}),tt.on("local_toggle_hold",({isOnHold:o,setIsOnHold:r})=>{if(on)try{const i=!o,l={sessionDescriptionHandlerOptions:{hold:i}};on.invite(l).then(()=>{r(i),console.log(i?"Call successfully put on hold":"Call successfully resumed")}).catch(f=>{console.error("Hold/Unhold failed",f)})}catch(i){console.error("Gagal mengubah status hold:",i)}}),tt.on("local_dtmf",({key:o})=>{on&&on.sessionDescriptionHandler&&on.sessionDescriptionHandler.sendDtmf(o)})},bk=async o=>{var v,S;window.__sipjsEventsBound||(wk(),window.__sipjsEventsBound=!0);const{auth:r}=o;if(!r)return;const i=r.user_pbx||r.username,l=r.pwd_pbx||r.secret,f=((S=(v=r.pabx_host)==null?void 0:v.replace("http://",""))==null?void 0:S.replace("https://",""))||r.pbxurl,p=r.port||8089;if(!(!i||!f))try{const w=Tc.makeURI(`sip:${i}@${f}`);if(!w)throw new Error("Failed to create SIP URI");const C=`wss://sip.omnix.co.id:${p}`,b=new Tc({uri:w,transportOptions:{server:C,useSSL:!0,keepAliveInterval:15},authorizationUsername:i,authorizationPassword:l,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn",contactParams:{transport:"tls"},registererOptions:{expires:600,refreshFrequency:90}});Xv=b;const R=new Co(b);R.stateChange.addListener(async T=>{var H;if(console.log("NEW STATE",T),T===Cr.Registered)if(((H=Ni.getConfig())==null?void 0:H.autoReady)!==!1)await Ni.updateExtensionStatus(i,"Ready","ready")?(tt.emitLocal("register_status","REGISTERED"),tt.emitLocal("agent_status","READY")):tt.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"});else{const j=await Ni.fetchExtensionStatus(i),z=j==null?void 0:j.extension_status;let O="NOT_READY";z==="Ready"?O="READY":typeof z=="string"&&z.toLowerCase().startsWith("aux")&&(O="AUX"),tt.emitLocal("register_status","SIP_CONNECTED"),tt.emitLocal("agent_status",O)}else(T===Cr.Unregistered||T===Cr.Terminated)&&tt.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),b.delegate={onInvite(T){let H=!1;on=T,tt.emitLocal("sipjsSession",T),Ni.pushSound(),Ni.pushNotification(`New incoming call from ${T.remoteIdentity.uri.user}`),tt.emitLocal("incoming_call",T),tt.emitToParent("sync_incoming_call",T),T.stateChange.addListener(P=>{if(P===xe.Established){tb(T),H=!0,tt.emitLocal("call_status","InCall"),tt.emitToParent("sync_call_answered",T);const j=Ve();eb=setInterval(()=>{const z=Ve.duration(Ve().diff(j));tt.emitLocal("call_duration",Ni.toHHMMSS(z.asSeconds()))},1e3)}else P===xe.Terminated&&(rb(),clearInterval(eb),Ni.stopSound(),tt.emitLocal("call_duration","00:00"),tt.emitLocal("call_status","Idle"),H?tt.emitToParent("sync_call_ended",T):tt.emitToParent("sync_call_unanswered"),on=null)})}},await b.start(),await R.register()}catch(w){console.error("SipJS init error:",w),tt.emitLocal("register_status",{status:"FAILED",reason:w.message||"Failed to connect to SIP server"})}},nb={"bottom-left":"bottom-6 left-3 items-start","bottom-right":"bottom-6 right-3 items-end","top-left":"top-6 left-3 items-start","top-right":"top-6 right-3 items-end"};function _k({config:o,placement:r="bottom-left",offset:i,onIncomingCall:l,onCallAnswered:f,onCallEnded:p,onCallUnanswered:v,onRegisterStatus:S,onAgentStatus:w}){const[C,b]=qt.useState(!1),[R,T]=qt.useState("CONNECTING"),[H,P]=qt.useState("NOT_READY"),[j,z]=qt.useState(!1),O=qt.useRef(!1),B=qt.useRef({}),U=(o==null?void 0:o.autoReady)!==!1,q=(o==null?void 0:o.showAuxButton)===!0,K=(o==null?void 0:o.auxOptions)||[];qt.useEffect(()=>{B.current={onIncomingCall:l,onCallAnswered:f,onCallEnded:p,onCallUnanswered:v,onRegisterStatus:S,onAgentStatus:w}}),qt.useEffect(()=>{var F;o&&Ni.setConfig(o);const X=(o==null?void 0:o.auth)||((F=o==null?void 0:o.pabxConfig)==null?void 0:F.auth)||{};!O.current&&(X.username||X.user_pbx)&&(X.pwd_pbx||X.secret)&&(X.pabx_host||X.pbxurl||X.host)&&(O.current=!0,bk({auth:X}))},[o]),qt.useEffect(()=>{const X=[tt.on("register_status",F=>{var M,_e;const L=typeof F=="string"?F:(F==null?void 0:F.status)??"FAILED";T(L),(L==="REGISTERED"||L==="SIP_CONNECTED")&&b(!0),L!=="SIP_CONNECTED"&&((_e=(M=B.current).onRegisterStatus)==null||_e.call(M,L==="FAILED"?F:L))}),tt.on("agent_status",F=>{var L,M;P(F),(M=(L=B.current).onAgentStatus)==null||M.call(L,F)}),tt.on("sync_incoming_call",F=>{var L,M;z(!0),b(!0),(M=(L=B.current).onIncomingCall)==null||M.call(L,F)}),tt.on("sync_call_answered",F=>{var L,M;z(!1),(M=(L=B.current).onCallAnswered)==null||M.call(L,F)}),tt.on("sync_call_ended",F=>{var L,M;z(!1),(M=(L=B.current).onCallEnded)==null||M.call(L,F)}),tt.on("sync_call_unanswered",F=>{var L,M;z(!1),(M=(L=B.current).onCallUnanswered)==null||M.call(L,F)})];return()=>X.forEach(F=>F())},[]);const Z=nb[r]||nb["bottom-left"],ee=R!=="REGISTERED"?R==="FAILED"?"bg-red-500":"bg-blue-400":H==="READY"?"bg-green-500":H==="AUX"?"bg-amber-400":"bg-gray-400",A=i?{position:"fixed",zIndex:9999,...i}:void 0,Ce=r!=null&&r.includes("right")?"origin-bottom-right":"origin-bottom-left";return ie.jsxs("div",{className:i?void 0:`fixed ${Z} z-[9999] flex flex-col gap-3`,style:A,children:[ie.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${Ce} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${C?"animate-slideUp":"hidden"}`,children:[ie.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[ie.jsx("div",{className:"flex items-center gap-2.5",children:ie.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),ie.jsx("button",{onClick:()=>b(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:ie.jsx(XT,{className:"w-4 h-4"})})]}),ie.jsx(HR,{initialRegisterStatus:R,autoReady:U,showAuxButton:q,auxOptions:K})]}),ie.jsxs("button",{onClick:()=>b(X=>!X),className:"w-12 h-12 rounded-full bg-primary hover:bg-primary-hover text-white shadow-lg shadow-primary/30 flex items-center justify-center transition-all active:scale-95 relative",title:"Voice Widget",children:[ie.jsx(Xh,{className:"w-5 h-5"}),j&&ie.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),ie.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white ${ee}`})]})]})}let wu=null,us=null;function Dk(o,r){if(Gh.createRoot){const i=Gh.createRoot(r);return i.render(o),{render:l=>i.render(l),unmount:()=>i.unmount()}}return Gh.render(o,r),{render:i=>Gh.render(i,r),unmount:()=>Gh.unmountComponentAtNode(r)}}const Tk={init(o={}){const{container:r,placement:i="bottom-left",offset:l,platform:f="sipjs",auth:p,pabxConfig:v,autoReady:S=!0,showAuxButton:w=!1,auxOptions:C=[],onIncomingCall:b,onCallAnswered:R,onCallEnded:T,onCallUnanswered:H,onRegisterStatus:P,onAgentStatus:j,...z}=o;typeof r=="string"?us=document.querySelector(r):r instanceof HTMLElement&&(us=r),us||(us=document.createElement("div"),us.id="omnix-widget-root",document.body.appendChild(us)),wu&&(wu.unmount(),wu=null);const O=UT.createElement(_k,{config:{platform:f,auth:p,pabxConfig:v,autoReady:S,showAuxButton:w,auxOptions:C,...z},placement:i,offset:l,onIncomingCall:b,onCallAnswered:R,onCallEnded:T,onCallUnanswered:H,onRegisterStatus:P,onAgentStatus:j});return wu=Dk(O,us),{answer:()=>tt.emitLocal("local_answer"),hangup:()=>tt.emitLocal("local_hangup"),reject:()=>tt.emitLocal("local_reject"),mute:B=>tt.emitLocal("local_toggle_mute",{muted:B}),hold:B=>tt.emitLocal("local_toggle_hold",{isOnHold:B,setIsOnHold:()=>{}}),dial:B=>tt.emitLocal("local_dial",{number:B}),destroy:()=>{wu==null||wu.unmount(),wu=null,(us==null?void 0:us.id)==="omnix-widget-root"&&us.remove(),us=null}}}};return zy.OmnixWidget=Tk,Object.defineProperty(zy,Symbol.toStringTag,{value:"Module"}),zy}({});
|
package/dist/voxnix.js
CHANGED
|
@@ -18194,7 +18194,7 @@ const ku = () => {
|
|
|
18194
18194
|
if (!d) throw new Error("Failed to create SIP URI");
|
|
18195
18195
|
const c = `wss://sip.omnix.co.id:${n}`, l = new hr({
|
|
18196
18196
|
uri: d,
|
|
18197
|
-
transportOptions: { server: c, useSSL: !0 },
|
|
18197
|
+
transportOptions: { server: c, useSSL: !0, keepAliveInterval: 15 },
|
|
18198
18198
|
authorizationUsername: t,
|
|
18199
18199
|
authorizationPassword: s,
|
|
18200
18200
|
sessionDescriptionHandlerFactoryOptions: {
|
|
@@ -18202,7 +18202,13 @@ const ku = () => {
|
|
|
18202
18202
|
constraints: { audio: !0, video: !1 }
|
|
18203
18203
|
},
|
|
18204
18204
|
logLevel: "warn",
|
|
18205
|
-
contactParams: { transport: "tls" }
|
|
18205
|
+
contactParams: { transport: "tls" },
|
|
18206
|
+
registererOptions: {
|
|
18207
|
+
expires: 600,
|
|
18208
|
+
// Registrasi aktif selama 10 menit (600 detik)
|
|
18209
|
+
refreshFrequency: 90
|
|
18210
|
+
// SIP.js otomatis renew registrasi di detik ke-540
|
|
18211
|
+
}
|
|
18206
18212
|
});
|
|
18207
18213
|
Cs = l;
|
|
18208
18214
|
const g = new _t(l);
|
package/dist/voxnix.umd.cjs
CHANGED
|
@@ -215,4 +215,4 @@ Arguments: `+Array.prototype.slice.call(s).join("")+`
|
|
|
215
215
|
Y.version="2.30.1",bc(_e),Y.fn=M,Y.min=dd,Y.max=hd,Y.now=ud,Y.utc=Ct,Y.unix=jh,Y.months=Uh,Y.isDate=Yr,Y.locale=Jt,Y.invalid=ps,Y.duration=xt,Y.isMoment=ft,Y.weekdays=Yh,Y.parseZone=qh,Y.localeData=Ot,Y.isDuration=Fs,Y.monthsShort=Lh,Y.weekdaysMin=Gh,Y.defineLocale=cn,Y.updateLocale=ql,Y.locales=Ul,Y.weekdaysShort=Wh,Y.normalizeUnits=nt,Y.relativeTimeRounding=yu,Y.relativeTimeThreshold=wu,Y.calendarFormat=Nd,Y.prototype=M,Y.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"GGGG-[W]WW",MONTH:"YYYY-MM"};let Ns=null,Se=null,Oo=null,St=null;function bu(r,e){if(!r||!r.sessionDescriptionHandler)return;const t=r.sessionDescriptionHandler.peerConnection;t&&t.getSenders().forEach(s=>{s.track&&s.track.kind==="audio"&&(s.track.enabled=e)})}function Mo(r){St||(St=document.createElement("audio"),St.id="voxnix-remote-audio",St.autoplay=!0,document.body.appendChild(St));const e=new MediaStream;if(r.sessionDescriptionHandler&&r.sessionDescriptionHandler.peerConnection){r.sessionDescriptionHandler.peerConnection.getReceivers().forEach(s=>{s.track&&e.addTrack(s.track)});const t=r.sessionDescriptionHandler.peerConnection;if(!t._isSetRemoteDescPatched){const s=t.setRemoteDescription.bind(t);t.setRemoteDescription=function(i){if(i&&i.sdp&&i.type==="answer"){const a=(((t.localDescription||{}).sdp||"").match(/^m=/gm)||[]).length,o=(i.sdp.match(/^m=/gm)||[]).length;if(console.log("[RTC Patch] local offer m-lines:",a,"| remote answer m-lines:",o),a>0&&o>a){const d=i.sdp.split(/\r?\n/);let c=0,l=!1;const g=[];for(const y of d)y.startsWith("m=")&&(c++,l=c>a),l||g.push(y);let u=g.join(`\r
|
|
216
216
|
`);u.endsWith(`\r
|
|
217
217
|
`)||(u+=`\r
|
|
218
|
-
`),console.log("[RTC Patch] filtered to",(u.match(/^m=/gm)||[]).length,"m-lines. Applying to Chrome."),i={type:"answer",sdp:u}}}return s(i)},t._isSetRemoteDescPatched=!0}}St.srcObject=e,St.play().catch(t=>console.error("Error playing media:",t))}function jo(){St&&(St.srcObject=null,St.pause())}const Cu=()=>{V.on("incoming_call",()=>{qe.pushSound()}),V.on("local_dial",({number:r})=>{if(Ns){const e=lr.makeURI(`sip:${r}@${Ns.configuration.uri.domain}`),t=new Fa(Ns,e);t.stateChange.addListener(s=>{s===B.Establishing?V.emitLocal("call_status","Calling..."):s===B.Established?(Mo(t),Se=t,V.emitLocal("call_status","InCall")):s===B.Terminated&&(jo(),V.emitLocal("call_status","Idle"),Se=null)}),t.invite()}}),V.on("local_hangup",()=>{qe.stopSound(),Se&&(Se.state===B.Established?Se.bye():typeof Se.reject=="function"?Se.reject():Se.cancel()),V.emitLocal("call_status","Idle"),V.emitLocal("call_duration","00:00"),V.emitToParent("sync_call_ended")}),V.on("local_reject",()=>{qe.stopSound(),Se&&(typeof Se.reject=="function"?Se.reject():Se.cancel()),V.emitLocal("call_status","Idle"),V.emitLocal("call_duration","00:00"),V.emitToParent("sync_call_ended")}),V.on("local_answer",()=>{qe.stopSound();const r={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};Se&&Se.accept(r)}),V.on("local_toggle_mute",({muted:r})=>{Se&&bu(Se,!r)}),V.on("local_toggle_hold",({isOnHold:r,setIsOnHold:e})=>{if(Se)try{const t=!r,s={sessionDescriptionHandlerOptions:{hold:t}};Se.invite(s).then(()=>{e(t),console.log(t?"Call successfully put on hold":"Call successfully resumed")}).catch(i=>{console.error("Hold/Unhold failed",i)})}catch(t){console.error("Gagal mengubah status hold:",t)}}),V.on("local_dtmf",({key:r})=>{Se&&Se.sessionDescriptionHandler&&Se.sessionDescriptionHandler.sendDtmf(r)})},_u=async r=>{var a,o;window.__sipjsEventsBound||(Cu(),window.__sipjsEventsBound=!0);const{auth:e}=r;if(!e)return;const t=e.user_pbx||e.username,s=e.pwd_pbx||e.secret,i=((o=(a=e.pabx_host)==null?void 0:a.replace("http://",""))==null?void 0:o.replace("https://",""))||e.pbxurl,n=e.port||8089;if(!(!t||!i))try{const d=lr.makeURI(`sip:${t}@${i}`);if(!d)throw new Error("Failed to create SIP URI");const c=`wss://sip.omnix.co.id:${n}`,l=new lr({uri:d,transportOptions:{server:c,useSSL:!0},authorizationUsername:t,authorizationPassword:s,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn",contactParams:{transport:"tls"}});Ns=l;const g=new Et(l);g.stateChange.addListener(async u=>{var y;if(console.log("NEW STATE",u),u===me.Registered)if(((y=qe.getConfig())==null?void 0:y.autoReady)!==!1)await qe.updateExtensionStatus(t,"Ready","ready")?(V.emitLocal("register_status","REGISTERED"),V.emitLocal("agent_status","READY")):V.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"});else{const b=await qe.fetchExtensionStatus(t),C=b==null?void 0:b.extension_status;let x="NOT_READY";C==="Ready"?x="READY":typeof C=="string"&&C.toLowerCase().startsWith("aux")&&(x="AUX"),V.emitLocal("register_status","SIP_CONNECTED"),V.emitLocal("agent_status",x)}else(u===me.Unregistered||u===me.Terminated)&&V.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),l.delegate={onInvite(u){let y=!1;Se=u,V.emitLocal("sipjsSession",u),qe.pushSound(),qe.pushNotification(`New incoming call from ${u.remoteIdentity.uri.user}`),V.emitLocal("incoming_call",u),V.emitToParent("sync_incoming_call",u),u.stateChange.addListener(w=>{if(w===B.Established){Mo(u),y=!0,V.emitLocal("call_status","InCall"),V.emitToParent("sync_call_answered",u);const b=Y();Oo=setInterval(()=>{const C=Y.duration(Y().diff(b));V.emitLocal("call_duration",qe.toHHMMSS(C.asSeconds()))},1e3)}else w===B.Terminated&&(jo(),clearInterval(Oo),qe.stopSound(),V.emitLocal("call_duration","00:00"),V.emitLocal("call_status","Idle"),y?V.emitToParent("sync_call_ended",u):V.emitToParent("sync_call_unanswered"),Se=null)})}},await l.start(),await g.register()}catch(d){console.error("SipJS init error:",d),V.emitLocal("register_status",{status:"FAILED",reason:d.message||"Failed to connect to SIP server"})}},qo={"bottom-left":"bottom-6 left-3 items-start","bottom-right":"bottom-6 right-3 items-end","top-left":"top-6 left-3 items-start","top-right":"top-6 right-3 items-end"};function Du({config:r,placement:e="bottom-left",offset:t,onIncomingCall:s,onCallAnswered:i,onCallEnded:n,onCallUnanswered:a,onRegisterStatus:o,onAgentStatus:d}){const[c,l]=se.useState(!1),[g,u]=se.useState("CONNECTING"),[y,w]=se.useState("NOT_READY"),[b,C]=se.useState(!1),x=se.useRef(!1),p=se.useRef({}),E=(r==null?void 0:r.autoReady)!==!1,_=(r==null?void 0:r.showAuxButton)===!0,R=(r==null?void 0:r.auxOptions)||[];se.useEffect(()=>{p.current={onIncomingCall:s,onCallAnswered:i,onCallEnded:n,onCallUnanswered:a,onRegisterStatus:o,onAgentStatus:d}}),se.useEffect(()=>{var f;r&&qe.setConfig(r);const A=(r==null?void 0:r.auth)||((f=r==null?void 0:r.pabxConfig)==null?void 0:f.auth)||{};!x.current&&(A.username||A.user_pbx)&&(A.pwd_pbx||A.secret)&&(A.pabx_host||A.pbxurl||A.host)&&(x.current=!0,_u({auth:A}))},[r]),se.useEffect(()=>{const A=[V.on("register_status",f=>{var m,U;const v=typeof f=="string"?f:(f==null?void 0:f.status)??"FAILED";u(v),(v==="REGISTERED"||v==="SIP_CONNECTED")&&l(!0),v!=="SIP_CONNECTED"&&((U=(m=p.current).onRegisterStatus)==null||U.call(m,v==="FAILED"?f:v))}),V.on("agent_status",f=>{var v,m;w(f),(m=(v=p.current).onAgentStatus)==null||m.call(v,f)}),V.on("sync_incoming_call",f=>{var v,m;C(!0),l(!0),(m=(v=p.current).onIncomingCall)==null||m.call(v,f)}),V.on("sync_call_answered",f=>{var v,m;C(!1),(m=(v=p.current).onCallAnswered)==null||m.call(v,f)}),V.on("sync_call_ended",f=>{var v,m;C(!1),(m=(v=p.current).onCallEnded)==null||m.call(v,f)}),V.on("sync_call_unanswered",f=>{var v,m;C(!1),(m=(v=p.current).onCallUnanswered)==null||m.call(v,f)})];return()=>A.forEach(f=>f())},[]);const T=qo[e]||qo["bottom-left"],F=g!=="REGISTERED"?g==="FAILED"?"bg-red-500":"bg-blue-400":y==="READY"?"bg-green-500":y==="AUX"?"bg-amber-400":"bg-gray-400",h=t?{position:"fixed",zIndex:9999,...t}:void 0,O=e!=null&&e.includes("right")?"origin-bottom-right":"origin-bottom-left";return S.jsxs("div",{className:t?void 0:`fixed ${T} z-[9999] flex flex-col gap-3`,style:h,children:[S.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${O} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${c?"animate-slideUp":"hidden"}`,children:[S.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[S.jsx("div",{className:"flex items-center gap-2.5",children:S.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),S.jsx("button",{onClick:()=>l(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:S.jsx(Xo,{className:"w-4 h-4"})})]}),S.jsx($0,{initialRegisterStatus:g,autoReady:E,showAuxButton:_,auxOptions:R})]}),S.jsxs("button",{onClick:()=>l(A=>!A),className:"w-12 h-12 rounded-full bg-primary hover:bg-primary-hover text-white shadow-lg shadow-primary/30 flex items-center justify-center transition-all active:scale-95 relative",title:"Voice Widget",children:[S.jsx(Or,{className:"w-5 h-5"}),b&&S.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),S.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white ${F}`})]})]})}let er=null,ot=null;function Au(r,e){if(Hr.createRoot){const t=Hr.createRoot(e);return t.render(r),{render:s=>t.render(s),unmount:()=>t.unmount()}}return Hr.render(r,e),{render:t=>Hr.render(t,e),unmount:()=>Hr.unmountComponentAtNode(e)}}const Su={init(r={}){const{container:e,placement:t="bottom-left",offset:s,platform:i="sipjs",auth:n,pabxConfig:a,autoReady:o=!0,showAuxButton:d=!1,auxOptions:c=[],onIncomingCall:l,onCallAnswered:g,onCallEnded:u,onCallUnanswered:y,onRegisterStatus:w,onAgentStatus:b,...C}=r;typeof e=="string"?ot=document.querySelector(e):e instanceof HTMLElement&&(ot=e),ot||(ot=document.createElement("div"),ot.id="omnix-widget-root",document.body.appendChild(ot)),er&&(er.unmount(),er=null);const x=se.createElement(Du,{config:{platform:i,auth:n,pabxConfig:a,autoReady:o,showAuxButton:d,auxOptions:c,...C},placement:t,offset:s,onIncomingCall:l,onCallAnswered:g,onCallEnded:u,onCallUnanswered:y,onRegisterStatus:w,onAgentStatus:b});return er=Au(x,ot),{answer:()=>V.emitLocal("local_answer"),hangup:()=>V.emitLocal("local_hangup"),reject:()=>V.emitLocal("local_reject"),mute:p=>V.emitLocal("local_toggle_mute",{muted:p}),hold:p=>V.emitLocal("local_toggle_hold",{isOnHold:p,setIsOnHold:()=>{}}),dial:p=>V.emitLocal("local_dial",{number:p}),destroy:()=>{er==null||er.unmount(),er=null,(ot==null?void 0:ot.id)==="omnix-widget-root"&&ot.remove(),ot=null}}}};Yt.OmnixWidget=Su,Object.defineProperty(Yt,Symbol.toStringTag,{value:"Module"})});
|
|
218
|
+
`),console.log("[RTC Patch] filtered to",(u.match(/^m=/gm)||[]).length,"m-lines. Applying to Chrome."),i={type:"answer",sdp:u}}}return s(i)},t._isSetRemoteDescPatched=!0}}St.srcObject=e,St.play().catch(t=>console.error("Error playing media:",t))}function jo(){St&&(St.srcObject=null,St.pause())}const Cu=()=>{V.on("incoming_call",()=>{qe.pushSound()}),V.on("local_dial",({number:r})=>{if(Ns){const e=lr.makeURI(`sip:${r}@${Ns.configuration.uri.domain}`),t=new Fa(Ns,e);t.stateChange.addListener(s=>{s===B.Establishing?V.emitLocal("call_status","Calling..."):s===B.Established?(Mo(t),Se=t,V.emitLocal("call_status","InCall")):s===B.Terminated&&(jo(),V.emitLocal("call_status","Idle"),Se=null)}),t.invite()}}),V.on("local_hangup",()=>{qe.stopSound(),Se&&(Se.state===B.Established?Se.bye():typeof Se.reject=="function"?Se.reject():Se.cancel()),V.emitLocal("call_status","Idle"),V.emitLocal("call_duration","00:00"),V.emitToParent("sync_call_ended")}),V.on("local_reject",()=>{qe.stopSound(),Se&&(typeof Se.reject=="function"?Se.reject():Se.cancel()),V.emitLocal("call_status","Idle"),V.emitLocal("call_duration","00:00"),V.emitToParent("sync_call_ended")}),V.on("local_answer",()=>{qe.stopSound();const r={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};Se&&Se.accept(r)}),V.on("local_toggle_mute",({muted:r})=>{Se&&bu(Se,!r)}),V.on("local_toggle_hold",({isOnHold:r,setIsOnHold:e})=>{if(Se)try{const t=!r,s={sessionDescriptionHandlerOptions:{hold:t}};Se.invite(s).then(()=>{e(t),console.log(t?"Call successfully put on hold":"Call successfully resumed")}).catch(i=>{console.error("Hold/Unhold failed",i)})}catch(t){console.error("Gagal mengubah status hold:",t)}}),V.on("local_dtmf",({key:r})=>{Se&&Se.sessionDescriptionHandler&&Se.sessionDescriptionHandler.sendDtmf(r)})},_u=async r=>{var a,o;window.__sipjsEventsBound||(Cu(),window.__sipjsEventsBound=!0);const{auth:e}=r;if(!e)return;const t=e.user_pbx||e.username,s=e.pwd_pbx||e.secret,i=((o=(a=e.pabx_host)==null?void 0:a.replace("http://",""))==null?void 0:o.replace("https://",""))||e.pbxurl,n=e.port||8089;if(!(!t||!i))try{const d=lr.makeURI(`sip:${t}@${i}`);if(!d)throw new Error("Failed to create SIP URI");const c=`wss://sip.omnix.co.id:${n}`,l=new lr({uri:d,transportOptions:{server:c,useSSL:!0,keepAliveInterval:15},authorizationUsername:t,authorizationPassword:s,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn",contactParams:{transport:"tls"},registererOptions:{expires:600,refreshFrequency:90}});Ns=l;const g=new Et(l);g.stateChange.addListener(async u=>{var y;if(console.log("NEW STATE",u),u===me.Registered)if(((y=qe.getConfig())==null?void 0:y.autoReady)!==!1)await qe.updateExtensionStatus(t,"Ready","ready")?(V.emitLocal("register_status","REGISTERED"),V.emitLocal("agent_status","READY")):V.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"});else{const b=await qe.fetchExtensionStatus(t),C=b==null?void 0:b.extension_status;let x="NOT_READY";C==="Ready"?x="READY":typeof C=="string"&&C.toLowerCase().startsWith("aux")&&(x="AUX"),V.emitLocal("register_status","SIP_CONNECTED"),V.emitLocal("agent_status",x)}else(u===me.Unregistered||u===me.Terminated)&&V.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),l.delegate={onInvite(u){let y=!1;Se=u,V.emitLocal("sipjsSession",u),qe.pushSound(),qe.pushNotification(`New incoming call from ${u.remoteIdentity.uri.user}`),V.emitLocal("incoming_call",u),V.emitToParent("sync_incoming_call",u),u.stateChange.addListener(w=>{if(w===B.Established){Mo(u),y=!0,V.emitLocal("call_status","InCall"),V.emitToParent("sync_call_answered",u);const b=Y();Oo=setInterval(()=>{const C=Y.duration(Y().diff(b));V.emitLocal("call_duration",qe.toHHMMSS(C.asSeconds()))},1e3)}else w===B.Terminated&&(jo(),clearInterval(Oo),qe.stopSound(),V.emitLocal("call_duration","00:00"),V.emitLocal("call_status","Idle"),y?V.emitToParent("sync_call_ended",u):V.emitToParent("sync_call_unanswered"),Se=null)})}},await l.start(),await g.register()}catch(d){console.error("SipJS init error:",d),V.emitLocal("register_status",{status:"FAILED",reason:d.message||"Failed to connect to SIP server"})}},qo={"bottom-left":"bottom-6 left-3 items-start","bottom-right":"bottom-6 right-3 items-end","top-left":"top-6 left-3 items-start","top-right":"top-6 right-3 items-end"};function Du({config:r,placement:e="bottom-left",offset:t,onIncomingCall:s,onCallAnswered:i,onCallEnded:n,onCallUnanswered:a,onRegisterStatus:o,onAgentStatus:d}){const[c,l]=se.useState(!1),[g,u]=se.useState("CONNECTING"),[y,w]=se.useState("NOT_READY"),[b,C]=se.useState(!1),x=se.useRef(!1),p=se.useRef({}),E=(r==null?void 0:r.autoReady)!==!1,_=(r==null?void 0:r.showAuxButton)===!0,R=(r==null?void 0:r.auxOptions)||[];se.useEffect(()=>{p.current={onIncomingCall:s,onCallAnswered:i,onCallEnded:n,onCallUnanswered:a,onRegisterStatus:o,onAgentStatus:d}}),se.useEffect(()=>{var f;r&&qe.setConfig(r);const A=(r==null?void 0:r.auth)||((f=r==null?void 0:r.pabxConfig)==null?void 0:f.auth)||{};!x.current&&(A.username||A.user_pbx)&&(A.pwd_pbx||A.secret)&&(A.pabx_host||A.pbxurl||A.host)&&(x.current=!0,_u({auth:A}))},[r]),se.useEffect(()=>{const A=[V.on("register_status",f=>{var m,U;const v=typeof f=="string"?f:(f==null?void 0:f.status)??"FAILED";u(v),(v==="REGISTERED"||v==="SIP_CONNECTED")&&l(!0),v!=="SIP_CONNECTED"&&((U=(m=p.current).onRegisterStatus)==null||U.call(m,v==="FAILED"?f:v))}),V.on("agent_status",f=>{var v,m;w(f),(m=(v=p.current).onAgentStatus)==null||m.call(v,f)}),V.on("sync_incoming_call",f=>{var v,m;C(!0),l(!0),(m=(v=p.current).onIncomingCall)==null||m.call(v,f)}),V.on("sync_call_answered",f=>{var v,m;C(!1),(m=(v=p.current).onCallAnswered)==null||m.call(v,f)}),V.on("sync_call_ended",f=>{var v,m;C(!1),(m=(v=p.current).onCallEnded)==null||m.call(v,f)}),V.on("sync_call_unanswered",f=>{var v,m;C(!1),(m=(v=p.current).onCallUnanswered)==null||m.call(v,f)})];return()=>A.forEach(f=>f())},[]);const T=qo[e]||qo["bottom-left"],F=g!=="REGISTERED"?g==="FAILED"?"bg-red-500":"bg-blue-400":y==="READY"?"bg-green-500":y==="AUX"?"bg-amber-400":"bg-gray-400",h=t?{position:"fixed",zIndex:9999,...t}:void 0,O=e!=null&&e.includes("right")?"origin-bottom-right":"origin-bottom-left";return S.jsxs("div",{className:t?void 0:`fixed ${T} z-[9999] flex flex-col gap-3`,style:h,children:[S.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${O} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${c?"animate-slideUp":"hidden"}`,children:[S.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[S.jsx("div",{className:"flex items-center gap-2.5",children:S.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),S.jsx("button",{onClick:()=>l(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:S.jsx(Xo,{className:"w-4 h-4"})})]}),S.jsx($0,{initialRegisterStatus:g,autoReady:E,showAuxButton:_,auxOptions:R})]}),S.jsxs("button",{onClick:()=>l(A=>!A),className:"w-12 h-12 rounded-full bg-primary hover:bg-primary-hover text-white shadow-lg shadow-primary/30 flex items-center justify-center transition-all active:scale-95 relative",title:"Voice Widget",children:[S.jsx(Or,{className:"w-5 h-5"}),b&&S.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),S.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white ${F}`})]})]})}let er=null,ot=null;function Au(r,e){if(Hr.createRoot){const t=Hr.createRoot(e);return t.render(r),{render:s=>t.render(s),unmount:()=>t.unmount()}}return Hr.render(r,e),{render:t=>Hr.render(t,e),unmount:()=>Hr.unmountComponentAtNode(e)}}const Su={init(r={}){const{container:e,placement:t="bottom-left",offset:s,platform:i="sipjs",auth:n,pabxConfig:a,autoReady:o=!0,showAuxButton:d=!1,auxOptions:c=[],onIncomingCall:l,onCallAnswered:g,onCallEnded:u,onCallUnanswered:y,onRegisterStatus:w,onAgentStatus:b,...C}=r;typeof e=="string"?ot=document.querySelector(e):e instanceof HTMLElement&&(ot=e),ot||(ot=document.createElement("div"),ot.id="omnix-widget-root",document.body.appendChild(ot)),er&&(er.unmount(),er=null);const x=se.createElement(Du,{config:{platform:i,auth:n,pabxConfig:a,autoReady:o,showAuxButton:d,auxOptions:c,...C},placement:t,offset:s,onIncomingCall:l,onCallAnswered:g,onCallEnded:u,onCallUnanswered:y,onRegisterStatus:w,onAgentStatus:b});return er=Au(x,ot),{answer:()=>V.emitLocal("local_answer"),hangup:()=>V.emitLocal("local_hangup"),reject:()=>V.emitLocal("local_reject"),mute:p=>V.emitLocal("local_toggle_mute",{muted:p}),hold:p=>V.emitLocal("local_toggle_hold",{isOnHold:p,setIsOnHold:()=>{}}),dial:p=>V.emitLocal("local_dial",{number:p}),destroy:()=>{er==null||er.unmount(),er=null,(ot==null?void 0:ot.id)==="omnix-widget-root"&&ot.remove(),ot=null}}}};Yt.OmnixWidget=Su,Object.defineProperty(Yt,Symbol.toStringTag,{value:"Module"})});
|