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