@16x/webphone-sdk 3.2.4 → 3.2.6

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/ui/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../createJsSipFactory-B1ORbJiP.cjs");var e={call:`Call`,numberLabel:`Number`,statusReady:`Ready`,statusSetup:`Not initialized`,statusConnecting:`Connecting`,statusIncoming:`Incoming call`,statusActive:`On a call`,statusHeld:`On hold`,statusDialing:`Dialing`,statusEnded:`Call ended`,statusFailed:`Call failed`,statusUnsupported:`Unsupported browser`,statusPermission:`Microphone unavailable`,statusError:`Unable to continue`,incoming:`Incoming call`,answer:`Answer`,reject:`Decline`,hangup:`Hang up`,mute:`Mute`,unmute:`Unmute`,hold:`Hold`,resume:`Resume`,transfer:`Transfer`,blindTransfer:`Blind transfer`,more:`More`,devices:`Devices`,enablePhone:`Enable phone`,retryPermission:`Check again`,permissionTitle:`Microphone unavailable`,permissionBody:`Allow microphone access in the browser settings, then check again.`,errorTitle:`Unable to continue`,errorBody:`Check the network, origin allowlist, or agent permission, then retry.`,currentCall:`Current call`,inbound:`Inbound`,outbound:`Outbound`,foregroundChecking:`Back in foreground, checking the connection`,foregroundFailed:`Foreground recovery failed. Retry.`,signIn:`Sign in`,signOut:`Sign out`,outboundCall:`Outbound`,internalCall:`Internal`,agentIdle:`Available`,agentBusy:`Busy`,agentBreak:`Break`,agentBusyHint:`Busy is controlled by the call or server`,rowSignIn:`Presence`,rowCall:`Call`,rowAgent:`Agent`,extensionLabel:`Extension`,extensionPlaceholder:`Optional, assigned by the server`},t={call:`呼叫`,numberLabel:`号码`,statusReady:`可拨号`,statusSetup:`未初始化`,statusConnecting:`正在连接`,statusIncoming:`来电`,statusActive:`通话中`,statusHeld:`保持中`,statusDialing:`正在拨号`,statusEnded:`通话结束`,statusFailed:`呼叫失败`,statusUnsupported:`不支持的浏览器`,statusPermission:`无法使用麦克风`,statusError:`无法继续通话`,incoming:`来电`,answer:`接听`,reject:`拒绝`,hangup:`挂断`,mute:`静音`,unmute:`取消静音`,hold:`保持`,resume:`恢复`,transfer:`转接`,blindTransfer:`盲转`,more:`更多`,devices:`设备`,enablePhone:`启用电话`,retryPermission:`重新检测`,permissionTitle:`无法使用麦克风`,permissionBody:`请在浏览器设置中允许本网站访问麦克风,然后重新检测。`,errorTitle:`无法继续通话`,errorBody:`请检查网络、域名授权或坐席权限后重试。`,currentCall:`当前通话`,inbound:`呼入`,outbound:`呼出`,foregroundChecking:`已返回前台,正在检查连接`,foregroundFailed:`前台恢复失败,请重试`,signIn:`签入`,signOut:`退签`,outboundCall:`外呼`,internalCall:`内呼`,agentIdle:`空闲`,agentBusy:`置忙`,agentBreak:`休息`,agentBusyHint:`置忙由通话或服务端状态控制`,rowSignIn:`签入`,rowCall:`通话`,rowAgent:`坐席`,extensionLabel:`分机`,extensionPlaceholder:`可空,由服务端分配`};function n(n){return n.toLowerCase().startsWith(`en`)?e:t}function r(e,t,r){return{...n(e),...r===void 0?{}:r(e),...t??{}}}async function i(e){await e.media.requestPermission(),await e.initialize(),await e.connect()}function a(e,t={}){let n=t.document??(typeof document>`u`?void 0:document);if(n===void 0)return()=>void 0;let r=()=>{if(n.visibilityState===`hidden`){t.onHidden?.();return}t.onChecking?.(),e.recover().then(()=>t.onRecovered?.()).catch(e=>t.onFailed?.(e))};return n.addEventListener(`visibilitychange`,r),()=>n.removeEventListener(`visibilitychange`,r)}function o(e){return e.replace(/\s+/g,``)}function s(e,t,n){return o(e).length>0&&n===`connected`&&t!==`denied`}async function c(e,t,n){let r=o(t);r!==``&&await e.dial({destination:r,...n===void 0?{}:{type:n}})}async function l(e,t){return t?await e.unmute():await e.mute(),!t}async function u(e){e.state===`held`?await e.resume():await e.hold()}async function d(e,t){await e.sendDtmf(t)}async function f(e,t){let n=o(t);n!==``&&await e.transfer({target:n,type:`blind`})}function p(e,t={}){let n=document.createElement(e);return t.className!==void 0&&(n.className=t.className),t.text!==void 0&&(n.textContent=t.text),Object.entries(t.attrs??{}).forEach(([e,t])=>n.setAttribute(e,t)),t.children?.forEach(e=>n.append(e)),n}function m(e){return p(`div`,{attrs:{part:`status-rail`,role:`status`,"aria-live":`polite`},text:e})}function h(e,t,n=`destination`){let r=p(`input`,{attrs:{id:e,type:`tel`,inputmode:`tel`,name:n,autocomplete:`tel`}});return{field:p(`div`,{children:[p(`label`,{attrs:{for:e},text:t}),r]}),input:r}}var g=[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`*`,`0`,`#`];function _(e){return e.mode===`compact`?v(e):y(e)}function v(e){let{field:t,input:n}=h(`ccbar-destination`,e.messages.numberLabel??`号码`);n.value=e.destination;let r=e.view.kind===`ready`||e.view.kind===`setup`||e.view.kind===`ended`?p(`button`,{attrs:{type:`button`,"data-action":`dial`,part:`call-button`,...e.canDial?{}:{disabled:``}},text:e.messages.call??`呼叫`}):p(`button`,{attrs:{type:`button`,"data-action":`hangup`,part:`hangup-button`},text:e.messages.hangup??`挂断`}),i=[S(e.messages.status??``,e.floating),p(`div`,{className:`ccbar-toolbar`,children:[t,e.view.kind===`active`||e.view.kind===`held`?E(e):p(`span`),r,p(`button`,{attrs:{type:`button`,"data-action":`more`},text:e.messages.more??`更多`})]})];return e.moreOpen&&i.push(p(`div`,{className:`ccbar-more`,children:[D(e.view,e.messages),p(`button`,{attrs:{type:`button`,"data-action":`devices`},text:e.messages.devices??`设备`})]})),p(`div`,{attrs:{part:`panel`,"data-layout":`compact`},children:i})}function y(e){let{input:t}=h(`ccbar-destination`,e.messages.numberLabel??`号码`),{field:n}=h(`ccbar-transfer-target`,e.messages.transfer??`转接号码`,`transfer-target`);t.value=e.destination,t.placeholder=e.messages.numberLabel??`号码`,t.setAttribute(`aria-label`,e.messages.numberLabel??`号码`);let r=e.view.kind===`active`||e.view.kind===`held`||e.view.kind===`dialing`,i=e.view.kind===`held`,a=e.view.kind===`connecting`,o=[S(e.messages.status??``,e.floating,e.extension,e.messages.extensionLabel??`分机`),b(e.messages.rowSignIn??`签入`,[C(e),x(`signin`,e.messages.signIn??`签入`,{variant:`primary`,disabled:e.connected||a}),x(`signout`,e.messages.signOut??`退签`,{disabled:!e.connected})]),b(e.messages.numberLabel??`号码`,[t],{labelFor:t.id}),b(e.messages.rowCall??`通话`,[x(`dial`,e.messages.outboundCall??`外呼`,{variant:`primary`,disabled:!e.canDial}),x(`dial-internal`,e.messages.internalCall??`内呼`,{disabled:!e.canDial}),x(`hangup`,e.messages.hangup??`挂断`,{variant:`danger`,disabled:!r}),x(`transfer`,e.messages.transfer??`转接`,{disabled:!r}),x(`hold`,e.messages.hold??`保持`,{pressed:i,disabled:!r||i}),x(`resume`,e.messages.resume??`恢复`,{disabled:!i}),E(e)]),...r?[b(e.messages.transfer??`转接号码`,[n],{labelFor:`ccbar-transfer-target`})]:[],b(e.messages.rowAgent??`坐席`,[x(`agent-available`,e.messages.agentIdle??`空闲`,{pressed:e.agentStatus===`available`,disabled:!e.connected}),x(`agent-busy`,e.messages.agentBusy??`置忙`,{disabled:!0,title:e.messages.agentBusyHint??`置忙由通话或服务端状态控制`}),x(`agent-break`,e.messages.agentBreak??`休息`,{pressed:e.agentStatus===`break`,disabled:!e.connected})]),T()];return e.calls.length>1&&o.push(O(e.calls,e.messages)),p(`div`,{attrs:{part:`panel`,"data-layout":`panel`},children:o})}function b(e,t,n={}){return p(`div`,{className:`ccbar-bar-row`,children:[p(n.labelFor===void 0?`div`:`label`,{className:`ccbar-bar-label`,attrs:n.labelFor===void 0?{}:{for:n.labelFor},text:e}),p(`div`,{className:`ccbar-bar-keys`,children:t})]})}function x(e,t,n={}){let r=e===`dial`?`call-button`:e===`hangup`?`hangup-button`:void 0;return p(`button`,{attrs:{type:`button`,"data-action":e,...r===void 0?{}:{part:r},...n.variant===void 0?{}:{"data-variant":n.variant},...n.disabled===!0?{disabled:``}:{},...n.pressed===void 0?{}:{"aria-pressed":n.pressed?`true`:`false`},...n.title===void 0?{}:{title:n.title}},text:t})}function S(e,t,n=``,r=`分机`){let i=w(e);return t&&i.setAttribute(`data-drag-handle`,``),n!==``&&i.append(p(`span`,{className:`ccbar-ext-chip`,text:`${r} ${n}`})),i}function C(e){let t=p(`input`,{attrs:{id:`ccbar-extension`,type:`tel`,inputmode:`numeric`,name:`extension`,autocomplete:`off`,placeholder:e.messages.extensionPlaceholder??`可空,由服务端分配`,"aria-label":e.messages.extensionLabel??`分机`}});return t.value=e.extension,e.connected&&(t.readOnly=!0),t}function w(e){return m(e)}function T(){return p(`div`,{className:`ccbar-dialpad`,children:g.map(e=>p(`button`,{attrs:{type:`button`,"data-digit":e},text:e}))})}function E(e){return p(`button`,{attrs:{type:`button`,"data-action":`mute`,"aria-pressed":e.muted?`true`:`false`},text:e.muted?e.messages.unmute??`取消静音`:e.messages.mute??`静音`})}function D(e,t){let n=e.kind===`held`;return p(`button`,{attrs:{type:`button`,"data-action":`hold`,"aria-pressed":n?`true`:`false`},text:n?t.resume??`恢复`:t.hold??`保持`})}function O(e,t){return p(`ul`,{className:`ccbar-call-list`,children:e.map(e=>p(`li`,{children:[p(`button`,{attrs:{type:`button`,"data-call-id":e.id},children:[p(`span`,{text:`${e.destination} ${e.direction===`inbound`?t.inbound??`呼入`:t.outbound??`呼出`} ${k(e.state,t)}`}),...e.current?[p(`span`,{className:`ccbar-call-current`,text:t.currentCall??`当前通话`})]:[]]})]}))})}function k(e,t){return e===`held`?t.statusHeld??`保持中`:e===`active`?t.statusActive??`通话中`:e===`dialing`||e===`ringing`||e===`connecting`?t.statusDialing??`拨号中`:e}function A(e){switch(e.view.kind){case`permission-error`:return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.permissionTitle??`无法使用麦克风`),p(`h2`,{text:e.messages.permissionTitle??`无法使用麦克风`}),p(`p`,{text:e.messages.permissionBody??`请在浏览器设置中允许本网站访问麦克风,然后重新检测。`}),p(`button`,{attrs:{type:`button`,"data-action":`retry-permission`},text:e.messages.retryPermission??`重新检测`})]});case`unrecoverable-error`:case`unsupported`:return p(`div`,{attrs:{part:`panel`},children:[p(`div`,{attrs:{role:`alert`,part:`status-rail`},text:e.messages.errorTitle??`无法继续通话`}),p(`p`,{text:e.messages.errorBody??`请检查网络、域名授权或坐席权限后重试。`})]});case`setup`:case`connecting`:case`incoming`:case`active`:case`held`:case`dialing`:case`ended`:case`ready`:return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.status??``)]});default:return e.view}}function j(e){return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.status??`来电`),p(`p`,{text:e.view.from}),p(`button`,{attrs:{type:`button`,"data-action":`answer`},text:e.messages.answer??`接听`}),p(`button`,{attrs:{type:`button`,"data-action":`reject`},text:e.messages.reject??`拒绝`})]})}var M=[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`*`,`0`,`#`];function N(e){return F(p(`div`,{attrs:{part:`panel`,"data-layout":`mobile`},children:[m(e.status),p(`button`,{attrs:{type:`button`,"data-action":`enable-phone`,...e.enabling?{disabled:``}:{}},text:e.enablePhone??`启用电话`})]}))}function P(e){let t=e.view.kind===`active`||e.view.kind===`dialing`,n=[m(e.messages.status??``)];if(t){let t=e.view.kind===`active`||e.view.kind===`dialing`?e.view.destination??``:``;n.push(p(`p`,{text:t}),I(p(`button`,{attrs:{type:`button`,"data-action":`mute`,"aria-pressed":e.muted?`true`:`false`},text:e.muted?e.messages.unmute??`取消静音`:e.messages.mute??`静音`}),44),L(),I(p(`button`,{attrs:{type:`button`,"data-action":`hangup`,part:`hangup-button`},text:e.messages.hangup??`挂断`}),52))}else{let{field:t,input:r}=h(`ccbar-destination`,e.messages.numberLabel??`号码`);r.value=e.destination,n.push(t,L(),p(`button`,{attrs:{type:`button`,"data-action":`dial`,part:`call-button`,...e.canDial?{}:{disabled:``}},text:e.messages.call??`呼叫`}))}return e.showOutputDevice&&n.push(p(`button`,{attrs:{type:`button`,"data-action":`devices`},text:e.messages.devices??`设备`})),F(p(`div`,{attrs:{part:`panel`,"data-layout":`mobile`},children:n}))}function F(e){return e.style.minHeight=`100dvh`,e.style.paddingBottom=`max(16px, env(safe-area-inset-bottom))`,e}function I(e,t){return e.style.minHeight=`${t}px`,e}function L(){return p(`div`,{className:`ccbar-dialpad`,children:M.map(e=>p(`button`,{attrs:{type:`button`,"data-digit":e},text:e}))})}var R={kind:`permission-error`,code:`MEDIA_PERMISSION_DENIED`,action:`retry-permission`};function z(e){if(e.supported===!1)return{kind:`unsupported`};if(e.permission===`denied`||e.error?.code===`MEDIA_PERMISSION_DENIED`)return R;if(e.error!==void 0&&e.error.code!==`MEDIA_PLAYBACK_BLOCKED`)return{kind:`unrecoverable-error`,code:e.error.code};let t=e.calls.find(e=>e.direction===`inbound`&&(e.state===`ringing`||e.state===`new`));if(t!==void 0)return{kind:`incoming`,callId:t.id,from:t.destination??``};let n=e.calls.find(e=>e.state===`active`);if(n!==void 0)return{kind:`active`,callId:n.id,destination:n.destination};let r=e.calls.find(e=>e.state===`held`);if(r!==void 0)return{kind:`held`,callId:r.id,destination:r.destination};let i=e.calls.find(e=>e.state===`dialing`||e.state===`ringing`||e.state===`connecting`);if(i!==void 0)return{kind:`dialing`,callId:i.id,destination:i.destination};let a=e.calls.find(e=>e.state===`ended`||e.state===`failed`);return a===void 0?e.connectionState===`connecting`||e.connectionState===`reconnecting`?{kind:`connecting`}:e.connectionState===`connected`?{kind:`ready`}:{kind:`setup`}:{kind:`ended`,callId:a.id}}var B=`:root,:host{--ccbar-color-surface:#fff;--ccbar-color-surface-muted:#f1f5f9;--ccbar-color-border:#d8e0ea;--ccbar-color-title:#0f172a;--ccbar-color-text:#334155;--ccbar-color-muted:#475569;--ccbar-color-primary:#2563eb;--ccbar-color-primary-hover:#1d4ed8;--ccbar-color-success:#15803d;--ccbar-color-warning:#a15c00;--ccbar-color-danger:#b91c1c;--ccbar-radius-sm:6px;--ccbar-radius:8px;--ccbar-radius-lg:12px;--ccbar-control-height:40px;--ccbar-control-height-touch:44px;--ccbar-space-1:4px;--ccbar-space-2:8px;--ccbar-space-3:12px;--ccbar-space-4:16px;--ccbar-space-6:24px;--ccbar-font-family:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;--ccbar-panel-width:560px}:host{color:var(--ccbar-color-text);font-family:var(--ccbar-font-family);display:block}:host([floating]){z-index:2147483646;right:var(--ccbar-space-6);bottom:var(--ccbar-space-6);position:fixed}[part=panel]{background:var(--ccbar-color-surface);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-lg)}[part=status-rail]{align-items:center;gap:var(--ccbar-space-2);min-height:var(--ccbar-control-height);padding:var(--ccbar-space-2) var(--ccbar-space-3);border-bottom:1px solid var(--ccbar-color-border);color:var(--ccbar-color-muted);font-variant-numeric:tabular-nums;display:flex}[part=status-rail]:before{content:"";background:var(--ccbar-color-muted);border-radius:50%;flex:none;width:8px;height:8px}button{min-height:var(--ccbar-control-height);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-sm);background:var(--ccbar-color-surface);color:var(--ccbar-color-title);font:inherit}button[data-action=dial],button[data-action=signin],button[data-action=answer],button[data-variant=primary]{background:var(--ccbar-color-primary);border-color:var(--ccbar-color-primary);color:#fff}button[aria-pressed=true]{border-color:var(--ccbar-color-primary);color:var(--ccbar-color-primary);background:var(--ccbar-color-surface-muted)}button[data-action=hangup],button[data-action=reject]{background:var(--ccbar-color-danger);border-color:var(--ccbar-color-danger);color:#fff;margin-top:var(--ccbar-space-4)}button:disabled{opacity:.5}button:focus-visible,input:focus-visible{outline:2px solid var(--ccbar-color-primary);outline-offset:2px}input[type=tel]{width:100%;min-height:var(--ccbar-control-height);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-sm);font-variant-numeric:tabular-nums}.ccbar-call-list{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0 0;padding:0;list-style:none;display:grid}.ccbar-call-list button{text-align:left;width:100%}.ccbar-call-current{color:var(--ccbar-color-title);display:block}[data-layout=compact]{min-height:80px;max-height:96px}[data-layout=compact] .ccbar-toolbar{gap:var(--ccbar-space-2);padding:var(--ccbar-space-2) var(--ccbar-space-3);grid-template-columns:minmax(0,1fr) auto auto auto;align-items:center;display:grid}[data-layout=compact] .ccbar-more{right:var(--ccbar-space-3);gap:var(--ccbar-space-2);display:grid;position:absolute}[data-layout=panel]{width:min(var(--ccbar-panel-width), 100%);min-width:420px;max-width:560px;padding:var(--ccbar-space-3)}[data-layout=panel] .ccbar-bar-row{gap:var(--ccbar-space-2) var(--ccbar-space-3);grid-template-columns:48px minmax(0,1fr);align-items:center;min-height:36px;display:grid}[data-layout=panel] .ccbar-bar-row+.ccbar-bar-row{margin-top:var(--ccbar-space-2)}[data-layout=panel] .ccbar-bar-label{color:var(--ccbar-color-muted);font-size:12px}[data-layout=panel] .ccbar-bar-keys{align-items:center;gap:var(--ccbar-space-2);flex-wrap:wrap;display:flex}[data-layout=panel] .ccbar-bar-keys button{min-width:48px;min-height:32px;padding:0 10px;font-size:13px}[data-layout=panel] .ccbar-bar-keys input[type=tel]{max-width:320px}[data-layout=panel] .ccbar-bar-keys input[name=extension]{width:148px;max-width:148px}[data-layout=panel] .ccbar-ext-chip{background:var(--ccbar-color-surface-muted);height:28px;color:var(--ccbar-color-title);font-variant-numeric:tabular-nums;border-radius:999px;align-items:center;margin-left:auto;padding:0 10px;font-size:12px;display:inline-flex}[data-layout=panel] [data-action=hangup]{margin-top:0}[data-layout=panel] .ccbar-dialpad{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0 0;grid-template-columns:repeat(3,1fr);display:grid}[data-layout=panel] .ccbar-safe-actions{gap:var(--ccbar-space-2);flex-wrap:wrap;display:flex}[data-layout=mobile]{min-height:100vh;padding:var(--ccbar-space-4);padding-bottom:max(16px, env(safe-area-inset-bottom))}[data-layout=mobile] button{min-width:44px;min-height:44px}[data-layout=mobile] [data-action=enable-phone],[data-layout=mobile] [data-action=dial],[data-layout=mobile] [data-action=hangup]{min-height:52px}[data-layout=mobile] .ccbar-dialpad{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0;grid-template-columns:repeat(3,1fr);display:grid}:host([data-theme=dark]){--ccbar-color-surface:#0f172a;--ccbar-color-surface-muted:#1e293b;--ccbar-color-border:#334155;--ccbar-color-title:#f8fafc;--ccbar-color-text:#e2e8f0;--ccbar-color-muted:#94a3b8;--ccbar-color-primary:#3b82f6;--ccbar-color-primary-hover:#2563eb;--ccbar-color-success:#22c55e;--ccbar-color-warning:#f59e0b;--ccbar-color-danger:#ef4444}@media (prefers-reduced-motion:reduce){:host *,:host :before,:host :after{transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}}`,V=typeof HTMLElement==`function`?HTMLElement:class{},H=new WeakSet,U=[`connection.stateChanged`,`connection.reconnecting`,`connection.failed`,`call.incoming`,`call.stateChanged`,`call.activeChanged`,`call.ended`,`call.failed`,`media.permissionChanged`,`agent.statusChanged`,`error`],W=class extends V{static get observedAttributes(){return[`mode`,`floating`,`draggable`,`locale`,`theme`]}#e;#t=!1;#n=[];#r=`idle`;#i=`unknown`;#a;#o=new Set;#s=``;#c=``;#l=`offline`;#u=!1;#d=!1;#f=Promise.resolve();#p;#m=!1;#h=!1;#g;#_;#v;#y;#b;get messageResolver(){return this.#y}set messageResolver(e){this.#y=e,this.shadowRoot!==null&&this.render()}get client(){return this.#e}set client(e){this.#O(),this.#e=e,this.#D(),this.render()}get ownsClient(){return this.#t}set ownsClient(e){this.#t=e===!0}connectedCallback(){this.#V(),this.#B(),this.render()}disconnectedCallback(){let e=this.#e,t=this.#t;this.#O(),this.#G(),this.#b?.(),this.#b=void 0,t&&(this.#e=void 0,e?.dispose())}attributeChangedCallback(e){this.#V(),e===`theme`&&this.#B(),this.shadowRoot!==null&&this.render()}render(){let e=this.#k();e!==void 0&&(e.innerHTML=`<style>${B}</style>`,e.append(this.#S(this.#x())))}#x(){let e=this.#e?.getCalls?.().map(e=>({id:e.id,state:e.state,destination:e.destination,direction:this.#o.has(e.id)?`inbound`:`outbound`}))??[];return z({connectionState:this.#r,permission:this.#i,calls:e,error:this.#a})}#S(e){let t=this.#z(),n=this.#_??this.#g??K(e,t),r={...t,status:n},i=this.#C(e,r,n);return i.setAttribute(`data-view`,this.#E()&&!this.#m?`setup`:e.kind),i.hasAttribute(`data-layout`)||i.setAttribute(`data-layout`,this.#E()?`mobile`:`panel`),i}#C(e,t,n){if(this.#E()&&!this.#m)return N({enabling:this.#h,status:n,enablePhone:t.enablePhone});switch(e.kind){case`permission-error`:case`unrecoverable-error`:case`unsupported`:return A({view:e,messages:t});case`incoming`:return this.#E()?P({view:{kind:`ready`},messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),showOutputDevice:this.#e?.media.supportsOutputSelection()===!0}):j({view:e,messages:t});case`setup`:case`connecting`:case`ended`:case`ready`:case`active`:case`held`:case`dialing`:return this.#E()?P({view:e.kind===`held`?{kind:`ready`}:e,messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),showOutputDevice:this.#e?.media.supportsOutputSelection()===!0}):_({mode:this.#T()===`compact`?`compact`:`panel`,view:e,messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),moreOpen:this.#d,floating:this.hasAttribute(`floating`),connected:this.#r===`connected`,agentStatus:this.#l,extension:this.#c,calls:this.#w()});default:return e}}#w(){let e=this.#e?.getActiveCall?.()?.id;return this.#e?.getCalls?.().map(t=>({id:t.id,destination:t.destination,state:t.state,direction:this.#o.has(t.id)?`inbound`:`outbound`,current:t.id===e}))??[]}#T(){let e=this.getAttribute(`mode`);return e===`compact`||e===`mobile`?e:`panel`}#E(){return this.#T()===`mobile`}#D(){let e=this.#e;e!==void 0&&(this.#n.push(e.on(`connection.stateChanged`,t=>{if(this.#r=t.state,t.state!==`connected`&&(this.#l=`offline`),t.state===`connected`){let t=e.getAgent?.()?.extension?.trim();t!==void 0&&t!==``&&(this.#c=t)}})),this.#n.push(e.on(`agent.statusChanged`,e=>{(e.status===`available`||e.status===`offline`||e.status===`break`)&&(this.#l=e.status)})),this.#n.push(e.on(`connection.failed`,e=>{this.#r=`failed`,this.#a={code:e.error.code}})),this.#n.push(e.on(`media.permissionChanged`,e=>{this.#i=e.permission})),this.#n.push(e.on(`error`,e=>{this.#a={code:e.error.code}})),this.#n.push(e.on(`call.incoming`,e=>{this.#o.add(e.callId)})),this.#n.push(e.on(`call.ended`,e=>{this.#o.delete(e.callId),this.#u=!1})),this.#n.push(e.on(`call.failed`,()=>{this.#_=this.#z().statusFailed})),U.forEach(t=>{this.#n.push(e.on(t,()=>this.render()))}),this.#E()&&typeof e.recover==`function`&&(this.#v=a(e,{onChecking:()=>{this.#g=this.#z().foregroundChecking,this.render()},onRecovered:()=>{this.#g=void 0,this.render()},onFailed:()=>{this.#g=this.#z().foregroundFailed,this.render()}})))}#O(){let e=this.#n;this.#n=[],e.forEach(e=>e()),this.#r=`idle`,this.#i=`unknown`,this.#l=`offline`,this.#a=void 0,this.#o.clear(),this.#u=!1,this.#d=!1,this.#m=!1,this.#h=!1,this.#g=void 0,this.#v?.(),this.#v=void 0}#k(){if(typeof this.attachShadow!=`function`)return;let e=this.shadowRoot??this.attachShadow({mode:`open`});return H.has(e)||(H.add(e),e.addEventListener(`click`,e=>this.#A(e)),e.addEventListener(`input`,e=>this.#P(e)),e.addEventListener(`pointerdown`,e=>this.#H(e))),e}#A(e){let t=J(e,this),n=t?.closest(`[data-action="enable-phone"]`);n instanceof HTMLButtonElement&&(n.disabled=!0),this.#f=this.#f.then(()=>this.#F(t)).catch(e=>{this.#_=Y(e),this.render()})}#j(){let e=this.shadowRoot?.querySelector(`input[name="destination"]`);return e instanceof HTMLInputElement?e.value:this.#s}#M(){let e=this.shadowRoot?.querySelector(`input[name="extension"]`);return e instanceof HTMLInputElement?e.value.trim():this.#c}#N(){let e=this.shadowRoot?.querySelector(`input[name="transfer-target"]`);return e instanceof HTMLInputElement?e.value:``}#P(e){let t=J(e,this);if(t instanceof HTMLInputElement&&t.name!==`transfer-target`){if(t.name===`extension`){this.#c=t.value.trim();return}this.#s=t.value,this.#L()}}async#F(e){if(this.#_=void 0,e===void 0)return;let t=e.closest(`[data-call-id]`);if(t instanceof HTMLElement&&t.dataset.callId!==void 0){await this.#e?.setActiveCall(t.dataset.callId);return}let n=e.closest(`[data-digit]`);if(n instanceof HTMLElement&&n.dataset.digit!==void 0){await this.#I(n.dataset.digit);return}let r=e.closest(`[data-action]`);if(!(r instanceof HTMLElement)||r instanceof HTMLButtonElement&&r.disabled&&r.getAttribute(`data-action`)!==`enable-phone`)return;let a=this.#e?.getActiveCall?.();switch(r.getAttribute(`data-action`)){case`signin`:if(this.#e===void 0)return;this.#c=this.#M(),await this.#e.media?.requestPermission?.(),await this.#e.initialize(),await this.#e.connect();return;case`signout`:if(this.#e===void 0)return;this.#l=`offline`,await this.#e.disconnect();return;case`dial`:case`dial-internal`:if(this.#s=this.#j(),this.#e===void 0)return;this.#i!==`granted`&&await this.#e.media?.requestPermission?.(),await c(this.#e,this.#s,r.getAttribute(`data-action`)===`dial-internal`?`extension`:void 0);return;case`mute`:if(a===void 0)return;this.#u=await l(a,this.#u),this.#R();return;case`hold`:a!==void 0&&await u(a);return;case`resume`:a!==void 0&&await a.resume();return;case`transfer`:a!==void 0&&await f(a,this.#N());return;case`hangup`:await a?.hangup();return;case`answer`:a!==void 0&&await this.#e?.answer(a.id);return;case`reject`:await a?.reject();return;case`enable-phone`:if(this.#e===void 0||this.#m)return;this.#h=!0;try{await i(this.#e),this.#m=!0}finally{this.#h=!1,this.render()}return;case`more`:this.#d=!this.#d,this.render();return;case`retry-permission`:await this.#e?.media.requestPermission();return;case`devices`:return;case`agent-available`:await this.#e?.setAgentStatus(`available`);return;case`agent-break`:await this.#e?.setAgentStatus(`break`);return;case`agent-busy`:return;default:return}}async#I(e){let t=this.#e?.getActiveCall?.();if(t!==void 0&&(t.state===`active`||t.state===`held`)){await d(t,e);return}this.#s+=e;let n=this.shadowRoot?.querySelector(`input[name="destination"]`);n instanceof HTMLInputElement&&(n.value=this.#s),this.#L()}#L(){let e=!s(this.#s,this.#i,this.#r);for(let t of[`dial`,`dial-internal`]){let n=this.shadowRoot?.querySelector(`[data-action="${t}"]`);n instanceof HTMLButtonElement&&(n.disabled=e)}}#R(){let e=this.shadowRoot?.querySelector(`[data-action="mute"]`);e instanceof HTMLButtonElement&&(e.setAttribute(`aria-pressed`,this.#u?`true`:`false`),e.textContent=this.#u?this.#z().unmute:this.#z().mute)}#z(){return r(this.getAttribute(`locale`)??`zh-CN`,void 0,this.#y)}#B(){this.#b?.(),this.#b=void 0;let e=this.getAttribute(`theme`)??`light`;if(e===`dark`||e===`light`){this.setAttribute(`data-theme`,e);return}if(typeof window>`u`||typeof window.matchMedia!=`function`){this.setAttribute(`data-theme`,`light`);return}let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{this.setAttribute(`data-theme`,t.matches?`dark`:`light`)};n(),t.addEventListener(`change`,n),this.#b=()=>t.removeEventListener(`change`,n)}#V(){this.style.position=this.hasAttribute(`floating`)?`fixed`:``}#H(e){if(!(e instanceof PointerEvent)||!this.hasAttribute(`floating`)||!this.hasAttribute(`draggable`)||(e.target instanceof Element?e.target.closest(`[data-drag-handle]`):null)===null)return;e.preventDefault();let t=this.getBoundingClientRect();this.#p={pointerId:e.pointerId,offsetX:e.clientX-t.left,offsetY:e.clientY-t.top},window.addEventListener(`pointermove`,this.#U),window.addEventListener(`pointerup`,this.#W)}#U=e=>{if(this.#p===void 0||e.pointerId!==this.#p.pointerId)return;let t=window.visualViewport,n=t?.width??window.innerWidth,r=t?.height??window.innerHeight,i=q(e.clientX-this.#p.offsetX,0,Math.max(0,n-this.offsetWidth)),a=q(e.clientY-this.#p.offsetY,0,Math.max(0,r-this.offsetHeight));this.style.left=`${i}px`,this.style.top=`${a}px`,this.style.right=`auto`,this.style.bottom=`auto`};#W=e=>{this.#p!==void 0&&e.pointerId===this.#p.pointerId&&this.#G()};#G(){this.#p=void 0,window.removeEventListener(`pointermove`,this.#U),window.removeEventListener(`pointerup`,this.#W)}};function G(e={}){if(typeof customElements>`u`)return;let t=e.tagName??`xcall-ccbar`;if(customElements.get(t)!==void 0)return;let n=t===`xcall-ccbar`?W:class extends W{};customElements.define(t,n)}function K(e,t){switch(e.kind){case`unsupported`:return t.statusUnsupported;case`permission-error`:return t.statusPermission;case`unrecoverable-error`:return t.statusError;case`setup`:return t.statusSetup;case`connecting`:return t.statusConnecting;case`incoming`:return t.statusIncoming;case`active`:return t.statusActive;case`held`:return t.statusHeld;case`dialing`:return t.statusDialing;case`ended`:return t.statusEnded;case`ready`:return t.statusReady;default:return e}}function q(e,t,n){return Math.min(n,Math.max(t,e))}function J(e,t){for(let n of e.composedPath())if(n instanceof Element&&n!==t)return n;return e.target instanceof Element&&e.target!==t?e.target:void 0}function Y(e){return typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:`SDK_INTERNAL_ERROR`}var X=`0.1.0`;exports.XCallCCBarElement=W,exports.defineCCBarElement=G,exports.enUS=e,exports.resolveMessages=r,exports.uiVersion=X,exports.zhCN=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../createJsSipFactory-B1ORbJiP.cjs");var e={call:`Call`,numberLabel:`Number`,statusReady:`Ready`,statusSetup:`Not initialized`,statusConnecting:`Connecting`,statusIncoming:`Incoming call`,statusActive:`On a call`,statusHeld:`On hold`,statusDialing:`Dialing`,statusEnded:`Call ended`,statusFailed:`Call failed`,statusUnsupported:`Unsupported browser`,statusPermission:`Microphone unavailable`,statusError:`Unable to continue`,incoming:`Incoming call`,answer:`Answer`,reject:`Decline`,hangup:`Hang up`,mute:`Mute`,unmute:`Unmute`,hold:`Hold`,resume:`Resume`,transfer:`Transfer`,blindTransfer:`Blind transfer`,more:`More`,devices:`Devices`,enablePhone:`Enable phone`,retryPermission:`Check again`,permissionTitle:`Microphone unavailable`,permissionBody:`Allow microphone access in the browser settings, then check again.`,errorTitle:`Unable to continue`,errorBody:`Check the network, origin allowlist, or agent permission, then retry.`,errorTokenUnavailable:`Could not get a sign-in token. Check that the token service is running and configured.`,currentCall:`Current call`,inbound:`Inbound`,outbound:`Outbound`,foregroundChecking:`Back in foreground, checking the connection`,foregroundFailed:`Foreground recovery failed. Retry.`,signIn:`Sign in`,signOut:`Sign out`,outboundCall:`Outbound`,internalCall:`Internal`,agentIdle:`Available`,agentBusy:`Busy`,agentBreak:`Break`,agentBusyHint:`Busy is controlled by the call or server`,rowSignIn:`Presence`,rowCall:`Call`,rowAgent:`Agent`,extensionLabel:`Extension`,extensionPlaceholder:`Optional, assigned by the server`},t={call:`呼叫`,numberLabel:`号码`,statusReady:`可拨号`,statusSetup:`未初始化`,statusConnecting:`正在连接`,statusIncoming:`来电`,statusActive:`通话中`,statusHeld:`保持中`,statusDialing:`正在拨号`,statusEnded:`通话结束`,statusFailed:`呼叫失败`,statusUnsupported:`不支持的浏览器`,statusPermission:`无法使用麦克风`,statusError:`无法继续通话`,incoming:`来电`,answer:`接听`,reject:`拒绝`,hangup:`挂断`,mute:`静音`,unmute:`取消静音`,hold:`保持`,resume:`恢复`,transfer:`转接`,blindTransfer:`盲转`,more:`更多`,devices:`设备`,enablePhone:`启用电话`,retryPermission:`重新检测`,permissionTitle:`无法使用麦克风`,permissionBody:`请在浏览器设置中允许本网站访问麦克风,然后重新检测。`,errorTitle:`无法继续通话`,errorBody:`请检查网络、域名授权或坐席权限后重试。`,errorTokenUnavailable:`无法获取登录凭证,请检查 token 服务是否启动及配置是否正确。`,currentCall:`当前通话`,inbound:`呼入`,outbound:`呼出`,foregroundChecking:`已返回前台,正在检查连接`,foregroundFailed:`前台恢复失败,请重试`,signIn:`签入`,signOut:`退签`,outboundCall:`外呼`,internalCall:`内呼`,agentIdle:`空闲`,agentBusy:`置忙`,agentBreak:`休息`,agentBusyHint:`置忙由通话或服务端状态控制`,rowSignIn:`签入`,rowCall:`通话`,rowAgent:`坐席`,extensionLabel:`分机`,extensionPlaceholder:`可空,由服务端分配`};function n(n){return n.toLowerCase().startsWith(`en`)?e:t}function r(e,t,r){return{...n(e),...r===void 0?{}:r(e),...t??{}}}async function i(e){await e.media.requestPermission(),await e.initialize(),await e.connect()}function a(e,t={}){let n=t.document??(typeof document>`u`?void 0:document);if(n===void 0)return()=>void 0;let r=()=>{if(n.visibilityState===`hidden`){t.onHidden?.();return}t.onChecking?.(),e.recover().then(()=>t.onRecovered?.()).catch(e=>t.onFailed?.(e))};return n.addEventListener(`visibilitychange`,r),()=>n.removeEventListener(`visibilitychange`,r)}function o(e){return e.replace(/\s+/g,``)}function s(e,t,n){return o(e).length>0&&n===`connected`&&t!==`denied`}async function c(e,t,n){let r=o(t);r!==``&&await e.dial({destination:r,...n===void 0?{}:{type:n}})}async function l(e,t){return t?await e.unmute():await e.mute(),!t}async function u(e){e.state===`held`?await e.resume():await e.hold()}async function d(e,t){await e.sendDtmf(t)}async function f(e,t){let n=o(t);n!==``&&await e.transfer({target:n,type:`blind`})}function p(e,t={}){let n=document.createElement(e);return t.className!==void 0&&(n.className=t.className),t.text!==void 0&&(n.textContent=t.text),Object.entries(t.attrs??{}).forEach(([e,t])=>n.setAttribute(e,t)),t.children?.forEach(e=>n.append(e)),n}function m(e){return p(`div`,{attrs:{part:`status-rail`,role:`status`,"aria-live":`polite`},text:e})}function h(e,t,n=`destination`){let r=p(`input`,{attrs:{id:e,type:`tel`,inputmode:`tel`,name:n,autocomplete:`tel`}});return{field:p(`div`,{children:[p(`label`,{attrs:{for:e},text:t}),r]}),input:r}}var g=[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`*`,`0`,`#`];function _(e){return e.mode===`compact`?v(e):y(e)}function v(e){let{field:t,input:n}=h(`ccbar-destination`,e.messages.numberLabel??`号码`);n.value=e.destination;let r=e.view.kind===`ready`||e.view.kind===`setup`||e.view.kind===`ended`?p(`button`,{attrs:{type:`button`,"data-action":`dial`,part:`call-button`,...e.canDial?{}:{disabled:``}},text:e.messages.call??`呼叫`}):p(`button`,{attrs:{type:`button`,"data-action":`hangup`,part:`hangup-button`},text:e.messages.hangup??`挂断`}),i=[S(e.messages.status??``,e.floating),p(`div`,{className:`ccbar-toolbar`,children:[t,e.view.kind===`active`||e.view.kind===`held`?E(e):p(`span`),r,p(`button`,{attrs:{type:`button`,"data-action":`more`},text:e.messages.more??`更多`})]})];return e.moreOpen&&i.push(p(`div`,{className:`ccbar-more`,children:[D(e.view,e.messages),p(`button`,{attrs:{type:`button`,"data-action":`devices`},text:e.messages.devices??`设备`})]})),p(`div`,{attrs:{part:`panel`,"data-layout":`compact`},children:i})}function y(e){let{input:t}=h(`ccbar-destination`,e.messages.numberLabel??`号码`),{field:n}=h(`ccbar-transfer-target`,e.messages.transfer??`转接号码`,`transfer-target`);t.value=e.destination,t.placeholder=e.messages.numberLabel??`号码`,t.setAttribute(`aria-label`,e.messages.numberLabel??`号码`);let r=e.view.kind===`active`||e.view.kind===`held`||e.view.kind===`dialing`,i=e.view.kind===`held`,a=e.view.kind===`connecting`,o=[S(e.messages.status??``,e.floating,e.extension,e.messages.extensionLabel??`分机`),b(e.messages.rowSignIn??`签入`,[C(e),x(`signin`,e.messages.signIn??`签入`,{variant:`primary`,disabled:e.connected||a}),x(`signout`,e.messages.signOut??`退签`,{disabled:!e.connected})]),b(e.messages.numberLabel??`号码`,[t],{labelFor:t.id}),b(e.messages.rowCall??`通话`,[x(`dial`,e.messages.outboundCall??`外呼`,{variant:`primary`,disabled:!e.canDial}),x(`dial-internal`,e.messages.internalCall??`内呼`,{disabled:!e.canDial}),x(`hangup`,e.messages.hangup??`挂断`,{variant:`danger`,disabled:!r}),x(`transfer`,e.messages.transfer??`转接`,{disabled:!r}),x(`hold`,e.messages.hold??`保持`,{pressed:i,disabled:!r||i}),x(`resume`,e.messages.resume??`恢复`,{disabled:!i}),E(e)]),...r?[b(e.messages.transfer??`转接号码`,[n],{labelFor:`ccbar-transfer-target`})]:[],b(e.messages.rowAgent??`坐席`,[x(`agent-available`,e.messages.agentIdle??`空闲`,{pressed:e.agentStatus===`available`,disabled:!e.connected}),x(`agent-busy`,e.messages.agentBusy??`置忙`,{disabled:!0,title:e.messages.agentBusyHint??`置忙由通话或服务端状态控制`}),x(`agent-break`,e.messages.agentBreak??`休息`,{pressed:e.agentStatus===`break`,disabled:!e.connected})]),T()];return e.calls.length>1&&o.push(O(e.calls,e.messages)),p(`div`,{attrs:{part:`panel`,"data-layout":`panel`},children:o})}function b(e,t,n={}){return p(`div`,{className:`ccbar-bar-row`,children:[p(n.labelFor===void 0?`div`:`label`,{className:`ccbar-bar-label`,attrs:n.labelFor===void 0?{}:{for:n.labelFor},text:e}),p(`div`,{className:`ccbar-bar-keys`,children:t})]})}function x(e,t,n={}){let r=e===`dial`?`call-button`:e===`hangup`?`hangup-button`:void 0;return p(`button`,{attrs:{type:`button`,"data-action":e,...r===void 0?{}:{part:r},...n.variant===void 0?{}:{"data-variant":n.variant},...n.disabled===!0?{disabled:``}:{},...n.pressed===void 0?{}:{"aria-pressed":n.pressed?`true`:`false`},...n.title===void 0?{}:{title:n.title}},text:t})}function S(e,t,n=``,r=`分机`){let i=w(e);return t&&i.setAttribute(`data-drag-handle`,``),n!==``&&i.append(p(`span`,{className:`ccbar-ext-chip`,text:`${r} ${n}`})),i}function C(e){let t=p(`input`,{attrs:{id:`ccbar-extension`,type:`tel`,inputmode:`numeric`,name:`extension`,autocomplete:`off`,placeholder:e.messages.extensionPlaceholder??`可空,由服务端分配`,"aria-label":e.messages.extensionLabel??`分机`}});return t.value=e.extension,e.connected&&(t.readOnly=!0),t}function w(e){return m(e)}function T(){return p(`div`,{className:`ccbar-dialpad`,children:g.map(e=>p(`button`,{attrs:{type:`button`,"data-digit":e},text:e}))})}function E(e){return p(`button`,{attrs:{type:`button`,"data-action":`mute`,"aria-pressed":e.muted?`true`:`false`},text:e.muted?e.messages.unmute??`取消静音`:e.messages.mute??`静音`})}function D(e,t){let n=e.kind===`held`;return p(`button`,{attrs:{type:`button`,"data-action":`hold`,"aria-pressed":n?`true`:`false`},text:n?t.resume??`恢复`:t.hold??`保持`})}function O(e,t){return p(`ul`,{className:`ccbar-call-list`,children:e.map(e=>p(`li`,{children:[p(`button`,{attrs:{type:`button`,"data-call-id":e.id},children:[p(`span`,{text:`${e.destination} ${e.direction===`inbound`?t.inbound??`呼入`:t.outbound??`呼出`} ${k(e.state,t)}`}),...e.current?[p(`span`,{className:`ccbar-call-current`,text:t.currentCall??`当前通话`})]:[]]})]}))})}function k(e,t){return e===`held`?t.statusHeld??`保持中`:e===`active`?t.statusActive??`通话中`:e===`dialing`||e===`ringing`||e===`connecting`?t.statusDialing??`拨号中`:e}function A(e){switch(e.view.kind){case`permission-error`:return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.permissionTitle??`无法使用麦克风`),p(`h2`,{text:e.messages.permissionTitle??`无法使用麦克风`}),p(`p`,{text:e.messages.permissionBody??`请在浏览器设置中允许本网站访问麦克风,然后重新检测。`}),p(`button`,{attrs:{type:`button`,"data-action":`retry-permission`},text:e.messages.retryPermission??`重新检测`})]});case`unrecoverable-error`:case`unsupported`:return p(`div`,{attrs:{part:`panel`},children:[p(`div`,{attrs:{role:`alert`,part:`status-rail`},text:e.messages.errorTitle??`无法继续通话`}),p(`p`,{text:e.view.kind===`unrecoverable-error`&&e.view.code===`AUTH_TOKEN_UNAVAILABLE`?e.messages.errorTokenUnavailable??`无法获取登录凭证,请检查 token 服务是否启动及配置是否正确。`:e.messages.errorBody??`请检查网络、域名授权或坐席权限后重试。`}),...e.view.kind===`unrecoverable-error`?[p(`code`,{attrs:{"data-error-code":e.view.code},text:e.view.code})]:[]]});case`setup`:case`connecting`:case`incoming`:case`active`:case`held`:case`dialing`:case`ended`:case`ready`:return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.status??``)]});default:return e.view}}function j(e){return p(`div`,{attrs:{part:`panel`},children:[m(e.messages.status??`来电`),p(`p`,{text:e.view.from}),p(`button`,{attrs:{type:`button`,"data-action":`answer`},text:e.messages.answer??`接听`}),p(`button`,{attrs:{type:`button`,"data-action":`reject`},text:e.messages.reject??`拒绝`})]})}var M=[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`*`,`0`,`#`];function N(e){return F(p(`div`,{attrs:{part:`panel`,"data-layout":`mobile`},children:[m(e.status),p(`button`,{attrs:{type:`button`,"data-action":`enable-phone`,...e.enabling?{disabled:``}:{}},text:e.enablePhone??`启用电话`})]}))}function P(e){let t=e.view.kind===`active`||e.view.kind===`dialing`,n=[m(e.messages.status??``)];if(t){let t=e.view.kind===`active`||e.view.kind===`dialing`?e.view.destination??``:``;n.push(p(`p`,{text:t}),I(p(`button`,{attrs:{type:`button`,"data-action":`mute`,"aria-pressed":e.muted?`true`:`false`},text:e.muted?e.messages.unmute??`取消静音`:e.messages.mute??`静音`}),44),L(),I(p(`button`,{attrs:{type:`button`,"data-action":`hangup`,part:`hangup-button`},text:e.messages.hangup??`挂断`}),52))}else{let{field:t,input:r}=h(`ccbar-destination`,e.messages.numberLabel??`号码`);r.value=e.destination,n.push(t,L(),p(`button`,{attrs:{type:`button`,"data-action":`dial`,part:`call-button`,...e.canDial?{}:{disabled:``}},text:e.messages.call??`呼叫`}))}return e.showOutputDevice&&n.push(p(`button`,{attrs:{type:`button`,"data-action":`devices`},text:e.messages.devices??`设备`})),F(p(`div`,{attrs:{part:`panel`,"data-layout":`mobile`},children:n}))}function F(e){return e.style.minHeight=`100dvh`,e.style.paddingBottom=`max(16px, env(safe-area-inset-bottom))`,e}function I(e,t){return e.style.minHeight=`${t}px`,e}function L(){return p(`div`,{className:`ccbar-dialpad`,children:M.map(e=>p(`button`,{attrs:{type:`button`,"data-digit":e},text:e}))})}var R={kind:`permission-error`,code:`MEDIA_PERMISSION_DENIED`,action:`retry-permission`};function z(e){if(e.supported===!1)return{kind:`unsupported`};if(e.permission===`denied`||e.error?.code===`MEDIA_PERMISSION_DENIED`)return R;if(e.error!==void 0&&e.error.code!==`MEDIA_PLAYBACK_BLOCKED`)return{kind:`unrecoverable-error`,code:e.error.code};let t=e.calls.find(e=>e.direction===`inbound`&&(e.state===`ringing`||e.state===`new`));if(t!==void 0)return{kind:`incoming`,callId:t.id,from:t.destination??``};let n=e.calls.find(e=>e.state===`active`);if(n!==void 0)return{kind:`active`,callId:n.id,destination:n.destination};let r=e.calls.find(e=>e.state===`held`);if(r!==void 0)return{kind:`held`,callId:r.id,destination:r.destination};let i=e.calls.find(e=>e.state===`dialing`||e.state===`ringing`||e.state===`connecting`);if(i!==void 0)return{kind:`dialing`,callId:i.id,destination:i.destination};let a=e.calls.find(e=>e.state===`ended`||e.state===`failed`);return a===void 0?e.connectionState===`connecting`||e.connectionState===`reconnecting`?{kind:`connecting`}:e.connectionState===`connected`?{kind:`ready`}:{kind:`setup`}:{kind:`ended`,callId:a.id}}var B=`:root,:host{--ccbar-color-surface:#fff;--ccbar-color-surface-muted:#f1f5f9;--ccbar-color-border:#d8e0ea;--ccbar-color-title:#0f172a;--ccbar-color-text:#334155;--ccbar-color-muted:#475569;--ccbar-color-primary:#2563eb;--ccbar-color-primary-hover:#1d4ed8;--ccbar-color-success:#15803d;--ccbar-color-warning:#a15c00;--ccbar-color-danger:#b91c1c;--ccbar-radius-sm:6px;--ccbar-radius:8px;--ccbar-radius-lg:12px;--ccbar-control-height:40px;--ccbar-control-height-touch:44px;--ccbar-space-1:4px;--ccbar-space-2:8px;--ccbar-space-3:12px;--ccbar-space-4:16px;--ccbar-space-6:24px;--ccbar-font-family:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;--ccbar-panel-width:560px}:host{color:var(--ccbar-color-text);font-family:var(--ccbar-font-family);display:block}:host([floating]){z-index:2147483646;right:var(--ccbar-space-6);bottom:var(--ccbar-space-6);position:fixed}[part=panel]{background:var(--ccbar-color-surface);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-lg)}[part=status-rail]{align-items:center;gap:var(--ccbar-space-2);min-height:var(--ccbar-control-height);padding:var(--ccbar-space-2) var(--ccbar-space-3);border-bottom:1px solid var(--ccbar-color-border);color:var(--ccbar-color-muted);font-variant-numeric:tabular-nums;display:flex}[part=status-rail]:before{content:"";background:var(--ccbar-color-muted);border-radius:50%;flex:none;width:8px;height:8px}button{min-height:var(--ccbar-control-height);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-sm);background:var(--ccbar-color-surface);color:var(--ccbar-color-title);font:inherit}button[data-action=dial],button[data-action=signin],button[data-action=answer],button[data-variant=primary]{background:var(--ccbar-color-primary);border-color:var(--ccbar-color-primary);color:#fff}button[aria-pressed=true]{border-color:var(--ccbar-color-primary);color:var(--ccbar-color-primary);background:var(--ccbar-color-surface-muted)}button[data-action=hangup],button[data-action=reject]{background:var(--ccbar-color-danger);border-color:var(--ccbar-color-danger);color:#fff;margin-top:var(--ccbar-space-4)}button:disabled{opacity:.5}button:focus-visible,input:focus-visible{outline:2px solid var(--ccbar-color-primary);outline-offset:2px}input[type=tel]{width:100%;min-height:var(--ccbar-control-height);border:1px solid var(--ccbar-color-border);border-radius:var(--ccbar-radius-sm);font-variant-numeric:tabular-nums}.ccbar-call-list{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0 0;padding:0;list-style:none;display:grid}.ccbar-call-list button{text-align:left;width:100%}.ccbar-call-current{color:var(--ccbar-color-title);display:block}[data-layout=compact]{min-height:80px;max-height:96px}[data-layout=compact] .ccbar-toolbar{gap:var(--ccbar-space-2);padding:var(--ccbar-space-2) var(--ccbar-space-3);grid-template-columns:minmax(0,1fr) auto auto auto;align-items:center;display:grid}[data-layout=compact] .ccbar-more{right:var(--ccbar-space-3);gap:var(--ccbar-space-2);display:grid;position:absolute}[data-layout=panel]{width:min(var(--ccbar-panel-width), 100%);min-width:420px;max-width:560px;padding:var(--ccbar-space-3)}[data-layout=panel] .ccbar-bar-row{gap:var(--ccbar-space-2) var(--ccbar-space-3);grid-template-columns:48px minmax(0,1fr);align-items:center;min-height:36px;display:grid}[data-layout=panel] .ccbar-bar-row+.ccbar-bar-row{margin-top:var(--ccbar-space-2)}[data-layout=panel] .ccbar-bar-label{color:var(--ccbar-color-muted);font-size:12px}[data-layout=panel] .ccbar-bar-keys{align-items:center;gap:var(--ccbar-space-2);flex-wrap:wrap;display:flex}[data-layout=panel] .ccbar-bar-keys button{min-width:48px;min-height:32px;padding:0 10px;font-size:13px}[data-layout=panel] .ccbar-bar-keys input[type=tel]{max-width:320px}[data-layout=panel] .ccbar-bar-keys input[name=extension]{width:148px;max-width:148px}[data-layout=panel] .ccbar-ext-chip{background:var(--ccbar-color-surface-muted);height:28px;color:var(--ccbar-color-title);font-variant-numeric:tabular-nums;border-radius:999px;align-items:center;margin-left:auto;padding:0 10px;font-size:12px;display:inline-flex}[data-layout=panel] [data-action=hangup]{margin-top:0}[data-layout=panel] .ccbar-dialpad{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0 0;grid-template-columns:repeat(3,1fr);display:grid}[data-layout=panel] .ccbar-safe-actions{gap:var(--ccbar-space-2);flex-wrap:wrap;display:flex}[data-layout=mobile]{min-height:100vh;padding:var(--ccbar-space-4);padding-bottom:max(16px, env(safe-area-inset-bottom))}[data-layout=mobile] button{min-width:44px;min-height:44px}[data-layout=mobile] [data-action=enable-phone],[data-layout=mobile] [data-action=dial],[data-layout=mobile] [data-action=hangup]{min-height:52px}[data-layout=mobile] .ccbar-dialpad{gap:var(--ccbar-space-2);margin:var(--ccbar-space-3) 0;grid-template-columns:repeat(3,1fr);display:grid}:host([data-theme=dark]){--ccbar-color-surface:#0f172a;--ccbar-color-surface-muted:#1e293b;--ccbar-color-border:#334155;--ccbar-color-title:#f8fafc;--ccbar-color-text:#e2e8f0;--ccbar-color-muted:#94a3b8;--ccbar-color-primary:#3b82f6;--ccbar-color-primary-hover:#2563eb;--ccbar-color-success:#22c55e;--ccbar-color-warning:#f59e0b;--ccbar-color-danger:#ef4444}@media (prefers-reduced-motion:reduce){:host *,:host :before,:host :after{transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}}`,V=typeof HTMLElement==`function`?HTMLElement:class{},H=new WeakSet,U=[`connection.stateChanged`,`connection.reconnecting`,`connection.failed`,`call.incoming`,`call.stateChanged`,`call.activeChanged`,`call.ended`,`call.failed`,`media.permissionChanged`,`agent.statusChanged`,`error`],W=class extends V{static get observedAttributes(){return[`mode`,`floating`,`draggable`,`locale`,`theme`]}#e;#t=!1;#n=[];#r=`idle`;#i=`unknown`;#a;#o=new Set;#s=``;#c=``;#l=`offline`;#u=!1;#d=!1;#f=Promise.resolve();#p;#m=!1;#h=!1;#g;#_;#v;#y;#b;get messageResolver(){return this.#y}set messageResolver(e){this.#y=e,this.shadowRoot!==null&&this.render()}get client(){return this.#e}set client(e){this.#O(),this.#e=e,this.#D(),this.render()}get ownsClient(){return this.#t}set ownsClient(e){this.#t=e===!0}connectedCallback(){this.#V(),this.#B(),this.render()}disconnectedCallback(){let e=this.#e,t=this.#t;this.#O(),this.#G(),this.#b?.(),this.#b=void 0,t&&(this.#e=void 0,e?.dispose())}attributeChangedCallback(e){this.#V(),e===`theme`&&this.#B(),this.shadowRoot!==null&&this.render()}render(){let e=this.#k();e!==void 0&&(e.innerHTML=`<style>${B}</style>`,e.append(this.#S(this.#x())))}#x(){let e=this.#e?.getCalls?.().map(e=>({id:e.id,state:e.state,destination:e.destination,direction:this.#o.has(e.id)?`inbound`:`outbound`}))??[];return z({connectionState:this.#r,permission:this.#i,calls:e,error:this.#a})}#S(e){let t=this.#z(),n=this.#_??this.#g??K(e,t),r={...t,status:n},i=this.#C(e,r,n);return i.setAttribute(`data-view`,this.#E()&&!this.#m?`setup`:e.kind),i.hasAttribute(`data-layout`)||i.setAttribute(`data-layout`,this.#E()?`mobile`:`panel`),i}#C(e,t,n){if(this.#E()&&!this.#m)return N({enabling:this.#h,status:n,enablePhone:t.enablePhone});switch(e.kind){case`permission-error`:case`unrecoverable-error`:case`unsupported`:return A({view:e,messages:t});case`incoming`:return this.#E()?P({view:{kind:`ready`},messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),showOutputDevice:this.#e?.media.supportsOutputSelection()===!0}):j({view:e,messages:t});case`setup`:case`connecting`:case`ended`:case`ready`:case`active`:case`held`:case`dialing`:return this.#E()?P({view:e.kind===`held`?{kind:`ready`}:e,messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),showOutputDevice:this.#e?.media.supportsOutputSelection()===!0}):_({mode:this.#T()===`compact`?`compact`:`panel`,view:e,messages:t,destination:this.#s,muted:this.#u,canDial:s(this.#s,this.#i,this.#r),moreOpen:this.#d,floating:this.hasAttribute(`floating`),connected:this.#r===`connected`,agentStatus:this.#l,extension:this.#c,calls:this.#w()});default:return e}}#w(){let e=this.#e?.getActiveCall?.()?.id;return this.#e?.getCalls?.().map(t=>({id:t.id,destination:t.destination,state:t.state,direction:this.#o.has(t.id)?`inbound`:`outbound`,current:t.id===e}))??[]}#T(){let e=this.getAttribute(`mode`);return e===`compact`||e===`mobile`?e:`panel`}#E(){return this.#T()===`mobile`}#D(){let e=this.#e;e!==void 0&&(this.#n.push(e.on(`connection.stateChanged`,t=>{if(this.#r=t.state,t.state!==`connected`&&(this.#l=`offline`),t.state===`connected`){let t=e.getAgent?.()?.extension?.trim();t!==void 0&&t!==``&&(this.#c=t)}})),this.#n.push(e.on(`agent.statusChanged`,e=>{(e.status===`available`||e.status===`offline`||e.status===`break`)&&(this.#l=e.status)})),this.#n.push(e.on(`connection.failed`,e=>{this.#r=`failed`,this.#a={code:e.error.code}})),this.#n.push(e.on(`media.permissionChanged`,e=>{this.#i=e.permission})),this.#n.push(e.on(`error`,e=>{this.#a={code:e.error.code}})),this.#n.push(e.on(`call.incoming`,e=>{this.#o.add(e.callId)})),this.#n.push(e.on(`call.ended`,e=>{this.#o.delete(e.callId),this.#u=!1})),this.#n.push(e.on(`call.failed`,()=>{this.#_=this.#z().statusFailed})),U.forEach(t=>{this.#n.push(e.on(t,()=>this.render()))}),this.#E()&&typeof e.recover==`function`&&(this.#v=a(e,{onChecking:()=>{this.#g=this.#z().foregroundChecking,this.render()},onRecovered:()=>{this.#g=void 0,this.render()},onFailed:()=>{this.#g=this.#z().foregroundFailed,this.render()}})))}#O(){let e=this.#n;this.#n=[],e.forEach(e=>e()),this.#r=`idle`,this.#i=`unknown`,this.#l=`offline`,this.#a=void 0,this.#o.clear(),this.#u=!1,this.#d=!1,this.#m=!1,this.#h=!1,this.#g=void 0,this.#v?.(),this.#v=void 0}#k(){if(typeof this.attachShadow!=`function`)return;let e=this.shadowRoot??this.attachShadow({mode:`open`});return H.has(e)||(H.add(e),e.addEventListener(`click`,e=>this.#A(e)),e.addEventListener(`input`,e=>this.#P(e)),e.addEventListener(`pointerdown`,e=>this.#H(e))),e}#A(e){let t=J(e,this),n=t?.closest(`[data-action="enable-phone"]`);n instanceof HTMLButtonElement&&(n.disabled=!0),this.#f=this.#f.then(()=>this.#F(t)).catch(e=>{this.#_=Y(e),this.render()})}#j(){let e=this.shadowRoot?.querySelector(`input[name="destination"]`);return e instanceof HTMLInputElement?e.value:this.#s}#M(){let e=this.shadowRoot?.querySelector(`input[name="extension"]`);return e instanceof HTMLInputElement?e.value.trim():this.#c}#N(){let e=this.shadowRoot?.querySelector(`input[name="transfer-target"]`);return e instanceof HTMLInputElement?e.value:``}#P(e){let t=J(e,this);if(t instanceof HTMLInputElement&&t.name!==`transfer-target`){if(t.name===`extension`){this.#c=t.value.trim();return}this.#s=t.value,this.#L()}}async#F(e){if(this.#_=void 0,e===void 0)return;let t=e.closest(`[data-call-id]`);if(t instanceof HTMLElement&&t.dataset.callId!==void 0){await this.#e?.setActiveCall(t.dataset.callId);return}let n=e.closest(`[data-digit]`);if(n instanceof HTMLElement&&n.dataset.digit!==void 0){await this.#I(n.dataset.digit);return}let r=e.closest(`[data-action]`);if(!(r instanceof HTMLElement)||r instanceof HTMLButtonElement&&r.disabled&&r.getAttribute(`data-action`)!==`enable-phone`)return;let a=this.#e?.getActiveCall?.()??this.#e?.getCalls?.().find(e=>e.state===`held`);switch(r.getAttribute(`data-action`)){case`signin`:if(this.#e===void 0)return;this.#c=this.#M(),await this.#e.media?.requestPermission?.(),await this.#e.initialize(),await this.#e.connect();return;case`signout`:if(this.#e===void 0)return;this.#l=`offline`,await this.#e.disconnect();return;case`dial`:case`dial-internal`:if(this.#s=this.#j(),this.#e===void 0)return;this.#i!==`granted`&&await this.#e.media?.requestPermission?.(),await c(this.#e,this.#s,r.getAttribute(`data-action`)===`dial-internal`?`extension`:void 0);return;case`mute`:if(a===void 0)return;this.#u=await l(a,this.#u),this.#R();return;case`hold`:a!==void 0&&await u(a);return;case`resume`:a!==void 0&&await a.resume();return;case`transfer`:a!==void 0&&await f(a,this.#N());return;case`hangup`:await a?.hangup();return;case`answer`:a!==void 0&&await this.#e?.answer(a.id);return;case`reject`:await a?.reject();return;case`enable-phone`:if(this.#e===void 0||this.#m)return;this.#h=!0;try{await i(this.#e),this.#m=!0}finally{this.#h=!1,this.render()}return;case`more`:this.#d=!this.#d,this.render();return;case`retry-permission`:await this.#e?.media.requestPermission();return;case`devices`:return;case`agent-available`:await this.#e?.setAgentStatus(`available`);return;case`agent-break`:await this.#e?.setAgentStatus(`break`);return;case`agent-busy`:return;default:return}}async#I(e){let t=this.#e?.getActiveCall?.()??this.#e?.getCalls?.().find(e=>e.state===`held`);if(t!==void 0&&(t.state===`active`||t.state===`held`)){await d(t,e);return}this.#s+=e;let n=this.shadowRoot?.querySelector(`input[name="destination"]`);n instanceof HTMLInputElement&&(n.value=this.#s),this.#L()}#L(){let e=!s(this.#s,this.#i,this.#r);for(let t of[`dial`,`dial-internal`]){let n=this.shadowRoot?.querySelector(`[data-action="${t}"]`);n instanceof HTMLButtonElement&&(n.disabled=e)}}#R(){let e=this.shadowRoot?.querySelector(`[data-action="mute"]`);e instanceof HTMLButtonElement&&(e.setAttribute(`aria-pressed`,this.#u?`true`:`false`),e.textContent=this.#u?this.#z().unmute:this.#z().mute)}#z(){return r(this.getAttribute(`locale`)??`zh-CN`,void 0,this.#y)}#B(){this.#b?.(),this.#b=void 0;let e=this.getAttribute(`theme`)??`light`;if(e===`dark`||e===`light`){this.setAttribute(`data-theme`,e);return}if(typeof window>`u`||typeof window.matchMedia!=`function`){this.setAttribute(`data-theme`,`light`);return}let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{this.setAttribute(`data-theme`,t.matches?`dark`:`light`)};n(),t.addEventListener(`change`,n),this.#b=()=>t.removeEventListener(`change`,n)}#V(){this.style.position=this.hasAttribute(`floating`)?`fixed`:``}#H(e){if(!(e instanceof PointerEvent)||!this.hasAttribute(`floating`)||!this.hasAttribute(`draggable`)||(e.target instanceof Element?e.target.closest(`[data-drag-handle]`):null)===null)return;e.preventDefault();let t=this.getBoundingClientRect();this.#p={pointerId:e.pointerId,offsetX:e.clientX-t.left,offsetY:e.clientY-t.top},window.addEventListener(`pointermove`,this.#U),window.addEventListener(`pointerup`,this.#W)}#U=e=>{if(this.#p===void 0||e.pointerId!==this.#p.pointerId)return;let t=window.visualViewport,n=t?.width??window.innerWidth,r=t?.height??window.innerHeight,i=q(e.clientX-this.#p.offsetX,0,Math.max(0,n-this.offsetWidth)),a=q(e.clientY-this.#p.offsetY,0,Math.max(0,r-this.offsetHeight));this.style.left=`${i}px`,this.style.top=`${a}px`,this.style.right=`auto`,this.style.bottom=`auto`};#W=e=>{this.#p!==void 0&&e.pointerId===this.#p.pointerId&&this.#G()};#G(){this.#p=void 0,window.removeEventListener(`pointermove`,this.#U),window.removeEventListener(`pointerup`,this.#W)}};function G(e={}){if(typeof customElements>`u`)return;let t=e.tagName??`xcall-ccbar`;if(customElements.get(t)!==void 0)return;let n=t===`xcall-ccbar`?W:class extends W{};customElements.define(t,n)}function K(e,t){switch(e.kind){case`unsupported`:return t.statusUnsupported;case`permission-error`:return t.statusPermission;case`unrecoverable-error`:return t.statusError;case`setup`:return t.statusSetup;case`connecting`:return t.statusConnecting;case`incoming`:return t.statusIncoming;case`active`:return t.statusActive;case`held`:return t.statusHeld;case`dialing`:return t.statusDialing;case`ended`:return t.statusEnded;case`ready`:return t.statusReady;default:return e}}function q(e,t,n){return Math.min(n,Math.max(t,e))}function J(e,t){for(let n of e.composedPath())if(n instanceof Element&&n!==t)return n;return e.target instanceof Element&&e.target!==t?e.target:void 0}function Y(e){return typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:`SDK_INTERNAL_ERROR`}var X=`0.1.0`;exports.XCallCCBarElement=W,exports.defineCCBarElement=G,exports.enUS=e,exports.resolveMessages=r,exports.uiVersion=X,exports.zhCN=t;
package/dist/ui/index.js CHANGED
@@ -32,6 +32,7 @@ var e = {
32
32
  permissionBody: "Allow microphone access in the browser settings, then check again.",
33
33
  errorTitle: "Unable to continue",
34
34
  errorBody: "Check the network, origin allowlist, or agent permission, then retry.",
35
+ errorTokenUnavailable: "Could not get a sign-in token. Check that the token service is running and configured.",
35
36
  currentCall: "Current call",
36
37
  inbound: "Inbound",
37
38
  outbound: "Outbound",
@@ -83,6 +84,7 @@ var e = {
83
84
  permissionBody: "请在浏览器设置中允许本网站访问麦克风,然后重新检测。",
84
85
  errorTitle: "无法继续通话",
85
86
  errorBody: "请检查网络、域名授权或坐席权限后重试。",
87
+ errorTokenUnavailable: "无法获取登录凭证,请检查 token 服务是否启动及配置是否正确。",
86
88
  currentCall: "当前通话",
87
89
  inbound: "呼入",
88
90
  outbound: "呼出",
@@ -443,13 +445,20 @@ function A(e) {
443
445
  case "unrecoverable-error":
444
446
  case "unsupported": return p("div", {
445
447
  attrs: { part: "panel" },
446
- children: [p("div", {
447
- attrs: {
448
- role: "alert",
449
- part: "status-rail"
450
- },
451
- text: e.messages.errorTitle ?? "无法继续通话"
452
- }), p("p", { text: e.messages.errorBody ?? "请检查网络、域名授权或坐席权限后重试。" })]
448
+ children: [
449
+ p("div", {
450
+ attrs: {
451
+ role: "alert",
452
+ part: "status-rail"
453
+ },
454
+ text: e.messages.errorTitle ?? "无法继续通话"
455
+ }),
456
+ p("p", { text: e.view.kind === "unrecoverable-error" && e.view.code === "AUTH_TOKEN_UNAVAILABLE" ? e.messages.errorTokenUnavailable ?? "无法获取登录凭证,请检查 token 服务是否启动及配置是否正确。" : e.messages.errorBody ?? "请检查网络、域名授权或坐席权限后重试。" }),
457
+ ...e.view.kind === "unrecoverable-error" ? [p("code", {
458
+ attrs: { "data-error-code": e.view.code },
459
+ text: e.view.code
460
+ })] : []
461
+ ]
453
462
  });
454
463
  case "setup":
455
464
  case "connecting":
@@ -884,7 +893,7 @@ var B = ":root,:host{--ccbar-color-surface:#fff;--ccbar-color-surface-muted:#f1f
884
893
  }
885
894
  let r = e.closest("[data-action]");
886
895
  if (!(r instanceof HTMLElement) || r instanceof HTMLButtonElement && r.disabled && r.getAttribute("data-action") !== "enable-phone") return;
887
- let a = this.#e?.getActiveCall?.();
896
+ let a = this.#e?.getActiveCall?.() ?? this.#e?.getCalls?.().find((e) => e.state === "held");
888
897
  switch (r.getAttribute("data-action")) {
889
898
  case "signin":
890
899
  if (this.#e === void 0) return;
@@ -948,7 +957,7 @@ var B = ":root,:host{--ccbar-color-surface:#fff;--ccbar-color-surface-muted:#f1f
948
957
  }
949
958
  }
950
959
  async #I(e) {
951
- let t = this.#e?.getActiveCall?.();
960
+ let t = this.#e?.getActiveCall?.() ?? this.#e?.getCalls?.().find((e) => e.state === "held");
952
961
  if (t !== void 0 && (t.state === "active" || t.state === "held")) {
953
962
  await d(t, e);
954
963
  return;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.2.4";
1
+ export declare const SDK_VERSION = "3.2.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@16x/webphone-sdk",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "homepage": "https://www.npmjs.com/package/@16x/webphone-sdk",
5
5
  "private": false,
6
6
  "license": "UNLICENSED",
@@ -66,7 +66,7 @@
66
66
  "./styles.css": "./dist/styles.css"
67
67
  },
68
68
  "scripts": {
69
- "build": "vite build && vite build -c vite.umd.config.ts",
69
+ "build": "vite build && vite build -c vite.umd.config.ts && node scripts/obfuscate-umd.mjs",
70
70
  "typecheck": "tsc -p tsconfig.json --noEmit",
71
71
  "test": "npm run build && npm run docs:build && vitest run",
72
72
  "lint": "eslint .",
@@ -100,6 +100,7 @@
100
100
  "@vitejs/plugin-vue": "^6.0.9",
101
101
  "eslint": "^10.10.0",
102
102
  "happy-dom": "^20.14.5",
103
+ "javascript-obfuscator": "^4.1.1",
103
104
  "react": "^19.3.0",
104
105
  "react-dom": "^19.3.0",
105
106
  "typescript": "^6.0.3",
@@ -1 +0,0 @@
1
- const e=require("./SharedWorkerProtocol-C-4KpECM.cjs");require("./createJsSipFactory-B1ORbJiP.cjs");function t(e){let t=new Map;return{peerConnection:{getSenders:()=>e.getSenders().map(n=>{let r=t.get(n);if(r!==void 0)return r;let i={get track(){return n.track},get senderKind(){let t=n.track;if(t!==null)return t.kind===`audio`||t.kind===`video`?t.kind:void 0;let r=e.getTransceivers().find(e=>e.sender===n)?.receiver.track;if(r?.kind===`audio`||r?.kind===`video`)return r.kind;let i=n.getParameters().codecs?.find(e=>typeof e.mimeType==`string`);if(i?.mimeType?.toLowerCase().startsWith(`video/`))return`video`;if(i?.mimeType?.toLowerCase().startsWith(`audio/`))return`audio`},replaceTrack:e=>n.replaceTrack(e)};return t.set(n,i),i}),close:()=>{e.connectionState!==`closed`&&e.close()}},trackSource:{onTrack(t){let n=e=>{let n=e.track;t({streams:[...e.streams],track:n})};return e.addEventListener(`track`,n),()=>e.removeEventListener(`track`,n)}}}}var n=300,r=25,i=2,a=``,o=120;function s(e){let t=Math.floor(Number(e.sip.registerExpires));return Number.isFinite(t)&&t>0?t:n}var c=class{factory;transportBaseUrl;keepaliveSeconds;agentTerminal;sessionTimers;ua;uaListeners;incomingHandlers;iceServers;pendingConnection;disposed=!1;warmPc;keepaliveTimer;keepaliveBusy=!1;registerExpiresSeconds=0;connectionHandlers=new Set;constructor(e,t,n=r,i=a,o=!1){this.factory=e,this.transportBaseUrl=t,this.keepaliveSeconds=n,this.agentTerminal=i,this.sessionTimers=o}terminalHeaders(){return this.agentTerminal===``?[]:[`X-Agent-Terminal: ${this.agentTerminal}`]}warmIceCandidatePool(){if(this.closeWarmPc(),typeof RTCPeerConnection<`u`&&this.iceServers!==void 0)try{this.warmPc=new RTCPeerConnection({iceServers:[...this.iceServers],iceCandidatePoolSize:i})}catch{this.warmPc=void 0}}closeWarmPc(){try{this.warmPc?.close()}catch{}this.warmPc=void 0}keepaliveTick(e){if(this.isCurrentUa(e)&&!this.keepaliveBusy)try{if(typeof e.isConnected==`function`&&e.isConnected()===!1||typeof e.register!=`function`)return;this.keepaliveBusy=!0,e.register({extraHeaders:this.terminalHeaders()})}catch{}finally{this.keepaliveBusy=!1}}startKeepalive(e,t){if(this.stopKeepalive(),!Number.isFinite(this.keepaliveSeconds)||this.keepaliveSeconds<=0||t>0&&t<=this.keepaliveSeconds)return;let n=Math.max(10,Math.floor(this.keepaliveSeconds))*1e3;this.keepaliveTimer=setInterval(()=>this.keepaliveTick(e),n)}stopKeepalive(){this.keepaliveTimer!==void 0&&clearInterval(this.keepaliveTimer),this.keepaliveTimer=void 0}connect(t){this.assertNotDisposed(),this.disconnect(this.registrationError(`SIP connection replaced`));try{let e=this.factory.createUa({sockets:f(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(t.transport.wssUrl)),t.transport.ticket)),uri:t.sip.uri,password:t.sip.registerTicket,registrar_server:t.sip.registrar,register:!0,register_expires:s(t),session_timers:this.sessionTimers,...this.agentTerminal===``?{}:{user_agent:this.agentTerminal}});return this.ua=e,this.registerExpiresSeconds=s(t),this.iceServers=t.iceServers,this.uaListeners=[],this.startRegistration(e)}catch(t){let n=t instanceof e.i&&t.code===`CONFIG_INVALID`?t:this.transportError(t);return this.disconnect(n),Promise.reject(n)}}disconnect(e=this.registrationError(`SIP connection disconnected`)){this.stopKeepalive(),this.closeWarmPc();let t=this.pendingConnection;this.pendingConnection=void 0,this.ua!==void 0&&(this.removeUaListeners(this.ua),this.ua.stop()),this.ua=void 0,this.uaListeners=void 0,this.iceServers=void 0,t?.reject(e)}dial(t,n){let r=this.requireUa();if(t.trim()===``)throw new e.i(`CALL_INVALID_DESTINATION`,`call`,!1);try{let e=n===void 0?{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:o,pcConfig:{iceServers:this.iceServers,iceCandidatePoolSize:i}}:{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:o,pcConfig:{iceServers:[...n.iceServers],iceCandidatePoolSize:i},extraHeaders:[...this.terminalHeaders(),...n.extraHeaders,...n.type===`extension`?[`X-XCall-Destination-Type: extension`]:[]]};return new l(r.call(t,e))}catch(t){throw new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})}}onIncoming(e){this.assertNotDisposed();let t=this.incomingHandlers??new Set;return this.incomingHandlers=t,t.add(e),()=>t.delete(e)}onConnectionStateChanged(e){return this.disposed?()=>void 0:(this.connectionHandlers.add(e),()=>this.connectionHandlers.delete(e))}dispose(){this.disposed||(this.disposed=!0,this.disconnect(),this.incomingHandlers=void 0,this.connectionHandlers.clear())}getResourceCounts(){return{listeners:(this.uaListeners?.length??0)+(this.incomingHandlers?.size??0)+this.connectionHandlers.size,webSockets:this.ua===void 0?0:1}}handleIncoming(e){if(!u(e))return;let t=e.session;if(t===void 0)return;let n=new l(t);this.incomingHandlers?.forEach(e=>e(n))}startRegistration(e){let t=!0,n=!1,r=new Promise((t,n)=>{this.pendingConnection={ua:e,resolve:t,reject:n}});this.listen(e,`registered`,()=>{if(this.isCurrentUa(e)){if(t){n=!0;return}this.resolveConnection(e)}}),this.listen(e,`registrationFailed`,t=>{if(!this.isCurrentUa(e))return;let n=this.registrationError(this.registrationFailureCause(t));this.connectionHandlers.forEach(e=>e(`failed`,n)),this.disconnect(n)}),this.listen(e,`disconnected`,t=>{if(!this.isCurrentUa(e))return;let n=this.transportError(t);this.connectionHandlers.forEach(e=>e(`disconnected`,n)),this.disconnect(n)}),this.listen(e,`newRTCSession`,t=>{this.isCurrentUa(e)&&this.handleIncoming(t)});try{e.start()}catch(e){let t=this.transportError(e);this.connectionHandlers.forEach(e=>e(`failed`,t)),this.disconnect(t)}finally{t=!1}return n&&this.resolveConnection(e),r}listen(e,t,n){e.on(t,n),this.uaListeners?.push({event:t,handler:n})}removeUaListeners(e){this.uaListeners?.forEach(({event:t,handler:n})=>e.off(t,n))}isCurrentUa(e){return this.ua===e}resolveConnection(e){let t=this.pendingConnection;t?.ua===e&&(this.pendingConnection=void 0,t.resolve(),this.warmIceCandidatePool(),this.startKeepalive(e,this.registerExpiresSeconds),this.connectionHandlers.forEach(e=>e(`registered`)))}resolveWssUrl(e){let t=this.transportBaseUrl?.trim()===``||this.transportBaseUrl===void 0?typeof location>`u`?`http://localhost`:location.origin:this.transportBaseUrl,n=e.startsWith(`/`)?new URL(e,t):new URL(e);return n.protocol===`http:`&&(n.protocol=`ws:`),n.protocol===`https:`&&(n.protocol=`wss:`),this.assertAllowedWssUrl(n),n.toString()}assertAllowedWssUrl(t){if(t.protocol!==`wss:`&&!(t.protocol===`ws:`&&p(t.hostname)))throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:t.origin})}withoutTicket(e){let t=new URL(e);return t.searchParams.delete(`ticket`),t.toString()}requireUa(){if(this.assertNotDisposed(),this.ua===void 0)throw new e.i(`CALL_NOT_CONNECTED`,`call`,!1);return this.ua}assertNotDisposed(){if(this.disposed)throw new e.i(`SDK_ALREADY_DISPOSED`,`internal`,!1)}registrationError(t){return new e.i(`REGISTRATION_FAILED`,`registration`,!0,{cause:t})}transportError(t){return new e.i(`SIP_WS_UNAVAILABLE`,`registration`,!0,{cause:t})}registrationFailureCause(e){return typeof e==`object`&&e&&`cause`in e?e.cause:e}},l=class{session;pendingHoldReject;mediaRegistration;mediaConnection;mediaHandlers=new Set;mediaWatchStarted=!1;sessionUnsubscribeFromPeerConnection;constructor(e){this.session=e}get id(){return this.session.id}get from(){return this.session.from??m(this.session.remote_identity)}getMediaRegistration(){let e=this.session.connection;if(e!=null)return this.mediaRegistration!==void 0&&this.mediaConnection===e?this.mediaRegistration:(this.mediaConnection=e,this.mediaRegistration=t(e),this.mediaRegistration)}answer(e){this.session.answer({mediaConstraints:e.mediaConstraints,pcConfig:{iceServers:[...e.pcConfig.iceServers]}})}terminate(){this.pendingHoldReject?.(Error(`SIP session terminated`)),this.session.terminate()}hold(){return this.changeHoldState(`hold`)}unhold(){return this.changeHoldState(`unhold`)}mute(){this.session.mute()}unmute(){this.session.unmute()}sendDtmf(e){this.session.sendDTMF(e)}refer(e){this.session.refer(e)}on(e,t){return e===`mediaConnected`?(this.mediaHandlers.add(t),this.watchMediaConnection(),()=>{this.mediaHandlers.delete(t),this.mediaHandlers.size===0&&(this.sessionUnsubscribeFromPeerConnection?.(),this.sessionUnsubscribeFromPeerConnection=void 0)}):(this.session.on(e,t),()=>this.session.off(e,t))}watchMediaConnection(){if(this.mediaWatchStarted)return;this.mediaWatchStarted=!0;let e=!1,t=t=>{if(t==null)return;let n=()=>{if(e)return;let n=t.connectionState||t.iceConnectionState;if(n===`connected`){e=!0;for(let e of this.mediaHandlers)try{e({state:n})}catch{}}};t.addEventListener(`connectionstatechange`,n),n()},n=this.session.connection;if(n!=null){t(n);return}let r=e=>{t(e?.peerconnection??void 0)};this.session.on(`peerconnection`,r),this.sessionUnsubscribeFromPeerConnection=()=>this.session.off(`peerconnection`,r)}changeHoldState(t){return new Promise((n,r)=>{let i=!1,a=e=>{c(e)},o=()=>{try{this.session.off(`ended`,a)}catch{}try{this.session.off(`failed`,a)}catch{}this.pendingHoldReject===c&&(this.pendingHoldReject=void 0)},s=()=>{i||(i=!0,o(),n())},c=t=>{i||(i=!0,o(),r(new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})))};try{this.session.on(`ended`,a),this.session.on(`failed`,a)}catch(e){c(e);return}this.pendingHoldReject=c;try{this.session[t](void 0,s)||c({reason:`jssip_operation_rejected`,operation:t})}catch(e){c(e)}})}};function u(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.originator===`remote`&&d(t.session)}function d(e){return typeof e==`object`&&!!e&&`id`in e}function f(e){return typeof e==`object`&&e&&(e.via_transport=`WSS`),e}function p(e){let t=e.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`0:0:0:0:0:0:0:1`}function m(e){let t=e?.uri;if(t==null)return;if(typeof t.user==`string`&&t.user!==``)return t.user;let n=t.toString();return n.match(/^sips?:([^@;>]+)/i)?.[1]??(n===``?void 0:n)}exports.JsSipAdapter=c;