@16x/webphone-sdk 3.1.11 → 3.1.13
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/CHANGELOG.md +37 -215
- package/LICENSE +1 -1
- package/README.md +161 -219
- package/dist/{CCBarClient-Dmw3T0lF.js → CCBarClient-BJO4qjN2.js} +93 -64
- package/dist/CCBarClient-_sG61iiu.cjs +1 -0
- package/dist/{Diagnostics-Dmhx4niF.cjs → Diagnostics-B9EQ0Y8m.cjs} +1 -1
- package/dist/{Diagnostics-BLHANihC.js → Diagnostics-DdbpMSMr.js} +1 -1
- package/dist/JsSipAdapter-BB-SusrS.cjs +1 -0
- package/dist/{JsSipAdapter-CwDotPN2.js → JsSipAdapter-BHtCsy_S.js} +206 -35
- package/dist/SharedWorkerProtocol-C-4KpECM.cjs +1 -0
- package/dist/SharedWorkerProtocol-CffZrUXg.js +119 -0
- package/dist/core/CCBarCall.d.ts +3 -0
- package/dist/createJsSipFactory-B1ORbJiP.cjs +22 -0
- package/dist/createJsSipFactory-CoWZN-BC.js +7410 -0
- package/dist/diagnostics/Diagnostics.d.ts +8 -0
- package/dist/diagnostics/index.cjs +1 -1
- package/dist/diagnostics/index.js +1 -1
- package/dist/errors/CCBarError.d.ts +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/index.umd.js +1 -75
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.js +67 -69
- package/dist/legacy/legacySessionProvider.d.ts +4 -8
- package/dist/shared/SharedWorkerProtocol.d.ts +1 -0
- package/dist/shared-worker.cjs +1 -1
- package/dist/shared-worker.js +1 -1
- package/dist/styles.css +7 -7
- package/dist/types.d.ts +1 -1
- package/dist/ui/i18n/types.d.ts +1 -0
- package/dist/ui/index.cjs +1 -1
- package/dist/ui/index.js +16 -7
- package/dist/version.d.ts +1 -1
- package/package.json +4 -3
- package/dist/CCBarClient-B7SRICz8.cjs +0 -1
- package/dist/JsSipAdapter-BN9BAFHr.cjs +0 -1
- package/dist/SharedWorkerProtocol-39dch6xL.cjs +0 -1
- package/dist/SharedWorkerProtocol-DKVQ5-po.js +0 -87
- package/dist/createJsSipFactory-9CPsweDR.js +0 -9665
- package/dist/createJsSipFactory-Dr8HbLl-.cjs +0 -75
package/dist/legacy/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../SharedWorkerProtocol-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../SharedWorkerProtocol-C-4KpECM.cjs"),t=require("../CCBarClient-_sG61iiu.cjs");require("../createJsSipFactory-B1ORbJiP.cjs");var n=class extends Error{code=`LEGACY_METHOD_DEPRECATED`;constructor(e,t){super(`${e} 已废弃:${t}`),this.name=`DeprecatedError`}},r=class{client;warnedMethods=new Set;unsubscribeIncoming;currentCall;constructor(e){this.client=new t.t(e),this.unsubscribeIncoming=this.client.on(`call.incoming`,({callId:e})=>{this.currentCall=this.client.getCalls().find(t=>t.id===e)})}getToken(...e){return this.warn(`getToken`,`请改用 client.connect()`),this.client.connect()}getAccount(...e){return this.warn(`getAccount`,`请改用 client.connect()`),this.client.connect()}login(...e){return this.warn(`login`,`请改用 client.connect()`),this.client.connect()}async call(e,...t){this.warn(`call`,`请改用 client.dial({ destination })`);let n=await this.client.dial({destination:String(e)});return this.currentCall=n,n}async insideCall(e,...t){this.warn(`insideCall`,`请改用 client.dial({ destination, type: 'extension' })`);let n=await this.client.dial({destination:String(e),type:`extension`});return this.currentCall=n,n}answer(...e){this.warn(`answer`,`请改用 call.answer()`);let t=this.requireCurrentCall();return this.client.answer(t.id)}async hangup(...e){this.warn(`hangup`,`请改用 call.hangup()`);let t=this.requireCurrentCall();try{await t.hangup()}finally{this.currentCall===t&&(this.currentCall=void 0)}}holdCall(...e){return this.warn(`holdCall`,`请改用 call.hold()`),this.requireCurrentCall().hold()}unholdCall(...e){return this.warn(`unholdCall`,`请改用 call.resume()`),this.requireCurrentCall().resume()}transSo(e,...t){return this.warn(`transSo`,`请改用 call.transfer({ target, type: 'blind' })`),this.requireCurrentCall().transfer({target:String(e),type:`blind`})}async signOut(...e){this.warn(`signOut`,`请改用 client.disconnect() 和 client.dispose()`);let t;try{await this.client.disconnect()}catch(e){t=e}try{await this.client.dispose()}catch(e){t??=e}if(this.unsubscribeIncoming(),this.currentCall=void 0,t!==void 0)throw t}setId(...e){return this.warn(`setId`,`请改用 client.setAgentStatus('available')`),this.client.setAgentStatus(`available`)}setBu(...e){throw this.warn(`setBu`,`busy由通话状态或服务端状态策略控制,浏览器不得伪造`),new n(`setBu()`,`busy由通话状态或服务端状态策略控制,浏览器不得伪造`)}setRe(...e){return this.warn(`setRe`,`请改用 client.setAgentStatus('break')`),this.client.setAgentStatus(`break`)}requireCurrentCall(){let t=this.client.getActiveCall();if(t!==void 0&&(this.currentCall=t),this.currentCall===void 0)throw new e.i(`CALL_NOT_CONNECTED`,`call`,!1);return this.currentCall}warn(e,t){i()&&!this.warnedMethods.has(e)&&(this.warnedMethods.add(e),console.warn(`[CCBarSDK] ${e}() 已废弃。${t}`))}};function i(){return!1}var a=`/openapi/token/v1`,o=`/seat/account/get`,s=`/seats/set-status`,c=`/api/fs/sip-ws`,l=7443,u=3478,d=600,f=600,p=180,m=60,h=5e3,g=2e4,_=[`outbound`,`inbound`,`mute`,`dtmf`,`hold`,`blind_transfer`],v={available:{status:`Available`,reason:`空闲`},break:{status:`On Break`,reason:`休息`},offline:{status:`Logged Out`,reason:``}};function y(n){let r=b(n.host),i=x(n.pathPrefix??a),g=`${r}${i}${S(n.accountPath??o)}`,y=`${r}${i}${S(n.statusPath??s)}`,D=S(n.sipWsPath??c),O={...n.aesKey?{key:n.aesKey}:{},...n.aesIv?{iv:n.aesIv}:{}},k=Math.max(0,n.refreshBufferSeconds??p),A=n.fetchImpl??globalThis.fetch,j,M,N=``;async function P(){if(n.getToken!==void 0)return n.getToken();if(n.tokenUrl!==void 0){let t=n.tokenMethod??`POST`,r={method:t,headers:{Accept:`application/json`,...n.tokenHeaders??{}},credentials:`include`};t===`POST`&&(r.headers={"Content-Type":`application/json`,...r.headers},r.body=JSON.stringify(n.tokenBody??{}));let i=await E(A,n.tokenUrl,r,`取 token`),a=await i.text();try{return JSON.parse(a)}catch{throw new e.i(`AUTH_TOKEN_UNAVAILABLE`,`auth`,!0,{status:i.status,cause:`取 token 的接口返回了非 JSON 响应(HTTP ${i.status}):${a.trim().slice(0,120)}`})}}throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:`createLegacySessionProvider 需要 getToken 或 tokenUrl;坐席状态也可以直接用会话软电话地址里的 token(setAgentStatus 的 context.wssUrl),但这次调用没有会话可用`})}async function F(){if(j&&j.expiresAtMs-Date.now()>h)return j.token;let t;try{t=await P()}catch(t){throw t instanceof e.i?t:new e.i(`AUTH_TOKEN_UNAVAILABLE`,`auth`,!0,{cause:t})}let n=T(t);if(!n.token)throw new e.i(`AUTH_TOKEN_UNAVAILABLE`,`auth`,!0,{cause:`取 token 的返回里没有 token(支持 {token}、{accessToken}、{data:{token}} 或裸字符串)`});let r=w(n.expires,3600);return j={token:n.token,expiresAtMs:Date.now()+r*1e3},j.token}function I(e){if(!e)return``;try{return String(new URL(e).searchParams.get(`token`)??``).trim()}catch{return``}}async function L(e){let t=I(e?.wssUrl);return t?(N=t,t):N||F()}async function R(t){let n=t||await F(),r=await E(A,g,{method:`POST`,headers:{Authorization:n,"Content-Type":`application/json`,Accept:`application/json`},body:`{}`},`取坐席账号`),i=await r.text(),a;try{a=JSON.parse(i)}catch{throw new e.i(`LEGACY_PLATFORM_UNREACHABLE`,`network`,!0,{status:r.status,cause:`${g} 返回了非 JSON 响应(HTTP ${r.status});请确认 host 填的是接口网关(不是文档站)`})}let o=Number(a.code??NaN);if(!r.ok||o!==0)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,o===50,{status:r.status,serverCode:Number.isFinite(o)?String(o):void 0,cause:a.message||`取坐席账号失败(HTTP ${r.status})`});if(!a.data)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号接口没有返回 data`});return M=a.data,M}let z=e=>t.i(e,O);function B(t,i){let a=Number(t.wssPort)||l,o=String(t.domain??``).trim(),s=String(n.sipWsUrl??``).trim(),c;if(s)c=new URL(s,r),c.protocol===`http:`&&(c.protocol=`ws:`),c.protocol===`https:`&&(c.protocol=`wss:`);else{if(!o)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 domain,无法拼软电话地址;可用 sipWsUrl 显式指定`});let t=a===443?``:`:${a}`;c=new URL(`wss://${o}${t}${D}`)}return(n.attachTokenToWss??!0)&&i&&c.searchParams.set(`token`,i),c.toString()}function V(e){let t=(Array.isArray(e.iceServers)?e.iceServers:[]).map(e=>{let t=(Array.isArray(e?.urls)?e.urls:typeof e?.urls==`string`?[e.urls]:[]).map(e=>String(e??``).trim()).filter(Boolean);if(t.length!==0)return{urls:t,...e?.username?{username:String(e.username)}:{},...e?.credential?{credential:String(e.credential)}:{}}}).filter(e=>e!==void 0);if(t.length>0)return t;let n=String(e.turnIp??``).trim();return n?[{urls:[`stun:${n}:${Number(e.turnPort)||u}`]}]:[]}async function H(){let t=await F(),i=await R(),a=String(i.username??i.account??``).trim();if(!a)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 username`});let o=String(i.registerPassword??i.password??``),s=o?await z(o):``;if(!s)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 password/registerPassword,或解密后为空`});let c=w(i.expiresIn??i.expires_in,f),l=Math.max(0,Math.round((j.expiresAtMs-Date.now())/1e3)),u=Math.max(m,Math.min(l||c,c)-k),p=String(i.domain??``).trim()||C(r),h=B(i,t);return t&&(N=t),{sessionId:`legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,expiresAt:Math.floor(Date.now()/1e3)+u,agent:{id:a,externalUserId:a,displayName:a,extension:a,status:`Available`},sip:{uri:`sip:${a}@${p}`,registrar:p,registerTicket:s,registerExpires:Number(n.registerExpires)>0?Number(n.registerExpires):d,ticketExpiresIn:u},transport:{wssUrl:h,ticket:``,ticketExpiresIn:u},iceServers:V(i),policy:{maxConcurrentCalls:Number(n.maxConcurrentCalls)>0?Number(n.maxConcurrentCalls):2,incomingEnabled:n.incomingEnabled??!0,mobileIncomingEnabled:n.mobileIncomingEnabled??!0,backgroundCallingSupported:!1},capabilities:[...n.capabilities??_]}}return{createSession:H,refreshSession:H,setAgentStatus:async({status:t,reason:n},r)=>{let i=await L(r),a=M??await R(i),o=String(a.username??a.account??``).trim();if(!o)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 username`});let s=v[t],c=await E(A,y,{method:`POST`,headers:{Authorization:i,"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({extension:o,status:s.status,reason:n||s.reason})},`设置坐席状态`),l=await c.text(),u;try{u=JSON.parse(l)}catch{throw new e.i(`LEGACY_PLATFORM_UNREACHABLE`,`network`,!0,{status:c.status,cause:`${y} 返回了非 JSON 响应(HTTP ${c.status})`})}let d=Number(u.code??NaN);if(!c.ok||d!==0)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,d===50,{status:c.status,serverCode:Number.isFinite(d)?String(d):void 0,cause:u.message||`设置坐席状态失败(HTTP ${c.status})`})},invalidateToken:()=>{j=void 0,N=``},getSeatAccount:async()=>M??R()}}function b(t){let n=String(t??``).trim().replace(/\/+$/,``);if(!n)throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:`createLegacySessionProvider 需要 host`});return/^https?:\/\//i.test(n)?n:`https://${n}`}function x(e){let t=String(e??``).trim();return!t||t===`/`?``:`/${t.replace(/^\/+|\/+$/g,``)}`}function S(e){let t=String(e??``).trim();return t.startsWith(`/`)?t:`/${t}`}function C(e){try{return new URL(e).hostname}catch{return``}}function w(e,t){let n=Number(e);return!Number.isFinite(n)||n<=0?t:(n>86400&&(n/=1e3),Math.min(Math.max(Math.floor(n),m),86400))}function T(e){if(typeof e==`string`)return{token:e.trim()};let t=e??{},n=typeof t.data==`object`&&t.data!==null?t.data:void 0;for(let e of[t,n]){if(e===void 0)continue;let t=e.token??e.accessToken;if(typeof t==`string`&&t.trim()){let n=Number(e.expires??e.expiresIn??e.expires_at);return{token:t.trim(),...Number.isFinite(n)&&n>0?{expires:n}:{}}}}return{token:``}}async function E(t,n,r,i){let a=new AbortController,o=setTimeout(()=>a.abort(),g);try{return await t(n,{...r,signal:a.signal})}catch(t){let r=a.signal.aborted;throw new e.i(r?`NETWORK_TIMEOUT`:`LEGACY_PLATFORM_UNREACHABLE`,`network`,!0,{cause:r?`${i}超时(${g/1e3} 秒):POST ${n}`:`${i}失败:无法请求 ${n}(${t instanceof Error?t.message:String(t)})`})}finally{clearTimeout(o)}}var D=`0.1.0`;typeof window<`u`&&(window.CCBarSDK=r),exports.CCBarSDK=r,exports.DeprecatedError=n,exports.createLegacySessionProvider=y,exports.decryptSipPassword=t.i,exports.legacyVersion=D;
|
package/dist/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as e } from "../SharedWorkerProtocol-
|
|
2
|
-
import { i as t, t as n } from "../CCBarClient-
|
|
1
|
+
import { i as e } from "../SharedWorkerProtocol-CffZrUXg.js";
|
|
2
|
+
import { i as t, t as n } from "../CCBarClient-BJO4qjN2.js";
|
|
3
3
|
//#region src/legacy/CCBarSDK.ts
|
|
4
4
|
var r = class extends Error {
|
|
5
5
|
code = "LEGACY_METHOD_DEPRECATED";
|
|
@@ -102,14 +102,14 @@ function a() {
|
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region src/legacy/legacySessionProvider.ts
|
|
105
|
-
var o = "/openapi/token/v1", s = "/seat/account/get", c = "/seats/set-status", l =
|
|
105
|
+
var o = "/openapi/token/v1", s = "/seat/account/get", c = "/seats/set-status", l = "/api/fs/sip-ws", u = 7443, d = 3478, f = 600, p = 600, m = 180, h = 60, g = 5e3, _ = 2e4, v = [
|
|
106
106
|
"outbound",
|
|
107
107
|
"inbound",
|
|
108
108
|
"mute",
|
|
109
109
|
"dtmf",
|
|
110
110
|
"hold",
|
|
111
111
|
"blind_transfer"
|
|
112
|
-
],
|
|
112
|
+
], y = {
|
|
113
113
|
available: {
|
|
114
114
|
status: "Available",
|
|
115
115
|
reason: "空闲"
|
|
@@ -123,12 +123,12 @@ var o = "/openapi/token/v1", s = "/seat/account/get", c = "/seats/set-status", l
|
|
|
123
123
|
reason: ""
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
function
|
|
127
|
-
let r =
|
|
126
|
+
function b(n) {
|
|
127
|
+
let r = x(n.host), i = S(n.pathPrefix ?? o), a = `${r}${i}${C(n.accountPath ?? s)}`, _ = `${r}${i}${C(n.statusPath ?? c)}`, b = C(n.sipWsPath ?? l), O = {
|
|
128
128
|
...n.aesKey ? { key: n.aesKey } : {},
|
|
129
129
|
...n.aesIv ? { iv: n.aesIv } : {}
|
|
130
|
-
},
|
|
131
|
-
async function
|
|
130
|
+
}, k = Math.max(0, n.refreshBufferSeconds ?? m), A = n.fetchImpl ?? globalThis.fetch, j, M, N = "";
|
|
131
|
+
async function P() {
|
|
132
132
|
if (n.getToken !== void 0) return n.getToken();
|
|
133
133
|
if (n.tokenUrl !== void 0) {
|
|
134
134
|
let t = n.tokenMethod ?? "POST", r = {
|
|
@@ -143,7 +143,7 @@ function v(n) {
|
|
|
143
143
|
"Content-Type": "application/json",
|
|
144
144
|
...r.headers
|
|
145
145
|
}, r.body = JSON.stringify(n.tokenBody ?? {}));
|
|
146
|
-
let i = await
|
|
146
|
+
let i = await D(A, n.tokenUrl, r, "取 token"), a = await i.text();
|
|
147
147
|
try {
|
|
148
148
|
return JSON.parse(a);
|
|
149
149
|
} catch {
|
|
@@ -155,23 +155,23 @@ function v(n) {
|
|
|
155
155
|
}
|
|
156
156
|
throw new e("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 getToken 或 tokenUrl;坐席状态也可以直接用会话软电话地址里的 token(setAgentStatus 的 context.wssUrl),但这次调用没有会话可用" });
|
|
157
157
|
}
|
|
158
|
-
async function
|
|
159
|
-
if (
|
|
158
|
+
async function F() {
|
|
159
|
+
if (j && j.expiresAtMs - Date.now() > g) return j.token;
|
|
160
160
|
let t;
|
|
161
161
|
try {
|
|
162
|
-
t = await
|
|
162
|
+
t = await P();
|
|
163
163
|
} catch (t) {
|
|
164
164
|
throw t instanceof e ? t : new e("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: t });
|
|
165
165
|
}
|
|
166
|
-
let n =
|
|
166
|
+
let n = E(t);
|
|
167
167
|
if (!n.token) throw new e("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: "取 token 的返回里没有 token(支持 {token}、{accessToken}、{data:{token}} 或裸字符串)" });
|
|
168
|
-
let r =
|
|
169
|
-
return
|
|
168
|
+
let r = T(n.expires, 3600);
|
|
169
|
+
return j = {
|
|
170
170
|
token: n.token,
|
|
171
171
|
expiresAtMs: Date.now() + r * 1e3
|
|
172
|
-
},
|
|
172
|
+
}, j.token;
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function I(e) {
|
|
175
175
|
if (!e) return "";
|
|
176
176
|
try {
|
|
177
177
|
return String(new URL(e).searchParams.get("token") ?? "").trim();
|
|
@@ -179,12 +179,12 @@ function v(n) {
|
|
|
179
179
|
return "";
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
async function
|
|
183
|
-
let t =
|
|
184
|
-
return t ? (
|
|
182
|
+
async function L(e) {
|
|
183
|
+
let t = I(e?.wssUrl);
|
|
184
|
+
return t ? (N = t, t) : N || F();
|
|
185
185
|
}
|
|
186
|
-
async function
|
|
187
|
-
let n = t || await
|
|
186
|
+
async function R(t) {
|
|
187
|
+
let n = t || await F(), r = await D(A, a, {
|
|
188
188
|
method: "POST",
|
|
189
189
|
headers: {
|
|
190
190
|
Authorization: n,
|
|
@@ -208,22 +208,20 @@ function v(n) {
|
|
|
208
208
|
cause: o.message || `取坐席账号失败(HTTP ${r.status})`
|
|
209
209
|
});
|
|
210
210
|
if (!o.data) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号接口没有返回 data" });
|
|
211
|
-
return
|
|
211
|
+
return M = o.data, M;
|
|
212
212
|
}
|
|
213
|
-
let
|
|
214
|
-
function
|
|
215
|
-
let
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
throw new e("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 不是完整地址(需要 wss:// 或 ws:// 开头):${r}` });
|
|
213
|
+
let z = (e) => t(e, O);
|
|
214
|
+
function B(t, i) {
|
|
215
|
+
let a = Number(t.wssPort) || u, o = String(t.domain ?? "").trim(), s = String(n.sipWsUrl ?? "").trim(), c;
|
|
216
|
+
if (s) c = new URL(s, r), c.protocol === "http:" && (c.protocol = "ws:"), c.protocol === "https:" && (c.protocol = "wss:");
|
|
217
|
+
else {
|
|
218
|
+
if (!o) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 domain,无法拼软电话地址;可用 sipWsUrl 显式指定" });
|
|
219
|
+
let t = a === 443 ? "" : `:${a}`;
|
|
220
|
+
c = new URL(`wss://${o}${t}${b}`);
|
|
222
221
|
}
|
|
223
|
-
|
|
224
|
-
return (n.attachTokenToWss ?? !0) && t && i.searchParams.set("token", t), i.toString();
|
|
222
|
+
return (n.attachTokenToWss ?? !0) && i && c.searchParams.set("token", i), c.toString();
|
|
225
223
|
}
|
|
226
|
-
function
|
|
224
|
+
function V(e) {
|
|
227
225
|
let t = (Array.isArray(e.iceServers) ? e.iceServers : []).map((e) => {
|
|
228
226
|
let t = (Array.isArray(e?.urls) ? e.urls : typeof e?.urls == "string" ? [e.urls] : []).map((e) => String(e ?? "").trim()).filter(Boolean);
|
|
229
227
|
if (t.length !== 0) return {
|
|
@@ -234,17 +232,17 @@ function v(n) {
|
|
|
234
232
|
}).filter((e) => e !== void 0);
|
|
235
233
|
if (t.length > 0) return t;
|
|
236
234
|
let n = String(e.turnIp ?? "").trim();
|
|
237
|
-
return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) ||
|
|
235
|
+
return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) || d}`] }] : [];
|
|
238
236
|
}
|
|
239
|
-
async function
|
|
240
|
-
let t = await
|
|
237
|
+
async function H() {
|
|
238
|
+
let t = await F(), i = await R(), a = String(i.username ?? i.account ?? "").trim();
|
|
241
239
|
if (!a) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
242
|
-
let o = String(i.registerPassword ?? i.password ?? ""), s = o ? await
|
|
240
|
+
let o = String(i.registerPassword ?? i.password ?? ""), s = o ? await z(o) : "";
|
|
243
241
|
if (!s) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 password/registerPassword,或解密后为空" });
|
|
244
|
-
let c =
|
|
245
|
-
return t && (
|
|
242
|
+
let c = T(i.expiresIn ?? i.expires_in, p), l = Math.max(0, Math.round((j.expiresAtMs - Date.now()) / 1e3)), u = Math.max(h, Math.min(l || c, c) - k), d = String(i.domain ?? "").trim() || w(r), m = B(i, t);
|
|
243
|
+
return t && (N = t), {
|
|
246
244
|
sessionId: `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
247
|
-
expiresAt: Math.floor(Date.now() / 1e3) +
|
|
245
|
+
expiresAt: Math.floor(Date.now() / 1e3) + u,
|
|
248
246
|
agent: {
|
|
249
247
|
id: a,
|
|
250
248
|
externalUserId: a,
|
|
@@ -253,34 +251,34 @@ function v(n) {
|
|
|
253
251
|
status: "Available"
|
|
254
252
|
},
|
|
255
253
|
sip: {
|
|
256
|
-
uri: `sip:${a}@${
|
|
257
|
-
registrar:
|
|
254
|
+
uri: `sip:${a}@${d}`,
|
|
255
|
+
registrar: d,
|
|
258
256
|
registerTicket: s,
|
|
259
|
-
registerExpires: Number(n.registerExpires) > 0 ? Number(n.registerExpires) :
|
|
260
|
-
ticketExpiresIn:
|
|
257
|
+
registerExpires: Number(n.registerExpires) > 0 ? Number(n.registerExpires) : f,
|
|
258
|
+
ticketExpiresIn: u
|
|
261
259
|
},
|
|
262
260
|
transport: {
|
|
263
|
-
wssUrl:
|
|
261
|
+
wssUrl: m,
|
|
264
262
|
ticket: "",
|
|
265
|
-
ticketExpiresIn:
|
|
263
|
+
ticketExpiresIn: u
|
|
266
264
|
},
|
|
267
|
-
iceServers:
|
|
265
|
+
iceServers: V(i),
|
|
268
266
|
policy: {
|
|
269
267
|
maxConcurrentCalls: Number(n.maxConcurrentCalls) > 0 ? Number(n.maxConcurrentCalls) : 2,
|
|
270
268
|
incomingEnabled: n.incomingEnabled ?? !0,
|
|
271
269
|
mobileIncomingEnabled: n.mobileIncomingEnabled ?? !0,
|
|
272
270
|
backgroundCallingSupported: !1
|
|
273
271
|
},
|
|
274
|
-
capabilities: [...n.capabilities ??
|
|
272
|
+
capabilities: [...n.capabilities ?? v]
|
|
275
273
|
};
|
|
276
274
|
}
|
|
277
275
|
return {
|
|
278
|
-
createSession:
|
|
279
|
-
refreshSession:
|
|
276
|
+
createSession: H,
|
|
277
|
+
refreshSession: H,
|
|
280
278
|
setAgentStatus: async ({ status: t, reason: n }, r) => {
|
|
281
|
-
let i = await
|
|
279
|
+
let i = await L(r), a = M ?? await R(i), o = String(a.username ?? a.account ?? "").trim();
|
|
282
280
|
if (!o) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
283
|
-
let s =
|
|
281
|
+
let s = y[t], c = await D(A, _, {
|
|
284
282
|
method: "POST",
|
|
285
283
|
headers: {
|
|
286
284
|
Authorization: i,
|
|
@@ -298,7 +296,7 @@ function v(n) {
|
|
|
298
296
|
} catch {
|
|
299
297
|
throw new e("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
|
|
300
298
|
status: c.status,
|
|
301
|
-
cause: `${
|
|
299
|
+
cause: `${_} 返回了非 JSON 响应(HTTP ${c.status})`
|
|
302
300
|
});
|
|
303
301
|
}
|
|
304
302
|
let d = Number(u.code ?? NaN);
|
|
@@ -309,36 +307,36 @@ function v(n) {
|
|
|
309
307
|
});
|
|
310
308
|
},
|
|
311
309
|
invalidateToken: () => {
|
|
312
|
-
|
|
310
|
+
j = void 0, N = "";
|
|
313
311
|
},
|
|
314
|
-
getSeatAccount: async () =>
|
|
312
|
+
getSeatAccount: async () => M ?? R()
|
|
315
313
|
};
|
|
316
314
|
}
|
|
317
|
-
function
|
|
315
|
+
function x(t) {
|
|
318
316
|
let n = String(t ?? "").trim().replace(/\/+$/, "");
|
|
319
317
|
if (!n) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 host" });
|
|
320
318
|
return /^https?:\/\//i.test(n) ? n : `https://${n}`;
|
|
321
319
|
}
|
|
322
|
-
function
|
|
320
|
+
function S(e) {
|
|
323
321
|
let t = String(e ?? "").trim();
|
|
324
322
|
return !t || t === "/" ? "" : `/${t.replace(/^\/+|\/+$/g, "")}`;
|
|
325
323
|
}
|
|
326
|
-
function
|
|
324
|
+
function C(e) {
|
|
327
325
|
let t = String(e ?? "").trim();
|
|
328
326
|
return t.startsWith("/") ? t : `/${t}`;
|
|
329
327
|
}
|
|
330
|
-
function
|
|
328
|
+
function w(e) {
|
|
331
329
|
try {
|
|
332
330
|
return new URL(e).hostname;
|
|
333
331
|
} catch {
|
|
334
332
|
return "";
|
|
335
333
|
}
|
|
336
334
|
}
|
|
337
|
-
function
|
|
335
|
+
function T(e, t) {
|
|
338
336
|
let n = Number(e);
|
|
339
|
-
return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n),
|
|
337
|
+
return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n), h), 86400));
|
|
340
338
|
}
|
|
341
|
-
function
|
|
339
|
+
function E(e) {
|
|
342
340
|
if (typeof e == "string") return { token: e.trim() };
|
|
343
341
|
let t = e ?? {}, n = typeof t.data == "object" && t.data !== null ? t.data : void 0;
|
|
344
342
|
for (let e of [t, n]) {
|
|
@@ -354,8 +352,8 @@ function w(e) {
|
|
|
354
352
|
}
|
|
355
353
|
return { token: "" };
|
|
356
354
|
}
|
|
357
|
-
async function
|
|
358
|
-
let a = new AbortController(), o = setTimeout(() => a.abort(),
|
|
355
|
+
async function D(t, n, r, i) {
|
|
356
|
+
let a = new AbortController(), o = setTimeout(() => a.abort(), _);
|
|
359
357
|
try {
|
|
360
358
|
return await t(n, {
|
|
361
359
|
...r,
|
|
@@ -363,14 +361,14 @@ async function T(t, n, r, i) {
|
|
|
363
361
|
});
|
|
364
362
|
} catch (t) {
|
|
365
363
|
let r = a.signal.aborted;
|
|
366
|
-
throw new e(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${
|
|
364
|
+
throw new e(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${_ / 1e3} 秒):POST ${n}` : `${i}失败:无法请求 ${n}(${t instanceof Error ? t.message : String(t)})` });
|
|
367
365
|
} finally {
|
|
368
366
|
clearTimeout(o);
|
|
369
367
|
}
|
|
370
368
|
}
|
|
371
369
|
//#endregion
|
|
372
370
|
//#region src/legacy/index.ts
|
|
373
|
-
var
|
|
371
|
+
var O = "0.1.0";
|
|
374
372
|
typeof window < "u" && (window.CCBarSDK = i);
|
|
375
373
|
//#endregion
|
|
376
|
-
export { i as CCBarSDK, r as DeprecatedError,
|
|
374
|
+
export { i as CCBarSDK, r as DeprecatedError, b as createLegacySessionProvider, t as decryptSipPassword, O as legacyVersion };
|
|
@@ -15,9 +15,7 @@ export interface LegacySeatAccount {
|
|
|
15
15
|
registerPassword?: string;
|
|
16
16
|
expiresIn?: number;
|
|
17
17
|
expires_in?: number;
|
|
18
|
-
/** SIP 域名:拼 `sip.uri` / `sip.registrar` 用(软电话地址不再从这里拼,见 `sipWsUrl`) */
|
|
19
18
|
domain?: string;
|
|
20
|
-
/** 平台返回的端口字段:SDK 不再读它们(软电话地址由接入方传 `sipWsUrl`) */
|
|
21
19
|
wsPort?: number;
|
|
22
20
|
wssPort?: number;
|
|
23
21
|
turnIp?: string;
|
|
@@ -48,12 +46,10 @@ export interface LegacyPlatformSessionProviderOptions {
|
|
|
48
46
|
accountPath?: string;
|
|
49
47
|
/** 坐席状态路径(相对 pathPrefix),默认 `/seats/set-status` */
|
|
50
48
|
statusPath?: string;
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
sipWsUrl: string;
|
|
49
|
+
/** 软电话路径,默认 `/api/fs/sip-ws` */
|
|
50
|
+
sipWsPath?: string;
|
|
51
|
+
/** 显式指定 WSS 地址(覆盖按 domain/wssPort 拼装),可以是相对路径 */
|
|
52
|
+
sipWsUrl?: string;
|
|
57
53
|
/** 是否把 token 挂到 WSS 的 `?token=`,默认 true(旧页面那套不挂时可设 false) */
|
|
58
54
|
attachTokenToWss?: boolean;
|
|
59
55
|
/** AES key / iv(16 字节,UTF-8);默认用平台内置值 */
|
package/dist/shared-worker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./SharedWorkerProtocol-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./SharedWorkerProtocol-C-4KpECM.cjs");require("./createJsSipFactory-B1ORbJiP.cjs");var t=class{ports=new Map;requestResults=new Map;lifecycleState=`connected`;bootstrapOwner;options;constructor(e={}){this.options={timeoutMs:e.timeoutMs??15e3,...e}}attach(e,t){let n=e;o(t);let r=this.ports.get(t);r!==void 0&&r!==n&&this.detachPort(t,r),this.ports.set(t,n),n.onmessage=e=>{this.handlePortMessage(n,t,e.data)},n.start(),n.onclose=()=>{this.ports.get(t)===n&&this.detachPort(t,n)};let i=!1;return()=>{i||(i=!0,this.ports.get(t)===n&&this.detachPort(t,n))}}async handle(t){let n=e.t(t);if(!a(n))return i(t.requestId,new e.i(`SDK_INTERNAL_ERROR`,`internal`,!1));let r=`${n.tabId}:${n.requestId}`,o=this.requestResults.get(r);if(o!==void 0)return o;let s=this.execute(n).finally(()=>{this.requestResults.get(r)===s&&this.requestResults.delete(r)});return this.requestResults.set(r,s),s}broadcast(e){let t=r(e);this.ports.forEach(e=>e.postMessage(t))}getTabIds(){return[...this.ports.keys()]}getLifecycleState(){return this.lifecycleState}restart(){this.lifecycleState=`reconnecting`,this.bootstrapOwner=void 0,this.broadcast({version:1,type:`event`,event:`connection.stateChanged`,payload:{state:`reconnecting`}})}markReady(t=[]){this.lifecycleState=`connected`,this.bootstrapOwner=void 0,this.broadcast({version:1,type:`event`,event:`connection.stateChanged`,payload:{state:`connected`}}),t.forEach(t=>{this.broadcast({version:1,type:`event`,event:`call.snapshot`,payload:e.n(t)})})}async execute(t){try{if(this.assertCommandAllowed(t),t.type===`detach`){let e=this.ports.get(t.tabId);e!==void 0&&this.detachPort(t.tabId,e)}t.type===`command`&&t.command===`bootstrap`&&this.claimBootstrap(t.tabId);let e=await s(this.options.handleRequest?.(t)??Promise.resolve({attached:t.tabId}),this.options.timeoutMs);return{version:1,type:`response`,requestId:t.requestId,ok:!0,result:e}}catch(n){let r=n instanceof e.i?n:n instanceof c?new e.i(`NETWORK_TIMEOUT`,`network`,!0,{requestId:t.requestId}):new e.i(`SDK_INTERNAL_ERROR`,`internal`,!1,{requestId:t.requestId,cause:n});return i(t.requestId,r)}}assertCommandAllowed(t){if(t.type===`command`&&this.lifecycleState===`reconnecting`&&(t.command===`dial`||t.command===`answer`))throw new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0,{callId:t.payload?.callId})}claimBootstrap(t){if(this.bootstrapOwner===void 0){this.bootstrapOwner=t;return}if(this.bootstrapOwner!==t)throw new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0)}async handlePortMessage(t,n,r){try{let o=e.t(r);if(!a(o)||o.tabId!==n){t.postMessage(i(typeof r==`object`&&r&&`requestId`in r&&typeof r.requestId==`string`?r.requestId:``,new e.i(`SDK_INTERNAL_ERROR`,`internal`,!1)));return}t.postMessage(await this.handle(o))}catch(e){let n=typeof r==`object`&&r&&`requestId`in r&&typeof r.requestId==`string`?r.requestId:``;t.postMessage(i(n,e))}}detachPort(e,t){t.onmessage=null,t.onclose=null,this.ports.delete(e),this.options.onPortDetached?.(e)}};function n(n,r=new t){return n.onconnect=t=>{let n=t.ports[0];if(n===void 0)return;let o=!0;n.onmessage=t=>{try{let i=e.t(t.data);if(!a(i)||i.type!==`attach`)throw new e.i(`SDK_INTERNAL_ERROR`,`internal`,!1);o=!1,r.attach(n,i.tabId),r.handle(i).then(e=>n.postMessage(e))}catch(e){let r=typeof t.data==`object`&&t.data!==null&&`requestId`in t.data&&typeof t.data.requestId==`string`?t.data.requestId:``;n.postMessage(i(r,e))}},n.start(),o||(n.onmessage=null)},r}function r(t){if((t.event===`call.snapshot`||t.event===`call.created`)&&typeof t.payload==`object`&&t.payload!==null)return{...t,payload:e.n(t.payload)};if(t.event===`call.failed`&&typeof t.payload==`object`&&t.payload!==null&&`error`in t.payload){let n=t.payload;return{...t,payload:{...typeof n.callId==`string`?{callId:n.callId}:{},error:e.r(n.error)}}}return t.event===`error`?{...t,payload:e.r(t.payload)}:structuredClone(t)}function i(t,n){return{version:1,type:`response`,requestId:t,ok:!1,error:e.r(n)}}function a(e){return typeof e==`object`&&!!e&&`requestId`in e&&`tabId`in e&&`type`in e&&(e.type===`attach`||e.type===`detach`||e.type===`command`)}function o(t){if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(t))throw new e.i(`SDK_INTERNAL_ERROR`,`internal`,!1)}async function s(e,t){let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>r(new c),t)})])}finally{n!==void 0&&clearTimeout(n)}}var c=class extends Error{};function l(e){return n(e)}var u=typeof globalThis==`object`&&`onconnect`in globalThis?n(globalThis):void 0;exports.createSharedWorkerRuntime=l,exports.sharedWorkerRuntime=u;
|
package/dist/shared-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, n as t, r as n, t as r } from "./SharedWorkerProtocol-
|
|
1
|
+
import { i as e, n as t, r as n, t as r } from "./SharedWorkerProtocol-CffZrUXg.js";
|
|
2
2
|
//#region src/shared/SharedWorkerRuntime.ts
|
|
3
3
|
var i = class {
|
|
4
4
|
ports = /* @__PURE__ */ new Map();
|
package/dist/styles.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
@import './tokens.css';
|
|
2
|
-
@import './base.css';
|
|
3
|
-
@import './compact.css';
|
|
4
|
-
@import './panel.css';
|
|
5
|
-
@import './mobile.css';
|
|
6
|
-
@import './dark.css';
|
|
7
|
-
@import './reduced-motion.css';
|
|
1
|
+
@import './tokens.css';
|
|
2
|
+
@import './base.css';
|
|
3
|
+
@import './compact.css';
|
|
4
|
+
@import './panel.css';
|
|
5
|
+
@import './mobile.css';
|
|
6
|
+
@import './dark.css';
|
|
7
|
+
@import './reduced-motion.css';
|
package/dist/types.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface MediaManager {
|
|
|
58
58
|
releaseAll(): Promise<void>;
|
|
59
59
|
}
|
|
60
60
|
export type CCBarErrorCategory = 'auth' | 'configuration' | 'network' | 'registration' | 'media' | 'call' | 'capability' | 'internal';
|
|
61
|
-
export type CCBarErrorCode = 'AUTH_TOKEN_UNAVAILABLE' | 'AUTH_TOKEN_EXPIRED' | 'AUTH_PERMISSION_DENIED' | 'CONFIG_INVALID' | 'CONFIG_ORIGIN_NOT_ALLOWED' | 'NETWORK_OFFLINE' | 'NETWORK_TIMEOUT' | 'SIP_WS_UNAVAILABLE' | 'REGISTRATION_FAILED' | 'REGISTRATION_REJECTED' | 'MEDIA_PERMISSION_DENIED' | 'MEDIA_DEVICE_NOT_FOUND' | 'MEDIA_DEVICE_IN_USE' | 'MEDIA_PLAYBACK_BLOCKED' | 'CALL_INVALID_DESTINATION' | 'CALL_INVALID_USERDATA' | 'CALL_ALREADY_EXISTS' | 'CALL_REJECTED' | 'CALL_BUSY' | 'CALL_NOT_CONNECTED' | 'CALL_OPERATION_NOT_ALLOWED' | 'CAPABILITY_NOT_SUPPORTED' | 'H5_BACKGROUND_NOT_SUPPORTED' | 'SDK_ALREADY_DISPOSED' | 'SDK_INTERNAL_ERROR'
|
|
61
|
+
export type CCBarErrorCode = 'AUTH_TOKEN_UNAVAILABLE' | 'AUTH_TOKEN_EXPIRED' | 'AUTH_TOKEN_REJECTED' | 'AUTH_PERMISSION_DENIED' | 'CONFIG_INVALID' | 'CONFIG_ORIGIN_NOT_ALLOWED' | 'NETWORK_OFFLINE' | 'NETWORK_TIMEOUT' | 'SIP_WS_UNAVAILABLE' | 'REGISTRATION_FAILED' | 'REGISTRATION_REJECTED' | 'MEDIA_PERMISSION_DENIED' | 'MEDIA_DEVICE_NOT_FOUND' | 'MEDIA_DEVICE_IN_USE' | 'MEDIA_PLAYBACK_BLOCKED' | 'CALL_INVALID_DESTINATION' | 'CALL_INVALID_USERDATA' | 'CALL_ALREADY_EXISTS' | 'CALL_REJECTED' | 'CALL_BUSY' | 'CALL_NOT_CONNECTED' | 'NOT_SIGNED_IN' | 'CALL_OPERATION_NOT_ALLOWED' | 'CAPABILITY_NOT_SUPPORTED' | 'H5_BACKGROUND_NOT_SUPPORTED' | 'SDK_ALREADY_DISPOSED' | 'SDK_INTERNAL_ERROR'
|
|
62
62
|
/** 老平台接口(seat/account/get、seats/set-status)不可达:网络失败、超时或返回非 JSON */
|
|
63
63
|
| 'LEGACY_PLATFORM_UNREACHABLE'
|
|
64
64
|
/** 老平台接口返回了业务错误(code != 0)或缺少必需字段;平台的 code 在 error.serverCode 上 */
|
package/dist/ui/i18n/types.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface UiMessages {
|
|
|
31
31
|
readonly permissionBody: string;
|
|
32
32
|
readonly errorTitle: string;
|
|
33
33
|
readonly errorBody: string;
|
|
34
|
+
readonly errorTokenUnavailable?: string;
|
|
34
35
|
readonly currentCall: string;
|
|
35
36
|
readonly inbound: string;
|
|
36
37
|
readonly outbound: string;
|
package/dist/ui/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../createJsSipFactory-Dr8HbLl-.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?.();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;
|