@sphoro/bugcatch-web-sdk 0.18.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 +36 -3
- package/dist/bugcatch-call.es.js +201 -200
- package/dist/bugcatch-call.es.js.map +1 -1
- package/dist/bugcatch-call.umd.js +1 -1
- package/dist/bugcatch-call.umd.js.map +1 -1
- package/dist/bugcatch-core.es.js +1085 -1007
- package/dist/bugcatch-core.es.js.map +1 -1
- package/dist/bugcatch-panel.es.js +1179 -1050
- package/dist/bugcatch-panel.es.js.map +1 -1
- package/dist/bugcatch-panel.umd.js +397 -326
- package/dist/bugcatch-panel.umd.js.map +1 -1
- package/dist/bugcatch.standalone.umd.js +520 -437
- package/dist/bugcatch.standalone.umd.js.map +1 -1
- package/dist/bugcatch.umd.js +132 -120
- package/dist/bugcatch.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/accent.js +38 -0
- package/src/incoming-call.js +17 -15
- package/src/index.d.ts +43 -2
- package/src/index.js +26 -7
- package/src/panel/icons.js +2 -0
- package/src/panel/index.js +17 -3
- package/src/panel/messages.js +2 -2
- package/src/panel/picks.js +6 -2
- package/src/panel/refs.js +1 -1
- package/src/panel/render.js +11 -3
- package/src/panel/styles.js +242 -186
- package/src/panel/thread.js +117 -7
- package/src/updates.js +77 -27
- package/src/widget.js +160 -141
package/dist/bugcatch-call.es.js
CHANGED
|
@@ -1,71 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
6
|
+
return new s({ sampleRate: e });
|
|
5
7
|
} catch {
|
|
6
|
-
return new
|
|
8
|
+
return new s();
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
|
-
async function
|
|
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
|
|
17
|
-
const a =
|
|
18
|
-
for (let
|
|
19
|
-
const
|
|
20
|
-
let
|
|
21
|
-
for (let r =
|
|
22
|
-
c[
|
|
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
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
for (let
|
|
30
|
-
const a = Math.max(-1, Math.min(1, e[
|
|
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
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
for (let
|
|
36
|
-
const g = c >>
|
|
37
|
-
|
|
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
|
|
41
|
+
return s;
|
|
40
42
|
}
|
|
41
|
-
const
|
|
42
|
-
function
|
|
43
|
-
const c = e.createMediaStreamSource(
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
}, c.connect(
|
|
48
|
-
const
|
|
49
|
-
return
|
|
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
|
-
|
|
53
|
+
d.onaudioprocess = null;
|
|
52
54
|
try {
|
|
53
55
|
c.disconnect();
|
|
54
56
|
} catch {
|
|
55
57
|
}
|
|
56
58
|
try {
|
|
57
|
-
|
|
59
|
+
d.disconnect();
|
|
58
60
|
} catch {
|
|
59
61
|
}
|
|
60
62
|
try {
|
|
61
|
-
|
|
63
|
+
u.disconnect();
|
|
62
64
|
} catch {
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
|
-
const
|
|
68
|
-
function
|
|
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
|
|
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
|
|
87
|
+
async function Lt({
|
|
86
88
|
realtimeUrl: e,
|
|
87
|
-
stream:
|
|
88
|
-
ringsUntil:
|
|
89
|
+
stream: s,
|
|
90
|
+
ringsUntil: l,
|
|
89
91
|
onState: a,
|
|
90
92
|
onAudioBlocked: c,
|
|
91
|
-
onMicrophone:
|
|
93
|
+
onMicrophone: d
|
|
92
94
|
}) {
|
|
93
|
-
const
|
|
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
|
-
},
|
|
105
|
+
}, y = (t) => {
|
|
104
106
|
try {
|
|
105
|
-
|
|
107
|
+
d == null || d(t);
|
|
106
108
|
} catch {
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
|
-
if (!
|
|
111
|
+
if (!Et()) {
|
|
110
112
|
const t = new Error("[BugCatch] this browser cannot make live calls.");
|
|
111
|
-
throw
|
|
113
|
+
throw u("failed", { reason: "unsupported" }), t;
|
|
112
114
|
}
|
|
113
|
-
let r =
|
|
115
|
+
let r = s;
|
|
114
116
|
if (!r)
|
|
115
117
|
try {
|
|
116
|
-
r = await
|
|
118
|
+
r = await St();
|
|
117
119
|
} catch (t) {
|
|
118
|
-
throw
|
|
120
|
+
throw u("failed", { reason: "microphone", error: String((t == null ? void 0 : t.name) || t) }), t;
|
|
119
121
|
}
|
|
120
|
-
let
|
|
122
|
+
let m;
|
|
121
123
|
try {
|
|
122
|
-
|
|
124
|
+
m = await Mt(e);
|
|
123
125
|
} catch (t) {
|
|
124
|
-
throw tt(r),
|
|
126
|
+
throw tt(r), u("failed", { reason: "connect" }), t;
|
|
125
127
|
}
|
|
126
|
-
let o = null, i = null, p = !1, w = null, h = null,
|
|
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,
|
|
129
|
-
const
|
|
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),
|
|
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
|
-
|
|
140
|
+
m.readyState === WebSocket.OPEN && m.close(1e3, "call over");
|
|
139
141
|
} catch {
|
|
140
142
|
}
|
|
141
|
-
|
|
143
|
+
u(t, n);
|
|
142
144
|
}
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
+
}, A = (t) => {
|
|
146
|
+
m.readyState === WebSocket.OPEN && m.send(JSON.stringify(t));
|
|
145
147
|
}, j = async () => {
|
|
146
|
-
if (
|
|
147
|
-
|
|
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
|
|
156
|
-
if (await
|
|
157
|
+
const f = gt(n);
|
|
158
|
+
if (await wt(f), p) {
|
|
157
159
|
try {
|
|
158
|
-
|
|
160
|
+
f.close();
|
|
159
161
|
} catch {
|
|
160
162
|
}
|
|
161
163
|
return;
|
|
162
164
|
}
|
|
163
|
-
const v =
|
|
164
|
-
|
|
165
|
+
const v = Ct(f, r, (T) => {
|
|
166
|
+
m.readyState === WebSocket.OPEN && m.send(T);
|
|
165
167
|
}, n);
|
|
166
|
-
|
|
167
|
-
} catch (
|
|
168
|
-
Z(`could not send the copy this call is keeping: ${String((
|
|
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
|
|
172
|
-
if (
|
|
173
|
-
const { context: t, tap: n } =
|
|
174
|
-
|
|
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,
|
|
203
|
+
b == null || b(), b = null, E && (E = !1, g(!1));
|
|
202
204
|
}
|
|
203
205
|
function V() {
|
|
204
|
-
p || (
|
|
206
|
+
p || (E || (E = !0, g(!0)), it());
|
|
205
207
|
}
|
|
206
|
-
function
|
|
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
|
|
210
|
-
window.addEventListener(
|
|
211
|
+
for (const f of n)
|
|
212
|
+
window.addEventListener(f, t, { capture: !0, passive: !0 });
|
|
211
213
|
b = () => {
|
|
212
|
-
for (const
|
|
214
|
+
for (const f of n)
|
|
213
215
|
try {
|
|
214
|
-
window.removeEventListener(
|
|
216
|
+
window.removeEventListener(f, t, { capture: !0 });
|
|
215
217
|
} catch {
|
|
216
218
|
}
|
|
217
219
|
};
|
|
218
220
|
}
|
|
219
|
-
const
|
|
220
|
-
o = new RTCPeerConnection({ iceServers: t != null && t.length ? t :
|
|
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 =
|
|
223
|
-
n.candidate &&
|
|
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 [
|
|
227
|
-
|
|
228
|
-
}, o.onconnectionstatechange =
|
|
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
|
|
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
|
-
|
|
236
|
+
$ = !0, P = 0, q(), D = !1, u("connected");
|
|
235
237
|
return;
|
|
236
238
|
}
|
|
237
239
|
if (t === "disconnected") {
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
+
if (!$) return;
|
|
241
|
+
W(ot);
|
|
240
242
|
return;
|
|
241
243
|
}
|
|
242
244
|
if (t === "failed") {
|
|
243
|
-
if (
|
|
245
|
+
if (!$) {
|
|
244
246
|
k("failed", { reason: "ice" });
|
|
245
247
|
return;
|
|
246
248
|
}
|
|
247
|
-
|
|
249
|
+
W(0);
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
|
-
function
|
|
251
|
-
p || (
|
|
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
|
|
254
|
-
R && (clearTimeout(R), R = null),
|
|
255
|
+
function q() {
|
|
256
|
+
R && (clearTimeout(R), R = null), I && (clearTimeout(I), I = null);
|
|
255
257
|
}
|
|
256
|
-
async function
|
|
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
|
-
|
|
263
|
+
A({ type: "signal", signal: { kind: "restart", payload: {} } }), R = setTimeout(B, U);
|
|
262
264
|
return;
|
|
263
265
|
}
|
|
264
|
-
|
|
266
|
+
P >= at || (P += 1, await K(), R = setTimeout(B, U));
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
|
-
async function
|
|
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),
|
|
273
|
+
await o.setLocalDescription(t), A({ type: "signal", signal: { kind: "offer", payload: o.localDescription.toJSON() } });
|
|
272
274
|
} catch {
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
|
-
function
|
|
276
|
-
let n = null,
|
|
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 (!
|
|
280
|
-
|
|
281
|
+
if (!f) return;
|
|
282
|
+
f = !1, y(!0);
|
|
281
283
|
return;
|
|
282
284
|
}
|
|
283
|
-
|
|
284
|
-
n = null, !p && (
|
|
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), !
|
|
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
|
|
299
|
+
const ut = async () => {
|
|
298
300
|
try {
|
|
299
301
|
const t = await o.createOffer();
|
|
300
|
-
await o.setLocalDescription(t),
|
|
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
|
-
},
|
|
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),
|
|
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
|
-
},
|
|
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
|
|
322
|
-
|
|
323
|
-
|
|
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
|
|
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 (
|
|
338
|
-
|
|
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
|
-
|
|
343
|
+
u("ringing"), pt();
|
|
342
344
|
break;
|
|
343
345
|
}
|
|
344
346
|
case "peer.joined": {
|
|
345
|
-
w && (clearTimeout(w), w = null),
|
|
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:
|
|
351
|
-
if (
|
|
352
|
-
await
|
|
353
|
-
else if (
|
|
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
|
|
357
|
+
await o.setRemoteDescription(new RTCSessionDescription(L)), await Y();
|
|
356
358
|
} catch {
|
|
357
359
|
k("failed", { reason: "negotiation" });
|
|
358
360
|
}
|
|
359
|
-
else if (
|
|
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
|
|
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
|
-
|
|
382
|
-
function
|
|
383
|
-
if (!
|
|
384
|
-
const t = new Date(
|
|
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
|
-
|
|
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
|
|
401
|
-
return new Promise((
|
|
402
|
+
function Mt(e) {
|
|
403
|
+
return new Promise((s, l) => {
|
|
402
404
|
let a;
|
|
403
405
|
try {
|
|
404
|
-
a = new WebSocket(e,
|
|
406
|
+
a = new WebSocket(e, vt);
|
|
405
407
|
} catch (c) {
|
|
406
|
-
|
|
408
|
+
l(c);
|
|
407
409
|
return;
|
|
408
410
|
}
|
|
409
411
|
a.onopen = () => {
|
|
410
|
-
a.onopen = null, a.onerror = null,
|
|
412
|
+
a.onopen = null, a.onerror = null, s(a);
|
|
411
413
|
}, a.onerror = () => {
|
|
412
|
-
a.onopen = null, a.onerror = null,
|
|
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
|
|
424
|
-
for (const
|
|
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
|
-
|
|
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
|
|
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
|
|
447
|
-
if (!e() && !
|
|
448
|
+
function Ot(e) {
|
|
449
|
+
if (!e() && !At()) return () => {
|
|
448
450
|
};
|
|
449
|
-
const
|
|
450
|
-
if (!
|
|
451
|
+
const s = typeof window < "u" && (window.AudioContext || window.webkitAudioContext);
|
|
452
|
+
if (!s) return () => {
|
|
451
453
|
};
|
|
452
|
-
let
|
|
454
|
+
let l;
|
|
453
455
|
try {
|
|
454
|
-
|
|
456
|
+
l = new s();
|
|
455
457
|
} catch {
|
|
456
458
|
return () => {
|
|
457
459
|
};
|
|
458
460
|
}
|
|
459
461
|
let a = !1, c = null;
|
|
460
|
-
const
|
|
461
|
-
const i =
|
|
462
|
-
p.connect(
|
|
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 =
|
|
465
|
-
h.type = "sine", h.frequency.value = w, h.connect(p), h.start(i), h.stop(i +
|
|
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(
|
|
472
|
+
N.bursts.forEach(u);
|
|
471
473
|
} catch {
|
|
472
474
|
}
|
|
473
|
-
},
|
|
475
|
+
}, y = () => {
|
|
474
476
|
a || (g(), c = setInterval(g, N.cycleMs));
|
|
475
477
|
};
|
|
476
|
-
return
|
|
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
|
|
481
|
+
for (const r of d)
|
|
480
482
|
try {
|
|
481
483
|
r.stop();
|
|
482
484
|
} catch {
|
|
483
485
|
}
|
|
484
486
|
try {
|
|
485
|
-
|
|
487
|
+
l.close();
|
|
486
488
|
} catch {
|
|
487
489
|
}
|
|
488
490
|
};
|
|
489
491
|
}
|
|
490
|
-
function
|
|
491
|
-
const
|
|
492
|
-
return Number.isNaN(
|
|
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:
|
|
499
|
-
"font:
|
|
500
|
+
"border-radius:999px",
|
|
501
|
+
"font:560 13px/1.4 inherit",
|
|
500
502
|
"cursor:pointer"
|
|
501
503
|
].join(";");
|
|
502
|
-
function
|
|
504
|
+
function Nt({
|
|
503
505
|
call: e,
|
|
504
|
-
accent:
|
|
505
|
-
position:
|
|
506
|
+
accent: s = null,
|
|
507
|
+
position: l = "bottom-right",
|
|
506
508
|
onAnswer: a,
|
|
507
509
|
onDecline: c,
|
|
508
|
-
onExpire:
|
|
509
|
-
touched:
|
|
510
|
+
onExpire: d,
|
|
511
|
+
touched: u = () => !1
|
|
510
512
|
}) {
|
|
511
513
|
if (typeof document > "u" || !document.body) return () => {
|
|
512
514
|
};
|
|
513
|
-
const [g,
|
|
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
|
-
`${
|
|
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:
|
|
524
|
-
"border-radius:
|
|
525
|
-
"background:#
|
|
526
|
-
"color:#
|
|
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
|
-
|
|
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
|
|
535
|
-
|
|
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:#
|
|
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:#
|
|
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:${
|
|
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
|
|
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(
|
|
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:#
|
|
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
|
|
551
|
-
let
|
|
551
|
+
const S = Ot(u);
|
|
552
|
+
let E = !1, b = null;
|
|
552
553
|
const C = () => {
|
|
553
|
-
|
|
554
|
-
},
|
|
555
|
-
const x =
|
|
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
|
-
|
|
560
|
+
d == null || d();
|
|
560
561
|
} catch {
|
|
561
562
|
}
|
|
562
563
|
}
|
|
563
564
|
};
|
|
564
|
-
return
|
|
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
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
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
|