@16x/webphone-sdk 3.1.10 → 3.1.11
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 +9 -0
- package/README.md +6 -1
- package/dist/{CCBarClient-z-TFUjTB.cjs → CCBarClient-B7SRICz8.cjs} +1 -1
- package/dist/{CCBarClient-Sr_zlDBu.js → CCBarClient-Dmw3T0lF.js} +1 -1
- package/dist/{Diagnostics-WkQagE6_.js → Diagnostics-BLHANihC.js} +1 -1
- package/dist/{Diagnostics-x4G0ho6W.cjs → Diagnostics-Dmhx4niF.cjs} +1 -1
- package/dist/diagnostics/index.cjs +1 -1
- package/dist/diagnostics/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.umd.js +1 -1
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.js +68 -66
- package/dist/legacy/legacySessionProvider.d.ts +8 -4
- package/dist/version.d.ts +1 -1
- package/package.json +109 -109
package/dist/legacy/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../SharedWorkerProtocol-39dch6xL.cjs"),t=require("../CCBarClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../SharedWorkerProtocol-39dch6xL.cjs"),t=require("../CCBarClient-B7SRICz8.cjs");require("../createJsSipFactory-Dr8HbLl-.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=3478,l=600,u=600,d=180,f=60,p=5e3,m=2e4,h=[`outbound`,`inbound`,`mute`,`dtmf`,`hold`,`blind_transfer`],g={available:{status:`Available`,reason:`空闲`},break:{status:`On Break`,reason:`休息`},offline:{status:`Logged Out`,reason:``}};function _(n){let r=v(n.host),i=y(n.pathPrefix??a),m=`${r}${i}${b(n.accountPath??o)}`,_=`${r}${i}${b(n.statusPath??s)}`,T={...n.aesKey?{key:n.aesKey}:{},...n.aesIv?{iv:n.aesIv}:{}},E=Math.max(0,n.refreshBufferSeconds??d),D=n.fetchImpl??globalThis.fetch,O,k,A=``;async function j(){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 w(D,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 M(){if(O&&O.expiresAtMs-Date.now()>p)return O.token;let t;try{t=await j()}catch(t){throw t instanceof e.i?t:new e.i(`AUTH_TOKEN_UNAVAILABLE`,`auth`,!0,{cause:t})}let n=C(t);if(!n.token)throw new e.i(`AUTH_TOKEN_UNAVAILABLE`,`auth`,!0,{cause:`取 token 的返回里没有 token(支持 {token}、{accessToken}、{data:{token}} 或裸字符串)`});let r=S(n.expires,3600);return O={token:n.token,expiresAtMs:Date.now()+r*1e3},O.token}function N(e){if(!e)return``;try{return String(new URL(e).searchParams.get(`token`)??``).trim()}catch{return``}}async function P(e){let t=N(e?.wssUrl);return t?(A=t,t):A||M()}async function F(t){let n=t||await M(),r=await w(D,m,{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:`${m} 返回了非 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 k=a.data,k}let I=e=>t.i(e,T);function L(t){let r=String(n.sipWsUrl??``).trim();if(!r)throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:`需要 sipWsUrl:软电话 WSS 地址由接入方提供(wss:// 或 ws:// 开头的完整地址)`});let i;try{i=new URL(r)}catch{throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:`sipWsUrl 不是完整地址(需要 wss:// 或 ws:// 开头):${r}`})}if(i.protocol!==`wss:`&&i.protocol!==`ws:`)throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:`sipWsUrl 需要 wss:// 或 ws:// 开头:${r}`});return(n.attachTokenToWss??!0)&&t&&i.searchParams.set(`token`,t),i.toString()}function R(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)||c}`]}]:[]}async function z(){let t=await M(),i=await F(),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 I(o):``;if(!s)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 password/registerPassword,或解密后为空`});let c=S(i.expiresIn??i.expires_in,u),d=Math.max(0,Math.round((O.expiresAtMs-Date.now())/1e3)),p=Math.max(f,Math.min(d||c,c)-E),m=String(i.domain??``).trim()||x(r),g=L(t);return t&&(A=t),{sessionId:`legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,expiresAt:Math.floor(Date.now()/1e3)+p,agent:{id:a,externalUserId:a,displayName:a,extension:a,status:`Available`},sip:{uri:`sip:${a}@${m}`,registrar:m,registerTicket:s,registerExpires:Number(n.registerExpires)>0?Number(n.registerExpires):l,ticketExpiresIn:p},transport:{wssUrl:g,ticket:``,ticketExpiresIn:p},iceServers:R(i),policy:{maxConcurrentCalls:Number(n.maxConcurrentCalls)>0?Number(n.maxConcurrentCalls):2,incomingEnabled:n.incomingEnabled??!0,mobileIncomingEnabled:n.mobileIncomingEnabled??!0,backgroundCallingSupported:!1},capabilities:[...n.capabilities??h]}}return{createSession:z,refreshSession:z,setAgentStatus:async({status:t,reason:n},r)=>{let i=await P(r),a=k??await F(i),o=String(a.username??a.account??``).trim();if(!o)throw new e.i(`LEGACY_PLATFORM_REJECTED`,`auth`,!1,{cause:`坐席账号里没有 username`});let s=g[t],c=await w(D,_,{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:`${_} 返回了非 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:()=>{O=void 0,A=``},getSeatAccount:async()=>k??F()}}function v(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 y(e){let t=String(e??``).trim();return!t||t===`/`?``:`/${t.replace(/^\/+|\/+$/g,``)}`}function b(e){let t=String(e??``).trim();return t.startsWith(`/`)?t:`/${t}`}function x(e){try{return new URL(e).hostname}catch{return``}}function S(e,t){let n=Number(e);return!Number.isFinite(n)||n<=0?t:(n>86400&&(n/=1e3),Math.min(Math.max(Math.floor(n),f),86400))}function C(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 w(t,n,r,i){let a=new AbortController,o=setTimeout(()=>a.abort(),m);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}超时(${m/1e3} 秒):POST ${n}`:`${i}失败:无法请求 ${n}(${t instanceof Error?t.message:String(t)})`})}finally{clearTimeout(o)}}var T=`0.1.0`;typeof window<`u`&&(window.CCBarSDK=r),exports.CCBarSDK=r,exports.DeprecatedError=n,exports.createLegacySessionProvider=_,exports.decryptSipPassword=t.i,exports.legacyVersion=T;
|
package/dist/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as e } from "../SharedWorkerProtocol-DKVQ5-po.js";
|
|
2
|
-
import { i as t, t as n } from "../CCBarClient-
|
|
2
|
+
import { i as t, t as n } from "../CCBarClient-Dmw3T0lF.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 = 3478, u = 600, d = 600, f = 180, p = 60, m = 5e3, h = 2e4, g = [
|
|
106
106
|
"outbound",
|
|
107
107
|
"inbound",
|
|
108
108
|
"mute",
|
|
109
109
|
"dtmf",
|
|
110
110
|
"hold",
|
|
111
111
|
"blind_transfer"
|
|
112
|
-
],
|
|
112
|
+
], _ = {
|
|
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 v(n) {
|
|
127
|
+
let r = y(n.host), i = b(n.pathPrefix ?? o), a = `${r}${i}${x(n.accountPath ?? s)}`, h = `${r}${i}${x(n.statusPath ?? c)}`, v = {
|
|
128
128
|
...n.aesKey ? { key: n.aesKey } : {},
|
|
129
129
|
...n.aesIv ? { iv: n.aesIv } : {}
|
|
130
|
-
},
|
|
131
|
-
async function
|
|
130
|
+
}, E = Math.max(0, n.refreshBufferSeconds ?? f), D = n.fetchImpl ?? globalThis.fetch, O, k, A = "";
|
|
131
|
+
async function j() {
|
|
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 b(n) {
|
|
|
143
143
|
"Content-Type": "application/json",
|
|
144
144
|
...r.headers
|
|
145
145
|
}, r.body = JSON.stringify(n.tokenBody ?? {}));
|
|
146
|
-
let i = await D
|
|
146
|
+
let i = await T(D, 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 b(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 M() {
|
|
159
|
+
if (O && O.expiresAtMs - Date.now() > m) return O.token;
|
|
160
160
|
let t;
|
|
161
161
|
try {
|
|
162
|
-
t = await
|
|
162
|
+
t = await j();
|
|
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 = w(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 = C(n.expires, 3600);
|
|
169
|
+
return O = {
|
|
170
170
|
token: n.token,
|
|
171
171
|
expiresAtMs: Date.now() + r * 1e3
|
|
172
|
-
},
|
|
172
|
+
}, O.token;
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function N(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 b(n) {
|
|
|
179
179
|
return "";
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
async function
|
|
183
|
-
let t =
|
|
184
|
-
return t ? (
|
|
182
|
+
async function P(e) {
|
|
183
|
+
let t = N(e?.wssUrl);
|
|
184
|
+
return t ? (A = t, t) : A || M();
|
|
185
185
|
}
|
|
186
|
-
async function
|
|
187
|
-
let n = t || await
|
|
186
|
+
async function F(t) {
|
|
187
|
+
let n = t || await M(), r = await T(D, a, {
|
|
188
188
|
method: "POST",
|
|
189
189
|
headers: {
|
|
190
190
|
Authorization: n,
|
|
@@ -208,20 +208,22 @@ function b(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 k = o.data, k;
|
|
212
212
|
}
|
|
213
|
-
let
|
|
214
|
-
function
|
|
215
|
-
let
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
let I = (e) => t(e, v);
|
|
214
|
+
function L(t) {
|
|
215
|
+
let r = String(n.sipWsUrl ?? "").trim();
|
|
216
|
+
if (!r) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 sipWsUrl:软电话 WSS 地址由接入方提供(wss:// 或 ws:// 开头的完整地址)" });
|
|
217
|
+
let i;
|
|
218
|
+
try {
|
|
219
|
+
i = new URL(r);
|
|
220
|
+
} catch {
|
|
221
|
+
throw new e("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 不是完整地址(需要 wss:// 或 ws:// 开头):${r}` });
|
|
221
222
|
}
|
|
222
|
-
|
|
223
|
+
if (i.protocol !== "wss:" && i.protocol !== "ws:") throw new e("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 需要 wss:// 或 ws:// 开头:${r}` });
|
|
224
|
+
return (n.attachTokenToWss ?? !0) && t && i.searchParams.set("token", t), i.toString();
|
|
223
225
|
}
|
|
224
|
-
function
|
|
226
|
+
function R(e) {
|
|
225
227
|
let t = (Array.isArray(e.iceServers) ? e.iceServers : []).map((e) => {
|
|
226
228
|
let t = (Array.isArray(e?.urls) ? e.urls : typeof e?.urls == "string" ? [e.urls] : []).map((e) => String(e ?? "").trim()).filter(Boolean);
|
|
227
229
|
if (t.length !== 0) return {
|
|
@@ -232,17 +234,17 @@ function b(n) {
|
|
|
232
234
|
}).filter((e) => e !== void 0);
|
|
233
235
|
if (t.length > 0) return t;
|
|
234
236
|
let n = String(e.turnIp ?? "").trim();
|
|
235
|
-
return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) ||
|
|
237
|
+
return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) || l}`] }] : [];
|
|
236
238
|
}
|
|
237
|
-
async function
|
|
238
|
-
let t = await
|
|
239
|
+
async function z() {
|
|
240
|
+
let t = await M(), i = await F(), a = String(i.username ?? i.account ?? "").trim();
|
|
239
241
|
if (!a) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
240
|
-
let o = String(i.registerPassword ?? i.password ?? ""), s = o ? await
|
|
242
|
+
let o = String(i.registerPassword ?? i.password ?? ""), s = o ? await I(o) : "";
|
|
241
243
|
if (!s) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 password/registerPassword,或解密后为空" });
|
|
242
|
-
let c =
|
|
243
|
-
return t && (
|
|
244
|
+
let c = C(i.expiresIn ?? i.expires_in, d), l = Math.max(0, Math.round((O.expiresAtMs - Date.now()) / 1e3)), f = Math.max(p, Math.min(l || c, c) - E), m = String(i.domain ?? "").trim() || S(r), h = L(t);
|
|
245
|
+
return t && (A = t), {
|
|
244
246
|
sessionId: `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
245
|
-
expiresAt: Math.floor(Date.now() / 1e3) +
|
|
247
|
+
expiresAt: Math.floor(Date.now() / 1e3) + f,
|
|
246
248
|
agent: {
|
|
247
249
|
id: a,
|
|
248
250
|
externalUserId: a,
|
|
@@ -251,34 +253,34 @@ function b(n) {
|
|
|
251
253
|
status: "Available"
|
|
252
254
|
},
|
|
253
255
|
sip: {
|
|
254
|
-
uri: `sip:${a}@${
|
|
255
|
-
registrar:
|
|
256
|
+
uri: `sip:${a}@${m}`,
|
|
257
|
+
registrar: m,
|
|
256
258
|
registerTicket: s,
|
|
257
|
-
registerExpires: Number(n.registerExpires) > 0 ? Number(n.registerExpires) :
|
|
258
|
-
ticketExpiresIn:
|
|
259
|
+
registerExpires: Number(n.registerExpires) > 0 ? Number(n.registerExpires) : u,
|
|
260
|
+
ticketExpiresIn: f
|
|
259
261
|
},
|
|
260
262
|
transport: {
|
|
261
|
-
wssUrl:
|
|
263
|
+
wssUrl: h,
|
|
262
264
|
ticket: "",
|
|
263
|
-
ticketExpiresIn:
|
|
265
|
+
ticketExpiresIn: f
|
|
264
266
|
},
|
|
265
|
-
iceServers:
|
|
267
|
+
iceServers: R(i),
|
|
266
268
|
policy: {
|
|
267
269
|
maxConcurrentCalls: Number(n.maxConcurrentCalls) > 0 ? Number(n.maxConcurrentCalls) : 2,
|
|
268
270
|
incomingEnabled: n.incomingEnabled ?? !0,
|
|
269
271
|
mobileIncomingEnabled: n.mobileIncomingEnabled ?? !0,
|
|
270
272
|
backgroundCallingSupported: !1
|
|
271
273
|
},
|
|
272
|
-
capabilities: [...n.capabilities ??
|
|
274
|
+
capabilities: [...n.capabilities ?? g]
|
|
273
275
|
};
|
|
274
276
|
}
|
|
275
277
|
return {
|
|
276
|
-
createSession:
|
|
277
|
-
refreshSession:
|
|
278
|
+
createSession: z,
|
|
279
|
+
refreshSession: z,
|
|
278
280
|
setAgentStatus: async ({ status: t, reason: n }, r) => {
|
|
279
|
-
let i = await
|
|
281
|
+
let i = await P(r), a = k ?? await F(i), o = String(a.username ?? a.account ?? "").trim();
|
|
280
282
|
if (!o) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
281
|
-
let s =
|
|
283
|
+
let s = _[t], c = await T(D, h, {
|
|
282
284
|
method: "POST",
|
|
283
285
|
headers: {
|
|
284
286
|
Authorization: i,
|
|
@@ -296,7 +298,7 @@ function b(n) {
|
|
|
296
298
|
} catch {
|
|
297
299
|
throw new e("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
|
|
298
300
|
status: c.status,
|
|
299
|
-
cause: `${
|
|
301
|
+
cause: `${h} 返回了非 JSON 响应(HTTP ${c.status})`
|
|
300
302
|
});
|
|
301
303
|
}
|
|
302
304
|
let d = Number(u.code ?? NaN);
|
|
@@ -307,36 +309,36 @@ function b(n) {
|
|
|
307
309
|
});
|
|
308
310
|
},
|
|
309
311
|
invalidateToken: () => {
|
|
310
|
-
|
|
312
|
+
O = void 0, A = "";
|
|
311
313
|
},
|
|
312
|
-
getSeatAccount: async () =>
|
|
314
|
+
getSeatAccount: async () => k ?? F()
|
|
313
315
|
};
|
|
314
316
|
}
|
|
315
|
-
function
|
|
317
|
+
function y(t) {
|
|
316
318
|
let n = String(t ?? "").trim().replace(/\/+$/, "");
|
|
317
319
|
if (!n) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 host" });
|
|
318
320
|
return /^https?:\/\//i.test(n) ? n : `https://${n}`;
|
|
319
321
|
}
|
|
320
|
-
function
|
|
322
|
+
function b(e) {
|
|
321
323
|
let t = String(e ?? "").trim();
|
|
322
324
|
return !t || t === "/" ? "" : `/${t.replace(/^\/+|\/+$/g, "")}`;
|
|
323
325
|
}
|
|
324
|
-
function
|
|
326
|
+
function x(e) {
|
|
325
327
|
let t = String(e ?? "").trim();
|
|
326
328
|
return t.startsWith("/") ? t : `/${t}`;
|
|
327
329
|
}
|
|
328
|
-
function
|
|
330
|
+
function S(e) {
|
|
329
331
|
try {
|
|
330
332
|
return new URL(e).hostname;
|
|
331
333
|
} catch {
|
|
332
334
|
return "";
|
|
333
335
|
}
|
|
334
336
|
}
|
|
335
|
-
function
|
|
337
|
+
function C(e, t) {
|
|
336
338
|
let n = Number(e);
|
|
337
|
-
return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n),
|
|
339
|
+
return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n), p), 86400));
|
|
338
340
|
}
|
|
339
|
-
function
|
|
341
|
+
function w(e) {
|
|
340
342
|
if (typeof e == "string") return { token: e.trim() };
|
|
341
343
|
let t = e ?? {}, n = typeof t.data == "object" && t.data !== null ? t.data : void 0;
|
|
342
344
|
for (let e of [t, n]) {
|
|
@@ -352,8 +354,8 @@ function E(e) {
|
|
|
352
354
|
}
|
|
353
355
|
return { token: "" };
|
|
354
356
|
}
|
|
355
|
-
async function
|
|
356
|
-
let a = new AbortController(), o = setTimeout(() => a.abort(),
|
|
357
|
+
async function T(t, n, r, i) {
|
|
358
|
+
let a = new AbortController(), o = setTimeout(() => a.abort(), h);
|
|
357
359
|
try {
|
|
358
360
|
return await t(n, {
|
|
359
361
|
...r,
|
|
@@ -361,14 +363,14 @@ async function D(t, n, r, i) {
|
|
|
361
363
|
});
|
|
362
364
|
} catch (t) {
|
|
363
365
|
let r = a.signal.aborted;
|
|
364
|
-
throw new e(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${
|
|
366
|
+
throw new e(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${h / 1e3} 秒):POST ${n}` : `${i}失败:无法请求 ${n}(${t instanceof Error ? t.message : String(t)})` });
|
|
365
367
|
} finally {
|
|
366
368
|
clearTimeout(o);
|
|
367
369
|
}
|
|
368
370
|
}
|
|
369
371
|
//#endregion
|
|
370
372
|
//#region src/legacy/index.ts
|
|
371
|
-
var
|
|
373
|
+
var E = "0.1.0";
|
|
372
374
|
typeof window < "u" && (window.CCBarSDK = i);
|
|
373
375
|
//#endregion
|
|
374
|
-
export { i as CCBarSDK, r as DeprecatedError,
|
|
376
|
+
export { i as CCBarSDK, r as DeprecatedError, v as createLegacySessionProvider, t as decryptSipPassword, E as legacyVersion };
|
|
@@ -15,7 +15,9 @@ export interface LegacySeatAccount {
|
|
|
15
15
|
registerPassword?: string;
|
|
16
16
|
expiresIn?: number;
|
|
17
17
|
expires_in?: number;
|
|
18
|
+
/** SIP 域名:拼 `sip.uri` / `sip.registrar` 用(软电话地址不再从这里拼,见 `sipWsUrl`) */
|
|
18
19
|
domain?: string;
|
|
20
|
+
/** 平台返回的端口字段:SDK 不再读它们(软电话地址由接入方传 `sipWsUrl`) */
|
|
19
21
|
wsPort?: number;
|
|
20
22
|
wssPort?: number;
|
|
21
23
|
turnIp?: string;
|
|
@@ -46,10 +48,12 @@ export interface LegacyPlatformSessionProviderOptions {
|
|
|
46
48
|
accountPath?: string;
|
|
47
49
|
/** 坐席状态路径(相对 pathPrefix),默认 `/seats/set-status` */
|
|
48
50
|
statusPath?: string;
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* 软电话 WSS 地址(必填):`wss://` 或 `ws://` 开头的**完整地址**。
|
|
53
|
+
* SDK 只在这个地址上挂 `?token=<fs token>`(见 `attachTokenToWss`),
|
|
54
|
+
* 不再按坐席账号的 domain / wssPort 拼装,也不接受相对路径。
|
|
55
|
+
*/
|
|
56
|
+
sipWsUrl: string;
|
|
53
57
|
/** 是否把 token 挂到 WSS 的 `?token=`,默认 true(旧页面那套不挂时可设 false) */
|
|
54
58
|
attachTokenToWss?: boolean;
|
|
55
59
|
/** AES key / iv(16 字节,UTF-8);默认用平台内置值 */
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "3.1.
|
|
1
|
+
export declare const SDK_VERSION = "3.1.11";
|
package/package.json
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@16x/webphone-sdk",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"homepage": "https://www.npmjs.com/package/@16x/webphone-sdk",
|
|
5
|
-
"private": false,
|
|
6
|
-
"license": "UNLICENSED",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public",
|
|
9
|
-
"registry": "https://registry.npmjs.org"
|
|
10
|
-
},
|
|
11
|
-
"type": "module",
|
|
12
|
-
"sideEffects": [
|
|
13
|
-
"./dist/styles.css"
|
|
14
|
-
],
|
|
15
|
-
"files": [
|
|
16
|
-
"dist/index.js",
|
|
17
|
-
"dist/index.cjs",
|
|
18
|
-
"dist/index.umd.js",
|
|
19
|
-
"dist/*.js",
|
|
20
|
-
"dist/*.cjs",
|
|
21
|
-
"dist/index.d.ts",
|
|
22
|
-
"dist/types.d.ts",
|
|
23
|
-
"dist/version.d.ts",
|
|
24
|
-
"dist/errors",
|
|
25
|
-
"dist/events",
|
|
26
|
-
"dist/state",
|
|
27
|
-
"dist/api",
|
|
28
|
-
"dist/core",
|
|
29
|
-
"dist/shared",
|
|
30
|
-
"dist/ui",
|
|
31
|
-
"dist/legacy",
|
|
32
|
-
"dist/diagnostics",
|
|
33
|
-
"dist/shared-worker.js",
|
|
34
|
-
"dist/shared-worker.d.ts",
|
|
35
|
-
"dist/styles.css",
|
|
36
|
-
"README.md",
|
|
37
|
-
"LICENSE",
|
|
38
|
-
"CHANGELOG.md"
|
|
39
|
-
],
|
|
40
|
-
"exports": {
|
|
41
|
-
".": {
|
|
42
|
-
"types": "./dist/index.d.ts",
|
|
43
|
-
"import": "./dist/index.js",
|
|
44
|
-
"require": "./dist/index.cjs"
|
|
45
|
-
},
|
|
46
|
-
"./ui": {
|
|
47
|
-
"types": "./dist/ui/index.d.ts",
|
|
48
|
-
"import": "./dist/ui/index.js",
|
|
49
|
-
"require": "./dist/ui/index.cjs"
|
|
50
|
-
},
|
|
51
|
-
"./legacy": {
|
|
52
|
-
"types": "./dist/legacy/index.d.ts",
|
|
53
|
-
"import": "./dist/legacy/index.js",
|
|
54
|
-
"require": "./dist/legacy/index.cjs"
|
|
55
|
-
},
|
|
56
|
-
"./diagnostics": {
|
|
57
|
-
"types": "./dist/diagnostics/index.d.ts",
|
|
58
|
-
"import": "./dist/diagnostics/index.js",
|
|
59
|
-
"require": "./dist/diagnostics/index.cjs"
|
|
60
|
-
},
|
|
61
|
-
"./shared-worker": {
|
|
62
|
-
"types": "./dist/shared-worker.d.ts",
|
|
63
|
-
"import": "./dist/shared-worker.js"
|
|
64
|
-
},
|
|
65
|
-
"./styles.css": "./dist/styles.css"
|
|
66
|
-
},
|
|
67
|
-
"scripts": {
|
|
68
|
-
"build": "vite build && vite build -c vite.umd.config.ts",
|
|
69
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
70
|
-
"test": "npm run build && npm run docs:build && vitest run",
|
|
71
|
-
"lint": "eslint .",
|
|
72
|
-
"pack:check": "node scripts/check-package.mjs",
|
|
73
|
-
"sbom": "node scripts/generate-sbom.mjs",
|
|
74
|
-
"release:artifacts": "node scripts/generate-release-artifacts.mjs",
|
|
75
|
-
"check:node-next": "npm run build && node scripts/check-node-next-consumer.mjs",
|
|
76
|
-
"verify:bundle": "node scripts/check-bundle-size.mjs",
|
|
77
|
-
"verify:memory": "node scripts/run-memory-soak.mjs",
|
|
78
|
-
"verify:call-soak": "node scripts/run-call-soak.mjs",
|
|
79
|
-
"verify:hour-soak": "node scripts/run-browser-call-soak.mjs",
|
|
80
|
-
"verify:staged": "npm run verify:memory && npm run verify:call-soak",
|
|
81
|
-
"docs:build": "node scripts/build-docs-site.mjs",
|
|
82
|
-
"docs:check": "node scripts/check-docs-site.mjs",
|
|
83
|
-
"docs:test": "npm run docs:build && npx vitest run tests/docs-site/static-site.test.ts tests/docs-site/navigation.test.ts tests/docs-site/check-docs-site.test.ts",
|
|
84
|
-
"docs:release": "npm run customer:packages && npm run docs:build && node scripts/create-integration-package.mjs && npm run docs:build && npm run docs:check",
|
|
85
|
-
"customer:packages": "node scripts/create-customer-packages.mjs",
|
|
86
|
-
"publish:npm": "bash scripts/publish-npm.sh",
|
|
87
|
-
"verify:release": "npm run lint && npm run typecheck && npm test && npm run build && npm run verify:bundle && npm run pack:check && npm run sbom"
|
|
88
|
-
},
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"jssip": "3.10.1"
|
|
91
|
-
},
|
|
92
|
-
"devDependencies": {
|
|
93
|
-
"@eslint/js": "^10.0.1",
|
|
94
|
-
"@types/react": "^19.3.0",
|
|
95
|
-
"@types/react-dom": "^19.3.0",
|
|
96
|
-
"@vitejs/plugin-react": "^6.1.1",
|
|
97
|
-
"@vitejs/plugin-vue": "^6.0.9",
|
|
98
|
-
"eslint": "^10.10.0",
|
|
99
|
-
"happy-dom": "^20.14.5",
|
|
100
|
-
"react": "^19.3.0",
|
|
101
|
-
"react-dom": "^19.3.0",
|
|
102
|
-
"typescript": "^6.0.3",
|
|
103
|
-
"typescript-eslint": "^8.70.0",
|
|
104
|
-
"vite": "^8.3.0",
|
|
105
|
-
"vite-plugin-dts": "^5.1.0",
|
|
106
|
-
"vitest": "^5.0.1",
|
|
107
|
-
"vue": "^3.5.43"
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@16x/webphone-sdk",
|
|
3
|
+
"version": "3.1.11",
|
|
4
|
+
"homepage": "https://www.npmjs.com/package/@16x/webphone-sdk",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/styles.css"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/index.js",
|
|
17
|
+
"dist/index.cjs",
|
|
18
|
+
"dist/index.umd.js",
|
|
19
|
+
"dist/*.js",
|
|
20
|
+
"dist/*.cjs",
|
|
21
|
+
"dist/index.d.ts",
|
|
22
|
+
"dist/types.d.ts",
|
|
23
|
+
"dist/version.d.ts",
|
|
24
|
+
"dist/errors",
|
|
25
|
+
"dist/events",
|
|
26
|
+
"dist/state",
|
|
27
|
+
"dist/api",
|
|
28
|
+
"dist/core",
|
|
29
|
+
"dist/shared",
|
|
30
|
+
"dist/ui",
|
|
31
|
+
"dist/legacy",
|
|
32
|
+
"dist/diagnostics",
|
|
33
|
+
"dist/shared-worker.js",
|
|
34
|
+
"dist/shared-worker.d.ts",
|
|
35
|
+
"dist/styles.css",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"CHANGELOG.md"
|
|
39
|
+
],
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"require": "./dist/index.cjs"
|
|
45
|
+
},
|
|
46
|
+
"./ui": {
|
|
47
|
+
"types": "./dist/ui/index.d.ts",
|
|
48
|
+
"import": "./dist/ui/index.js",
|
|
49
|
+
"require": "./dist/ui/index.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./legacy": {
|
|
52
|
+
"types": "./dist/legacy/index.d.ts",
|
|
53
|
+
"import": "./dist/legacy/index.js",
|
|
54
|
+
"require": "./dist/legacy/index.cjs"
|
|
55
|
+
},
|
|
56
|
+
"./diagnostics": {
|
|
57
|
+
"types": "./dist/diagnostics/index.d.ts",
|
|
58
|
+
"import": "./dist/diagnostics/index.js",
|
|
59
|
+
"require": "./dist/diagnostics/index.cjs"
|
|
60
|
+
},
|
|
61
|
+
"./shared-worker": {
|
|
62
|
+
"types": "./dist/shared-worker.d.ts",
|
|
63
|
+
"import": "./dist/shared-worker.js"
|
|
64
|
+
},
|
|
65
|
+
"./styles.css": "./dist/styles.css"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "vite build && vite build -c vite.umd.config.ts",
|
|
69
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
70
|
+
"test": "npm run build && npm run docs:build && vitest run",
|
|
71
|
+
"lint": "eslint .",
|
|
72
|
+
"pack:check": "node scripts/check-package.mjs",
|
|
73
|
+
"sbom": "node scripts/generate-sbom.mjs",
|
|
74
|
+
"release:artifacts": "node scripts/generate-release-artifacts.mjs",
|
|
75
|
+
"check:node-next": "npm run build && node scripts/check-node-next-consumer.mjs",
|
|
76
|
+
"verify:bundle": "node scripts/check-bundle-size.mjs",
|
|
77
|
+
"verify:memory": "node scripts/run-memory-soak.mjs",
|
|
78
|
+
"verify:call-soak": "node scripts/run-call-soak.mjs",
|
|
79
|
+
"verify:hour-soak": "node scripts/run-browser-call-soak.mjs",
|
|
80
|
+
"verify:staged": "npm run verify:memory && npm run verify:call-soak",
|
|
81
|
+
"docs:build": "node scripts/build-docs-site.mjs",
|
|
82
|
+
"docs:check": "node scripts/check-docs-site.mjs",
|
|
83
|
+
"docs:test": "npm run docs:build && npx vitest run tests/docs-site/static-site.test.ts tests/docs-site/navigation.test.ts tests/docs-site/check-docs-site.test.ts",
|
|
84
|
+
"docs:release": "npm run customer:packages && npm run docs:build && node scripts/create-integration-package.mjs && npm run docs:build && npm run docs:check",
|
|
85
|
+
"customer:packages": "node scripts/create-customer-packages.mjs",
|
|
86
|
+
"publish:npm": "bash scripts/publish-npm.sh",
|
|
87
|
+
"verify:release": "npm run lint && npm run typecheck && npm test && npm run build && npm run verify:bundle && npm run pack:check && npm run sbom"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"jssip": "3.10.1"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@eslint/js": "^10.0.1",
|
|
94
|
+
"@types/react": "^19.3.0",
|
|
95
|
+
"@types/react-dom": "^19.3.0",
|
|
96
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
97
|
+
"@vitejs/plugin-vue": "^6.0.9",
|
|
98
|
+
"eslint": "^10.10.0",
|
|
99
|
+
"happy-dom": "^20.14.5",
|
|
100
|
+
"react": "^19.3.0",
|
|
101
|
+
"react-dom": "^19.3.0",
|
|
102
|
+
"typescript": "^6.0.3",
|
|
103
|
+
"typescript-eslint": "^8.70.0",
|
|
104
|
+
"vite": "^8.3.0",
|
|
105
|
+
"vite-plugin-dts": "^5.1.0",
|
|
106
|
+
"vitest": "^5.0.1",
|
|
107
|
+
"vue": "^3.5.43"
|
|
108
|
+
}
|
|
109
|
+
}
|