@sphoro/bugcatch-web-sdk 0.17.0 → 0.18.0
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/README.md +69 -4
- package/dist/bugcatch-call.es.js +586 -0
- package/dist/bugcatch-call.es.js.map +1 -0
- package/dist/bugcatch-call.umd.js +2 -0
- package/dist/bugcatch-call.umd.js.map +1 -0
- package/dist/bugcatch-core.es.js +3214 -0
- package/dist/bugcatch-core.es.js.map +1 -0
- package/dist/bugcatch-panel.es.js +2402 -0
- package/dist/bugcatch-panel.es.js.map +1 -0
- package/dist/bugcatch-panel.umd.js +1240 -0
- package/dist/bugcatch-panel.umd.js.map +1 -0
- package/dist/bugcatch.es.js +2 -5625
- package/dist/bugcatch.es.js.map +1 -1
- package/dist/bugcatch.standalone.umd.js +1536 -0
- package/dist/bugcatch.standalone.umd.js.map +1 -0
- package/dist/bugcatch.umd.js +89 -1224
- package/dist/bugcatch.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/announcements.js +147 -0
- package/src/busy.js +18 -0
- package/src/call.js +7 -0
- package/src/capture.js +9 -0
- package/src/chunks.js +56 -0
- package/src/gesture.js +33 -0
- package/src/icons.js +18 -0
- package/src/identity.js +13 -8
- package/src/incoming-call.js +8 -30
- package/src/index.d.ts +50 -0
- package/src/index.js +138 -35
- package/src/lazy.js +23 -0
- package/src/notice.js +68 -0
- package/src/panel/call.js +242 -0
- package/src/panel/compose.js +416 -0
- package/src/panel/composer.js +235 -0
- package/src/panel/icons.js +34 -0
- package/src/panel/index.js +251 -0
- package/src/panel/known.js +130 -0
- package/src/panel/messages.js +176 -0
- package/src/panel/notices.js +34 -0
- package/src/panel/picks.js +61 -0
- package/src/panel/refs.js +321 -0
- package/src/panel/render.js +124 -0
- package/src/panel/signin.js +228 -0
- package/src/panel/styles.js +960 -0
- package/src/panel/thread.js +384 -0
- package/src/session.js +8 -3
- package/src/umd/call.js +6 -0
- package/src/umd/lazy.js +98 -0
- package/src/umd/panel.js +6 -0
- package/src/updates.js +20 -7
- package/src/widget.js +250 -3260
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
function pt(e = 8e3) {
|
|
2
|
+
const d = window.AudioContext || window.webkitAudioContext;
|
|
3
|
+
try {
|
|
4
|
+
return new d({ sampleRate: e });
|
|
5
|
+
} catch {
|
|
6
|
+
return new d();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
async function yt(e) {
|
|
10
|
+
if (e.state === "suspended")
|
|
11
|
+
try {
|
|
12
|
+
await e.resume();
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function mt(e, d, s) {
|
|
17
|
+
const a = d / s, c = new Float32Array(Math.floor(e.length / a));
|
|
18
|
+
for (let f = 0; f < c.length; f++) {
|
|
19
|
+
const l = Math.floor(f * a), g = Math.min(Math.floor((f + 1) * a), e.length);
|
|
20
|
+
let m = 0;
|
|
21
|
+
for (let r = l; r < g; r++) m += e[r];
|
|
22
|
+
c[f] = g > l ? m / (g - l) : 0;
|
|
23
|
+
}
|
|
24
|
+
return c;
|
|
25
|
+
}
|
|
26
|
+
const ht = 132, Q = 32635;
|
|
27
|
+
function gt(e) {
|
|
28
|
+
const d = new Uint8Array(e.length);
|
|
29
|
+
for (let s = 0; s < e.length; s++) {
|
|
30
|
+
const a = Math.max(-1, Math.min(1, e[s]));
|
|
31
|
+
let c = Math.round(a * 32767);
|
|
32
|
+
const f = c < 0 ? 128 : 0;
|
|
33
|
+
f && (c = -c), c > Q && (c = Q), c += ht;
|
|
34
|
+
let l = 7;
|
|
35
|
+
for (let m = 16384; !(c & m) && l > 0; l--, m >>= 1) ;
|
|
36
|
+
const g = c >> l + 3 & 15;
|
|
37
|
+
d[s] = ~(f | l << 4 | g) & 255;
|
|
38
|
+
}
|
|
39
|
+
return d;
|
|
40
|
+
}
|
|
41
|
+
const wt = 512;
|
|
42
|
+
function bt(e, d, s, a = 8e3) {
|
|
43
|
+
const c = e.createMediaStreamSource(d), f = e.createScriptProcessor(wt, 1, 1);
|
|
44
|
+
f.onaudioprocess = (g) => {
|
|
45
|
+
const m = g.inputBuffer.getChannelData(0), r = e.sampleRate === a ? m : mt(m, e.sampleRate, a);
|
|
46
|
+
s(gt(r));
|
|
47
|
+
}, c.connect(f);
|
|
48
|
+
const l = e.createGain();
|
|
49
|
+
return l.gain.value = 0, f.connect(l), l.connect(e.destination), {
|
|
50
|
+
stop() {
|
|
51
|
+
f.onaudioprocess = null;
|
|
52
|
+
try {
|
|
53
|
+
c.disconnect();
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
f.disconnect();
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
l.disconnect();
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const Tt = "voiceai.realtime.v1", kt = [{ urls: "stun:stun.l.google.com:19302" }];
|
|
68
|
+
function xt() {
|
|
69
|
+
return navigator.mediaDevices.getUserMedia({
|
|
70
|
+
audio: {
|
|
71
|
+
// Both ends are on speakers as often as not. Without cancellation each
|
|
72
|
+
// hears themselves back through the other, half a second late, which is
|
|
73
|
+
// the single most effective way to make a conversation impossible.
|
|
74
|
+
echoCancellation: !0,
|
|
75
|
+
noiseSuppression: !0,
|
|
76
|
+
autoGainControl: !0,
|
|
77
|
+
channelCount: 1
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function Ct() {
|
|
82
|
+
var e;
|
|
83
|
+
return typeof window < "u" && typeof window.RTCPeerConnection == "function" && !!((e = navigator.mediaDevices) != null && e.getUserMedia);
|
|
84
|
+
}
|
|
85
|
+
async function At({
|
|
86
|
+
realtimeUrl: e,
|
|
87
|
+
stream: d,
|
|
88
|
+
ringsUntil: s,
|
|
89
|
+
onState: a,
|
|
90
|
+
onAudioBlocked: c,
|
|
91
|
+
onMicrophone: f
|
|
92
|
+
}) {
|
|
93
|
+
const l = (t, n) => {
|
|
94
|
+
try {
|
|
95
|
+
a == null || a(t, n);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}, g = (t) => {
|
|
99
|
+
try {
|
|
100
|
+
c == null || c(t);
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}, m = (t) => {
|
|
104
|
+
try {
|
|
105
|
+
f == null || f(t);
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
if (!Ct()) {
|
|
110
|
+
const t = new Error("[BugCatch] this browser cannot make live calls.");
|
|
111
|
+
throw l("failed", { reason: "unsupported" }), t;
|
|
112
|
+
}
|
|
113
|
+
let r = d;
|
|
114
|
+
if (!r)
|
|
115
|
+
try {
|
|
116
|
+
r = await xt();
|
|
117
|
+
} catch (t) {
|
|
118
|
+
throw l("failed", { reason: "microphone", error: String((t == null ? void 0 : t.name) || t) }), t;
|
|
119
|
+
}
|
|
120
|
+
let y;
|
|
121
|
+
try {
|
|
122
|
+
y = await vt(e);
|
|
123
|
+
} catch (t) {
|
|
124
|
+
throw tt(r), l("failed", { reason: "connect" }), t;
|
|
125
|
+
}
|
|
126
|
+
let o = null, i = null, p = !1, w = null, h = null, E = null, S = !1, b = null, C = null, A = !1;
|
|
127
|
+
const x = [];
|
|
128
|
+
let O = !1, D = !1, $ = !1, R = null, _ = null, B = 0;
|
|
129
|
+
const nt = 2e3, P = 5e3, ot = 3e4, rt = 4, k = (t, n) => {
|
|
130
|
+
if (!p) {
|
|
131
|
+
p = !0, w && (clearTimeout(w), w = null), Y(), C == null || C(), C = null, at(), b == null || b(), b = null;
|
|
132
|
+
try {
|
|
133
|
+
o == null || o.close();
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
136
|
+
tt(r), i && (i.srcObject = null, i.remove(), i = null);
|
|
137
|
+
try {
|
|
138
|
+
y.readyState === WebSocket.OPEN && y.close(1e3, "call over");
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
l(t, n);
|
|
142
|
+
}
|
|
143
|
+
}, M = (t) => {
|
|
144
|
+
y.readyState === WebSocket.OPEN && y.send(JSON.stringify(t));
|
|
145
|
+
}, j = async () => {
|
|
146
|
+
if (A || E || p || !h || !h.audio && !h.transcript) return;
|
|
147
|
+
A = !0;
|
|
148
|
+
const t = h.encoding || "mulaw";
|
|
149
|
+
if (t !== "mulaw") {
|
|
150
|
+
Z(`this call is kept as ${t}, which this SDK cannot produce.`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const n = Number(h.sample_rate) || 8e3;
|
|
154
|
+
try {
|
|
155
|
+
const u = pt(n);
|
|
156
|
+
if (await yt(u), p) {
|
|
157
|
+
try {
|
|
158
|
+
u.close();
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const v = bt(u, r, (T) => {
|
|
164
|
+
y.readyState === WebSocket.OPEN && y.send(T);
|
|
165
|
+
}, n);
|
|
166
|
+
E = { context: u, tap: v };
|
|
167
|
+
} catch (u) {
|
|
168
|
+
Z(`could not send the copy this call is keeping: ${String((u == null ? void 0 : u.message) || u)}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
function at() {
|
|
172
|
+
if (A = !1, !E) return;
|
|
173
|
+
const { context: t, tap: n } = E;
|
|
174
|
+
E = null;
|
|
175
|
+
try {
|
|
176
|
+
n.stop();
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
t.close();
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function F() {
|
|
185
|
+
var n;
|
|
186
|
+
if (!i || p) return;
|
|
187
|
+
let t;
|
|
188
|
+
try {
|
|
189
|
+
t = (n = i.play) == null ? void 0 : n.call(i);
|
|
190
|
+
} catch {
|
|
191
|
+
V();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!t || typeof t.then != "function") {
|
|
195
|
+
z();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
t.then(z, V);
|
|
199
|
+
}
|
|
200
|
+
function z() {
|
|
201
|
+
b == null || b(), b = null, S && (S = !1, g(!1));
|
|
202
|
+
}
|
|
203
|
+
function V() {
|
|
204
|
+
p || (S || (S = !0, g(!0)), ct());
|
|
205
|
+
}
|
|
206
|
+
function ct() {
|
|
207
|
+
if (b || typeof window > "u" || typeof window.addEventListener != "function") return;
|
|
208
|
+
const t = () => F(), n = ["pointerdown", "keydown", "touchstart"];
|
|
209
|
+
for (const u of n)
|
|
210
|
+
window.addEventListener(u, t, { capture: !0, passive: !0 });
|
|
211
|
+
b = () => {
|
|
212
|
+
for (const u of n)
|
|
213
|
+
try {
|
|
214
|
+
window.removeEventListener(u, t, { capture: !0 });
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const it = (t) => {
|
|
220
|
+
o = new RTCPeerConnection({ iceServers: t != null && t.length ? t : kt });
|
|
221
|
+
for (const n of r.getAudioTracks()) o.addTrack(n, r);
|
|
222
|
+
C = st(), o.onicecandidate = (n) => {
|
|
223
|
+
n.candidate && M({ type: "signal", signal: { kind: "candidate", payload: n.candidate.toJSON() } });
|
|
224
|
+
}, o.ontrack = (n) => {
|
|
225
|
+
var v;
|
|
226
|
+
const [u] = n.streams;
|
|
227
|
+
u && (i || (i = document.createElement("audio"), i.autoplay = !0, i.playsInline = !0, (v = i.setAttribute) == null || v.call(i, "playsinline", ""), i.style.cssText = "position:fixed;width:0;height:0;opacity:0;pointer-events:none", document.body.appendChild(i)), i.srcObject = u, F());
|
|
228
|
+
}, o.onconnectionstatechange = W, o.oniceconnectionstatechange = W;
|
|
229
|
+
};
|
|
230
|
+
function W() {
|
|
231
|
+
if (!o || p) return;
|
|
232
|
+
const t = o.connectionState || o.iceConnectionState;
|
|
233
|
+
if (t === "connected" || t === "completed") {
|
|
234
|
+
D = !0, B = 0, Y(), $ = !1, l("connected");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (t === "disconnected") {
|
|
238
|
+
if (!D) return;
|
|
239
|
+
J(nt);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (t === "failed") {
|
|
243
|
+
if (!D) {
|
|
244
|
+
k("failed", { reason: "ice" });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
J(0);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function J(t) {
|
|
251
|
+
p || ($ || ($ = !0, l("reconnecting"), _ = setTimeout(() => k("failed", { reason: "network" }), ot)), !R && (R = setTimeout(U, t)));
|
|
252
|
+
}
|
|
253
|
+
function Y() {
|
|
254
|
+
R && (clearTimeout(R), R = null), _ && (clearTimeout(_), _ = null);
|
|
255
|
+
}
|
|
256
|
+
async function U() {
|
|
257
|
+
if (R = null, p || !o) return;
|
|
258
|
+
const t = o.connectionState || o.iceConnectionState;
|
|
259
|
+
if (!(t === "connected" || t === "completed")) {
|
|
260
|
+
if (!O) {
|
|
261
|
+
M({ type: "signal", signal: { kind: "restart", payload: {} } }), R = setTimeout(U, P);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
B >= rt || (B += 1, await q(), R = setTimeout(U, P));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async function q() {
|
|
268
|
+
if (!(p || !o))
|
|
269
|
+
try {
|
|
270
|
+
const t = await o.createOffer({ iceRestart: !0 });
|
|
271
|
+
await o.setLocalDescription(t), M({ type: "signal", signal: { kind: "offer", payload: o.localDescription.toJSON() } });
|
|
272
|
+
} catch {
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function st() {
|
|
276
|
+
let n = null, u = !1;
|
|
277
|
+
const v = (T) => {
|
|
278
|
+
if (n && (clearTimeout(n), n = null), T) {
|
|
279
|
+
if (!u) return;
|
|
280
|
+
u = !1, m(!0);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
u || (n = setTimeout(() => {
|
|
284
|
+
n = null, !p && (u = !0, m(!1));
|
|
285
|
+
}, 600));
|
|
286
|
+
};
|
|
287
|
+
for (const T of r.getAudioTracks())
|
|
288
|
+
T.onmute = () => v(!1), T.onunmute = () => v(!0), T.onended = () => {
|
|
289
|
+
n && (clearTimeout(n), n = null), !u && (u = !0, m(!1));
|
|
290
|
+
};
|
|
291
|
+
return () => {
|
|
292
|
+
n && (clearTimeout(n), n = null);
|
|
293
|
+
for (const T of r.getAudioTracks())
|
|
294
|
+
T.onmute = null, T.onunmute = null, T.onended = null;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const lt = async () => {
|
|
298
|
+
try {
|
|
299
|
+
const t = await o.createOffer();
|
|
300
|
+
await o.setLocalDescription(t), M({ type: "signal", signal: { kind: "offer", payload: o.localDescription.toJSON() } });
|
|
301
|
+
} catch {
|
|
302
|
+
k("failed", { reason: "negotiation" });
|
|
303
|
+
}
|
|
304
|
+
}, ut = async (t) => {
|
|
305
|
+
try {
|
|
306
|
+
await o.setRemoteDescription(new RTCSessionDescription(t));
|
|
307
|
+
const n = await o.createAnswer();
|
|
308
|
+
await o.setLocalDescription(n), M({ type: "signal", signal: { kind: "answer", payload: o.localDescription.toJSON() } }), await G();
|
|
309
|
+
} catch {
|
|
310
|
+
k("failed", { reason: "negotiation" });
|
|
311
|
+
}
|
|
312
|
+
}, G = async () => {
|
|
313
|
+
for (; x.length; ) {
|
|
314
|
+
const t = x.shift();
|
|
315
|
+
try {
|
|
316
|
+
await o.addIceCandidate(new RTCIceCandidate(t));
|
|
317
|
+
} catch {
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
let K = Promise.resolve();
|
|
322
|
+
y.onmessage = (t) => {
|
|
323
|
+
K = K.then(() => dt(t)).catch(() => {
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
const dt = async (t) => {
|
|
327
|
+
var u, v, T, X, H;
|
|
328
|
+
if (typeof t.data != "string") return;
|
|
329
|
+
let n;
|
|
330
|
+
try {
|
|
331
|
+
n = JSON.parse(t.data);
|
|
332
|
+
} catch {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
switch (n.type) {
|
|
336
|
+
case "session.created": {
|
|
337
|
+
if (it((u = n.data) == null ? void 0 : u.ice_servers), h = ((v = n.data) == null ? void 0 : v.capture) || null, (T = n.data) != null && T.peer_present) {
|
|
338
|
+
l("connecting"), j();
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
l("ringing"), ft();
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "peer.joined": {
|
|
345
|
+
w && (clearTimeout(w), w = null), l("connecting"), O = !!((X = n.data) != null && X.should_offer), O && await lt(), j();
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
case "signal": {
|
|
349
|
+
if (!o) break;
|
|
350
|
+
const { kind: I, payload: L } = n.data || {};
|
|
351
|
+
if (I === "offer")
|
|
352
|
+
await ut(L);
|
|
353
|
+
else if (I === "answer")
|
|
354
|
+
try {
|
|
355
|
+
await o.setRemoteDescription(new RTCSessionDescription(L)), await G();
|
|
356
|
+
} catch {
|
|
357
|
+
k("failed", { reason: "negotiation" });
|
|
358
|
+
}
|
|
359
|
+
else if (I === "candidate")
|
|
360
|
+
if (o.remoteDescription)
|
|
361
|
+
try {
|
|
362
|
+
await o.addIceCandidate(new RTCIceCandidate(L));
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
else
|
|
366
|
+
x.push(L);
|
|
367
|
+
else I === "restart" && O && await q();
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case "peer.left":
|
|
371
|
+
k("ended", { reason: "peer_left" });
|
|
372
|
+
break;
|
|
373
|
+
case "error":
|
|
374
|
+
k("failed", { reason: "server", detail: (H = n.error) == null ? void 0 : H.detail });
|
|
375
|
+
break;
|
|
376
|
+
case "session.ended":
|
|
377
|
+
k("ended", { reason: "server" });
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
y.onclose = () => k("ended", { reason: "disconnected" }), y.onerror = () => k("failed", { reason: "socket" });
|
|
382
|
+
function ft() {
|
|
383
|
+
if (!s) return;
|
|
384
|
+
const t = new Date(s).getTime() - Date.now();
|
|
385
|
+
Number.isFinite(t) && (w = setTimeout(() => k("missed"), Math.max(0, t)));
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
hangUp() {
|
|
389
|
+
M({ type: "session.end" }), k("ended", { reason: "hung_up" });
|
|
390
|
+
},
|
|
391
|
+
setMuted(t) {
|
|
392
|
+
for (const n of r.getAudioTracks()) n.enabled = !t;
|
|
393
|
+
return t;
|
|
394
|
+
},
|
|
395
|
+
isMuted() {
|
|
396
|
+
return r.getAudioTracks().every((t) => !t.enabled);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function vt(e) {
|
|
401
|
+
return new Promise((d, s) => {
|
|
402
|
+
let a;
|
|
403
|
+
try {
|
|
404
|
+
a = new WebSocket(e, Tt);
|
|
405
|
+
} catch (c) {
|
|
406
|
+
s(c);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
a.onopen = () => {
|
|
410
|
+
a.onopen = null, a.onerror = null, d(a);
|
|
411
|
+
}, a.onerror = () => {
|
|
412
|
+
a.onopen = null, a.onerror = null, s(new Error("[BugCatch] could not connect the call."));
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function Z(e) {
|
|
417
|
+
try {
|
|
418
|
+
console.warn(`[BugCatch] ${e}`);
|
|
419
|
+
} catch {
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function tt(e) {
|
|
423
|
+
var d;
|
|
424
|
+
for (const s of ((d = e == null ? void 0 : e.getTracks) == null ? void 0 : d.call(e)) ?? [])
|
|
425
|
+
try {
|
|
426
|
+
s.stop();
|
|
427
|
+
} catch {
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const N = {
|
|
431
|
+
cycleMs: 3e3,
|
|
432
|
+
peak: 0.045,
|
|
433
|
+
bursts: [
|
|
434
|
+
{ at: 0, seconds: 0.4, hz: [440, 660] },
|
|
435
|
+
{ at: 0.55, seconds: 0.4, hz: [440, 660] }
|
|
436
|
+
]
|
|
437
|
+
};
|
|
438
|
+
function Rt() {
|
|
439
|
+
var e;
|
|
440
|
+
try {
|
|
441
|
+
return !!((e = navigator.userActivation) != null && e.hasBeenActive);
|
|
442
|
+
} catch {
|
|
443
|
+
return !1;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function Et(e) {
|
|
447
|
+
if (!e() && !Rt()) return () => {
|
|
448
|
+
};
|
|
449
|
+
const d = typeof window < "u" && (window.AudioContext || window.webkitAudioContext);
|
|
450
|
+
if (!d) return () => {
|
|
451
|
+
};
|
|
452
|
+
let s;
|
|
453
|
+
try {
|
|
454
|
+
s = new d();
|
|
455
|
+
} catch {
|
|
456
|
+
return () => {
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
let a = !1, c = null;
|
|
460
|
+
const f = [], l = ({ at: r, seconds: y, hz: o }) => {
|
|
461
|
+
const i = s.currentTime + r, p = s.createGain();
|
|
462
|
+
p.connect(s.destination), p.gain.setValueAtTime(0, i), p.gain.linearRampToValueAtTime(N.peak, i + 0.02), p.gain.setValueAtTime(N.peak, i + y - 0.06), p.gain.linearRampToValueAtTime(0, i + y);
|
|
463
|
+
for (const w of o) {
|
|
464
|
+
const h = s.createOscillator();
|
|
465
|
+
h.type = "sine", h.frequency.value = w, h.connect(p), h.start(i), h.stop(i + y + 0.02), f.push(h);
|
|
466
|
+
}
|
|
467
|
+
}, g = () => {
|
|
468
|
+
if (!a)
|
|
469
|
+
try {
|
|
470
|
+
N.bursts.forEach(l);
|
|
471
|
+
} catch {
|
|
472
|
+
}
|
|
473
|
+
}, m = () => {
|
|
474
|
+
a || (g(), c = setInterval(g, N.cycleMs));
|
|
475
|
+
};
|
|
476
|
+
return s.state === "running" ? m() : s.resume().then(m).catch(() => {
|
|
477
|
+
}), () => {
|
|
478
|
+
a = !0, c && clearInterval(c);
|
|
479
|
+
for (const r of f)
|
|
480
|
+
try {
|
|
481
|
+
r.stop();
|
|
482
|
+
} catch {
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
s.close();
|
|
486
|
+
} catch {
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function St(e) {
|
|
491
|
+
const d = Date.parse(e || "");
|
|
492
|
+
return Number.isNaN(d) ? 0 : Math.max(0, Math.round((d - Date.now()) / 1e3));
|
|
493
|
+
}
|
|
494
|
+
const et = [
|
|
495
|
+
"flex:1",
|
|
496
|
+
"padding:9px 12px",
|
|
497
|
+
"border:0",
|
|
498
|
+
"border-radius:8px",
|
|
499
|
+
"font:600 13px/1.4 inherit",
|
|
500
|
+
"cursor:pointer"
|
|
501
|
+
].join(";");
|
|
502
|
+
function Mt({
|
|
503
|
+
call: e,
|
|
504
|
+
accent: d = "#5b6ef5",
|
|
505
|
+
position: s = "bottom-right",
|
|
506
|
+
onAnswer: a,
|
|
507
|
+
onDecline: c,
|
|
508
|
+
onExpire: f,
|
|
509
|
+
touched: l = () => !1
|
|
510
|
+
}) {
|
|
511
|
+
if (typeof document > "u" || !document.body) return () => {
|
|
512
|
+
};
|
|
513
|
+
const [g, m] = String(s).split("-"), r = document.createElement("div");
|
|
514
|
+
r.setAttribute("role", "alertdialog"), r.setAttribute("aria-live", "assertive"), r.setAttribute("aria-label", `${e.from || "Support"} is calling about ${e.reference}`), r.style.cssText = [
|
|
515
|
+
"position:fixed",
|
|
516
|
+
`${g === "top" ? "top" : "bottom"}:20px`,
|
|
517
|
+
`${m === "left" ? "left" : "right"}:20px`,
|
|
518
|
+
// Above the update toast, which uses the maximum and may be on screen at
|
|
519
|
+
// the same moment — a status line must not sit on top of a ringing phone.
|
|
520
|
+
"z-index:2147483647",
|
|
521
|
+
"width:300px",
|
|
522
|
+
"max-width:calc(100vw - 40px)",
|
|
523
|
+
"padding:14px",
|
|
524
|
+
"border-radius:12px",
|
|
525
|
+
"background:#1b1e26",
|
|
526
|
+
"color:#eceef2",
|
|
527
|
+
'font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',
|
|
528
|
+
"box-shadow:0 18px 44px rgba(0,0,0,0.5)",
|
|
529
|
+
`border:1px solid ${d}`,
|
|
530
|
+
"opacity:0",
|
|
531
|
+
"transform:translateY(8px)",
|
|
532
|
+
"transition:opacity .2s ease,transform .2s ease"
|
|
533
|
+
].join(";");
|
|
534
|
+
const y = document.createElement("div");
|
|
535
|
+
y.style.cssText = "font-weight:600;font-size:14px;margin-bottom:2px", y.textContent = `${e.from || "Support"} is calling`;
|
|
536
|
+
const o = document.createElement("div");
|
|
537
|
+
o.style.cssText = "color:#a4abba;margin-bottom:10px", o.textContent = e.project ? `About your report ${e.reference} · ${e.project}` : `About your report ${e.reference}`;
|
|
538
|
+
const i = document.createElement("div");
|
|
539
|
+
i.style.cssText = "color:#7d8598;font-size:12px;margin-bottom:10px";
|
|
540
|
+
const p = document.createElement("button");
|
|
541
|
+
p.type = "button", p.textContent = "Answer", p.style.cssText = `${et};background:${d};color:#fff`;
|
|
542
|
+
const w = document.createElement("button");
|
|
543
|
+
w.type = "button", w.textContent = "Not now", w.style.cssText = `${et};background:#2b2f3a;color:#c8cedb`;
|
|
544
|
+
const h = document.createElement("div");
|
|
545
|
+
if (h.style.cssText = "display:flex;gap:8px", h.append(p, w), r.append(y, o, i), e.recorded) {
|
|
546
|
+
const x = document.createElement("div");
|
|
547
|
+
x.style.cssText = "color:#7d8598;font-size:12px;margin-bottom:10px", x.textContent = "This call will be recorded.", r.append(x);
|
|
548
|
+
}
|
|
549
|
+
r.append(h), document.body.appendChild(r);
|
|
550
|
+
const E = Et(l);
|
|
551
|
+
let S = !1, b = null;
|
|
552
|
+
const C = () => {
|
|
553
|
+
S || (S = !0, b && clearInterval(b), E(), r.style.opacity = "0", r.style.transform = "translateY(8px)", setTimeout(() => r.remove(), 250));
|
|
554
|
+
}, A = () => {
|
|
555
|
+
const x = St(e.ringsUntil);
|
|
556
|
+
if (i.textContent = x ? `Ringing — ${x}s` : "The call has stopped ringing.", !x) {
|
|
557
|
+
C();
|
|
558
|
+
try {
|
|
559
|
+
f == null || f();
|
|
560
|
+
} catch {
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
return A(), b = setInterval(A, 1e3), p.addEventListener("click", () => {
|
|
565
|
+
C();
|
|
566
|
+
try {
|
|
567
|
+
a == null || a();
|
|
568
|
+
} catch {
|
|
569
|
+
}
|
|
570
|
+
}), w.addEventListener("click", () => {
|
|
571
|
+
C();
|
|
572
|
+
try {
|
|
573
|
+
c == null || c();
|
|
574
|
+
} catch {
|
|
575
|
+
}
|
|
576
|
+
}), requestAnimationFrame(() => {
|
|
577
|
+
r.style.opacity = "1", r.style.transform = "translateY(0)";
|
|
578
|
+
}), C;
|
|
579
|
+
}
|
|
580
|
+
export {
|
|
581
|
+
At as joinLiveCall,
|
|
582
|
+
Ct as liveCallSupported,
|
|
583
|
+
xt as openMicrophone,
|
|
584
|
+
Mt as showIncomingCall
|
|
585
|
+
};
|
|
586
|
+
//# sourceMappingURL=bugcatch-call.es.js.map
|