voxnix 1.0.8 → 1.0.10
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 +5 -12
- 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=Ne,Ve.min=c6,Ve.max=f6,Ve.now=d6,Ve.utc=wo,Ve.unix=LA,Ve.months=jA,Ve.isDate=r0,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=Ne,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 Zv=null,on=null,Jw=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 eb(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 tb(){To&&(To.srcObject=null,To.pause())}const wk=()=>{it.on("incoming_call",()=>{ea.pushSound()}),it.on("local_dial",({number:o})=>{if(Zv){const r=Tc.makeURI(`sip:${o}@${Zv.configuration.uri.domain}`),i=new VS(Zv,r);i.stateChange.addListener(l=>{l===xe.Establishing?it.emitLocal("call_status","Calling..."):l===xe.Established?(eb(i),on=i,it.emitLocal("call_status","InCall")):l===xe.Terminated&&(tb(),it.emitLocal("call_status","Idle"),on=null)}),i.invite()}}),it.on("local_hangup",()=>{ea.stopSound(),on&&(on.state===xe.Established?on.bye():typeof on.reject=="function"?on.reject():on.cancel()),it.emitLocal("call_status","Idle"),it.emitLocal("call_duration","00:00"),it.emitToParent("sync_call_ended")}),it.on("local_reject",()=>{ea.stopSound(),on&&(typeof on.reject=="function"?on.reject():on.cancel()),it.emitLocal("call_status","Idle"),it.emitLocal("call_duration","00:00"),it.emitToParent("sync_call_ended")}),it.on("local_answer",()=>{ea.stopSound();const o={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};on&&on.accept(o)}),it.on("local_toggle_mute",({muted:o})=>{on&&Sk(on,!o)}),it.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)}}),it.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");
|
|
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 tb(){To&&(To.srcObject=null,To.pause())}const wk=()=>{it.on("incoming_call",()=>{ea.pushSound()}),it.on("local_dial",({number:o})=>{if(Zv){const r=Tc.makeURI(`sip:${o}@${Zv.configuration.uri.domain}`),i=new VS(Zv,r);i.stateChange.addListener(l=>{l===xe.Establishing?it.emitLocal("call_status","Calling..."):l===xe.Established?(eb(i),on=i,it.emitLocal("call_status","InCall")):l===xe.Terminated&&(tb(),it.emitLocal("call_status","Idle"),on=null)}),i.invite()}}),it.on("local_hangup",()=>{ea.stopSound(),on&&(on.state===xe.Established?on.bye():typeof on.reject=="function"?on.reject():on.cancel()),it.emitLocal("call_status","Idle"),it.emitLocal("call_duration","00:00"),it.emitToParent("sync_call_ended")}),it.on("local_reject",()=>{ea.stopSound(),on&&(typeof on.reject=="function"?on.reject():on.cancel()),it.emitLocal("call_status","Idle"),it.emitLocal("call_duration","00:00"),it.emitToParent("sync_call_ended")}),it.on("local_answer",()=>{ea.stopSound();const o={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};on&&on.accept(o)}),it.on("local_toggle_mute",({muted:o})=>{on&&Sk(on,!o)}),it.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)}}),it.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://${f}:${p}`,b=new Tc({uri:w,transportOptions:{server:C},authorizationUsername:i,authorizationPassword:l,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn"});Zv=b;const R=new Co(b);R.stateChange.addListener(async T=>{var H;T===Cr.Registered?((H=ea.getConfig())==null?void 0:H.autoReady)!==!1?await ea.updateExtensionStatus(i,"Ready","ready")?(it.emitLocal("register_status","REGISTERED"),it.emitLocal("agent_status","READY")):it.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"}):(it.emitLocal("register_status","REGISTERED"),it.emitLocal("agent_status","NOT_READY")):(T===Cr.Unregistered||T===Cr.Terminated)&&it.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),b.delegate={onInvite(T){let H=!1;on=T,it.emitLocal("sipjsSession",T),ea.pushSound(),ea.pushNotification(`New incoming call from ${T.remoteIdentity.uri.user}`),it.emitLocal("incoming_call",T),it.emitToParent("sync_incoming_call",T),T.stateChange.addListener(P=>{if(P===xe.Established){eb(T),H=!0,it.emitLocal("call_status","InCall"),it.emitToParent("sync_call_answered",T);const j=Ve();Jw=setInterval(()=>{const z=Ve.duration(Ve().diff(j));it.emitLocal("call_duration",ea.toHHMMSS(z.asSeconds()))},1e3)}else P===xe.Terminated&&(tb(),clearInterval(Jw),ea.stopSound(),it.emitLocal("call_duration","00:00"),it.emitLocal("call_status","Idle"),H?it.emitToParent("sync_call_ended",T):it.emitToParent("sync_call_unanswered"),on=null)})}},await b.start(),await R.register()}catch(w){console.error("SipJS init error:",w),it.emitLocal("register_status",{status:"FAILED",reason:w.message||"Failed to connect to SIP server"})}},rb={"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]=zt.useState(!1),[R,T]=zt.useState("CONNECTING"),[H,P]=zt.useState("NOT_READY"),[j,z]=zt.useState(!1),B=zt.useRef(!1),M=zt.useRef({}),U=(o==null?void 0:o.autoReady)!==!1,q=(o==null?void 0:o.showAuxButton)===!0,K=(o==null?void 0:o.auxOptions)||[];zt.useEffect(()=>{M.current={onIncomingCall:l,onCallAnswered:f,onCallEnded:p,onCallUnanswered:v,onRegisterStatus:S,onAgentStatus:w}}),zt.useEffect(()=>{var F;o&&ea.setConfig(o);const Z=(o==null?void 0:o.auth)||((F=o==null?void 0:o.pabxConfig)==null?void 0:F.auth)||{};!B.current&&(Z.username||Z.user_pbx)&&(Z.pwd_pbx||Z.secret)&&(Z.pabx_host||Z.pbxurl||Z.host)&&(B.current=!0,bk({auth:Z}))},[o]),zt.useEffect(()=>{const Z=[it.on("register_status",F=>{var N,De;const L=typeof F=="string"?F:(F==null?void 0:F.status)??"FAILED";T(L),L==="REGISTERED"&&b(!0),(De=(N=M.current).onRegisterStatus)==null||De.call(N,L==="FAILED"?F:L)}),it.on("agent_status",F=>{var L,N;P(F),(N=(L=M.current).onAgentStatus)==null||N.call(L,F)}),it.on("sync_incoming_call",F=>{var L,N;z(!0),b(!0),(N=(L=M.current).onIncomingCall)==null||N.call(L,F)}),it.on("sync_call_answered",F=>{var L,N;z(!1),(N=(L=M.current).onCallAnswered)==null||N.call(L,F)}),it.on("sync_call_ended",F=>{var L,N;z(!1),(N=(L=M.current).onCallEnded)==null||N.call(L,F)}),it.on("sync_call_unanswered",F=>{var L,N;z(!1),(N=(L=M.current).onCallUnanswered)==null||N.call(L,F)})];return()=>Z.forEach(F=>F())},[]);const X=rb[r]||rb["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,Ee=r!=null&&r.includes("right")?"origin-bottom-right":"origin-bottom-left";return he.jsxs("div",{className:i?void 0:`fixed ${X} z-[9999] flex flex-col gap-3`,style:A,children:[he.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${Ee} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${C?"animate-slideUp":"hidden"}`,children:[he.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[he.jsx("div",{className:"flex items-center gap-2.5",children:he.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),he.jsx("button",{onClick:()=>b(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:he.jsx(ZT,{className:"w-4 h-4"})})]}),he.jsx(HR,{initialRegisterStatus:R,autoReady:U,showAuxButton:q,auxOptions:K})]}),he.jsxs("button",{onClick:()=>b(Z=>!Z),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:[he.jsx(Ev,{className:"w-5 h-5"}),j&&he.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),he.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(Wh.createRoot){const i=Wh.createRoot(r);return i.render(o),{render:l=>i.render(l),unmount:()=>i.unmount()}}return Wh.render(o,r),{render:i=>Wh.render(i,r),unmount:()=>Wh.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 B=LT.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(B,us),{answer:()=>it.emitLocal("local_answer"),hangup:()=>it.emitLocal("local_hangup"),reject:()=>it.emitLocal("local_reject"),mute:M=>it.emitLocal("local_toggle_mute",{muted:M}),hold:M=>it.emitLocal("local_toggle_hold",{isOnHold:M,setIsOnHold:()=>{}}),dial:M=>it.emitLocal("local_dial",{number:M}),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
|
@@ -18112,17 +18112,6 @@ const ku = () => {
|
|
|
18112
18112
|
try {
|
|
18113
18113
|
const d = hr.makeURI(`sip:${t}@${i}`);
|
|
18114
18114
|
if (!d) throw new Error("Failed to create SIP URI");
|
|
18115
|
-
console.log("init...", {
|
|
18116
|
-
uri: d,
|
|
18117
|
-
transportOptions: { server: c },
|
|
18118
|
-
authorizationUsername: t,
|
|
18119
|
-
authorizationPassword: s,
|
|
18120
|
-
sessionDescriptionHandlerFactoryOptions: {
|
|
18121
|
-
peerConnectionConfiguration: { iceServers: [] },
|
|
18122
|
-
constraints: { audio: !0, video: !1 }
|
|
18123
|
-
},
|
|
18124
|
-
logLevel: "warn"
|
|
18125
|
-
});
|
|
18126
18115
|
const c = `wss://${i}:${n}`, l = new hr({
|
|
18127
18116
|
uri: d,
|
|
18128
18117
|
transportOptions: { server: c },
|
|
@@ -18138,7 +18127,11 @@ const ku = () => {
|
|
|
18138
18127
|
const g = new _t(l);
|
|
18139
18128
|
g.stateChange.addListener(async (u) => {
|
|
18140
18129
|
var y;
|
|
18141
|
-
u === pe.Registered ? ((y = Ve.getConfig()) == null ? void 0 : y.autoReady) !== !1 ? await Ve.updateExtensionStatus(
|
|
18130
|
+
u === pe.Registered ? ((y = Ve.getConfig()) == null ? void 0 : y.autoReady) !== !1 ? await Ve.updateExtensionStatus(
|
|
18131
|
+
t,
|
|
18132
|
+
"Ready",
|
|
18133
|
+
"ready"
|
|
18134
|
+
) ? (Z.emitLocal("register_status", "REGISTERED"), Z.emitLocal("agent_status", "READY")) : Z.emitLocal("register_status", {
|
|
18142
18135
|
status: "FAILED",
|
|
18143
18136
|
reason: "Failed to hit extension ready API"
|
|
18144
18137
|
}) : (Z.emitLocal("register_status", "REGISTERED"), Z.emitLocal("agent_status", "NOT_READY")) : (u === pe.Unregistered || u === pe.Terminated) && Z.emitLocal("register_status", {
|
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=qh,Y.months=Uh,Y.isDate=Lr,Y.locale=Jt,Y.invalid=ps,Y.duration=xt,Y.isMoment=ft,Y.weekdays=Yh,Y.parseZone=jh,Y.localeData=Nt,Y.isDuration=Fs,Y.monthsShort=Lh,Y.weekdaysMin=Gh,Y.defineLocale=cn,Y.updateLocale=jl,Y.locales=Ul,Y.weekdaysShort=Wh,Y.normalizeUnits=nt,Y.relativeTimeRounding=yu,Y.relativeTimeThreshold=wu,Y.calendarFormat=Od,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 Os=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 No(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 Mo(){St&&(St.srcObject=null,St.pause())}const Cu=()=>{Z.on("incoming_call",()=>{Ge.pushSound()}),Z.on("local_dial",({number:r})=>{if(Os){const e=lr.makeURI(`sip:${r}@${Os.configuration.uri.domain}`),t=new Ra(Os,e);t.stateChange.addListener(s=>{s===B.Establishing?Z.emitLocal("call_status","Calling..."):s===B.Established?(No(t),Se=t,Z.emitLocal("call_status","InCall")):s===B.Terminated&&(Mo(),Z.emitLocal("call_status","Idle"),Se=null)}),t.invite()}}),Z.on("local_hangup",()=>{Ge.stopSound(),Se&&(Se.state===B.Established?Se.bye():typeof Se.reject=="function"?Se.reject():Se.cancel()),Z.emitLocal("call_status","Idle"),Z.emitLocal("call_duration","00:00"),Z.emitToParent("sync_call_ended")}),Z.on("local_reject",()=>{Ge.stopSound(),Se&&(typeof Se.reject=="function"?Se.reject():Se.cancel()),Z.emitLocal("call_status","Idle"),Z.emitLocal("call_duration","00:00"),Z.emitToParent("sync_call_ended")}),Z.on("local_answer",()=>{Ge.stopSound();const r={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};Se&&Se.accept(r)}),Z.on("local_toggle_mute",({muted:r})=>{Se&&bu(Se,!r)}),Z.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)}}),Z.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");
|
|
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 Mo(){St&&(St.srcObject=null,St.pause())}const Cu=()=>{Z.on("incoming_call",()=>{Ge.pushSound()}),Z.on("local_dial",({number:r})=>{if(Os){const e=lr.makeURI(`sip:${r}@${Os.configuration.uri.domain}`),t=new Ra(Os,e);t.stateChange.addListener(s=>{s===B.Establishing?Z.emitLocal("call_status","Calling..."):s===B.Established?(No(t),Se=t,Z.emitLocal("call_status","InCall")):s===B.Terminated&&(Mo(),Z.emitLocal("call_status","Idle"),Se=null)}),t.invite()}}),Z.on("local_hangup",()=>{Ge.stopSound(),Se&&(Se.state===B.Established?Se.bye():typeof Se.reject=="function"?Se.reject():Se.cancel()),Z.emitLocal("call_status","Idle"),Z.emitLocal("call_duration","00:00"),Z.emitToParent("sync_call_ended")}),Z.on("local_reject",()=>{Ge.stopSound(),Se&&(typeof Se.reject=="function"?Se.reject():Se.cancel()),Z.emitLocal("call_status","Idle"),Z.emitLocal("call_duration","00:00"),Z.emitToParent("sync_call_ended")}),Z.on("local_answer",()=>{Ge.stopSound();const r={sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}};Se&&Se.accept(r)}),Z.on("local_toggle_mute",({muted:r})=>{Se&&bu(Se,!r)}),Z.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)}}),Z.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://${i}:${n}`,l=new lr({uri:d,transportOptions:{server:c},authorizationUsername:t,authorizationPassword:s,sessionDescriptionHandlerFactoryOptions:{peerConnectionConfiguration:{iceServers:[]},constraints:{audio:!0,video:!1}},logLevel:"warn"});Os=l;const g=new Et(l);g.stateChange.addListener(async u=>{var y;u===me.Registered?((y=Ge.getConfig())==null?void 0:y.autoReady)!==!1?await Ge.updateExtensionStatus(t,"Ready","ready")?(Z.emitLocal("register_status","REGISTERED"),Z.emitLocal("agent_status","READY")):Z.emitLocal("register_status",{status:"FAILED",reason:"Failed to hit extension ready API"}):(Z.emitLocal("register_status","REGISTERED"),Z.emitLocal("agent_status","NOT_READY")):(u===me.Unregistered||u===me.Terminated)&&Z.emitLocal("register_status",{status:"FAILED",reason:"SIP Unregistered or Terminated"})}),l.delegate={onInvite(u){let y=!1;Se=u,Z.emitLocal("sipjsSession",u),Ge.pushSound(),Ge.pushNotification(`New incoming call from ${u.remoteIdentity.uri.user}`),Z.emitLocal("incoming_call",u),Z.emitToParent("sync_incoming_call",u),u.stateChange.addListener(w=>{if(w===B.Established){No(u),y=!0,Z.emitLocal("call_status","InCall"),Z.emitToParent("sync_call_answered",u);const b=Y();Oo=setInterval(()=>{const C=Y.duration(Y().diff(b));Z.emitLocal("call_duration",Ge.toHHMMSS(C.asSeconds()))},1e3)}else w===B.Terminated&&(Mo(),clearInterval(Oo),Ge.stopSound(),Z.emitLocal("call_duration","00:00"),Z.emitLocal("call_status","Idle"),y?Z.emitToParent("sync_call_ended",u):Z.emitToParent("sync_call_unanswered"),Se=null)})}},await l.start(),await g.register()}catch(d){console.error("SipJS init error:",d),Z.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]=re.useState(!1),[g,u]=re.useState("CONNECTING"),[y,w]=re.useState("NOT_READY"),[b,C]=re.useState(!1),x=re.useRef(!1),p=re.useRef({}),E=(r==null?void 0:r.autoReady)!==!1,_=(r==null?void 0:r.showAuxButton)===!0,T=(r==null?void 0:r.auxOptions)||[];re.useEffect(()=>{p.current={onIncomingCall:s,onCallAnswered:i,onCallEnded:n,onCallUnanswered:a,onRegisterStatus:o,onAgentStatus:d}}),re.useEffect(()=>{var f;r&&Ge.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]),re.useEffect(()=>{const A=[Z.on("register_status",f=>{var m,U;const v=typeof f=="string"?f:(f==null?void 0:f.status)??"FAILED";u(v),v==="REGISTERED"&&l(!0),(U=(m=p.current).onRegisterStatus)==null||U.call(m,v==="FAILED"?f:v)}),Z.on("agent_status",f=>{var v,m;w(f),(m=(v=p.current).onAgentStatus)==null||m.call(v,f)}),Z.on("sync_incoming_call",f=>{var v,m;C(!0),l(!0),(m=(v=p.current).onIncomingCall)==null||m.call(v,f)}),Z.on("sync_call_answered",f=>{var v,m;C(!1),(m=(v=p.current).onCallAnswered)==null||m.call(v,f)}),Z.on("sync_call_ended",f=>{var v,m;C(!1),(m=(v=p.current).onCallEnded)==null||m.call(v,f)}),Z.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 S=qo[e]||qo["bottom-left"],R=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,N=e!=null&&e.includes("right")?"origin-bottom-right":"origin-bottom-left";return F.jsxs("div",{className:t?void 0:`fixed ${S} z-[9999] flex flex-col gap-3`,style:h,children:[F.jsxs("div",{className:`w-[360px] bg-white rounded-3xl overflow-hidden ${N} shadow-[0_20px_60px_rgba(0,0,0,0.18),0_4px_16px_rgba(0,0,0,0.08)] ${c?"animate-slideUp":"hidden"}`,children:[F.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 bg-gradient-to-r from-[#3f3192] to-[#5240c2]",children:[F.jsx("div",{className:"flex items-center gap-2.5",children:F.jsx("span",{className:"text-white font-semibold text-sm tracking-wide",children:"Voice Widget"})}),F.jsx("button",{onClick:()=>l(!1),className:"text-white/50 hover:text-white transition-colors p-1 rounded-lg",title:"Minimize",children:F.jsx(Xo,{className:"w-4 h-4"})})]}),F.jsx($0,{initialRegisterStatus:g,autoReady:E,showAuxButton:_,auxOptions:T})]}),F.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:[F.jsx(as,{className:"w-5 h-5"}),b&&F.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-green-500 border-2 border-white animate-ping"}),F.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white ${R}`})]})]})}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=re.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:()=>Z.emitLocal("local_answer"),hangup:()=>Z.emitLocal("local_hangup"),reject:()=>Z.emitLocal("local_reject"),mute:p=>Z.emitLocal("local_toggle_mute",{muted:p}),hold:p=>Z.emitLocal("local_toggle_hold",{isOnHold:p,setIsOnHold:()=>{}}),dial:p=>Z.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"})});
|