@16x/webphone-sdk 3.0.1
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 +22 -0
- package/LICENSE +2 -0
- package/README.md +113 -0
- package/dist/CCBarClient-BdbynNBi.js +2515 -0
- package/dist/CCBarClient-DKWdvgf5.cjs +1 -0
- package/dist/CCBarError-CIqJE8zK.cjs +1 -0
- package/dist/CCBarError-DSbPw2dA.js +14 -0
- package/dist/Diagnostics-BYVvmxil.cjs +1 -0
- package/dist/Diagnostics-Cw2HVrCD.js +123 -0
- package/dist/JsSipAdapter-GHzVSCDh.js +304 -0
- package/dist/JsSipAdapter-jtGdoXrm.cjs +1 -0
- package/dist/SharedWorkerProtocol-BqUafs8d.js +73 -0
- package/dist/SharedWorkerProtocol-CYN0AprP.cjs +1 -0
- package/dist/api/WebPhoneApi.d.ts +28 -0
- package/dist/api/contracts.d.ts +94 -0
- package/dist/auth/TokenManager.d.ts +22 -0
- package/dist/core/CCBarCall.d.ts +94 -0
- package/dist/core/CCBarClient.d.ts +113 -0
- package/dist/core/CallManager.d.ts +93 -0
- package/dist/core/callId.d.ts +1 -0
- package/dist/core/mediaBridge.d.ts +17 -0
- package/dist/createJsSipFactory-2X4FBIU2.cjs +75 -0
- package/dist/createJsSipFactory-yttVU3d6.js +9662 -0
- package/dist/diagnostics/Diagnostics.d.ts +74 -0
- package/dist/diagnostics/RingBuffer.d.ts +7 -0
- package/dist/diagnostics/index.cjs +1 -0
- package/dist/diagnostics/index.d.ts +4 -0
- package/dist/diagnostics/index.js +6 -0
- package/dist/diagnostics/redact.d.ts +5 -0
- package/dist/errors/CCBarError.d.ts +15 -0
- package/dist/events/TypedEventBus.d.ts +9 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +152 -0
- package/dist/index.umd.js +75 -0
- package/dist/legacy/CCBarSDK.d.ts +29 -0
- package/dist/legacy/index.cjs +1 -0
- package/dist/legacy/index.d.ts +8 -0
- package/dist/legacy/index.js +108 -0
- package/dist/redact-Bq26pObO.cjs +1 -0
- package/dist/redact-DB3CMbsK.js +21 -0
- package/dist/shared/SharedCallTransport.d.ts +55 -0
- package/dist/shared/SharedWorkerClient.d.ts +20 -0
- package/dist/shared/SharedWorkerEntry.d.ts +3 -0
- package/dist/shared/SharedWorkerFactory.d.ts +29 -0
- package/dist/shared/SharedWorkerProtocol.d.ts +47 -0
- package/dist/shared/SharedWorkerRuntime.d.ts +35 -0
- package/dist/shared-worker.cjs +1 -0
- package/dist/shared-worker.d.ts +1 -0
- package/dist/shared-worker.js +185 -0
- package/dist/state/callStateMachine.d.ts +9 -0
- package/dist/styles.css +7 -0
- package/dist/types.d.ts +134 -0
- package/dist/ui/XCallCCBarElement.d.ts +23 -0
- package/dist/ui/controllers/mobileLifecycle.d.ts +18 -0
- package/dist/ui/controllers/phoneActions.d.ts +27 -0
- package/dist/ui/i18n/en-US.d.ts +2 -0
- package/dist/ui/i18n/index.d.ts +6 -0
- package/dist/ui/i18n/types.d.ts +53 -0
- package/dist/ui/i18n/zh-CN.d.ts +2 -0
- package/dist/ui/icons/index.d.ts +5 -0
- package/dist/ui/index.cjs +1 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.js +1044 -0
- package/dist/ui/state/toPhoneViewModel.d.ts +54 -0
- package/dist/ui/views/dom.d.ts +11 -0
- package/dist/ui/views/messages.d.ts +5 -0
- package/dist/ui/views/renderActiveCall.d.ts +8 -0
- package/dist/ui/views/renderDesktop.d.ts +24 -0
- package/dist/ui/views/renderDialpad.d.ts +4 -0
- package/dist/ui/views/renderError.d.ts +6 -0
- package/dist/ui/views/renderIncoming.d.ts +8 -0
- package/dist/ui/views/renderMobile.d.ts +15 -0
- package/dist/ui/views/renderSetup.d.ts +6 -0
- package/package.json +107 -0
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,1044 @@
|
|
|
1
|
+
//#region src/ui/i18n/en-US.ts
|
|
2
|
+
var e = {
|
|
3
|
+
call: "Call",
|
|
4
|
+
numberLabel: "Number",
|
|
5
|
+
statusReady: "Ready",
|
|
6
|
+
statusSetup: "Not initialized",
|
|
7
|
+
statusConnecting: "Connecting",
|
|
8
|
+
statusIncoming: "Incoming call",
|
|
9
|
+
statusActive: "On a call",
|
|
10
|
+
statusHeld: "On hold",
|
|
11
|
+
statusDialing: "Dialing",
|
|
12
|
+
statusEnded: "Call ended",
|
|
13
|
+
statusFailed: "Call failed",
|
|
14
|
+
statusUnsupported: "Unsupported browser",
|
|
15
|
+
statusPermission: "Microphone unavailable",
|
|
16
|
+
statusError: "Unable to continue",
|
|
17
|
+
incoming: "Incoming call",
|
|
18
|
+
answer: "Answer",
|
|
19
|
+
reject: "Decline",
|
|
20
|
+
hangup: "Hang up",
|
|
21
|
+
mute: "Mute",
|
|
22
|
+
unmute: "Unmute",
|
|
23
|
+
hold: "Hold",
|
|
24
|
+
resume: "Resume",
|
|
25
|
+
transfer: "Transfer",
|
|
26
|
+
blindTransfer: "Blind transfer",
|
|
27
|
+
more: "More",
|
|
28
|
+
devices: "Devices",
|
|
29
|
+
enablePhone: "Enable phone",
|
|
30
|
+
retryPermission: "Check again",
|
|
31
|
+
permissionTitle: "Microphone unavailable",
|
|
32
|
+
permissionBody: "Allow microphone access in the browser settings, then check again.",
|
|
33
|
+
errorTitle: "Unable to continue",
|
|
34
|
+
errorBody: "Check the network, origin allowlist, or agent permission, then retry.",
|
|
35
|
+
currentCall: "Current call",
|
|
36
|
+
inbound: "Inbound",
|
|
37
|
+
outbound: "Outbound",
|
|
38
|
+
foregroundChecking: "Back in foreground, checking the connection",
|
|
39
|
+
foregroundFailed: "Foreground recovery failed. Retry.",
|
|
40
|
+
signIn: "Sign in",
|
|
41
|
+
signOut: "Sign out",
|
|
42
|
+
outboundCall: "Outbound",
|
|
43
|
+
internalCall: "Internal",
|
|
44
|
+
agentIdle: "Available",
|
|
45
|
+
agentBusy: "Busy",
|
|
46
|
+
agentBreak: "Break",
|
|
47
|
+
agentBusyHint: "Busy is controlled by the call or server",
|
|
48
|
+
rowSignIn: "Presence",
|
|
49
|
+
rowCall: "Call",
|
|
50
|
+
rowAgent: "Agent",
|
|
51
|
+
extensionLabel: "Extension",
|
|
52
|
+
extensionPlaceholder: "Optional, assigned by the server"
|
|
53
|
+
}, t = {
|
|
54
|
+
call: "呼叫",
|
|
55
|
+
numberLabel: "号码",
|
|
56
|
+
statusReady: "可拨号",
|
|
57
|
+
statusSetup: "未初始化",
|
|
58
|
+
statusConnecting: "正在连接",
|
|
59
|
+
statusIncoming: "来电",
|
|
60
|
+
statusActive: "通话中",
|
|
61
|
+
statusHeld: "保持中",
|
|
62
|
+
statusDialing: "正在拨号",
|
|
63
|
+
statusEnded: "通话结束",
|
|
64
|
+
statusFailed: "呼叫失败",
|
|
65
|
+
statusUnsupported: "不支持的浏览器",
|
|
66
|
+
statusPermission: "无法使用麦克风",
|
|
67
|
+
statusError: "无法继续通话",
|
|
68
|
+
incoming: "来电",
|
|
69
|
+
answer: "接听",
|
|
70
|
+
reject: "拒绝",
|
|
71
|
+
hangup: "挂断",
|
|
72
|
+
mute: "静音",
|
|
73
|
+
unmute: "取消静音",
|
|
74
|
+
hold: "保持",
|
|
75
|
+
resume: "恢复",
|
|
76
|
+
transfer: "转接",
|
|
77
|
+
blindTransfer: "盲转",
|
|
78
|
+
more: "更多",
|
|
79
|
+
devices: "设备",
|
|
80
|
+
enablePhone: "启用电话",
|
|
81
|
+
retryPermission: "重新检测",
|
|
82
|
+
permissionTitle: "无法使用麦克风",
|
|
83
|
+
permissionBody: "请在浏览器设置中允许本网站访问麦克风,然后重新检测。",
|
|
84
|
+
errorTitle: "无法继续通话",
|
|
85
|
+
errorBody: "请检查网络、域名授权或坐席权限后重试。",
|
|
86
|
+
currentCall: "当前通话",
|
|
87
|
+
inbound: "呼入",
|
|
88
|
+
outbound: "呼出",
|
|
89
|
+
foregroundChecking: "已返回前台,正在检查连接",
|
|
90
|
+
foregroundFailed: "前台恢复失败,请重试",
|
|
91
|
+
signIn: "签入",
|
|
92
|
+
signOut: "退签",
|
|
93
|
+
outboundCall: "外呼",
|
|
94
|
+
internalCall: "内呼",
|
|
95
|
+
agentIdle: "空闲",
|
|
96
|
+
agentBusy: "置忙",
|
|
97
|
+
agentBreak: "休息",
|
|
98
|
+
agentBusyHint: "置忙由通话或服务端状态控制",
|
|
99
|
+
rowSignIn: "签入",
|
|
100
|
+
rowCall: "通话",
|
|
101
|
+
rowAgent: "坐席",
|
|
102
|
+
extensionLabel: "分机",
|
|
103
|
+
extensionPlaceholder: "可空,由服务端分配"
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/ui/i18n/index.ts
|
|
107
|
+
function n(n) {
|
|
108
|
+
return n.toLowerCase().startsWith("en") ? e : t;
|
|
109
|
+
}
|
|
110
|
+
function r(e, t, r) {
|
|
111
|
+
return {
|
|
112
|
+
...n(e),
|
|
113
|
+
...r === void 0 ? {} : r(e),
|
|
114
|
+
...t ?? {}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/ui/controllers/mobileLifecycle.ts
|
|
119
|
+
async function i(e) {
|
|
120
|
+
await e.media.requestPermission(), await e.initialize(), await e.connect();
|
|
121
|
+
}
|
|
122
|
+
function a(e, t = {}) {
|
|
123
|
+
let n = t.document ?? (typeof document > "u" ? void 0 : document);
|
|
124
|
+
if (n === void 0) return () => void 0;
|
|
125
|
+
let r = () => {
|
|
126
|
+
if (n.visibilityState === "hidden") {
|
|
127
|
+
t.onHidden?.();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
t.onChecking?.(), e.recover().then(() => t.onRecovered?.()).catch((e) => t.onFailed?.(e));
|
|
131
|
+
};
|
|
132
|
+
return n.addEventListener("visibilitychange", r), () => n.removeEventListener("visibilitychange", r);
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/ui/controllers/phoneActions.ts
|
|
136
|
+
function o(e) {
|
|
137
|
+
return e.replace(/\s+/g, "");
|
|
138
|
+
}
|
|
139
|
+
function s(e, t, n) {
|
|
140
|
+
return o(e).length > 0 && n === "connected" && t !== "denied";
|
|
141
|
+
}
|
|
142
|
+
async function c(e, t, n) {
|
|
143
|
+
let r = o(t);
|
|
144
|
+
r !== "" && await e.dial({
|
|
145
|
+
destination: r,
|
|
146
|
+
...n === void 0 ? {} : { type: n }
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async function l(e, t) {
|
|
150
|
+
return t ? await e.unmute() : await e.mute(), !t;
|
|
151
|
+
}
|
|
152
|
+
async function u(e) {
|
|
153
|
+
e.state === "held" ? await e.resume() : await e.hold();
|
|
154
|
+
}
|
|
155
|
+
async function d(e, t) {
|
|
156
|
+
await e.sendDtmf(t);
|
|
157
|
+
}
|
|
158
|
+
async function f(e, t) {
|
|
159
|
+
let n = o(t);
|
|
160
|
+
n !== "" && await e.transfer({
|
|
161
|
+
target: n,
|
|
162
|
+
type: "blind"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/ui/views/dom.ts
|
|
167
|
+
function p(e, t = {}) {
|
|
168
|
+
let n = document.createElement(e);
|
|
169
|
+
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;
|
|
170
|
+
}
|
|
171
|
+
function m(e) {
|
|
172
|
+
return p("div", {
|
|
173
|
+
attrs: {
|
|
174
|
+
part: "status-rail",
|
|
175
|
+
role: "status",
|
|
176
|
+
"aria-live": "polite"
|
|
177
|
+
},
|
|
178
|
+
text: e
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function h(e, t, n = "destination") {
|
|
182
|
+
let r = p("input", { attrs: {
|
|
183
|
+
id: e,
|
|
184
|
+
type: "tel",
|
|
185
|
+
inputmode: "tel",
|
|
186
|
+
name: n,
|
|
187
|
+
autocomplete: "tel"
|
|
188
|
+
} });
|
|
189
|
+
return {
|
|
190
|
+
field: p("div", { children: [p("label", {
|
|
191
|
+
attrs: { for: e },
|
|
192
|
+
text: t
|
|
193
|
+
}), r] }),
|
|
194
|
+
input: r
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/ui/views/renderDesktop.ts
|
|
199
|
+
var g = [
|
|
200
|
+
"1",
|
|
201
|
+
"2",
|
|
202
|
+
"3",
|
|
203
|
+
"4",
|
|
204
|
+
"5",
|
|
205
|
+
"6",
|
|
206
|
+
"7",
|
|
207
|
+
"8",
|
|
208
|
+
"9",
|
|
209
|
+
"*",
|
|
210
|
+
"0",
|
|
211
|
+
"#"
|
|
212
|
+
];
|
|
213
|
+
function _(e) {
|
|
214
|
+
return e.mode === "compact" ? v(e) : y(e);
|
|
215
|
+
}
|
|
216
|
+
function v(e) {
|
|
217
|
+
let { field: t, input: n } = h("ccbar-destination", e.messages.numberLabel ?? "号码");
|
|
218
|
+
n.value = e.destination;
|
|
219
|
+
let r = e.view.kind === "ready" || e.view.kind === "setup" || e.view.kind === "ended" ? p("button", {
|
|
220
|
+
attrs: {
|
|
221
|
+
type: "button",
|
|
222
|
+
"data-action": "dial",
|
|
223
|
+
part: "call-button",
|
|
224
|
+
...e.canDial ? {} : { disabled: "" }
|
|
225
|
+
},
|
|
226
|
+
text: e.messages.call ?? "呼叫"
|
|
227
|
+
}) : p("button", {
|
|
228
|
+
attrs: {
|
|
229
|
+
type: "button",
|
|
230
|
+
"data-action": "hangup",
|
|
231
|
+
part: "hangup-button"
|
|
232
|
+
},
|
|
233
|
+
text: e.messages.hangup ?? "挂断"
|
|
234
|
+
}), i = [S(e.messages.status ?? "", e.floating), p("div", {
|
|
235
|
+
className: "ccbar-toolbar",
|
|
236
|
+
children: [
|
|
237
|
+
t,
|
|
238
|
+
e.view.kind === "active" || e.view.kind === "held" ? E(e) : p("span"),
|
|
239
|
+
r,
|
|
240
|
+
p("button", {
|
|
241
|
+
attrs: {
|
|
242
|
+
type: "button",
|
|
243
|
+
"data-action": "more"
|
|
244
|
+
},
|
|
245
|
+
text: e.messages.more ?? "更多"
|
|
246
|
+
})
|
|
247
|
+
]
|
|
248
|
+
})];
|
|
249
|
+
return e.moreOpen && i.push(p("div", {
|
|
250
|
+
className: "ccbar-more",
|
|
251
|
+
children: [D(e.view, e.messages), p("button", {
|
|
252
|
+
attrs: {
|
|
253
|
+
type: "button",
|
|
254
|
+
"data-action": "devices"
|
|
255
|
+
},
|
|
256
|
+
text: e.messages.devices ?? "设备"
|
|
257
|
+
})]
|
|
258
|
+
})), p("div", {
|
|
259
|
+
attrs: {
|
|
260
|
+
part: "panel",
|
|
261
|
+
"data-layout": "compact"
|
|
262
|
+
},
|
|
263
|
+
children: i
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function y(e) {
|
|
267
|
+
let { input: t } = h("ccbar-destination", e.messages.numberLabel ?? "号码"), { field: n } = h("ccbar-transfer-target", e.messages.transfer ?? "转接号码", "transfer-target");
|
|
268
|
+
t.value = e.destination, t.placeholder = e.messages.numberLabel ?? "号码", t.setAttribute("aria-label", e.messages.numberLabel ?? "号码");
|
|
269
|
+
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 = [
|
|
270
|
+
S(e.messages.status ?? "", e.floating, e.extension, e.messages.extensionLabel ?? "分机"),
|
|
271
|
+
b(e.messages.rowSignIn ?? "签入", [
|
|
272
|
+
C(e),
|
|
273
|
+
x("signin", e.messages.signIn ?? "签入", {
|
|
274
|
+
variant: "primary",
|
|
275
|
+
disabled: e.connected || a
|
|
276
|
+
}),
|
|
277
|
+
x("signout", e.messages.signOut ?? "退签", { disabled: !e.connected })
|
|
278
|
+
]),
|
|
279
|
+
b(e.messages.numberLabel ?? "号码", [t], { labelFor: t.id }),
|
|
280
|
+
b(e.messages.rowCall ?? "通话", [
|
|
281
|
+
x("dial", e.messages.outboundCall ?? "外呼", {
|
|
282
|
+
variant: "primary",
|
|
283
|
+
disabled: !e.canDial
|
|
284
|
+
}),
|
|
285
|
+
x("dial-internal", e.messages.internalCall ?? "内呼", { disabled: !e.canDial }),
|
|
286
|
+
x("hangup", e.messages.hangup ?? "挂断", {
|
|
287
|
+
variant: "danger",
|
|
288
|
+
disabled: !r
|
|
289
|
+
}),
|
|
290
|
+
x("transfer", e.messages.transfer ?? "转接", { disabled: !r }),
|
|
291
|
+
x("hold", e.messages.hold ?? "保持", {
|
|
292
|
+
pressed: i,
|
|
293
|
+
disabled: !r || i
|
|
294
|
+
}),
|
|
295
|
+
x("resume", e.messages.resume ?? "恢复", { disabled: !i }),
|
|
296
|
+
E(e)
|
|
297
|
+
]),
|
|
298
|
+
...r ? [b(e.messages.transfer ?? "转接号码", [n], { labelFor: "ccbar-transfer-target" })] : [],
|
|
299
|
+
b(e.messages.rowAgent ?? "坐席", [
|
|
300
|
+
x("agent-available", e.messages.agentIdle ?? "空闲", {
|
|
301
|
+
pressed: e.agentStatus === "available",
|
|
302
|
+
disabled: !e.connected
|
|
303
|
+
}),
|
|
304
|
+
x("agent-busy", e.messages.agentBusy ?? "置忙", {
|
|
305
|
+
disabled: !0,
|
|
306
|
+
title: e.messages.agentBusyHint ?? "置忙由通话或服务端状态控制"
|
|
307
|
+
}),
|
|
308
|
+
x("agent-break", e.messages.agentBreak ?? "休息", {
|
|
309
|
+
pressed: e.agentStatus === "break",
|
|
310
|
+
disabled: !e.connected
|
|
311
|
+
})
|
|
312
|
+
]),
|
|
313
|
+
T()
|
|
314
|
+
];
|
|
315
|
+
return e.calls.length > 1 && o.push(O(e.calls, e.messages)), p("div", {
|
|
316
|
+
attrs: {
|
|
317
|
+
part: "panel",
|
|
318
|
+
"data-layout": "panel"
|
|
319
|
+
},
|
|
320
|
+
children: o
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function b(e, t, n = {}) {
|
|
324
|
+
return p("div", {
|
|
325
|
+
className: "ccbar-bar-row",
|
|
326
|
+
children: [p(n.labelFor === void 0 ? "div" : "label", {
|
|
327
|
+
className: "ccbar-bar-label",
|
|
328
|
+
attrs: n.labelFor === void 0 ? {} : { for: n.labelFor },
|
|
329
|
+
text: e
|
|
330
|
+
}), p("div", {
|
|
331
|
+
className: "ccbar-bar-keys",
|
|
332
|
+
children: t
|
|
333
|
+
})]
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function x(e, t, n = {}) {
|
|
337
|
+
let r = e === "dial" ? "call-button" : e === "hangup" ? "hangup-button" : void 0;
|
|
338
|
+
return p("button", {
|
|
339
|
+
attrs: {
|
|
340
|
+
type: "button",
|
|
341
|
+
"data-action": e,
|
|
342
|
+
...r === void 0 ? {} : { part: r },
|
|
343
|
+
...n.variant === void 0 ? {} : { "data-variant": n.variant },
|
|
344
|
+
...n.disabled === !0 ? { disabled: "" } : {},
|
|
345
|
+
...n.pressed === void 0 ? {} : { "aria-pressed": n.pressed ? "true" : "false" },
|
|
346
|
+
...n.title === void 0 ? {} : { title: n.title }
|
|
347
|
+
},
|
|
348
|
+
text: t
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function S(e, t, n = "", r = "分机") {
|
|
352
|
+
let i = w(e);
|
|
353
|
+
return t && i.setAttribute("data-drag-handle", ""), n !== "" && i.append(p("span", {
|
|
354
|
+
className: "ccbar-ext-chip",
|
|
355
|
+
text: `${r} ${n}`
|
|
356
|
+
})), i;
|
|
357
|
+
}
|
|
358
|
+
function C(e) {
|
|
359
|
+
let t = p("input", { attrs: {
|
|
360
|
+
id: "ccbar-extension",
|
|
361
|
+
type: "tel",
|
|
362
|
+
inputmode: "numeric",
|
|
363
|
+
name: "extension",
|
|
364
|
+
autocomplete: "off",
|
|
365
|
+
placeholder: e.messages.extensionPlaceholder ?? "可空,由服务端分配",
|
|
366
|
+
"aria-label": e.messages.extensionLabel ?? "分机"
|
|
367
|
+
} });
|
|
368
|
+
return t.value = e.extension, e.connected && (t.readOnly = !0), t;
|
|
369
|
+
}
|
|
370
|
+
function w(e) {
|
|
371
|
+
return m(e);
|
|
372
|
+
}
|
|
373
|
+
function T() {
|
|
374
|
+
return p("div", {
|
|
375
|
+
className: "ccbar-dialpad",
|
|
376
|
+
children: g.map((e) => p("button", {
|
|
377
|
+
attrs: {
|
|
378
|
+
type: "button",
|
|
379
|
+
"data-digit": e
|
|
380
|
+
},
|
|
381
|
+
text: e
|
|
382
|
+
}))
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function E(e) {
|
|
386
|
+
return p("button", {
|
|
387
|
+
attrs: {
|
|
388
|
+
type: "button",
|
|
389
|
+
"data-action": "mute",
|
|
390
|
+
"aria-pressed": e.muted ? "true" : "false"
|
|
391
|
+
},
|
|
392
|
+
text: e.muted ? e.messages.unmute ?? "取消静音" : e.messages.mute ?? "静音"
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function D(e, t) {
|
|
396
|
+
let n = e.kind === "held";
|
|
397
|
+
return p("button", {
|
|
398
|
+
attrs: {
|
|
399
|
+
type: "button",
|
|
400
|
+
"data-action": "hold",
|
|
401
|
+
"aria-pressed": n ? "true" : "false"
|
|
402
|
+
},
|
|
403
|
+
text: n ? t.resume ?? "恢复" : t.hold ?? "保持"
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function O(e, t) {
|
|
407
|
+
return p("ul", {
|
|
408
|
+
className: "ccbar-call-list",
|
|
409
|
+
children: e.map((e) => p("li", { children: [p("button", {
|
|
410
|
+
attrs: {
|
|
411
|
+
type: "button",
|
|
412
|
+
"data-call-id": e.id
|
|
413
|
+
},
|
|
414
|
+
children: [p("span", { text: `${e.destination} ${e.direction === "inbound" ? t.inbound ?? "呼入" : t.outbound ?? "呼出"} ${k(e.state, t)}` }), ...e.current ? [p("span", {
|
|
415
|
+
className: "ccbar-call-current",
|
|
416
|
+
text: t.currentCall ?? "当前通话"
|
|
417
|
+
})] : []]
|
|
418
|
+
})] }))
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function k(e, t) {
|
|
422
|
+
return e === "held" ? t.statusHeld ?? "保持中" : e === "active" ? t.statusActive ?? "通话中" : e === "dialing" || e === "ringing" || e === "connecting" ? t.statusDialing ?? "拨号中" : e;
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/ui/views/renderError.ts
|
|
426
|
+
function A(e) {
|
|
427
|
+
switch (e.view.kind) {
|
|
428
|
+
case "permission-error": return p("div", {
|
|
429
|
+
attrs: { part: "panel" },
|
|
430
|
+
children: [
|
|
431
|
+
m(e.messages.permissionTitle ?? "无法使用麦克风"),
|
|
432
|
+
p("h2", { text: e.messages.permissionTitle ?? "无法使用麦克风" }),
|
|
433
|
+
p("p", { text: e.messages.permissionBody ?? "请在浏览器设置中允许本网站访问麦克风,然后重新检测。" }),
|
|
434
|
+
p("button", {
|
|
435
|
+
attrs: {
|
|
436
|
+
type: "button",
|
|
437
|
+
"data-action": "retry-permission"
|
|
438
|
+
},
|
|
439
|
+
text: e.messages.retryPermission ?? "重新检测"
|
|
440
|
+
})
|
|
441
|
+
]
|
|
442
|
+
});
|
|
443
|
+
case "unrecoverable-error":
|
|
444
|
+
case "unsupported": return p("div", {
|
|
445
|
+
attrs: { part: "panel" },
|
|
446
|
+
children: [p("div", {
|
|
447
|
+
attrs: {
|
|
448
|
+
role: "alert",
|
|
449
|
+
part: "status-rail"
|
|
450
|
+
},
|
|
451
|
+
text: e.messages.errorTitle ?? "无法继续通话"
|
|
452
|
+
}), p("p", { text: e.messages.errorBody ?? "请检查网络、域名授权或坐席权限后重试。" })]
|
|
453
|
+
});
|
|
454
|
+
case "setup":
|
|
455
|
+
case "connecting":
|
|
456
|
+
case "incoming":
|
|
457
|
+
case "active":
|
|
458
|
+
case "held":
|
|
459
|
+
case "dialing":
|
|
460
|
+
case "ended":
|
|
461
|
+
case "ready": return p("div", {
|
|
462
|
+
attrs: { part: "panel" },
|
|
463
|
+
children: [m(e.messages.status ?? "")]
|
|
464
|
+
});
|
|
465
|
+
default: return e.view;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/ui/views/renderIncoming.ts
|
|
470
|
+
function j(e) {
|
|
471
|
+
return p("div", {
|
|
472
|
+
attrs: { part: "panel" },
|
|
473
|
+
children: [
|
|
474
|
+
m(e.messages.status ?? "来电"),
|
|
475
|
+
p("p", { text: e.view.from }),
|
|
476
|
+
p("button", {
|
|
477
|
+
attrs: {
|
|
478
|
+
type: "button",
|
|
479
|
+
"data-action": "answer"
|
|
480
|
+
},
|
|
481
|
+
text: e.messages.answer ?? "接听"
|
|
482
|
+
}),
|
|
483
|
+
p("button", {
|
|
484
|
+
attrs: {
|
|
485
|
+
type: "button",
|
|
486
|
+
"data-action": "reject"
|
|
487
|
+
},
|
|
488
|
+
text: e.messages.reject ?? "拒绝"
|
|
489
|
+
})
|
|
490
|
+
]
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/ui/views/renderMobile.ts
|
|
495
|
+
var M = [
|
|
496
|
+
"1",
|
|
497
|
+
"2",
|
|
498
|
+
"3",
|
|
499
|
+
"4",
|
|
500
|
+
"5",
|
|
501
|
+
"6",
|
|
502
|
+
"7",
|
|
503
|
+
"8",
|
|
504
|
+
"9",
|
|
505
|
+
"*",
|
|
506
|
+
"0",
|
|
507
|
+
"#"
|
|
508
|
+
];
|
|
509
|
+
function N(e) {
|
|
510
|
+
return F(p("div", {
|
|
511
|
+
attrs: {
|
|
512
|
+
part: "panel",
|
|
513
|
+
"data-layout": "mobile"
|
|
514
|
+
},
|
|
515
|
+
children: [m(e.status), p("button", {
|
|
516
|
+
attrs: {
|
|
517
|
+
type: "button",
|
|
518
|
+
"data-action": "enable-phone",
|
|
519
|
+
...e.enabling ? { disabled: "" } : {}
|
|
520
|
+
},
|
|
521
|
+
text: e.enablePhone ?? "启用电话"
|
|
522
|
+
})]
|
|
523
|
+
}));
|
|
524
|
+
}
|
|
525
|
+
function P(e) {
|
|
526
|
+
let t = e.view.kind === "active" || e.view.kind === "dialing", n = [m(e.messages.status ?? "")];
|
|
527
|
+
if (t) {
|
|
528
|
+
let t = e.view.kind === "active" || e.view.kind === "dialing" ? e.view.destination ?? "" : "";
|
|
529
|
+
n.push(p("p", { text: t }), I(p("button", {
|
|
530
|
+
attrs: {
|
|
531
|
+
type: "button",
|
|
532
|
+
"data-action": "mute",
|
|
533
|
+
"aria-pressed": e.muted ? "true" : "false"
|
|
534
|
+
},
|
|
535
|
+
text: e.muted ? e.messages.unmute ?? "取消静音" : e.messages.mute ?? "静音"
|
|
536
|
+
}), 44), L(), I(p("button", {
|
|
537
|
+
attrs: {
|
|
538
|
+
type: "button",
|
|
539
|
+
"data-action": "hangup",
|
|
540
|
+
part: "hangup-button"
|
|
541
|
+
},
|
|
542
|
+
text: e.messages.hangup ?? "挂断"
|
|
543
|
+
}), 52));
|
|
544
|
+
} else {
|
|
545
|
+
let { field: t, input: r } = h("ccbar-destination", e.messages.numberLabel ?? "号码");
|
|
546
|
+
r.value = e.destination, n.push(t, L(), p("button", {
|
|
547
|
+
attrs: {
|
|
548
|
+
type: "button",
|
|
549
|
+
"data-action": "dial",
|
|
550
|
+
part: "call-button",
|
|
551
|
+
...e.canDial ? {} : { disabled: "" }
|
|
552
|
+
},
|
|
553
|
+
text: e.messages.call ?? "呼叫"
|
|
554
|
+
}));
|
|
555
|
+
}
|
|
556
|
+
return e.showOutputDevice && n.push(p("button", {
|
|
557
|
+
attrs: {
|
|
558
|
+
type: "button",
|
|
559
|
+
"data-action": "devices"
|
|
560
|
+
},
|
|
561
|
+
text: e.messages.devices ?? "设备"
|
|
562
|
+
})), F(p("div", {
|
|
563
|
+
attrs: {
|
|
564
|
+
part: "panel",
|
|
565
|
+
"data-layout": "mobile"
|
|
566
|
+
},
|
|
567
|
+
children: n
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
function F(e) {
|
|
571
|
+
return e.style.minHeight = "100dvh", e.style.paddingBottom = "max(16px, env(safe-area-inset-bottom))", e;
|
|
572
|
+
}
|
|
573
|
+
function I(e, t) {
|
|
574
|
+
return e.style.minHeight = `${t}px`, e;
|
|
575
|
+
}
|
|
576
|
+
function L() {
|
|
577
|
+
return p("div", {
|
|
578
|
+
className: "ccbar-dialpad",
|
|
579
|
+
children: M.map((e) => p("button", {
|
|
580
|
+
attrs: {
|
|
581
|
+
type: "button",
|
|
582
|
+
"data-digit": e
|
|
583
|
+
},
|
|
584
|
+
text: e
|
|
585
|
+
}))
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/ui/state/toPhoneViewModel.ts
|
|
590
|
+
var R = {
|
|
591
|
+
kind: "permission-error",
|
|
592
|
+
code: "MEDIA_PERMISSION_DENIED",
|
|
593
|
+
action: "retry-permission"
|
|
594
|
+
};
|
|
595
|
+
function z(e) {
|
|
596
|
+
if (e.supported === !1) return { kind: "unsupported" };
|
|
597
|
+
if (e.permission === "denied" || e.error?.code === "MEDIA_PERMISSION_DENIED") return R;
|
|
598
|
+
if (e.error !== void 0 && e.error.code !== "MEDIA_PLAYBACK_BLOCKED") return {
|
|
599
|
+
kind: "unrecoverable-error",
|
|
600
|
+
code: e.error.code
|
|
601
|
+
};
|
|
602
|
+
let t = e.calls.find((e) => e.direction === "inbound" && (e.state === "ringing" || e.state === "new"));
|
|
603
|
+
if (t !== void 0) return {
|
|
604
|
+
kind: "incoming",
|
|
605
|
+
callId: t.id,
|
|
606
|
+
from: t.destination ?? ""
|
|
607
|
+
};
|
|
608
|
+
let n = e.calls.find((e) => e.state === "active");
|
|
609
|
+
if (n !== void 0) return {
|
|
610
|
+
kind: "active",
|
|
611
|
+
callId: n.id,
|
|
612
|
+
destination: n.destination
|
|
613
|
+
};
|
|
614
|
+
let r = e.calls.find((e) => e.state === "held");
|
|
615
|
+
if (r !== void 0) return {
|
|
616
|
+
kind: "held",
|
|
617
|
+
callId: r.id,
|
|
618
|
+
destination: r.destination
|
|
619
|
+
};
|
|
620
|
+
let i = e.calls.find((e) => e.state === "dialing" || e.state === "ringing" || e.state === "connecting");
|
|
621
|
+
if (i !== void 0) return {
|
|
622
|
+
kind: "dialing",
|
|
623
|
+
callId: i.id,
|
|
624
|
+
destination: i.destination
|
|
625
|
+
};
|
|
626
|
+
let a = e.calls.find((e) => e.state === "ended" || e.state === "failed");
|
|
627
|
+
return a === void 0 ? e.connectionState === "connecting" || e.connectionState === "reconnecting" ? { kind: "connecting" } : e.connectionState === "connected" ? { kind: "ready" } : { kind: "setup" } : {
|
|
628
|
+
kind: "ended",
|
|
629
|
+
callId: a.id
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/ui/styles/index.css?inline
|
|
634
|
+
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 = /* @__PURE__ */ new WeakSet(), U = [
|
|
635
|
+
"connection.stateChanged",
|
|
636
|
+
"connection.reconnecting",
|
|
637
|
+
"connection.failed",
|
|
638
|
+
"call.incoming",
|
|
639
|
+
"call.stateChanged",
|
|
640
|
+
"call.activeChanged",
|
|
641
|
+
"call.ended",
|
|
642
|
+
"call.failed",
|
|
643
|
+
"media.permissionChanged",
|
|
644
|
+
"agent.statusChanged",
|
|
645
|
+
"error"
|
|
646
|
+
], W = class extends V {
|
|
647
|
+
static get observedAttributes() {
|
|
648
|
+
return [
|
|
649
|
+
"mode",
|
|
650
|
+
"floating",
|
|
651
|
+
"draggable",
|
|
652
|
+
"locale",
|
|
653
|
+
"theme"
|
|
654
|
+
];
|
|
655
|
+
}
|
|
656
|
+
#e;
|
|
657
|
+
#t = [];
|
|
658
|
+
#n = "idle";
|
|
659
|
+
#r = "unknown";
|
|
660
|
+
#i;
|
|
661
|
+
#a = /* @__PURE__ */ new Set();
|
|
662
|
+
#o = "";
|
|
663
|
+
#s = "";
|
|
664
|
+
#c = "offline";
|
|
665
|
+
#l = !1;
|
|
666
|
+
#u = !1;
|
|
667
|
+
#d = Promise.resolve();
|
|
668
|
+
#f;
|
|
669
|
+
#p = !1;
|
|
670
|
+
#m = !1;
|
|
671
|
+
#h;
|
|
672
|
+
#g;
|
|
673
|
+
#_;
|
|
674
|
+
#v;
|
|
675
|
+
#y;
|
|
676
|
+
get messageResolver() {
|
|
677
|
+
return this.#v;
|
|
678
|
+
}
|
|
679
|
+
set messageResolver(e) {
|
|
680
|
+
this.#v = e, this.shadowRoot !== null && this.render();
|
|
681
|
+
}
|
|
682
|
+
get client() {
|
|
683
|
+
return this.#e;
|
|
684
|
+
}
|
|
685
|
+
set client(e) {
|
|
686
|
+
this.#D(), this.#e = e, this.#E(), this.render();
|
|
687
|
+
}
|
|
688
|
+
connectedCallback() {
|
|
689
|
+
this.#B(), this.#z(), this.render();
|
|
690
|
+
}
|
|
691
|
+
disconnectedCallback() {
|
|
692
|
+
this.#D(), this.#W(), this.#y?.(), this.#y = void 0;
|
|
693
|
+
}
|
|
694
|
+
attributeChangedCallback(e) {
|
|
695
|
+
this.#B(), e === "theme" && this.#z(), this.shadowRoot !== null && this.render();
|
|
696
|
+
}
|
|
697
|
+
render() {
|
|
698
|
+
let e = this.#O();
|
|
699
|
+
e !== void 0 && (e.innerHTML = `<style>${B}</style>`, e.append(this.#x(this.#b())));
|
|
700
|
+
}
|
|
701
|
+
#b() {
|
|
702
|
+
let e = this.#e?.getCalls?.().map((e) => ({
|
|
703
|
+
id: e.id,
|
|
704
|
+
state: e.state,
|
|
705
|
+
destination: e.destination,
|
|
706
|
+
direction: this.#a.has(e.id) ? "inbound" : "outbound"
|
|
707
|
+
})) ?? [];
|
|
708
|
+
return z({
|
|
709
|
+
connectionState: this.#n,
|
|
710
|
+
permission: this.#r,
|
|
711
|
+
calls: e,
|
|
712
|
+
error: this.#i
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
#x(e) {
|
|
716
|
+
let t = this.#R(), n = this.#g ?? this.#h ?? K(e, t), r = {
|
|
717
|
+
...t,
|
|
718
|
+
status: n
|
|
719
|
+
}, i = this.#S(e, r, n);
|
|
720
|
+
return i.setAttribute("data-view", this.#T() && !this.#p ? "setup" : e.kind), i.hasAttribute("data-layout") || i.setAttribute("data-layout", this.#T() ? "mobile" : "panel"), i;
|
|
721
|
+
}
|
|
722
|
+
#S(e, t, n) {
|
|
723
|
+
if (this.#T() && !this.#p) return N({
|
|
724
|
+
enabling: this.#m,
|
|
725
|
+
status: n,
|
|
726
|
+
enablePhone: t.enablePhone
|
|
727
|
+
});
|
|
728
|
+
switch (e.kind) {
|
|
729
|
+
case "permission-error":
|
|
730
|
+
case "unrecoverable-error":
|
|
731
|
+
case "unsupported": return A({
|
|
732
|
+
view: e,
|
|
733
|
+
messages: t
|
|
734
|
+
});
|
|
735
|
+
case "incoming": return this.#T() ? P({
|
|
736
|
+
view: { kind: "ready" },
|
|
737
|
+
messages: t,
|
|
738
|
+
destination: this.#o,
|
|
739
|
+
muted: this.#l,
|
|
740
|
+
canDial: s(this.#o, this.#r, this.#n),
|
|
741
|
+
showOutputDevice: this.#e?.media.supportsOutputSelection() === !0
|
|
742
|
+
}) : j({
|
|
743
|
+
view: e,
|
|
744
|
+
messages: t
|
|
745
|
+
});
|
|
746
|
+
case "setup":
|
|
747
|
+
case "connecting":
|
|
748
|
+
case "ended":
|
|
749
|
+
case "ready":
|
|
750
|
+
case "active":
|
|
751
|
+
case "held":
|
|
752
|
+
case "dialing": return this.#T() ? P({
|
|
753
|
+
view: e.kind === "held" ? { kind: "ready" } : e,
|
|
754
|
+
messages: t,
|
|
755
|
+
destination: this.#o,
|
|
756
|
+
muted: this.#l,
|
|
757
|
+
canDial: s(this.#o, this.#r, this.#n),
|
|
758
|
+
showOutputDevice: this.#e?.media.supportsOutputSelection() === !0
|
|
759
|
+
}) : _({
|
|
760
|
+
mode: this.#w() === "compact" ? "compact" : "panel",
|
|
761
|
+
view: e,
|
|
762
|
+
messages: t,
|
|
763
|
+
destination: this.#o,
|
|
764
|
+
muted: this.#l,
|
|
765
|
+
canDial: s(this.#o, this.#r, this.#n),
|
|
766
|
+
moreOpen: this.#u,
|
|
767
|
+
floating: this.hasAttribute("floating"),
|
|
768
|
+
connected: this.#n === "connected",
|
|
769
|
+
agentStatus: this.#c,
|
|
770
|
+
extension: this.#s,
|
|
771
|
+
calls: this.#C()
|
|
772
|
+
});
|
|
773
|
+
default: return e;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
#C() {
|
|
777
|
+
let e = this.#e?.getActiveCall?.()?.id;
|
|
778
|
+
return this.#e?.getCalls?.().map((t) => ({
|
|
779
|
+
id: t.id,
|
|
780
|
+
destination: t.destination,
|
|
781
|
+
state: t.state,
|
|
782
|
+
direction: this.#a.has(t.id) ? "inbound" : "outbound",
|
|
783
|
+
current: t.id === e
|
|
784
|
+
})) ?? [];
|
|
785
|
+
}
|
|
786
|
+
#w() {
|
|
787
|
+
let e = this.getAttribute("mode");
|
|
788
|
+
return e === "compact" || e === "mobile" ? e : "panel";
|
|
789
|
+
}
|
|
790
|
+
#T() {
|
|
791
|
+
return this.#w() === "mobile";
|
|
792
|
+
}
|
|
793
|
+
#E() {
|
|
794
|
+
let e = this.#e;
|
|
795
|
+
e !== void 0 && (this.#t.push(e.on("connection.stateChanged", (t) => {
|
|
796
|
+
if (this.#n = t.state, t.state !== "connected" && (this.#c = "offline"), t.state === "connected") {
|
|
797
|
+
let t = e.getAgent?.()?.extension?.trim();
|
|
798
|
+
t !== void 0 && t !== "" && (this.#s = t);
|
|
799
|
+
}
|
|
800
|
+
})), this.#t.push(e.on("agent.statusChanged", (e) => {
|
|
801
|
+
(e.status === "available" || e.status === "offline" || e.status === "break") && (this.#c = e.status);
|
|
802
|
+
})), this.#t.push(e.on("connection.failed", (e) => {
|
|
803
|
+
this.#n = "failed", this.#i = { code: e.error.code };
|
|
804
|
+
})), this.#t.push(e.on("media.permissionChanged", (e) => {
|
|
805
|
+
this.#r = e.permission;
|
|
806
|
+
})), this.#t.push(e.on("error", (e) => {
|
|
807
|
+
this.#i = { code: e.error.code };
|
|
808
|
+
})), this.#t.push(e.on("call.incoming", (e) => {
|
|
809
|
+
this.#a.add(e.callId);
|
|
810
|
+
})), this.#t.push(e.on("call.ended", (e) => {
|
|
811
|
+
this.#a.delete(e.callId), this.#l = !1;
|
|
812
|
+
})), this.#t.push(e.on("call.failed", () => {
|
|
813
|
+
this.#g = this.#R().statusFailed;
|
|
814
|
+
})), U.forEach((t) => {
|
|
815
|
+
this.#t.push(e.on(t, () => this.render()));
|
|
816
|
+
}), this.#T() && typeof e.recover == "function" && (this.#_ = a(e, {
|
|
817
|
+
onChecking: () => {
|
|
818
|
+
this.#h = this.#R().foregroundChecking, this.render();
|
|
819
|
+
},
|
|
820
|
+
onRecovered: () => {
|
|
821
|
+
this.#h = void 0, this.render();
|
|
822
|
+
},
|
|
823
|
+
onFailed: () => {
|
|
824
|
+
this.#h = this.#R().foregroundFailed, this.render();
|
|
825
|
+
}
|
|
826
|
+
})));
|
|
827
|
+
}
|
|
828
|
+
#D() {
|
|
829
|
+
let e = this.#t;
|
|
830
|
+
this.#t = [], e.forEach((e) => e()), this.#n = "idle", this.#r = "unknown", this.#c = "offline", this.#i = void 0, this.#a.clear(), this.#l = !1, this.#u = !1, this.#p = !1, this.#m = !1, this.#h = void 0, this.#_?.(), this.#_ = void 0;
|
|
831
|
+
}
|
|
832
|
+
#O() {
|
|
833
|
+
if (typeof this.attachShadow != "function") return;
|
|
834
|
+
let e = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
835
|
+
return H.has(e) || (H.add(e), e.addEventListener("click", (e) => this.#k(e)), e.addEventListener("input", (e) => this.#N(e)), e.addEventListener("pointerdown", (e) => this.#V(e))), e;
|
|
836
|
+
}
|
|
837
|
+
#k(e) {
|
|
838
|
+
let t = J(e, this), n = t?.closest("[data-action=\"enable-phone\"]");
|
|
839
|
+
n instanceof HTMLButtonElement && (n.disabled = !0), this.#d = this.#d.then(() => this.#P(t)).catch((e) => {
|
|
840
|
+
this.#g = Y(e), this.render();
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
#A() {
|
|
844
|
+
let e = this.shadowRoot?.querySelector("input[name=\"destination\"]");
|
|
845
|
+
return e instanceof HTMLInputElement ? e.value : this.#o;
|
|
846
|
+
}
|
|
847
|
+
#j() {
|
|
848
|
+
let e = this.shadowRoot?.querySelector("input[name=\"extension\"]");
|
|
849
|
+
return e instanceof HTMLInputElement ? e.value.trim() : this.#s;
|
|
850
|
+
}
|
|
851
|
+
#M() {
|
|
852
|
+
let e = this.shadowRoot?.querySelector("input[name=\"transfer-target\"]");
|
|
853
|
+
return e instanceof HTMLInputElement ? e.value : "";
|
|
854
|
+
}
|
|
855
|
+
#N(e) {
|
|
856
|
+
let t = J(e, this);
|
|
857
|
+
if (t instanceof HTMLInputElement && t.name !== "transfer-target") {
|
|
858
|
+
if (t.name === "extension") {
|
|
859
|
+
this.#s = t.value.trim();
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
this.#o = t.value, this.#I();
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
async #P(e) {
|
|
866
|
+
if (this.#g = void 0, e === void 0) return;
|
|
867
|
+
let t = e.closest("[data-call-id]");
|
|
868
|
+
if (t instanceof HTMLElement && t.dataset.callId !== void 0) {
|
|
869
|
+
await this.#e?.setActiveCall(t.dataset.callId);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
let n = e.closest("[data-digit]");
|
|
873
|
+
if (n instanceof HTMLElement && n.dataset.digit !== void 0) {
|
|
874
|
+
await this.#F(n.dataset.digit);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
let r = e.closest("[data-action]");
|
|
878
|
+
if (!(r instanceof HTMLElement) || r instanceof HTMLButtonElement && r.disabled && r.getAttribute("data-action") !== "enable-phone") return;
|
|
879
|
+
let a = this.#e?.getActiveCall?.();
|
|
880
|
+
switch (r.getAttribute("data-action")) {
|
|
881
|
+
case "signin":
|
|
882
|
+
if (this.#e === void 0) return;
|
|
883
|
+
this.#s = this.#j(), await this.#e.media?.requestPermission?.(), await this.#e.initialize(), await this.#e.connect(this.#s === "" ? void 0 : { extension: this.#s });
|
|
884
|
+
return;
|
|
885
|
+
case "signout":
|
|
886
|
+
if (this.#e === void 0) return;
|
|
887
|
+
this.#c = "offline", await this.#e.disconnect();
|
|
888
|
+
return;
|
|
889
|
+
case "dial":
|
|
890
|
+
case "dial-internal":
|
|
891
|
+
if (this.#o = this.#A(), this.#e === void 0) return;
|
|
892
|
+
this.#r !== "granted" && await this.#e.media?.requestPermission?.(), await c(this.#e, this.#o, r.getAttribute("data-action") === "dial-internal" ? "extension" : void 0);
|
|
893
|
+
return;
|
|
894
|
+
case "mute":
|
|
895
|
+
if (a === void 0) return;
|
|
896
|
+
this.#l = await l(a, this.#l), this.#L();
|
|
897
|
+
return;
|
|
898
|
+
case "hold":
|
|
899
|
+
a !== void 0 && await u(a);
|
|
900
|
+
return;
|
|
901
|
+
case "resume":
|
|
902
|
+
a !== void 0 && await a.resume();
|
|
903
|
+
return;
|
|
904
|
+
case "transfer":
|
|
905
|
+
a !== void 0 && await f(a, this.#M());
|
|
906
|
+
return;
|
|
907
|
+
case "hangup":
|
|
908
|
+
await a?.hangup();
|
|
909
|
+
return;
|
|
910
|
+
case "answer":
|
|
911
|
+
a !== void 0 && await this.#e?.answer(a.id);
|
|
912
|
+
return;
|
|
913
|
+
case "reject":
|
|
914
|
+
await a?.reject();
|
|
915
|
+
return;
|
|
916
|
+
case "enable-phone":
|
|
917
|
+
if (this.#e === void 0 || this.#p) return;
|
|
918
|
+
this.#m = !0;
|
|
919
|
+
try {
|
|
920
|
+
await i(this.#e), this.#p = !0;
|
|
921
|
+
} finally {
|
|
922
|
+
this.#m = !1, this.render();
|
|
923
|
+
}
|
|
924
|
+
return;
|
|
925
|
+
case "more":
|
|
926
|
+
this.#u = !this.#u, this.render();
|
|
927
|
+
return;
|
|
928
|
+
case "retry-permission":
|
|
929
|
+
await this.#e?.media.requestPermission();
|
|
930
|
+
return;
|
|
931
|
+
case "devices": return;
|
|
932
|
+
case "agent-available":
|
|
933
|
+
await this.#e?.setAgentStatus("available");
|
|
934
|
+
return;
|
|
935
|
+
case "agent-break":
|
|
936
|
+
await this.#e?.setAgentStatus("break");
|
|
937
|
+
return;
|
|
938
|
+
case "agent-busy": return;
|
|
939
|
+
default: return;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
async #F(e) {
|
|
943
|
+
let t = this.#e?.getActiveCall?.();
|
|
944
|
+
if (t !== void 0 && (t.state === "active" || t.state === "held")) {
|
|
945
|
+
await d(t, e);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
this.#o += e;
|
|
949
|
+
let n = this.shadowRoot?.querySelector("input[name=\"destination\"]");
|
|
950
|
+
n instanceof HTMLInputElement && (n.value = this.#o), this.#I();
|
|
951
|
+
}
|
|
952
|
+
#I() {
|
|
953
|
+
let e = !s(this.#o, this.#r, this.#n);
|
|
954
|
+
for (let t of ["dial", "dial-internal"]) {
|
|
955
|
+
let n = this.shadowRoot?.querySelector(`[data-action="${t}"]`);
|
|
956
|
+
n instanceof HTMLButtonElement && (n.disabled = e);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
#L() {
|
|
960
|
+
let e = this.shadowRoot?.querySelector("[data-action=\"mute\"]");
|
|
961
|
+
e instanceof HTMLButtonElement && (e.setAttribute("aria-pressed", this.#l ? "true" : "false"), e.textContent = this.#l ? this.#R().unmute : this.#R().mute);
|
|
962
|
+
}
|
|
963
|
+
#R() {
|
|
964
|
+
return r(this.getAttribute("locale") ?? "zh-CN", void 0, this.#v);
|
|
965
|
+
}
|
|
966
|
+
#z() {
|
|
967
|
+
this.#y?.(), this.#y = void 0;
|
|
968
|
+
let e = this.getAttribute("theme") ?? "light";
|
|
969
|
+
if (e === "dark" || e === "light") {
|
|
970
|
+
this.setAttribute("data-theme", e);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
if (typeof window > "u" || typeof window.matchMedia != "function") {
|
|
974
|
+
this.setAttribute("data-theme", "light");
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
let t = window.matchMedia("(prefers-color-scheme: dark)"), n = () => {
|
|
978
|
+
this.setAttribute("data-theme", t.matches ? "dark" : "light");
|
|
979
|
+
};
|
|
980
|
+
n(), t.addEventListener("change", n), this.#y = () => t.removeEventListener("change", n);
|
|
981
|
+
}
|
|
982
|
+
#B() {
|
|
983
|
+
this.style.position = this.hasAttribute("floating") ? "fixed" : "";
|
|
984
|
+
}
|
|
985
|
+
#V(e) {
|
|
986
|
+
if (!(e instanceof PointerEvent) || !this.hasAttribute("floating") || !this.hasAttribute("draggable") || (e.target instanceof Element ? e.target.closest("[data-drag-handle]") : null) === null) return;
|
|
987
|
+
e.preventDefault();
|
|
988
|
+
let t = this.getBoundingClientRect();
|
|
989
|
+
this.#f = {
|
|
990
|
+
pointerId: e.pointerId,
|
|
991
|
+
offsetX: e.clientX - t.left,
|
|
992
|
+
offsetY: e.clientY - t.top
|
|
993
|
+
}, window.addEventListener("pointermove", this.#H), window.addEventListener("pointerup", this.#U);
|
|
994
|
+
}
|
|
995
|
+
#H = (e) => {
|
|
996
|
+
if (this.#f === void 0 || e.pointerId !== this.#f.pointerId) return;
|
|
997
|
+
let t = window.visualViewport, n = t?.width ?? window.innerWidth, r = t?.height ?? window.innerHeight, i = q(e.clientX - this.#f.offsetX, 0, Math.max(0, n - this.offsetWidth)), a = q(e.clientY - this.#f.offsetY, 0, Math.max(0, r - this.offsetHeight));
|
|
998
|
+
this.style.left = `${i}px`, this.style.top = `${a}px`, this.style.right = "auto", this.style.bottom = "auto";
|
|
999
|
+
};
|
|
1000
|
+
#U = (e) => {
|
|
1001
|
+
this.#f !== void 0 && e.pointerId === this.#f.pointerId && this.#W();
|
|
1002
|
+
};
|
|
1003
|
+
#W() {
|
|
1004
|
+
this.#f = void 0, window.removeEventListener("pointermove", this.#H), window.removeEventListener("pointerup", this.#U);
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
function G(e = {}) {
|
|
1008
|
+
if (typeof customElements > "u") return;
|
|
1009
|
+
let t = e.tagName ?? "xcall-ccbar";
|
|
1010
|
+
if (customElements.get(t) !== void 0) return;
|
|
1011
|
+
let n = t === "xcall-ccbar" ? W : class extends W {};
|
|
1012
|
+
customElements.define(t, n);
|
|
1013
|
+
}
|
|
1014
|
+
function K(e, t) {
|
|
1015
|
+
switch (e.kind) {
|
|
1016
|
+
case "unsupported": return t.statusUnsupported;
|
|
1017
|
+
case "permission-error": return t.statusPermission;
|
|
1018
|
+
case "unrecoverable-error": return t.statusError;
|
|
1019
|
+
case "setup": return t.statusSetup;
|
|
1020
|
+
case "connecting": return t.statusConnecting;
|
|
1021
|
+
case "incoming": return t.statusIncoming;
|
|
1022
|
+
case "active": return t.statusActive;
|
|
1023
|
+
case "held": return t.statusHeld;
|
|
1024
|
+
case "dialing": return t.statusDialing;
|
|
1025
|
+
case "ended": return t.statusEnded;
|
|
1026
|
+
case "ready": return t.statusReady;
|
|
1027
|
+
default: return e;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
function q(e, t, n) {
|
|
1031
|
+
return Math.min(n, Math.max(t, e));
|
|
1032
|
+
}
|
|
1033
|
+
function J(e, t) {
|
|
1034
|
+
for (let n of e.composedPath()) if (n instanceof Element && n !== t) return n;
|
|
1035
|
+
return e.target instanceof Element && e.target !== t ? e.target : void 0;
|
|
1036
|
+
}
|
|
1037
|
+
function Y(e) {
|
|
1038
|
+
return typeof e == "object" && e && "code" in e && typeof e.code == "string" ? e.code : "SDK_INTERNAL_ERROR";
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/ui/index.ts
|
|
1042
|
+
var X = "0.1.0";
|
|
1043
|
+
//#endregion
|
|
1044
|
+
export { W as XCallCCBarElement, G as defineCCBarElement, e as enUS, r as resolveMessages, X as uiVersion, t as zhCN };
|