@tbisoftware/phone 1.0.9 → 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/index.cjs CHANGED
@@ -65,4 +65,4 @@ ${d}
65
65
  `,T+=`Call-ID: ${n.call_id}\r
66
66
  `,T+=`CSeq: ${n.cseq} ${n.method}\r
67
67
  `,T+=`\r
68
- `,c.send(T)}return _s}var dt={},Kn;function pi(){if(Kn)return dt;Kn=1;const b=fe(),y=oe(),i=Ce(),_=ye(),S=ll(),t=we();dt.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:y.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,register_from_tag_trail:"",registrar_server:null,sockets:null,connection_recovery_max_interval:y.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:y.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${b.createRandomToken(12)}.invalid`};const d={mandatory:{sockets(h){const n=[];if(S.isSocket(h))n.push({socket:h});else if(Array.isArray(h)&&h.length)for(const m of h)Object.prototype.hasOwnProperty.call(m,"socket")&&S.isSocket(m.socket)?n.push(m):S.isSocket(m)&&n.push({socket:m});else return;return n},uri(h){/^sip:/i.test(h)||(h=`${y.SIP}:${h}`);const n=_.parse(h);if(n)return n.user?n:void 0}},optional:{authorization_user(h){if(i.parse(`"${h}"`,"quoted_string")!==-1)return h},authorization_jwt(h){if(typeof h=="string")return h},user_agent(h){if(typeof h=="string")return h},connection_recovery_max_interval(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},connection_recovery_min_interval(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},contact_uri(h){if(typeof h=="string"){const n=i.parse(h,"SIP_URI");if(n!==-1)return n}},display_name(h){return h},instance_id(h){if(/^uuid:/i.test(h)&&(h=h.substr(5)),i.parse(h,"uuid")!==-1)return h},no_answer_timeout(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},session_timers(h){if(typeof h=="boolean")return h},session_timers_refresh_method(h){if(typeof h=="string"&&(h=h.toUpperCase(),h===y.INVITE||h===y.UPDATE))return h},session_timers_force_refresher(h){if(typeof h=="boolean")return h},password(h){return String(h)},realm(h){return String(h)},ha1(h){return String(h)},register(h){if(typeof h=="boolean")return h},register_expires(h){if(b.isDecimal(h)){const n=Number(h);if(n>=0)return n}},register_from_tag_trail(h){return typeof h=="function"?h:String(h)},registrar_server(h){/^sip:/i.test(h)||(h=`${y.SIP}:${h}`);const n=_.parse(h);if(n)return n.user?void 0:n},use_preloaded_route(h){if(typeof h=="boolean")return h},extra_headers(h){const n=[];if(Array.isArray(h)&&h.length)for(const m of h)typeof m=="string"&&n.push(m);else return;return n}}};return dt.load=(h,n)=>{for(const m in d.mandatory)if(n.hasOwnProperty(m)){const c=n[m],R=d.mandatory[m](c);if(R!==void 0)h[m]=R;else throw new t.ConfigurationError(m,c)}else throw new t.ConfigurationError(m);for(const m in d.optional)if(n.hasOwnProperty(m)){const c=n[m];if(b.isEmpty(c))continue;const R=d.optional[m](c);if(R!==void 0)h[m]=R;else throw new t.ConfigurationError(m,c)}},dt}var ps,Yn;function mi(){if(Yn)return ps;Yn=1;const b=Ie().EventEmitter,y=ce(),i=oe(),_=ri(),S=nl(),t=ci(),d=fi(),h=We(),n=hi(),m=fe(),c=we(),R=ye(),D=di(),E=Se(),N=_i(),$=pi(),C=new y("UA"),I={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};ps=class extends b{static get C(){return I}constructor(p){if(!p)throw new TypeError("Not enough arguments");const A=["password","ha1","authorization_jwt"];C.debug("new() [configuration:%o]",Object.entries(p).filter(([O])=>!A.includes(O))),super(),this._cache={credentials:{}},this._configuration=Object.assign({},$.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=I.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null;try{this._loadConfig(p)}catch(O){throw this._status=I.STATUS_NOT_READY,this._error=I.CONFIGURATION_ERROR,O}this._registrator=new _(this)}get C(){return I}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){C.debug("start()"),this._status===I.STATUS_INIT?this._transport.connect():this._status===I.STATUS_USER_CLOSED?(C.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=I.STATUS_INIT,this._transport.connect()):this._status===I.STATUS_READY?C.debug("UA is in READY status, not restarted"):C.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){C.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(p){C.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(p)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(p,A){C.debug("call()");const O=new S(this);return O.connect(p,A),O}sendMessage(p,A,O){C.debug("sendMessage()");const v=new t(this);return v.send(p,A,O),v}sendOptions(p,A,O){C.debug("sendOptions()");const v=new d(this);return v.send(p,A,O),v}terminateSessions(p){C.debug("terminateSessions()");for(const A in this._sessions)this._sessions[A].isEnded()||this._sessions[A].terminate(p)}stop(){if(C.debug("stop()"),this._dynConfiguration={},this._status===I.STATUS_USER_CLOSED){C.debug("UA already closed");return}this._registrator.close();const p=Object.keys(this._sessions).length;for(const O in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,O)){C.debug(`closing session ${O}`);try{this._sessions[O].terminate()}catch{}}for(const O in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,O))try{this._applicants[O].close()}catch{}this._status=I.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&p===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(p){return m.normalizeTarget(p,this._configuration.hostport_params)}get(p){switch(p){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:C.warn('get() | cannot get "%s" parameter in runtime',p);return}}set(p,A){switch(p){case"authorization_user":{this._configuration.authorization_user=String(A);break}case"password":{this._configuration.password=String(A);break}case"realm":{this._configuration.realm=String(A);break}case"ha1":{this._configuration.ha1=String(A),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(A);break}case"display_name":{this._configuration.display_name=A;break}case"extra_headers":{this._configuration.extra_headers=A;break}default:return C.warn('set() | cannot set "%s" parameter in runtime',p),!1}return!0}newTransaction(p){this._transactions[p.type][p.id]=p,this.emit("newTransaction",{transaction:p})}destroyTransaction(p){delete this._transactions[p.type][p.id],this.emit("transactionDestroyed",{transaction:p})}newDialog(p){this._dialogs[p.id]=p}destroyDialog(p){delete this._dialogs[p.id]}newMessage(p,A){this._applicants[p]=p,this.emit("newMessage",A)}newOptions(p,A){this._applicants[p]=p,this.emit("newOptions",A)}destroyMessage(p){delete this._applicants[p]}newRTCSession(p,A){this._sessions[p.id]=p,this.emit("newRTCSession",A)}destroyRTCSession(p){delete this._sessions[p.id]}registered(p){this.emit("registered",p)}unregistered(p){this.emit("unregistered",p)}registrationFailed(p){this.emit("registrationFailed",p)}receiveRequest(p){const A=p.method;if(p.ruri.user!==this._configuration.uri.user&&p.ruri.user!==this._contact.uri.user){C.debug("Request-URI does not point to us"),p.method!==i.ACK&&p.reply_sl(404);return}if(p.ruri.scheme===i.SIPS){p.reply_sl(416);return}if(h.checkTransaction(this,p))return;if(A===i.INVITE?new h.InviteServerTransaction(this,this._transport,p):A!==i.ACK&&A!==i.CANCEL&&new h.NonInviteServerTransaction(this,this._transport,p),A===i.OPTIONS){if(this.listeners("newOptions").length===0){p.reply(200);return}new d(this).init_incoming(p)}else if(A===i.MESSAGE){if(this.listeners("newMessage").length===0){p.reply(405);return}new t(this).init_incoming(p)}else if(A===i.INVITE&&!p.to_tag&&this.listeners("newRTCSession").length===0){p.reply(405);return}let O,v;if(p.to_tag)O=this._findDialog(p.call_id,p.from_tag,p.to_tag),O?O.receiveRequest(p):A===i.NOTIFY?(v=this._findSession(p),v?v.receiveRequest(p):(C.debug("received NOTIFY request for a non existent subscription"),p.reply(481,"Subscription does not exist"))):A!==i.ACK&&p.reply(481);else switch(A){case i.INVITE:if(window.RTCPeerConnection)if(p.hasHeader("replaces")){const w=p.replaces;O=this._findDialog(w.call_id,w.from_tag,w.to_tag),O?(v=O.owner,v.isEnded()?p.reply(603):v.receiveRequest(p)):p.reply(481)}else v=new S(this),v.init_incoming(p);else C.warn("INVITE received but WebRTC is not supported"),p.reply(488);break;case i.BYE:p.reply(481);break;case i.CANCEL:v=this._findSession(p),v?v.receiveRequest(p):C.debug("received CANCEL request for a non existent session");break;case i.ACK:break;case i.NOTIFY:this.emit("sipEvent",{event:p.event,request:p}),p.reply(200);break;default:p.reply(405);break}}_findSession({call_id:p,from_tag:A,to_tag:O}){const v=p+A,w=this._sessions[v],U=p+O,M=this._sessions[U];return w||M||null}_findDialog(p,A,O){let v=p+A+O,w=this._dialogs[v];return w||(v=p+O+A,w=this._dialogs[v],w||null)}_loadConfig(p){try{$.load(this._configuration,p)}catch(v){throw v}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=m.newUUID()),this._configuration.jssip_id=m.createRandomToken(5);const A=this._configuration.uri.clone();A.user=null,this._configuration.hostport_params=A.toString().replace(/^sip:/i,"");try{this._transport=new n(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=F.bind(this),this._transport.onconnect=H.bind(this),this._transport.ondisconnect=o.bind(this),this._transport.ondata=f.bind(this)}catch(v){throw C.warn(v),new c.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const v=this._configuration.uri.clone();v.user=null,v.clearParams(),v.clearHeaders(),this._configuration.registrar_server=v}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new R("sip",m.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(v={}){const w=v.anonymous||null,U=v.outbound||null;let M="<";return w?M+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":M+=this.pub_gruu||this.uri.toString(),U&&(w?!this.temp_gruu:!this.pub_gruu)&&(M+=";ob"),M+=">",M}};const O=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register","extra_headers"];for(const v in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,v)&&(O.indexOf(v)!==-1?Object.defineProperty(this._configuration,v,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,v,{writable:!1,configurable:!1}));C.debug("configuration parameters after validation:");for(const v in this._configuration)if(Object.prototype.hasOwnProperty.call($.settings,v))switch(v){case"uri":case"registrar_server":C.debug(`- ${v}: ${this._configuration[v]}`);break;case"password":case"ha1":case"authorization_jwt":C.debug(`- ${v}: NOT SHOWN`);break;default:C.debug(`- ${v}: ${JSON.stringify(this._configuration[v])}`)}}};function F(T){this.emit("connecting",T)}function H(T){this._status!==I.STATUS_USER_CLOSED&&(this._status=I.STATUS_READY,this._error=null,this.emit("connected",T),this._dynConfiguration.register&&this._registrator.register())}function o(T){const p=["nict","ict","nist","ist"];for(const A of p)for(const O in this._transactions[A])Object.prototype.hasOwnProperty.call(this._transactions[A],O)&&this._transactions[A][O].onTransportError();this.emit("disconnected",T),this._registrator.onTransportClosed(),this._status!==I.STATUS_USER_CLOSED&&(this._status=I.STATUS_NOT_READY,this._error=I.NETWORK_ERROR)}function f(T){const p=T.transport;let A=T.message;if(A=D.parseMessage(A,this),!!A&&!(this._status===I.STATUS_USER_CLOSED&&A instanceof E.IncomingRequest)&&N(A,this,p)){if(A instanceof E.IncomingRequest)A.transport=p,this.receiveRequest(A);else if(A instanceof E.IncomingResponse){let O;switch(A.method){case i.INVITE:O=this._transactions.ict[A.via_branch],O&&O.receiveResponse(A);break;case i.ACK:break;default:O=this._transactions.nict[A.via_branch],O&&O.receiveResponse(A);break}}}}return ps}var ms,Jn;function gi(){if(Jn)return ms;Jn=1;const b=ce(),y=Ce(),i=new b("WebSocketInterface");return ms=class{constructor(S){i.debug('new() [url:"%s"]',S),this._url=S,this._sip_uri=null,this._via_transport=null,this._ws=null;const t=y.parse(S,"absoluteURI");if(t===-1)throw i.warn(`invalid WebSocket URI: ${S}`),new TypeError(`Invalid argument: ${S}`);if(t.scheme!=="wss"&&t.scheme!=="ws")throw i.warn(`invalid WebSocket URI scheme: ${t.scheme}`),new TypeError(`Invalid argument: ${S}`);this._sip_uri=`sip:${t.host}${t.port?`:${t.port}`:""};transport=ws`,this._via_transport=t.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(S){this._via_transport=S.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(i.debug("connect()"),this.isConnected()){i.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){i.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),i.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(S){this._onError(S)}}disconnect(){i.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(S){return i.debug("send()"),this.isConnected()?(this._ws.send(S),!0):(i.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){i.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:S,code:t,reason:d}){i.debug(`WebSocket ${this._url} closed`),S===!1&&i.debug("WebSocket abrupt disconnection"),this.ondisconnect(!S,t,d)}_onMessage({data:S}){i.debug("received WebSocket message"),this.ondata(S)}_onError(S){i.warn(`WebSocket ${this._url} error: `,S)}},ms}var gs,Xn;function Ti(){if(Xn)return gs;Xn=1;const b=Zn,y=oe(),i=we(),_=fe(),S=mi(),t=ye(),d=As(),h=Ce(),n=gi(),m=vs()("JsSIP"),c=nl();return m("version %s",b.version),gs={C:y,Exceptions:i,Utils:_,UA:S,URI:t,NameAddrHeader:d,WebSocketInterface:n,Grammar:h,RTCSession:c,debug:vs(),get name(){return b.title},get version(){return b.version}},gs}var Ci=Ti();const Qn=Yl(Ci);let Me=null,Ts=null;function vi(b){return`${b.websocketUrl}|${b.sipUri}|${b.authorizationUser}`}function Ei(b){const y=vi(b);if(Me&&Ts===y)return Me;if(Me&&Ts!==y){try{Me.ua.stop()}catch{}Me=null}Ts=y;const _={sockets:[new Qn.WebSocketInterface(b.websocketUrl)],uri:b.sipUri,password:b.password,registrar_server:b.registrarServer,display_name:b.displayName,authorization_user:b.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},S=new Qn.UA(_),t=document.createElement("audio");t.autoplay=!0;const d={ua:S,audio:t,isStarted:!1,listeners:new Set};return S.on("connecting",()=>{d.listeners.forEach(h=>h.onConnecting?.())}),S.on("connected",()=>{d.listeners.forEach(h=>h.onConnected?.())}),S.on("disconnected",()=>{d.listeners.forEach(h=>h.onDisconnected?.())}),S.on("registered",()=>{d.listeners.forEach(h=>h.onRegistered?.())}),S.on("unregistered",()=>{d.listeners.forEach(h=>h.onUnregistered?.())}),S.on("registrationFailed",h=>{d.listeners.forEach(n=>n.onRegistrationFailed?.(h?.cause))}),S.on("newRTCSession",h=>{const n=h.session;n.direction==="outgoing"&&(d.listeners.forEach(m=>m.onNewSession?.(n)),n.on("peerconnection",()=>{n.connection.addEventListener("track",m=>{m.streams&&m.streams[0]&&(d.audio.srcObject=m.streams[0],d.audio.play().catch(console.error))})}))}),Me=d,d}function Si(b){b.isStarted||(b.ua.start(),b.isStarted=!0)}function Ai(b,y){b.listeners.add(y)}function Ri(b,y){b.listeners.delete(y)}function bi(b){return{isReady:b.ua.isRegistered(),isConnected:b.ua.isConnected()}}const il=re.createContext(null);function al({config:b,children:y,onCallStart:i,onCallEnd:_,onStatusChange:S}){const[t,d]=re.useState(""),[h,n]=re.useState("disconnected"),[m,c]=re.useState(null),[R,D]=re.useState(0),[E,N]=re.useState([]),[$,C]=re.useState(!1),[I,F]=re.useState("connecting"),H=re.useRef(null),o=re.useRef(null),f=re.useRef(null);re.useEffect(()=>{o.current=m},[m]),re.useEffect(()=>{const v=Ei(b);f.current=v;const w=bi(v);w.isReady?(C(!0),F("connected")):w.isConnected&&F("connected");const U={onConnecting:()=>F("connecting"),onConnected:()=>F("connected"),onDisconnected:()=>{F("disconnected"),C(!1)},onRegistered:()=>{C(!0),F("connected")},onUnregistered:()=>C(!1),onRegistrationFailed:M=>{console.error("Registration failed:",M),C(!1),F("failed")},onNewSession:M=>{H.current=M}};return Ai(v,U),Si(v),()=>{Ri(v,U)}},[b.websocketUrl,b.sipUri,b.password,b.registrarServer,b.displayName,b.authorizationUser]),re.useEffect(()=>{S?.(h)},[h,S]),re.useEffect(()=>{const v=localStorage.getItem("tbi-phone-call-history");if(v)try{N(JSON.parse(v))}catch(w){console.error("Error loading call history",w)}},[]),re.useEffect(()=>{E.length>0&&localStorage.setItem("tbi-phone-call-history",JSON.stringify(E))},[E]),re.useEffect(()=>{if(h==="confirmed"&&m){const v=setInterval(()=>{D(Math.floor((Date.now()-m)/1e3))},1e3);return()=>clearInterval(v)}else D(0)},[h,m]),re.useEffect(()=>{const v=w=>{const U=w.detail.number;h==="disconnected"&&A(U)};return window.addEventListener("StartCallEvent",v),()=>{window.removeEventListener("StartCallEvent",v)}},[h]);const T=re.useCallback((v,w,U)=>{const M={id:Date.now().toString(),number:v,timestamp:Date.now(),duration:w,status:U};N(Y=>[M,...Y].slice(0,50))},[]),p=re.useCallback(()=>{H.current&&(H.current.terminate(),H.current=null)},[]),A=re.useCallback(v=>{const w=f.current;if(!v.trim()||!w)return;if(!$){console.warn("Phone is not ready yet. Please wait for registration.");return}d(v),i?.(v);const M={eventHandlers:{progress:()=>{n("progress")},failed:Y=>{console.error("Call failed:",Y?.cause),n("failed"),T(v,0,"failed"),_?.(v,0,"failed"),H.current=null,setTimeout(()=>n("disconnected"),3e3)},ended:()=>{n("ended");const Y=o.current,B=Y?Math.floor((Date.now()-Y)/1e3):0;T(v,B,"completed"),_?.(v,B,"completed"),H.current=null,setTimeout(()=>{n("disconnected"),c(null)},2e3)},confirmed:()=>{n("confirmed"),c(Date.now())}},mediaConstraints:{audio:!0,video:!1}};n("progress");try{const Y=w.ua.call(v,M);H.current=Y}catch(Y){console.error("Failed to start call:",Y),n("failed"),T(v,0,"failed"),setTimeout(()=>n("disconnected"),3e3)}},[T,i,_,$]),O={status:h,callNumber:t,setCallNumber:d,callHistory:E,currentCallDuration:R,startCall:A,endCall:p,isReady:$,connectionStatus:I};return q.jsx(il.Provider,{value:O,children:y})}function ol(){const b=re.useContext(il);if(!b)throw new Error("usePhone must be used within a PhoneProvider");return b}const Ss=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})}),wi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),yi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z"})}),_t=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})}),ul=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"})}),Ii=({className:b})=>q.jsxs("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:[q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"}),q.jsx("path",{d:"M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z"})]}),xi=({className:b})=>q.jsxs("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:[q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"}),q.jsx("path",{d:"M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z"})]}),Ni=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"})}),Oi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})});function Di({className:b,labels:y}){const{status:i,callNumber:_,setCallNumber:S,callHistory:t,currentCallDuration:d,startCall:h,endCall:n,isReady:m,connectionStatus:c}=ol(),[R,D]=re.useState(!1),E={...Kl,...y},$=(()=>{switch(i){case"progress":return{text:`${E.calling}...`,color:"text-yellow-500",Icon:wi};case"confirmed":return{text:`${E.inCall} - ${pt(d)}`,color:"text-green-500",Icon:yi};case"failed":return{text:E.callEnded,color:"text-red-500",Icon:ul};case"ended":return{text:E.callEnded,color:"text-gray-500",Icon:_t};default:return{text:E.inactive,color:"text-gray-300",Icon:Ss}}})();return q.jsxs("div",{className:Cs("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",b),children:[i==="disconnected"&&q.jsxs("div",{className:"flex gap-2 items-center",children:[q.jsx("button",{onClick:()=>D(!0),className:"h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",type:"button",children:q.jsx(Ni,{className:"w-4 h-4"})}),q.jsx("input",{type:"text",value:_,onChange:C=>S(C.target.value),onKeyDown:C=>{C.key==="Enter"&&h(_)},placeholder:E.placeholder,className:"flex-1 h-8 px-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"}),q.jsx("button",{onClick:()=>h(_),disabled:_.length<9||!m,className:"h-8 w-8 flex items-center justify-center rounded-xl bg-green-500 hover:bg-green-600 disabled:bg-gray-300 disabled:cursor-not-allowed text-white transition-colors",type:"button",title:m?"Call":"Connecting...",children:c==="connecting"?q.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}):q.jsx(Ss,{className:"w-4 h-4"})})]}),i==="progress"&&q.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[q.jsxs("div",{className:"relative",children:[q.jsx($.Icon,{className:"w-12 h-12 text-yellow-500 animate-pulse"}),q.jsx("div",{className:"absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping"})]}),q.jsxs("div",{className:"text-center",children:[q.jsxs("p",{className:"text-base font-semibold",children:[E.calling," ",_]}),q.jsx("p",{className:"text-sm text-gray-500",children:E.waitingResponse})]}),q.jsxs("button",{onClick:n,className:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button",children:[q.jsx(_t,{className:"w-4 h-4"}),E.cancel]})]}),i==="confirmed"&&q.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[q.jsxs("div",{className:"relative",children:[q.jsx($.Icon,{className:"w-12 h-12 text-green-500"}),q.jsx("div",{className:"absolute inset-0 rounded-full bg-green-500/20 animate-pulse"})]}),q.jsxs("div",{className:"text-center space-y-1",children:[q.jsx("p",{className:"text-xl font-bold",children:_}),q.jsx("p",{className:"text-2xl font-mono text-green-600 tabular-nums",children:pt(d)})]}),q.jsxs("button",{onClick:n,className:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button",children:[q.jsx(_t,{className:"w-4 h-4"}),E.hangUp]})]}),(i==="failed"||i==="ended")&&q.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[q.jsx($.Icon,{className:Cs("w-12 h-12",i==="failed"?"text-red-500":"text-gray-500")}),q.jsx("div",{className:"text-center",children:q.jsx("p",{className:"text-base font-semibold",children:$.text})})]}),R&&q.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[q.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>D(!1)}),q.jsx("div",{className:"fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",children:q.jsxs("div",{className:"flex flex-col h-full",children:[q.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[q.jsxs("div",{children:[q.jsx("h2",{className:"text-lg font-semibold",children:E.callHistory}),q.jsx("p",{className:"text-sm text-gray-500",children:t.length===0?E.noCallsRegistered:`${t.length} ${E.callsRegistered}`})]}),q.jsx("button",{onClick:()=>D(!1),className:"h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:q.jsx(Oi,{className:"w-5 h-5"})})]}),q.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:t.length===0?q.jsxs("div",{className:"text-center py-12 text-gray-500",children:[q.jsx(_t,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),q.jsx("p",{children:E.noCalls})]}):q.jsx("div",{className:"space-y-2",children:t.map((C,I)=>q.jsx(Ui,{entry:C,index:I,onCall:()=>{S(C.number),D(!1),h(C.number)}},C.id))})})]})})]})]})}function Ui({entry:b,index:y,onCall:i}){const _=()=>{switch(b.status){case"completed":return q.jsx(Ii,{className:"w-4 h-4 text-green-600"});case"failed":return q.jsx(xi,{className:"w-4 h-4 text-red-600"});case"missed":return q.jsx(ul,{className:"w-4 h-4 text-yellow-600"})}},S=()=>{switch(b.status){case"completed":return"bg-green-100";case"failed":return"bg-red-100";case"missed":return"bg-yellow-100"}};return q.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",style:{animationDelay:`${y*30}ms`},children:[q.jsx("div",{className:Cs("w-9 h-9 rounded-full flex items-center justify-center shrink-0",S()),children:_()}),q.jsxs("div",{className:"flex-1 min-w-0",children:[q.jsx("p",{className:"font-medium text-sm truncate",children:b.number}),q.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[q.jsx("span",{children:new Date(b.timestamp).toLocaleString("es-ES",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}),b.duration>0&&q.jsxs(q.Fragment,{children:[q.jsx("span",{children:"•"}),q.jsx("span",{className:"font-mono tabular-nums",children:pt(b.duration)})]})]})]}),q.jsx("button",{onClick:i,className:"h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:q.jsx(Ss,{className:"w-4 h-4"})})]})}function Pi({config:b,className:y,onCallStart:i,onCallEnd:_,onStatusChange:S,labels:t}){return q.jsx(al,{config:b,onCallStart:i,onCallEnd:_,onStatusChange:S,children:q.jsx(Di,{className:y,labels:t})})}exports.Phone=Pi;exports.PhoneProvider=al;exports.formatDuration=pt;exports.usePhone=ol;
68
+ `,c.send(T)}return _s}var dt={},Kn;function pi(){if(Kn)return dt;Kn=1;const b=fe(),y=oe(),i=Ce(),_=ye(),S=ll(),t=we();dt.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:y.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,register_from_tag_trail:"",registrar_server:null,sockets:null,connection_recovery_max_interval:y.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:y.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${b.createRandomToken(12)}.invalid`};const d={mandatory:{sockets(h){const n=[];if(S.isSocket(h))n.push({socket:h});else if(Array.isArray(h)&&h.length)for(const m of h)Object.prototype.hasOwnProperty.call(m,"socket")&&S.isSocket(m.socket)?n.push(m):S.isSocket(m)&&n.push({socket:m});else return;return n},uri(h){/^sip:/i.test(h)||(h=`${y.SIP}:${h}`);const n=_.parse(h);if(n)return n.user?n:void 0}},optional:{authorization_user(h){if(i.parse(`"${h}"`,"quoted_string")!==-1)return h},authorization_jwt(h){if(typeof h=="string")return h},user_agent(h){if(typeof h=="string")return h},connection_recovery_max_interval(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},connection_recovery_min_interval(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},contact_uri(h){if(typeof h=="string"){const n=i.parse(h,"SIP_URI");if(n!==-1)return n}},display_name(h){return h},instance_id(h){if(/^uuid:/i.test(h)&&(h=h.substr(5)),i.parse(h,"uuid")!==-1)return h},no_answer_timeout(h){if(b.isDecimal(h)){const n=Number(h);if(n>0)return n}},session_timers(h){if(typeof h=="boolean")return h},session_timers_refresh_method(h){if(typeof h=="string"&&(h=h.toUpperCase(),h===y.INVITE||h===y.UPDATE))return h},session_timers_force_refresher(h){if(typeof h=="boolean")return h},password(h){return String(h)},realm(h){return String(h)},ha1(h){return String(h)},register(h){if(typeof h=="boolean")return h},register_expires(h){if(b.isDecimal(h)){const n=Number(h);if(n>=0)return n}},register_from_tag_trail(h){return typeof h=="function"?h:String(h)},registrar_server(h){/^sip:/i.test(h)||(h=`${y.SIP}:${h}`);const n=_.parse(h);if(n)return n.user?void 0:n},use_preloaded_route(h){if(typeof h=="boolean")return h},extra_headers(h){const n=[];if(Array.isArray(h)&&h.length)for(const m of h)typeof m=="string"&&n.push(m);else return;return n}}};return dt.load=(h,n)=>{for(const m in d.mandatory)if(n.hasOwnProperty(m)){const c=n[m],R=d.mandatory[m](c);if(R!==void 0)h[m]=R;else throw new t.ConfigurationError(m,c)}else throw new t.ConfigurationError(m);for(const m in d.optional)if(n.hasOwnProperty(m)){const c=n[m];if(b.isEmpty(c))continue;const R=d.optional[m](c);if(R!==void 0)h[m]=R;else throw new t.ConfigurationError(m,c)}},dt}var ps,Yn;function mi(){if(Yn)return ps;Yn=1;const b=Ie().EventEmitter,y=ce(),i=oe(),_=ri(),S=nl(),t=ci(),d=fi(),h=We(),n=hi(),m=fe(),c=we(),R=ye(),D=di(),E=Se(),N=_i(),$=pi(),C=new y("UA"),I={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};ps=class extends b{static get C(){return I}constructor(p){if(!p)throw new TypeError("Not enough arguments");const A=["password","ha1","authorization_jwt"];C.debug("new() [configuration:%o]",Object.entries(p).filter(([O])=>!A.includes(O))),super(),this._cache={credentials:{}},this._configuration=Object.assign({},$.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=I.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null;try{this._loadConfig(p)}catch(O){throw this._status=I.STATUS_NOT_READY,this._error=I.CONFIGURATION_ERROR,O}this._registrator=new _(this)}get C(){return I}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){C.debug("start()"),this._status===I.STATUS_INIT?this._transport.connect():this._status===I.STATUS_USER_CLOSED?(C.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=I.STATUS_INIT,this._transport.connect()):this._status===I.STATUS_READY?C.debug("UA is in READY status, not restarted"):C.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){C.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(p){C.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(p)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(p,A){C.debug("call()");const O=new S(this);return O.connect(p,A),O}sendMessage(p,A,O){C.debug("sendMessage()");const v=new t(this);return v.send(p,A,O),v}sendOptions(p,A,O){C.debug("sendOptions()");const v=new d(this);return v.send(p,A,O),v}terminateSessions(p){C.debug("terminateSessions()");for(const A in this._sessions)this._sessions[A].isEnded()||this._sessions[A].terminate(p)}stop(){if(C.debug("stop()"),this._dynConfiguration={},this._status===I.STATUS_USER_CLOSED){C.debug("UA already closed");return}this._registrator.close();const p=Object.keys(this._sessions).length;for(const O in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,O)){C.debug(`closing session ${O}`);try{this._sessions[O].terminate()}catch{}}for(const O in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,O))try{this._applicants[O].close()}catch{}this._status=I.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&p===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(p){return m.normalizeTarget(p,this._configuration.hostport_params)}get(p){switch(p){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:C.warn('get() | cannot get "%s" parameter in runtime',p);return}}set(p,A){switch(p){case"authorization_user":{this._configuration.authorization_user=String(A);break}case"password":{this._configuration.password=String(A);break}case"realm":{this._configuration.realm=String(A);break}case"ha1":{this._configuration.ha1=String(A),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(A);break}case"display_name":{this._configuration.display_name=A;break}case"extra_headers":{this._configuration.extra_headers=A;break}default:return C.warn('set() | cannot set "%s" parameter in runtime',p),!1}return!0}newTransaction(p){this._transactions[p.type][p.id]=p,this.emit("newTransaction",{transaction:p})}destroyTransaction(p){delete this._transactions[p.type][p.id],this.emit("transactionDestroyed",{transaction:p})}newDialog(p){this._dialogs[p.id]=p}destroyDialog(p){delete this._dialogs[p.id]}newMessage(p,A){this._applicants[p]=p,this.emit("newMessage",A)}newOptions(p,A){this._applicants[p]=p,this.emit("newOptions",A)}destroyMessage(p){delete this._applicants[p]}newRTCSession(p,A){this._sessions[p.id]=p,this.emit("newRTCSession",A)}destroyRTCSession(p){delete this._sessions[p.id]}registered(p){this.emit("registered",p)}unregistered(p){this.emit("unregistered",p)}registrationFailed(p){this.emit("registrationFailed",p)}receiveRequest(p){const A=p.method;if(p.ruri.user!==this._configuration.uri.user&&p.ruri.user!==this._contact.uri.user){C.debug("Request-URI does not point to us"),p.method!==i.ACK&&p.reply_sl(404);return}if(p.ruri.scheme===i.SIPS){p.reply_sl(416);return}if(h.checkTransaction(this,p))return;if(A===i.INVITE?new h.InviteServerTransaction(this,this._transport,p):A!==i.ACK&&A!==i.CANCEL&&new h.NonInviteServerTransaction(this,this._transport,p),A===i.OPTIONS){if(this.listeners("newOptions").length===0){p.reply(200);return}new d(this).init_incoming(p)}else if(A===i.MESSAGE){if(this.listeners("newMessage").length===0){p.reply(405);return}new t(this).init_incoming(p)}else if(A===i.INVITE&&!p.to_tag&&this.listeners("newRTCSession").length===0){p.reply(405);return}let O,v;if(p.to_tag)O=this._findDialog(p.call_id,p.from_tag,p.to_tag),O?O.receiveRequest(p):A===i.NOTIFY?(v=this._findSession(p),v?v.receiveRequest(p):(C.debug("received NOTIFY request for a non existent subscription"),p.reply(481,"Subscription does not exist"))):A!==i.ACK&&p.reply(481);else switch(A){case i.INVITE:if(window.RTCPeerConnection)if(p.hasHeader("replaces")){const w=p.replaces;O=this._findDialog(w.call_id,w.from_tag,w.to_tag),O?(v=O.owner,v.isEnded()?p.reply(603):v.receiveRequest(p)):p.reply(481)}else v=new S(this),v.init_incoming(p);else C.warn("INVITE received but WebRTC is not supported"),p.reply(488);break;case i.BYE:p.reply(481);break;case i.CANCEL:v=this._findSession(p),v?v.receiveRequest(p):C.debug("received CANCEL request for a non existent session");break;case i.ACK:break;case i.NOTIFY:this.emit("sipEvent",{event:p.event,request:p}),p.reply(200);break;default:p.reply(405);break}}_findSession({call_id:p,from_tag:A,to_tag:O}){const v=p+A,w=this._sessions[v],U=p+O,M=this._sessions[U];return w||M||null}_findDialog(p,A,O){let v=p+A+O,w=this._dialogs[v];return w||(v=p+O+A,w=this._dialogs[v],w||null)}_loadConfig(p){try{$.load(this._configuration,p)}catch(v){throw v}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=m.newUUID()),this._configuration.jssip_id=m.createRandomToken(5);const A=this._configuration.uri.clone();A.user=null,this._configuration.hostport_params=A.toString().replace(/^sip:/i,"");try{this._transport=new n(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=F.bind(this),this._transport.onconnect=H.bind(this),this._transport.ondisconnect=o.bind(this),this._transport.ondata=f.bind(this)}catch(v){throw C.warn(v),new c.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const v=this._configuration.uri.clone();v.user=null,v.clearParams(),v.clearHeaders(),this._configuration.registrar_server=v}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new R("sip",m.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(v={}){const w=v.anonymous||null,U=v.outbound||null;let M="<";return w?M+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":M+=this.pub_gruu||this.uri.toString(),U&&(w?!this.temp_gruu:!this.pub_gruu)&&(M+=";ob"),M+=">",M}};const O=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register","extra_headers"];for(const v in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,v)&&(O.indexOf(v)!==-1?Object.defineProperty(this._configuration,v,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,v,{writable:!1,configurable:!1}));C.debug("configuration parameters after validation:");for(const v in this._configuration)if(Object.prototype.hasOwnProperty.call($.settings,v))switch(v){case"uri":case"registrar_server":C.debug(`- ${v}: ${this._configuration[v]}`);break;case"password":case"ha1":case"authorization_jwt":C.debug(`- ${v}: NOT SHOWN`);break;default:C.debug(`- ${v}: ${JSON.stringify(this._configuration[v])}`)}}};function F(T){this.emit("connecting",T)}function H(T){this._status!==I.STATUS_USER_CLOSED&&(this._status=I.STATUS_READY,this._error=null,this.emit("connected",T),this._dynConfiguration.register&&this._registrator.register())}function o(T){const p=["nict","ict","nist","ist"];for(const A of p)for(const O in this._transactions[A])Object.prototype.hasOwnProperty.call(this._transactions[A],O)&&this._transactions[A][O].onTransportError();this.emit("disconnected",T),this._registrator.onTransportClosed(),this._status!==I.STATUS_USER_CLOSED&&(this._status=I.STATUS_NOT_READY,this._error=I.NETWORK_ERROR)}function f(T){const p=T.transport;let A=T.message;if(A=D.parseMessage(A,this),!!A&&!(this._status===I.STATUS_USER_CLOSED&&A instanceof E.IncomingRequest)&&N(A,this,p)){if(A instanceof E.IncomingRequest)A.transport=p,this.receiveRequest(A);else if(A instanceof E.IncomingResponse){let O;switch(A.method){case i.INVITE:O=this._transactions.ict[A.via_branch],O&&O.receiveResponse(A);break;case i.ACK:break;default:O=this._transactions.nict[A.via_branch],O&&O.receiveResponse(A);break}}}}return ps}var ms,Jn;function gi(){if(Jn)return ms;Jn=1;const b=ce(),y=Ce(),i=new b("WebSocketInterface");return ms=class{constructor(S){i.debug('new() [url:"%s"]',S),this._url=S,this._sip_uri=null,this._via_transport=null,this._ws=null;const t=y.parse(S,"absoluteURI");if(t===-1)throw i.warn(`invalid WebSocket URI: ${S}`),new TypeError(`Invalid argument: ${S}`);if(t.scheme!=="wss"&&t.scheme!=="ws")throw i.warn(`invalid WebSocket URI scheme: ${t.scheme}`),new TypeError(`Invalid argument: ${S}`);this._sip_uri=`sip:${t.host}${t.port?`:${t.port}`:""};transport=ws`,this._via_transport=t.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(S){this._via_transport=S.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(i.debug("connect()"),this.isConnected()){i.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){i.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),i.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(S){this._onError(S)}}disconnect(){i.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(S){return i.debug("send()"),this.isConnected()?(this._ws.send(S),!0):(i.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){i.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:S,code:t,reason:d}){i.debug(`WebSocket ${this._url} closed`),S===!1&&i.debug("WebSocket abrupt disconnection"),this.ondisconnect(!S,t,d)}_onMessage({data:S}){i.debug("received WebSocket message"),this.ondata(S)}_onError(S){i.warn(`WebSocket ${this._url} error: `,S)}},ms}var gs,Xn;function Ti(){if(Xn)return gs;Xn=1;const b=Zn,y=oe(),i=we(),_=fe(),S=mi(),t=ye(),d=As(),h=Ce(),n=gi(),m=vs()("JsSIP"),c=nl();return m("version %s",b.version),gs={C:y,Exceptions:i,Utils:_,UA:S,URI:t,NameAddrHeader:d,WebSocketInterface:n,Grammar:h,RTCSession:c,debug:vs(),get name(){return b.title},get version(){return b.version}},gs}var Ci=Ti();const Qn=Yl(Ci);let Me=null,Ts=null;function vi(b){return`${b.websocketUrl}|${b.sipUri}|${b.authorizationUser}`}function Ei(b){const y=vi(b);if(Me&&Ts===y)return Me;if(Me&&Ts!==y){try{Me.ua.stop()}catch{}Me=null}Ts=y;const _={sockets:[new Qn.WebSocketInterface(b.websocketUrl)],uri:b.sipUri,password:b.password,registrar_server:b.registrarServer,display_name:b.displayName,authorization_user:b.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},S=new Qn.UA(_),t=document.createElement("audio");t.autoplay=!0;const d={ua:S,audio:t,isStarted:!1,listeners:new Set};return S.on("connecting",()=>{d.listeners.forEach(h=>h.onConnecting?.())}),S.on("connected",()=>{d.listeners.forEach(h=>h.onConnected?.())}),S.on("disconnected",()=>{d.listeners.forEach(h=>h.onDisconnected?.())}),S.on("registered",()=>{d.listeners.forEach(h=>h.onRegistered?.())}),S.on("unregistered",()=>{d.listeners.forEach(h=>h.onUnregistered?.())}),S.on("registrationFailed",h=>{d.listeners.forEach(n=>n.onRegistrationFailed?.(h?.cause))}),S.on("newRTCSession",h=>{const n=h.session;n.direction==="outgoing"&&(d.listeners.forEach(m=>m.onNewSession?.(n)),n.connection&&(n.connection.addEventListener("addstream",m=>{var c=document.createElement("audio");m.streams!==void 0&&m.streams.length!==0&&(c.srcObject=m.streams[0],c.play())}),n.connection.addEventListener("track",m=>{var c=document.createElement("audio");c.srcObject=m.streams[0],c.play()})))}),Me=d,d}function Si(b){b.isStarted||(b.ua.start(),b.isStarted=!0)}function Ai(b,y){b.listeners.add(y)}function Ri(b,y){b.listeners.delete(y)}function bi(b){return{isReady:b.ua.isRegistered(),isConnected:b.ua.isConnected()}}const il=re.createContext(null);function al({config:b,children:y,onCallStart:i,onCallEnd:_,onStatusChange:S}){const[t,d]=re.useState(""),[h,n]=re.useState("disconnected"),[m,c]=re.useState(null),[R,D]=re.useState(0),[E,N]=re.useState([]),[$,C]=re.useState(!1),[I,F]=re.useState("connecting"),H=re.useRef(null),o=re.useRef(null),f=re.useRef(null);re.useEffect(()=>{o.current=m},[m]),re.useEffect(()=>{const v=Ei(b);f.current=v;const w=bi(v);w.isReady?(C(!0),F("connected")):w.isConnected&&F("connected");const U={onConnecting:()=>F("connecting"),onConnected:()=>F("connected"),onDisconnected:()=>{F("disconnected"),C(!1)},onRegistered:()=>{C(!0),F("connected")},onUnregistered:()=>C(!1),onRegistrationFailed:M=>{console.error("Registration failed:",M),C(!1),F("failed")},onNewSession:M=>{H.current=M}};return Ai(v,U),Si(v),()=>{Ri(v,U)}},[b.websocketUrl,b.sipUri,b.password,b.registrarServer,b.displayName,b.authorizationUser]),re.useEffect(()=>{S?.(h)},[h,S]),re.useEffect(()=>{const v=localStorage.getItem("tbi-phone-call-history");if(v)try{N(JSON.parse(v))}catch(w){console.error("Error loading call history",w)}},[]),re.useEffect(()=>{E.length>0&&localStorage.setItem("tbi-phone-call-history",JSON.stringify(E))},[E]),re.useEffect(()=>{if(h==="confirmed"&&m){const v=setInterval(()=>{D(Math.floor((Date.now()-m)/1e3))},1e3);return()=>clearInterval(v)}else D(0)},[h,m]),re.useEffect(()=>{const v=w=>{const U=w.detail.number;h==="disconnected"&&A(U)};return window.addEventListener("StartCallEvent",v),()=>{window.removeEventListener("StartCallEvent",v)}},[h]);const T=re.useCallback((v,w,U)=>{const M={id:Date.now().toString(),number:v,timestamp:Date.now(),duration:w,status:U};N(Y=>[M,...Y].slice(0,50))},[]),p=re.useCallback(()=>{H.current&&(H.current.terminate(),H.current=null)},[]),A=re.useCallback(v=>{const w=f.current;if(!v.trim()||!w)return;if(!$){console.warn("Phone is not ready yet. Please wait for registration.");return}d(v),i?.(v);const M={eventHandlers:{progress:()=>{n("progress")},failed:Y=>{console.error("Call failed:",Y?.cause),n("failed"),T(v,0,"failed"),_?.(v,0,"failed"),H.current=null,setTimeout(()=>n("disconnected"),3e3)},ended:()=>{n("ended");const Y=o.current,B=Y?Math.floor((Date.now()-Y)/1e3):0;T(v,B,"completed"),_?.(v,B,"completed"),H.current=null,setTimeout(()=>{n("disconnected"),c(null)},2e3)},confirmed:()=>{n("confirmed"),c(Date.now())}},mediaConstraints:{audio:!0,video:!1}};n("progress");try{const Y=w.ua.call(v,M);H.current=Y}catch(Y){console.error("Failed to start call:",Y),n("failed"),T(v,0,"failed"),setTimeout(()=>n("disconnected"),3e3)}},[T,i,_,$]),O={status:h,callNumber:t,setCallNumber:d,callHistory:E,currentCallDuration:R,startCall:A,endCall:p,isReady:$,connectionStatus:I};return q.jsx(il.Provider,{value:O,children:y})}function ol(){const b=re.useContext(il);if(!b)throw new Error("usePhone must be used within a PhoneProvider");return b}const Ss=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})}),wi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),yi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z"})}),_t=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})}),ul=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"})}),Ii=({className:b})=>q.jsxs("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:[q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"}),q.jsx("path",{d:"M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z"})]}),xi=({className:b})=>q.jsxs("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:[q.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"}),q.jsx("path",{d:"M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z"})]}),Ni=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"})}),Oi=({className:b})=>q.jsx("svg",{className:b,viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})});function Di({className:b,labels:y}){const{status:i,callNumber:_,setCallNumber:S,callHistory:t,currentCallDuration:d,startCall:h,endCall:n,isReady:m,connectionStatus:c}=ol(),[R,D]=re.useState(!1),E={...Kl,...y},$=(()=>{switch(i){case"progress":return{text:`${E.calling}...`,color:"text-yellow-500",Icon:wi};case"confirmed":return{text:`${E.inCall} - ${pt(d)}`,color:"text-green-500",Icon:yi};case"failed":return{text:E.callEnded,color:"text-red-500",Icon:ul};case"ended":return{text:E.callEnded,color:"text-gray-500",Icon:_t};default:return{text:E.inactive,color:"text-gray-300",Icon:Ss}}})();return q.jsxs("div",{className:Cs("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",b),children:[i==="disconnected"&&q.jsxs("div",{className:"flex gap-2 items-center",children:[q.jsx("button",{onClick:()=>D(!0),className:"h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",type:"button",children:q.jsx(Ni,{className:"w-4 h-4"})}),q.jsx("input",{type:"text",value:_,onChange:C=>S(C.target.value),onKeyDown:C=>{C.key==="Enter"&&h(_)},placeholder:E.placeholder,className:"flex-1 h-8 px-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"}),q.jsx("button",{onClick:()=>h(_),disabled:_.length<9||!m,className:"h-8 w-8 flex items-center justify-center rounded-xl bg-green-500 hover:bg-green-600 disabled:bg-gray-300 disabled:cursor-not-allowed text-white transition-colors",type:"button",title:m?"Call":"Connecting...",children:c==="connecting"?q.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}):q.jsx(Ss,{className:"w-4 h-4"})})]}),i==="progress"&&q.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[q.jsxs("div",{className:"relative",children:[q.jsx($.Icon,{className:"w-12 h-12 text-yellow-500 animate-pulse"}),q.jsx("div",{className:"absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping"})]}),q.jsxs("div",{className:"text-center",children:[q.jsxs("p",{className:"text-base font-semibold",children:[E.calling," ",_]}),q.jsx("p",{className:"text-sm text-gray-500",children:E.waitingResponse})]}),q.jsxs("button",{onClick:n,className:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button",children:[q.jsx(_t,{className:"w-4 h-4"}),E.cancel]})]}),i==="confirmed"&&q.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[q.jsxs("div",{className:"relative",children:[q.jsx($.Icon,{className:"w-12 h-12 text-green-500"}),q.jsx("div",{className:"absolute inset-0 rounded-full bg-green-500/20 animate-pulse"})]}),q.jsxs("div",{className:"text-center space-y-1",children:[q.jsx("p",{className:"text-xl font-bold",children:_}),q.jsx("p",{className:"text-2xl font-mono text-green-600 tabular-nums",children:pt(d)})]}),q.jsxs("button",{onClick:n,className:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button",children:[q.jsx(_t,{className:"w-4 h-4"}),E.hangUp]})]}),(i==="failed"||i==="ended")&&q.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[q.jsx($.Icon,{className:Cs("w-12 h-12",i==="failed"?"text-red-500":"text-gray-500")}),q.jsx("div",{className:"text-center",children:q.jsx("p",{className:"text-base font-semibold",children:$.text})})]}),R&&q.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[q.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>D(!1)}),q.jsx("div",{className:"fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",children:q.jsxs("div",{className:"flex flex-col h-full",children:[q.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[q.jsxs("div",{children:[q.jsx("h2",{className:"text-lg font-semibold",children:E.callHistory}),q.jsx("p",{className:"text-sm text-gray-500",children:t.length===0?E.noCallsRegistered:`${t.length} ${E.callsRegistered}`})]}),q.jsx("button",{onClick:()=>D(!1),className:"h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:q.jsx(Oi,{className:"w-5 h-5"})})]}),q.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:t.length===0?q.jsxs("div",{className:"text-center py-12 text-gray-500",children:[q.jsx(_t,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),q.jsx("p",{children:E.noCalls})]}):q.jsx("div",{className:"space-y-2",children:t.map((C,I)=>q.jsx(Ui,{entry:C,index:I,onCall:()=>{S(C.number),D(!1),h(C.number)}},C.id))})})]})})]})]})}function Ui({entry:b,index:y,onCall:i}){const _=()=>{switch(b.status){case"completed":return q.jsx(Ii,{className:"w-4 h-4 text-green-600"});case"failed":return q.jsx(xi,{className:"w-4 h-4 text-red-600"});case"missed":return q.jsx(ul,{className:"w-4 h-4 text-yellow-600"})}},S=()=>{switch(b.status){case"completed":return"bg-green-100";case"failed":return"bg-red-100";case"missed":return"bg-yellow-100"}};return q.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",style:{animationDelay:`${y*30}ms`},children:[q.jsx("div",{className:Cs("w-9 h-9 rounded-full flex items-center justify-center shrink-0",S()),children:_()}),q.jsxs("div",{className:"flex-1 min-w-0",children:[q.jsx("p",{className:"font-medium text-sm truncate",children:b.number}),q.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[q.jsx("span",{children:new Date(b.timestamp).toLocaleString("es-ES",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}),b.duration>0&&q.jsxs(q.Fragment,{children:[q.jsx("span",{children:"•"}),q.jsx("span",{className:"font-mono tabular-nums",children:pt(b.duration)})]})]})]}),q.jsx("button",{onClick:i,className:"h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:q.jsx(Ss,{className:"w-4 h-4"})})]})}function Pi({config:b,className:y,onCallStart:i,onCallEnd:_,onStatusChange:S,labels:t}){return q.jsx(al,{config:b,onCallStart:i,onCallEnd:_,onStatusChange:S,children:q.jsx(Di,{className:y,labels:t})})}exports.Phone=Pi;exports.PhoneProvider=al;exports.formatDuration=pt;exports.usePhone=ol;
package/dist/index.js CHANGED
@@ -8015,11 +8015,13 @@ function wi(b) {
8015
8015
  d.listeners.forEach((n) => n.onRegistrationFailed?.(h?.cause));
8016
8016
  }), S.on("newRTCSession", (h) => {
8017
8017
  const n = h.session;
8018
- n.direction === "outgoing" && (d.listeners.forEach((m) => m.onNewSession?.(n)), n.on("peerconnection", () => {
8019
- n.connection.addEventListener("track", (m) => {
8020
- m.streams && m.streams[0] && (d.audio.srcObject = m.streams[0], d.audio.play().catch(console.error));
8021
- });
8022
- }));
8018
+ n.direction === "outgoing" && (d.listeners.forEach((m) => m.onNewSession?.(n)), n.connection && (n.connection.addEventListener("addstream", (m) => {
8019
+ var c = document.createElement("audio");
8020
+ m.streams !== void 0 && m.streams.length !== 0 && (c.srcObject = m.streams[0], c.play());
8021
+ }), n.connection.addEventListener("track", (m) => {
8022
+ var c = document.createElement("audio");
8023
+ c.srcObject = m.streams[0], c.play();
8024
+ })));
8023
8025
  }), Fe = d, d;
8024
8026
  }
8025
8027
  function yi(b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbisoftware/phone",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
5
  "description": "A reusable SIP phone component for React applications",
6
6
  "author": "TBI",