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