@streamoji/avatar-widget 0.2.5 → 0.2.6
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/dist/avatar-widget.cjs +5 -5
- package/dist/avatar-widget.cjs.map +1 -1
- package/dist/avatar-widget.js +444 -432
- package/dist/avatar-widget.js.map +1 -1
- package/dist/avatar-widget.umd.js +155 -155
- package/dist/avatar-widget.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import { useGLTF as
|
|
3
|
-
import { useFrame as
|
|
4
|
-
import { memo as
|
|
5
|
-
import * as
|
|
6
|
-
import { GLTFLoader as
|
|
7
|
-
const
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
const
|
|
1
|
+
import { jsx as l, jsxs as oe } from "react/jsx-runtime";
|
|
2
|
+
import { useGLTF as ct, Environment as zt } from "@react-three/drei";
|
|
3
|
+
import { useFrame as Yt, Canvas as Qt, useThree as Xt } from "@react-three/fiber";
|
|
4
|
+
import { memo as Kt, useMemo as dt, useRef as c, useState as b, useEffect as P, useCallback as Qe, useLayoutEffect as Zt, Suspense as en } from "react";
|
|
5
|
+
import * as Ve from "three";
|
|
6
|
+
import { GLTFLoader as tn } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
|
+
const lt = "https://ai.streamoji.com", B = (...f) => {
|
|
8
|
+
}, nn = (...f) => {
|
|
9
|
+
}, Tt = ({ analyser: f }) => {
|
|
10
|
+
const A = c(null), w = c(null);
|
|
11
11
|
return P(() => {
|
|
12
|
-
const g =
|
|
12
|
+
const g = A.current;
|
|
13
13
|
if (!g) return;
|
|
14
14
|
const T = g.getContext("2d", { alpha: !0 });
|
|
15
15
|
if (!T) return;
|
|
16
|
-
let
|
|
16
|
+
let V, E = null;
|
|
17
17
|
f && (f.fftSize = 128, E = new Uint8Array(f.frequencyBinCount));
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
T.clearRect(0, 0,
|
|
24
|
-
const
|
|
18
|
+
const ee = () => {
|
|
19
|
+
V = requestAnimationFrame(ee), (g.width !== g.offsetWidth || g.height !== g.offsetHeight) && (g.width = g.offsetWidth, g.height = g.offsetHeight);
|
|
20
|
+
const ae = g.width, N = g.height;
|
|
21
|
+
if (ae === 0 || N === 0) return;
|
|
22
|
+
const U = N / 2;
|
|
23
|
+
T.clearRect(0, 0, ae, N), T.fillStyle = "#1e293b";
|
|
24
|
+
const _ = 2, m = _ + 2, Y = ae * 0.95, $ = Math.floor(Y / m);
|
|
25
25
|
(!w.current || w.current.length !== $) && (w.current = new Float32Array($).fill(2));
|
|
26
|
-
const
|
|
26
|
+
const pe = $ * m, k = (ae - pe) / 2;
|
|
27
27
|
f && E && f.getByteFrequencyData(E);
|
|
28
|
-
const
|
|
28
|
+
const He = E ? E.length : 0, q = Math.floor(He * 0.7) / $, ge = new Float32Array($);
|
|
29
29
|
for (let I = 0; I < $; I++) {
|
|
30
30
|
let C = 0;
|
|
31
31
|
if (E && q > 0) {
|
|
32
|
-
const
|
|
33
|
-
for (let v =
|
|
32
|
+
const be = Math.floor(I * q), L = Math.floor((I + 1) * q);
|
|
33
|
+
for (let v = be; v < L; v++) {
|
|
34
34
|
const y = E[v] || 0;
|
|
35
35
|
y > C && (C = y);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
C < 10 && (C = 0);
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const W = C / 255, M = C > 0 ? Math.max(2, Math.pow(W, 1.4) * N * 0.25) : 2;
|
|
40
|
+
ge[I] = M;
|
|
41
41
|
}
|
|
42
42
|
for (let I = 0; I < $; I++) {
|
|
43
|
-
const C = $ - 1 - I,
|
|
43
|
+
const C = $ - 1 - I, W = Math.max(ge[I], ge[C]), M = w.current[I] + (W - w.current[I]) * 0.3;
|
|
44
44
|
w.current[I] = M;
|
|
45
|
-
const
|
|
46
|
-
T.beginPath(), T.roundRect ? T.roundRect(
|
|
45
|
+
const be = k + I * m, L = U - M / 2;
|
|
46
|
+
T.beginPath(), T.roundRect ? T.roundRect(be, L, _, M, 4) : T.fillRect(be, L, _, M), T.fill();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
return
|
|
50
|
-
cancelAnimationFrame(
|
|
49
|
+
return ee(), () => {
|
|
50
|
+
cancelAnimationFrame(V);
|
|
51
51
|
};
|
|
52
52
|
}, [f]), /* @__PURE__ */ l(
|
|
53
53
|
"canvas",
|
|
54
54
|
{
|
|
55
|
-
ref:
|
|
55
|
+
ref: A,
|
|
56
56
|
style: { width: "100%", height: "100%", display: "block" }
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
|
-
},
|
|
60
|
-
async function
|
|
61
|
-
const
|
|
59
|
+
}, rn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Et = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.glb";
|
|
60
|
+
async function sn(f) {
|
|
61
|
+
const A = await crypto.subtle.digest(
|
|
62
62
|
"SHA-256",
|
|
63
63
|
new TextEncoder().encode(f)
|
|
64
64
|
);
|
|
65
|
-
return Array.from(new Uint8Array(
|
|
65
|
+
return Array.from(new Uint8Array(A)).map((w) => w.toString(16).padStart(2, "0")).join("");
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
const [
|
|
67
|
+
function on(f) {
|
|
68
|
+
const [A, w] = b(null);
|
|
69
69
|
return P(() => {
|
|
70
70
|
if (!f) {
|
|
71
71
|
w(null);
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
let g = !1;
|
|
75
|
-
return
|
|
75
|
+
return sn(f).then((T) => {
|
|
76
76
|
if (g) return;
|
|
77
|
-
const
|
|
78
|
-
fetch(
|
|
79
|
-
g || w(E.ok ?
|
|
77
|
+
const V = `${rn}/${T}.glb`;
|
|
78
|
+
fetch(V, { method: "HEAD" }).then((E) => {
|
|
79
|
+
g || w(E.ok ? V : Et);
|
|
80
80
|
}).catch(() => {
|
|
81
|
-
g || w(
|
|
81
|
+
g || w(Et);
|
|
82
82
|
});
|
|
83
83
|
}), () => {
|
|
84
84
|
g = !0;
|
|
85
85
|
};
|
|
86
|
-
}, [f]),
|
|
86
|
+
}, [f]), A;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
88
|
+
const an = [
|
|
89
89
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
|
|
90
90
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
|
|
91
91
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
|
|
92
92
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
|
|
93
|
-
],
|
|
93
|
+
], cn = [
|
|
94
94
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb",
|
|
95
95
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb",
|
|
96
96
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"
|
|
97
|
-
],
|
|
97
|
+
], ln = [
|
|
98
98
|
{
|
|
99
99
|
id: "m_expr_01",
|
|
100
100
|
name: "Friendly Wave",
|
|
@@ -260,17 +260,17 @@ const nn = [
|
|
|
260
260
|
name: "Take It Easy",
|
|
261
261
|
url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
|
|
262
262
|
}
|
|
263
|
-
],
|
|
263
|
+
], un = [
|
|
264
264
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
|
|
265
265
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"
|
|
266
|
-
],
|
|
266
|
+
], dn = {
|
|
267
267
|
zoom: 0.85,
|
|
268
268
|
position: [0.15, -0.8, 0],
|
|
269
269
|
scale: 1.5,
|
|
270
270
|
rotation: [0.15, 0.02, 0]
|
|
271
|
-
},
|
|
271
|
+
}, fn = [-0.45, 1.9, 0.1], hn = {
|
|
272
272
|
browInnerUp: 0.2
|
|
273
|
-
},
|
|
273
|
+
}, ut = 0.18, mn = 1, It = "__branding__", Xe = {
|
|
274
274
|
neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
|
|
275
275
|
happy: {
|
|
276
276
|
mouthSmileLeft: 0.2,
|
|
@@ -352,7 +352,7 @@ const nn = [
|
|
|
352
352
|
mouthUpperUpLeft: 0.1,
|
|
353
353
|
mouthUpperUpRight: 0.1
|
|
354
354
|
}
|
|
355
|
-
},
|
|
355
|
+
}, pn = [
|
|
356
356
|
{ key: "viseme_aa", mix: { jawOpen: 0.6 } },
|
|
357
357
|
{
|
|
358
358
|
key: "viseme_E",
|
|
@@ -448,7 +448,7 @@ const nn = [
|
|
|
448
448
|
}
|
|
449
449
|
},
|
|
450
450
|
{ key: "viseme_sil", mix: {} }
|
|
451
|
-
],
|
|
451
|
+
], gn = {
|
|
452
452
|
aei: [
|
|
453
453
|
{ v: "E", w: 0.8 },
|
|
454
454
|
{ v: "I", w: 0.2 }
|
|
@@ -477,109 +477,109 @@ const nn = [
|
|
|
477
477
|
],
|
|
478
478
|
sil: [{ v: "sil", w: 1 }]
|
|
479
479
|
};
|
|
480
|
-
function
|
|
480
|
+
function bn(f) {
|
|
481
481
|
if (!f) return [{ v: "sil", w: 1 }];
|
|
482
|
-
const
|
|
483
|
-
return
|
|
482
|
+
const A = f.toLowerCase();
|
|
483
|
+
return gn[A] ?? [{ v: "sil", w: 1 }];
|
|
484
484
|
}
|
|
485
|
-
function
|
|
486
|
-
const { camera:
|
|
485
|
+
function _n({ target: f }) {
|
|
486
|
+
const { camera: A } = Xt();
|
|
487
487
|
return P(() => {
|
|
488
|
-
|
|
489
|
-
}, [
|
|
488
|
+
A.lookAt(...f);
|
|
489
|
+
}, [A, f]), null;
|
|
490
490
|
}
|
|
491
|
-
function z(f,
|
|
491
|
+
function z(f, A, w) {
|
|
492
492
|
if (!f || !f.morphTargetDictionary)
|
|
493
493
|
return;
|
|
494
|
-
const g = f, T = g.morphTargetDictionary,
|
|
495
|
-
if (
|
|
494
|
+
const g = f, T = g.morphTargetDictionary, V = g.morphTargetInfluences;
|
|
495
|
+
if (V)
|
|
496
496
|
for (const E in T)
|
|
497
|
-
E.toLowerCase() ===
|
|
497
|
+
E.toLowerCase() === A.toLowerCase() && (V[T[E]] = w);
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function Mt(f, A = 0.97) {
|
|
500
500
|
if (!f) return;
|
|
501
501
|
const w = f;
|
|
502
502
|
if (w.morphTargetInfluences)
|
|
503
503
|
for (let g = 0; g < w.morphTargetInfluences.length; g++)
|
|
504
|
-
w.morphTargetInfluences[g] *=
|
|
504
|
+
w.morphTargetInfluences[g] *= A;
|
|
505
505
|
}
|
|
506
|
-
const
|
|
506
|
+
const wn = Kt(
|
|
507
507
|
({
|
|
508
508
|
avatarUrl: f,
|
|
509
|
-
isPlayingRef:
|
|
509
|
+
isPlayingRef: A,
|
|
510
510
|
visemeQueueRef: w,
|
|
511
511
|
audioContextRef: g,
|
|
512
512
|
responseAudioStartTimeRef: T,
|
|
513
|
-
adjustments:
|
|
513
|
+
adjustments: V,
|
|
514
514
|
mood: E,
|
|
515
|
-
expression:
|
|
516
|
-
agentResponse:
|
|
517
|
-
isSpeaking:
|
|
518
|
-
nextStartTimeRef:
|
|
519
|
-
stopPlayback:
|
|
520
|
-
setIsSpeaking:
|
|
521
|
-
expressionUrl:
|
|
515
|
+
expression: ee,
|
|
516
|
+
agentResponse: ae,
|
|
517
|
+
isSpeaking: N,
|
|
518
|
+
nextStartTimeRef: U,
|
|
519
|
+
stopPlayback: _,
|
|
520
|
+
setIsSpeaking: ce,
|
|
521
|
+
expressionUrl: m,
|
|
522
522
|
onExpressionFinished: Y,
|
|
523
523
|
isNudgeResponse: $,
|
|
524
|
-
avatarGender:
|
|
524
|
+
avatarGender: pe
|
|
525
525
|
}) => {
|
|
526
|
-
const { scene: k } =
|
|
527
|
-
() =>
|
|
528
|
-
[
|
|
529
|
-
),
|
|
530
|
-
() =>
|
|
531
|
-
[
|
|
532
|
-
), C = c(null),
|
|
526
|
+
const { scene: k } = ct(f), xe = ct(pe === "female" ? cn : an), q = dt(
|
|
527
|
+
() => xe.flatMap((d) => d.animations),
|
|
528
|
+
[xe]
|
|
529
|
+
), ge = ct(un), I = dt(
|
|
530
|
+
() => ge.flatMap((d) => d.animations),
|
|
531
|
+
[ge]
|
|
532
|
+
), C = c(null), W = c(null), M = c(null), be = c([]), [L] = b(() => new Ve.AnimationMixer(k)), v = c({}), y = c(null), _e = c(0), Ie = c(!1), we = c(0), le = c(null);
|
|
533
533
|
P(() => {
|
|
534
534
|
if (!(!q || !k)) {
|
|
535
535
|
if (q.forEach((d, u) => {
|
|
536
536
|
const i = `idle_${u}`;
|
|
537
537
|
if (!v.current[i]) {
|
|
538
|
-
const r =
|
|
539
|
-
r.name = i, r.setLoop(
|
|
538
|
+
const r = L.clipAction(d, k);
|
|
539
|
+
r.name = i, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[i] = r;
|
|
540
540
|
}
|
|
541
541
|
}), I.forEach((d, u) => {
|
|
542
542
|
const i = `talk_${u}`;
|
|
543
543
|
if (!v.current[i]) {
|
|
544
|
-
const r =
|
|
545
|
-
r.name = i, r.setLoop(
|
|
544
|
+
const r = L.clipAction(d, k);
|
|
545
|
+
r.name = i, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[i] = r;
|
|
546
546
|
}
|
|
547
547
|
}), q.length > 0) {
|
|
548
|
-
const d = v.current.idle_0, u = y.current &&
|
|
548
|
+
const d = v.current.idle_0, u = y.current && L.existingAction(y.current.getClip());
|
|
549
549
|
d && !u && (d.reset().fadeIn(0.5).play(), y.current = d);
|
|
550
550
|
}
|
|
551
551
|
return () => {
|
|
552
|
-
|
|
552
|
+
L.stopAllAction(), v.current = {}, y.current = null;
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
|
-
}, [q, I, k,
|
|
556
|
-
const
|
|
555
|
+
}, [q, I, k, L]);
|
|
556
|
+
const ve = c("");
|
|
557
557
|
P(() => {
|
|
558
|
-
if (!
|
|
559
|
-
|
|
560
|
-
|
|
558
|
+
if (!m || !k || m === ve.current) return;
|
|
559
|
+
ve.current = m, le.current = m, new tn().load(
|
|
560
|
+
m,
|
|
561
561
|
(u) => {
|
|
562
562
|
if (u.animations && u.animations.length > 0) {
|
|
563
|
-
const i = u.animations[0], r =
|
|
564
|
-
if (r.name = `EXPR_${
|
|
563
|
+
const i = u.animations[0], r = L.clipAction(i, k);
|
|
564
|
+
if (r.name = `EXPR_${m}`, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[`EXPR_${m}`] = r, N && le.current === m) {
|
|
565
565
|
const h = y.current;
|
|
566
|
-
r.reset().fadeIn(0.3).play(), h && h !== r && h.crossFadeTo(r, 0.3, !0), y.current = r,
|
|
566
|
+
r.reset().fadeIn(0.3).play(), h && h !== r && h.crossFadeTo(r, 0.3, !0), y.current = r, le.current = null;
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
},
|
|
570
570
|
void 0,
|
|
571
571
|
(u) => {
|
|
572
|
-
console.error(`[ANIMATION] Failed to load ${
|
|
572
|
+
console.error(`[ANIMATION] Failed to load ${m}`, u);
|
|
573
573
|
}
|
|
574
574
|
);
|
|
575
|
-
}, [
|
|
575
|
+
}, [m, k, L, N]), P(() => {
|
|
576
576
|
const d = (u) => {
|
|
577
577
|
const i = u.action, r = i.name || "";
|
|
578
578
|
if (r.startsWith("idle_")) {
|
|
579
579
|
const G = (parseInt(r.split("_")[1]) + 1) % q.length, Q = v.current[`idle_${G}`];
|
|
580
580
|
Q && (Q.reset().fadeIn(0.5).play(), i.crossFadeTo(Q, 0.5, !0), y.current = Q);
|
|
581
581
|
} else if (r.startsWith("EXPR_")) {
|
|
582
|
-
if (
|
|
582
|
+
if (N) {
|
|
583
583
|
const h = v.current.talk_0;
|
|
584
584
|
h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), y.current = h);
|
|
585
585
|
} else {
|
|
@@ -588,7 +588,7 @@ const mn = zt(
|
|
|
588
588
|
}
|
|
589
589
|
Y && Y();
|
|
590
590
|
} else if (r.startsWith("talk_"))
|
|
591
|
-
if (
|
|
591
|
+
if (N && !$) {
|
|
592
592
|
const G = (parseInt(r.split("_")[1]) + 1) % I.length, Q = v.current[`talk_${G}`];
|
|
593
593
|
Q && (Q.reset().fadeIn(0.3).play(), i.crossFadeTo(Q, 0.3, !0), y.current = Q);
|
|
594
594
|
} else {
|
|
@@ -596,23 +596,23 @@ const mn = zt(
|
|
|
596
596
|
h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), y.current = h);
|
|
597
597
|
}
|
|
598
598
|
};
|
|
599
|
-
return
|
|
599
|
+
return L.addEventListener("finished", d), () => L.removeEventListener("finished", d);
|
|
600
600
|
}, [
|
|
601
|
-
|
|
601
|
+
L,
|
|
602
602
|
q,
|
|
603
603
|
I,
|
|
604
|
-
|
|
604
|
+
N,
|
|
605
605
|
$,
|
|
606
606
|
Y
|
|
607
607
|
]), P(() => {
|
|
608
|
-
if (
|
|
608
|
+
if (N && k) {
|
|
609
609
|
const d = y.current, u = d?.name || "";
|
|
610
610
|
if (u.startsWith("idle_") || u.startsWith("talk_") || u === "") {
|
|
611
|
-
const i =
|
|
611
|
+
const i = le.current;
|
|
612
612
|
if (i) {
|
|
613
613
|
const r = v.current[`EXPR_${i}`];
|
|
614
614
|
if (r) {
|
|
615
|
-
r.reset().fadeIn(0.3).play(), d && d !== r && d.crossFadeTo(r, 0.3, !0), y.current = r,
|
|
615
|
+
r.reset().fadeIn(0.3).play(), d && d !== r && d.crossFadeTo(r, 0.3, !0), y.current = r, le.current = null;
|
|
616
616
|
return;
|
|
617
617
|
}
|
|
618
618
|
}
|
|
@@ -621,22 +621,22 @@ const mn = zt(
|
|
|
621
621
|
r && (r.reset().fadeIn(0.5).play(), d && d.crossFadeTo(r, 0.5, !0), y.current = r);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
} else if (!
|
|
624
|
+
} else if (!N && k) {
|
|
625
625
|
const d = y.current, u = d?.name || "";
|
|
626
626
|
if (u.startsWith("talk_") || u.startsWith("EXPR_")) {
|
|
627
627
|
const i = v.current.idle_0;
|
|
628
628
|
i && (i.reset().fadeIn(0.5).play(), d && d.crossFadeTo(i, 0.5, !0), y.current = i);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
-
}, [
|
|
631
|
+
}, [N, k, m]), P(() => {
|
|
632
632
|
if (!k) return;
|
|
633
633
|
k.traverse((i) => {
|
|
634
634
|
if (i.isMesh && i.morphTargetDictionary) {
|
|
635
635
|
const r = i.name.toLowerCase();
|
|
636
|
-
(r.includes("head") || r.includes("avatar")) && (
|
|
636
|
+
(r.includes("head") || r.includes("avatar")) && (W.current = i, B(`[ANIMATION] Found head mesh: ${i.name}`)), r.includes("teeth") && (M.current = i, B(`[ANIMATION] Found teeth mesh: ${i.name}`));
|
|
637
637
|
}
|
|
638
638
|
});
|
|
639
|
-
const d =
|
|
639
|
+
const d = W.current?.morphTargetDictionary;
|
|
640
640
|
d && Object.keys(d).filter(
|
|
641
641
|
(i) => i.toLowerCase().includes("brow")
|
|
642
642
|
);
|
|
@@ -646,126 +646,138 @@ const mn = zt(
|
|
|
646
646
|
const h = i.morphTargetDictionary;
|
|
647
647
|
h && Object.keys(h).some((G) => G.toLowerCase().includes("brow")) && u.push(i);
|
|
648
648
|
}
|
|
649
|
-
}),
|
|
649
|
+
}), be.current = u, u.length > 0 && B("[ANIMATION] Meshes with brow morphs:", u.length);
|
|
650
650
|
}, [k]);
|
|
651
651
|
const Ne = (d, u = 1) => {
|
|
652
|
-
const i = `viseme_${d}`.toLowerCase(), r =
|
|
652
|
+
const i = `viseme_${d}`.toLowerCase(), r = pn.find((h) => h.key.toLowerCase() === i);
|
|
653
653
|
if (r)
|
|
654
654
|
for (const h in r.mix) {
|
|
655
655
|
const G = r.mix[h] * u;
|
|
656
|
-
z(
|
|
656
|
+
z(W.current, h, G), z(M.current, h, G);
|
|
657
657
|
}
|
|
658
|
-
},
|
|
659
|
-
const u =
|
|
658
|
+
}, ke = (d) => {
|
|
659
|
+
const u = Xe[d] ?? Xe.neutral;
|
|
660
660
|
for (const i in u)
|
|
661
|
-
z(
|
|
661
|
+
z(W.current, i, u[i]), z(M.current, i, u[i]);
|
|
662
662
|
};
|
|
663
|
-
return
|
|
663
|
+
return Yt((d, u) => {
|
|
664
664
|
const i = Math.pow(0.88, 60 * u);
|
|
665
|
-
|
|
665
|
+
Mt(W.current, i), Mt(M.current, i), ke(E);
|
|
666
666
|
const r = d.clock.elapsedTime;
|
|
667
667
|
let h = 0;
|
|
668
668
|
if (Math.floor(r) % 5 === 0 && Math.floor((r - u) % 5) !== 0) {
|
|
669
669
|
let J = null;
|
|
670
|
-
k.traverse((
|
|
671
|
-
|
|
670
|
+
k.traverse((ne) => {
|
|
671
|
+
ne.name.toLowerCase().includes("hips") && (J = ne);
|
|
672
672
|
});
|
|
673
|
-
const
|
|
674
|
-
|
|
673
|
+
const ye = J ? `Hips Y: ${J.position.y.toFixed(4)}` : "Hips not found";
|
|
674
|
+
B(`[ANIMATION] Mixer Time: ${L.time.toFixed(2)}, ${ye}`);
|
|
675
675
|
}
|
|
676
|
-
if (
|
|
677
|
-
const
|
|
678
|
-
if (
|
|
679
|
-
|
|
676
|
+
if (L.update(u), r > _e.current && !Ie.current && (Ie.current = !0, we.current = r), Ie.current) {
|
|
677
|
+
const ye = (r - we.current) / 0.3;
|
|
678
|
+
if (ye >= 1)
|
|
679
|
+
Ie.current = !1, _e.current = r + 2 + Math.random() * 5;
|
|
680
680
|
else {
|
|
681
|
-
const
|
|
682
|
-
z(
|
|
681
|
+
const ne = ye < 0.5 ? ye * 2 : (1 - ye) * 2;
|
|
682
|
+
z(W.current, "eyeBlinkLeft", ne), z(W.current, "eyeBlinkRight", ne), z(M.current, "eyeBlinkLeft", ne), z(M.current, "eyeBlinkRight", ne), h = ne * hn.browInnerUp;
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
|
-
const G =
|
|
686
|
-
if (z(
|
|
687
|
-
const J =
|
|
688
|
-
C.current.rotation.y =
|
|
685
|
+
const G = Xe[E] ?? Xe.neutral, Q = G.browInnerUp ?? 0, Ke = G.browOuterUpLeft ?? 0, $e = G.browOuterUpRight ?? 0, Ue = r * mn, Re = ut * Math.sin(Ue), K = ut * 0.7 * Math.sin(Ue + 0.7), je = ut * 0.7 * Math.sin(Ue + 1.3), te = (J) => Math.max(0, Math.min(1, J)), Ae = te(Q + Re), Le = te(Ke + K), Be = te($e + je), Me = te(Ae + h);
|
|
686
|
+
if (z(W.current, "browInnerUp", Me), z(M.current, "browInnerUp", Me), z(W.current, "browOuterUpLeft", Le), z(M.current, "browOuterUpLeft", Le), z(W.current, "browOuterUpRight", Be), z(M.current, "browOuterUpRight", Be), C.current) {
|
|
687
|
+
const J = A.current ? 0 : V.rotation[1];
|
|
688
|
+
C.current.rotation.y = Ve.MathUtils.lerp(
|
|
689
689
|
C.current.rotation.y,
|
|
690
690
|
J,
|
|
691
691
|
0.1
|
|
692
|
-
), C.current.position.set(...
|
|
692
|
+
), C.current.position.set(...V.position), C.current.scale.setScalar(V.scale), C.current.rotation.x = V.rotation[0], C.current.rotation.z = V.rotation[2];
|
|
693
693
|
}
|
|
694
|
-
if (
|
|
695
|
-
const J = g.current.currentTime,
|
|
696
|
-
for (let
|
|
697
|
-
const
|
|
698
|
-
|
|
694
|
+
if (A.current && g.current) {
|
|
695
|
+
const J = g.current.currentTime, De = (J - T.current) * 1e3 - -150;
|
|
696
|
+
for (let Z = 0; Z < w.current.length; Z++) {
|
|
697
|
+
const re = w.current[Z];
|
|
698
|
+
De >= re.vtime && De < re.vtime + re.vduration && Ne(re.viseme, re.weight ?? 1);
|
|
699
699
|
}
|
|
700
|
-
J >
|
|
700
|
+
J > U.current + 0.5 && (_(), ce(!1));
|
|
701
701
|
}
|
|
702
702
|
}), /* @__PURE__ */ l("group", { ref: C, children: /* @__PURE__ */ l("primitive", { object: k }) });
|
|
703
703
|
}
|
|
704
704
|
);
|
|
705
|
-
function
|
|
705
|
+
function vn(f) {
|
|
706
706
|
return f ? f.charAt(0).toUpperCase() + f.slice(1).toLowerCase() : "";
|
|
707
707
|
}
|
|
708
|
-
const
|
|
708
|
+
const yn = ({
|
|
709
709
|
token: f,
|
|
710
|
-
agentToken:
|
|
710
|
+
agentToken: A,
|
|
711
711
|
onNavigationRequested: w,
|
|
712
712
|
avatarGender: g
|
|
713
713
|
} = {}) => {
|
|
714
|
-
const T = f ??
|
|
714
|
+
const T = f ?? A ?? "", V = on(T || void 0), [E, ee] = b(""), [ae, N] = b(""), [U, _] = b("Ready"), [ce, m] = b(!1), [Y, $] = b(!1), [pe, k] = b([]), [He, xe] = b(""), q = c(null), [ge, I] = b(
|
|
715
715
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
716
716
|
);
|
|
717
717
|
P(() => {
|
|
718
718
|
const e = window.matchMedia("(max-width: 480px)"), t = () => I(e.matches);
|
|
719
719
|
return e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
720
720
|
}, []);
|
|
721
|
-
const C =
|
|
721
|
+
const C = ge ? 80 : 600, W = c(!1), M = c([]), be = c(0), L = c(!1), v = c([]), y = c(null), _e = c([]);
|
|
722
722
|
c([]);
|
|
723
|
-
const
|
|
723
|
+
const Ie = c([]), we = c(0), le = c(0), ve = c(0), Ne = c(0), ke = c(!1), [d, u] = b(
|
|
724
724
|
null
|
|
725
|
-
), i = c(null), [r, h] =
|
|
725
|
+
), i = c(null), [r, h] = b("neutral"), [G, Q] = b(""), [Ke, $e] = b(""), [Ue, Re] = b("Chat with us"), [K, je] = b(
|
|
726
726
|
null
|
|
727
|
-
), [
|
|
728
|
-
J.current =
|
|
729
|
-
const [
|
|
730
|
-
|
|
731
|
-
const
|
|
727
|
+
), [te, Ae] = b("hidden"), [Le, Be] = b(""), Me = c(null), J = c(te);
|
|
728
|
+
J.current = te;
|
|
729
|
+
const [ye, ne] = b(null), De = c(null), Z = c(null), [re, ft] = b(!1), ht = c(null), [ue, Je] = b("hidden"), [mt, Dt] = b(""), Ze = c(ue);
|
|
730
|
+
Ze.current = ue;
|
|
731
|
+
const he = c(""), Ce = c(!1), Oe = c(""), pt = c(Date.now()), et = c([]), Pe = c(!1), [tt, We] = b(!1), [gt, bt] = b(!1), Se = c(null), Fe = dt(() => re ? "Try again" : U === "Busy" ? "Busy" : U === "Thinking..." || U === "Processing Voice..." ? U : K != null && K !== "" && K !== "none" && K !== "<none>" ? `Enter ${vn(K)}` : ue !== "hidden" || !gt ? null : It, [U, K, re, ue, gt]), _t = !re && U !== "Busy" && U !== "Thinking..." && U !== "Processing Voice..." && (K == null || K === "" || K === "none" || K === "<none>");
|
|
732
|
+
P(() => {
|
|
733
|
+
if (ue !== "hidden" || !_t) {
|
|
734
|
+
bt(!1), Se.current != null && (clearTimeout(Se.current), Se.current = null);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
return Se.current = setTimeout(() => {
|
|
738
|
+
Se.current = null, bt(!0);
|
|
739
|
+
}, 400), () => {
|
|
740
|
+
Se.current != null && (clearTimeout(Se.current), Se.current = null);
|
|
741
|
+
};
|
|
742
|
+
}, [ue, _t]);
|
|
743
|
+
const qe = Fe != null && Fe !== "";
|
|
732
744
|
P(() => {
|
|
733
745
|
const e = J.current;
|
|
734
746
|
if (!(e === "exiting" || e === "entering")) {
|
|
735
747
|
if (e === "hidden") {
|
|
736
|
-
|
|
748
|
+
qe && (Be(Fe ?? ""), Ae("entering"));
|
|
737
749
|
return;
|
|
738
750
|
}
|
|
739
|
-
e === "visible" && (!
|
|
751
|
+
e === "visible" && (!qe || Fe !== Le) && (Me.current = qe ? Fe : null, Ae("exiting"));
|
|
740
752
|
}
|
|
741
753
|
}, [
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
754
|
+
qe,
|
|
755
|
+
Fe,
|
|
756
|
+
te,
|
|
757
|
+
Le
|
|
746
758
|
]), P(() => {
|
|
747
|
-
if (
|
|
748
|
-
|
|
759
|
+
if (U !== "Busy") {
|
|
760
|
+
Z.current != null && (clearTimeout(Z.current), Z.current = null);
|
|
749
761
|
return;
|
|
750
762
|
}
|
|
751
|
-
return
|
|
752
|
-
|
|
763
|
+
return Z.current = setTimeout(() => {
|
|
764
|
+
Z.current = null, _("Ready"), ft(!0);
|
|
753
765
|
}, 12e3), () => {
|
|
754
|
-
|
|
766
|
+
Z.current != null && (clearTimeout(Z.current), Z.current = null);
|
|
755
767
|
};
|
|
756
|
-
}, [
|
|
757
|
-
if (!
|
|
758
|
-
const e = setTimeout(() =>
|
|
768
|
+
}, [U]), P(() => {
|
|
769
|
+
if (!re) return;
|
|
770
|
+
const e = setTimeout(() => ft(!1), 2500);
|
|
759
771
|
return () => clearTimeout(e);
|
|
760
|
-
}, [
|
|
761
|
-
const
|
|
772
|
+
}, [re]);
|
|
773
|
+
const Ct = Qe(() => {
|
|
762
774
|
const e = J.current;
|
|
763
775
|
if (e === "exiting") {
|
|
764
|
-
|
|
765
|
-
const t =
|
|
766
|
-
|
|
767
|
-
} else e === "entering" &&
|
|
768
|
-
}, []),
|
|
776
|
+
Ae("hidden");
|
|
777
|
+
const t = Me.current;
|
|
778
|
+
Me.current = null, t != null && t !== "" && (Be(t), Ae("entering"));
|
|
779
|
+
} else e === "entering" && Ae("visible");
|
|
780
|
+
}, []), Ot = (e) => {
|
|
769
781
|
if (!e) return;
|
|
770
782
|
if (e.mood != null) {
|
|
771
783
|
const n = String(e.mood).toLowerCase();
|
|
@@ -774,12 +786,12 @@ const bn = ({
|
|
|
774
786
|
if (e.expression != null) {
|
|
775
787
|
const n = String(e.expression).trim();
|
|
776
788
|
Q(n);
|
|
777
|
-
const a =
|
|
778
|
-
(
|
|
789
|
+
const a = ln.find(
|
|
790
|
+
(p) => p.name.toLowerCase() === n.toLowerCase()
|
|
779
791
|
);
|
|
780
|
-
|
|
792
|
+
B(
|
|
781
793
|
`[STREAM] Animation match for "${n}": ${a ? a.name : "NONE"}`
|
|
782
|
-
),
|
|
794
|
+
), $e(a?.url ?? "");
|
|
783
795
|
}
|
|
784
796
|
if (e.navigation != null) {
|
|
785
797
|
const n = String(e.navigation).trim();
|
|
@@ -788,10 +800,10 @@ const bn = ({
|
|
|
788
800
|
const t = e.ask_for || e.lead_capture?.ask_for, s = t ? String(t).trim().toLowerCase() : "", o = s === "none" || s === "<none>";
|
|
789
801
|
if (t && !o) {
|
|
790
802
|
const n = s;
|
|
791
|
-
|
|
792
|
-
} else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (
|
|
803
|
+
je(n || null), Re(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
|
|
804
|
+
} else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (je(null), Ue !== "Chat with us" && Re("Chat with us"));
|
|
793
805
|
e.collected, e.valid;
|
|
794
|
-
},
|
|
806
|
+
}, Ft = (e) => {
|
|
795
807
|
const t = e.trim();
|
|
796
808
|
if (!t) return null;
|
|
797
809
|
if (t.startsWith("{"))
|
|
@@ -805,21 +817,21 @@ const bn = ({
|
|
|
805
817
|
return { [o]: n };
|
|
806
818
|
}
|
|
807
819
|
return null;
|
|
808
|
-
},
|
|
809
|
-
}, []),
|
|
810
|
-
if (
|
|
811
|
-
e === "§" ?
|
|
820
|
+
}, Nt = Qe(() => {
|
|
821
|
+
}, []), wt = (e) => {
|
|
822
|
+
if (Ce.current)
|
|
823
|
+
e === "§" ? Ce.current = !1 : (Oe.current += e, N((t) => t + e));
|
|
812
824
|
else if (e === "§") {
|
|
813
|
-
|
|
825
|
+
Ce.current = !0;
|
|
814
826
|
return;
|
|
815
827
|
} else
|
|
816
|
-
for (
|
|
828
|
+
for (he.current += e; he.current.includes(`
|
|
817
829
|
`); ) {
|
|
818
|
-
const t =
|
|
819
|
-
`), s =
|
|
820
|
-
|
|
821
|
-
const o =
|
|
822
|
-
o &&
|
|
830
|
+
const t = he.current.indexOf(`
|
|
831
|
+
`), s = he.current.slice(0, t).trim();
|
|
832
|
+
he.current = he.current.slice(t + 1);
|
|
833
|
+
const o = Ft(s);
|
|
834
|
+
o && Ot(o);
|
|
823
835
|
}
|
|
824
836
|
};
|
|
825
837
|
P(() => {
|
|
@@ -835,12 +847,12 @@ const bn = ({
|
|
|
835
847
|
{ name: "HMAC", hash: "SHA-256" },
|
|
836
848
|
!1,
|
|
837
849
|
["sign"]
|
|
838
|
-
),
|
|
850
|
+
), p = await crypto.subtle.sign(
|
|
839
851
|
"HMAC",
|
|
840
852
|
a,
|
|
841
853
|
n.encode(o)
|
|
842
|
-
), S = Array.from(new Uint8Array(
|
|
843
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", S),
|
|
854
|
+
), S = Array.from(new Uint8Array(p)).map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
855
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", S), B("[SESSION] New HMAC UID generated and saved:", S);
|
|
844
856
|
} catch (n) {
|
|
845
857
|
console.error("[SESSION] HMAC generation failed:", n);
|
|
846
858
|
const a = Math.random().toString(36) + Date.now().toString();
|
|
@@ -854,55 +866,55 @@ const bn = ({
|
|
|
854
866
|
})();
|
|
855
867
|
}, []), P(() => {
|
|
856
868
|
const e = () => {
|
|
857
|
-
pt.current = Date.now(),
|
|
869
|
+
pt.current = Date.now(), Pe.current && (Pe.current = !1, We(!1), k([]), xe(""), N(""), $(!1));
|
|
858
870
|
};
|
|
859
871
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
860
872
|
const t = setInterval(async () => {
|
|
861
|
-
if (Date.now() - pt.current >= 3e4 && !Y && !
|
|
862
|
-
if (
|
|
863
|
-
|
|
873
|
+
if (Date.now() - pt.current >= 3e4 && !Y && !ce && U === "Ready" && !Pe.current)
|
|
874
|
+
if (Pe.current = !0, et.current.length > 0)
|
|
875
|
+
We(!0), k(et.current);
|
|
864
876
|
else
|
|
865
877
|
try {
|
|
866
|
-
const n = `${
|
|
878
|
+
const n = `${lt}/nudgeUser`, a = {
|
|
867
879
|
navigationUrl: window.location.href,
|
|
868
880
|
token: T
|
|
869
|
-
},
|
|
881
|
+
}, p = await fetch(n, {
|
|
870
882
|
method: "POST",
|
|
871
883
|
headers: {
|
|
872
884
|
"Content-Type": "application/json"
|
|
873
885
|
},
|
|
874
886
|
body: JSON.stringify(a)
|
|
875
887
|
});
|
|
876
|
-
if (
|
|
877
|
-
const S = (await
|
|
878
|
-
S && S.length > 0 && (
|
|
888
|
+
if (p.ok) {
|
|
889
|
+
const S = (await p.json()).nudge_questions;
|
|
890
|
+
S && S.length > 0 && (B("[NUDGE] Received nudge questions from API:", S), et.current = S, We(!0), k(S));
|
|
879
891
|
}
|
|
880
892
|
} catch (n) {
|
|
881
|
-
console.error("[NUDGE] Error calling /nudgeUser:", n),
|
|
893
|
+
console.error("[NUDGE] Error calling /nudgeUser:", n), Pe.current = !1;
|
|
882
894
|
}
|
|
883
895
|
}, 1e3);
|
|
884
896
|
return () => {
|
|
885
897
|
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(t);
|
|
886
898
|
};
|
|
887
|
-
}, [T, Y,
|
|
888
|
-
if (
|
|
899
|
+
}, [T, Y, ce, U]), P(() => {
|
|
900
|
+
if (pe.length === 0) return;
|
|
889
901
|
let e = 0, t = 0, s = !1, o = 100;
|
|
890
902
|
const n = () => {
|
|
891
|
-
const a =
|
|
903
|
+
const a = pe[e];
|
|
892
904
|
if (s) {
|
|
893
|
-
const
|
|
894
|
-
|
|
905
|
+
const p = a.substring(0, t - 1);
|
|
906
|
+
xe(p), t--, o = 50;
|
|
895
907
|
} else {
|
|
896
|
-
const
|
|
897
|
-
|
|
908
|
+
const p = a.substring(0, t + 1);
|
|
909
|
+
xe(p), t++, o = 100;
|
|
898
910
|
}
|
|
899
|
-
!s && t === a.length ? (s = !0, o = 3e3) : s && t === 0 && (s = !1, e = (e + 1) %
|
|
911
|
+
!s && t === a.length ? (s = !0, o = 3e3) : s && t === 0 && (s = !1, e = (e + 1) % pe.length, o = 500), q.current = setTimeout(n, o);
|
|
900
912
|
};
|
|
901
913
|
return n(), () => {
|
|
902
914
|
q.current && clearTimeout(q.current);
|
|
903
915
|
};
|
|
904
|
-
}, [
|
|
905
|
-
const
|
|
916
|
+
}, [pe]);
|
|
917
|
+
const vt = () => {
|
|
906
918
|
try {
|
|
907
919
|
return JSON.parse(
|
|
908
920
|
sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
|
|
@@ -910,95 +922,95 @@ const bn = ({
|
|
|
910
922
|
} catch {
|
|
911
923
|
return [];
|
|
912
924
|
}
|
|
913
|
-
},
|
|
925
|
+
}, Ut = (e) => {
|
|
914
926
|
sessionStorage.setItem(
|
|
915
927
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
916
928
|
JSON.stringify(e)
|
|
917
929
|
);
|
|
918
|
-
}, [
|
|
930
|
+
}, [nt, rt] = b(!1), [yt, st] = b(0), de = c(null), Ge = c([]), St = c(0), [xt, Bt] = b(
|
|
919
931
|
null
|
|
920
|
-
), [
|
|
932
|
+
), [Pt, it] = b(
|
|
921
933
|
null
|
|
922
|
-
),
|
|
934
|
+
), me = c(null), Te = c(
|
|
923
935
|
null
|
|
924
|
-
),
|
|
925
|
-
e && (
|
|
936
|
+
), ze = Qe((e = !1) => {
|
|
937
|
+
e && (ke.current = !0, m(!1), _("Ready")), v.current = [], M.current = [], L.current = !1, $(!1), we.current = 0, le.current = 0, ve.current = 0, _e.current.forEach((t) => {
|
|
926
938
|
try {
|
|
927
939
|
t.stop();
|
|
928
940
|
} catch {
|
|
929
941
|
}
|
|
930
|
-
}),
|
|
931
|
-
}, []),
|
|
942
|
+
}), De.current && (clearTimeout(De.current), De.current = null), ne(null), $e(""), _e.current = [];
|
|
943
|
+
}, []), Wt = async () => {
|
|
932
944
|
try {
|
|
933
945
|
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, s = new t(), o = s.createMediaStreamSource(e), n = s.createAnalyser();
|
|
934
|
-
n.fftSize = 64, o.connect(n),
|
|
946
|
+
n.fftSize = 64, o.connect(n), me.current = s, Te.current = o, it(n);
|
|
935
947
|
const a = new MediaRecorder(e);
|
|
936
|
-
|
|
937
|
-
|
|
948
|
+
de.current = a, Ge.current = [], a.ondataavailable = (p) => {
|
|
949
|
+
p.data.size > 0 && Ge.current.push(p.data);
|
|
938
950
|
}, a.onstop = async () => {
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
|
|
951
|
+
const p = Date.now() - St.current;
|
|
952
|
+
if (it(null), Te.current && (Te.current.disconnect(), Te.current = null), me.current && me.current.state !== "closed" && (me.current.close(), me.current = null), p < 1e3) {
|
|
953
|
+
_("Recording too short. Hold or click longer."), m(!1);
|
|
942
954
|
return;
|
|
943
955
|
}
|
|
944
|
-
const
|
|
956
|
+
const R = new Blob(Ge.current, {
|
|
945
957
|
type: "audio/wav"
|
|
946
958
|
});
|
|
947
|
-
await
|
|
948
|
-
},
|
|
959
|
+
await jt(R);
|
|
960
|
+
}, St.current = Date.now(), a.start(100), rt(!0), _("Listening...");
|
|
949
961
|
} catch (e) {
|
|
950
|
-
console.error("Error accessing microphone:", e),
|
|
962
|
+
console.error("Error accessing microphone:", e), _("Mic Access Error");
|
|
951
963
|
}
|
|
952
|
-
},
|
|
953
|
-
|
|
954
|
-
},
|
|
955
|
-
|
|
964
|
+
}, Vt = () => {
|
|
965
|
+
de.current && de.current.state !== "inactive" && (de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), rt(!1));
|
|
966
|
+
}, Ht = () => {
|
|
967
|
+
de.current && de.current.state !== "inactive" && (de.current.onstop = null, de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), it(null), Te.current && (Te.current.disconnect(), Te.current = null), me.current && me.current.state !== "closed" && (me.current.close(), me.current = null), rt(!1), Ge.current = [], _("Ready"));
|
|
956
968
|
};
|
|
957
969
|
P(() => {
|
|
958
970
|
if (!Y) return;
|
|
959
971
|
const e = () => {
|
|
960
|
-
const t =
|
|
972
|
+
const t = ve.current;
|
|
961
973
|
if (t <= 0) return;
|
|
962
|
-
const s = y.current, o =
|
|
974
|
+
const s = y.current, o = we.current;
|
|
963
975
|
if (!s) return;
|
|
964
|
-
const n = s.currentTime - o, a = Math.min(Math.max(0, n), t),
|
|
965
|
-
if (
|
|
966
|
-
const
|
|
967
|
-
Math.round(a / t *
|
|
968
|
-
|
|
976
|
+
const n = s.currentTime - o, a = Math.min(Math.max(0, n), t), p = ae.trim().length;
|
|
977
|
+
if (p <= 0) return;
|
|
978
|
+
const R = Math.min(
|
|
979
|
+
Math.round(a / t * p),
|
|
980
|
+
p
|
|
969
981
|
);
|
|
970
|
-
u(
|
|
982
|
+
u(R);
|
|
971
983
|
};
|
|
972
984
|
return clearInterval(i.current ?? void 0), i.current = setInterval(e, 90), () => clearInterval(i.current ?? void 0);
|
|
973
|
-
}, [Y,
|
|
985
|
+
}, [Y, ae, ve.current]), P(() => {
|
|
974
986
|
let e;
|
|
975
|
-
return
|
|
976
|
-
|
|
977
|
-
}, 1e3)) :
|
|
978
|
-
}, [
|
|
979
|
-
const
|
|
987
|
+
return nt ? (st(0), e = window.setInterval(() => {
|
|
988
|
+
st((t) => t + 1);
|
|
989
|
+
}, 1e3)) : st(0), () => clearInterval(e);
|
|
990
|
+
}, [nt]);
|
|
991
|
+
const $t = (e) => {
|
|
980
992
|
const t = e.numberOfChannels, s = e.length * t * 2 + 44, o = new ArrayBuffer(s), n = new DataView(o);
|
|
981
993
|
let a = 0;
|
|
982
|
-
const
|
|
994
|
+
const p = (O) => {
|
|
983
995
|
n.setUint16(a, O, !0), a += 2;
|
|
984
|
-
},
|
|
996
|
+
}, R = (O) => {
|
|
985
997
|
n.setUint32(a, O, !0), a += 4;
|
|
986
998
|
};
|
|
987
|
-
|
|
999
|
+
R(1179011410), R(s - 8), R(1163280727), R(544501094), R(16), p(1), p(t), R(e.sampleRate), R(e.sampleRate * 2 * t), p(t * 2), p(16), R(1635017060), R(s - a - 4);
|
|
988
1000
|
const S = [];
|
|
989
1001
|
for (let O = 0; O < t; O++) S.push(e.getChannelData(O));
|
|
990
1002
|
let x = 0;
|
|
991
1003
|
for (; a < s; ) {
|
|
992
1004
|
for (let O = 0; O < t; O++) {
|
|
993
|
-
let
|
|
994
|
-
|
|
1005
|
+
let H = Math.max(-1, Math.min(1, S[O][x]));
|
|
1006
|
+
H = H < 0 ? H * 32768 : H * 32767, n.setInt16(a, H, !0), a += 2;
|
|
995
1007
|
}
|
|
996
1008
|
x++;
|
|
997
1009
|
}
|
|
998
1010
|
return new Blob([o], { type: "audio/wav" });
|
|
999
|
-
},
|
|
1000
|
-
if (!
|
|
1001
|
-
if (
|
|
1011
|
+
}, ot = async (e, t, s = !1) => {
|
|
1012
|
+
if (!ke.current) {
|
|
1013
|
+
if (W.current) {
|
|
1002
1014
|
M.current.push({
|
|
1003
1015
|
audio: e,
|
|
1004
1016
|
visemes: t,
|
|
@@ -1006,136 +1018,136 @@ const bn = ({
|
|
|
1006
1018
|
});
|
|
1007
1019
|
return;
|
|
1008
1020
|
}
|
|
1009
|
-
|
|
1021
|
+
W.current = !0;
|
|
1010
1022
|
try {
|
|
1011
1023
|
const o = window.AudioContext || window.webkitAudioContext, n = y.current ?? new o();
|
|
1012
1024
|
n.state === "suspended" && await n.resume(), y.current = n;
|
|
1013
|
-
const a = window.atob(e),
|
|
1014
|
-
for (let
|
|
1015
|
-
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1025
|
+
const a = window.atob(e), p = new Uint8Array(a.length);
|
|
1026
|
+
for (let F = 0; F < a.length; F++)
|
|
1027
|
+
p[F] = a.charCodeAt(F);
|
|
1028
|
+
const R = await n.decodeAudioData(p.buffer.slice(0));
|
|
1029
|
+
ve.current += R.duration;
|
|
1018
1030
|
const S = n.currentTime;
|
|
1019
|
-
let x =
|
|
1020
|
-
const O = !
|
|
1021
|
-
x < S && (x = S + 0.1),
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
let j =
|
|
1025
|
-
if ((!j || j.context !== n) && (j = n.createAnalyser(), j.fftSize = 64, j.connect(n.destination),
|
|
1026
|
-
|
|
1031
|
+
let x = le.current;
|
|
1032
|
+
const O = !L.current;
|
|
1033
|
+
x < S && (x = S + 0.1), le.current = x + R.duration;
|
|
1034
|
+
const H = n.createBufferSource();
|
|
1035
|
+
H.buffer = R;
|
|
1036
|
+
let j = xt;
|
|
1037
|
+
if ((!j || j.context !== n) && (j = n.createAnalyser(), j.fftSize = 64, j.connect(n.destination), Bt(j)), H.connect(j), _e.current.push(H), ke.current) {
|
|
1038
|
+
_e.current = _e.current.filter((F) => F !== H);
|
|
1027
1039
|
return;
|
|
1028
1040
|
}
|
|
1029
1041
|
if (O) {
|
|
1030
|
-
|
|
1042
|
+
L.current = !0, $(!0), B(
|
|
1031
1043
|
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${x.toFixed(
|
|
1032
1044
|
3
|
|
1033
1045
|
)}`
|
|
1034
|
-
),
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1046
|
+
), we.current = x;
|
|
1047
|
+
const F = (x - S) * 1e3;
|
|
1048
|
+
be.current = performance.now() + F, B(
|
|
1037
1049
|
`[AUDIO] Response started. Initial startTime: ${x.toFixed(
|
|
1038
1050
|
3
|
|
1039
1051
|
)}, CT: ${S.toFixed(3)}`
|
|
1040
1052
|
);
|
|
1041
1053
|
}
|
|
1042
|
-
|
|
1043
|
-
const X = (x -
|
|
1044
|
-
s && (Ne.current = X,
|
|
1054
|
+
H.start(x);
|
|
1055
|
+
const X = (x - we.current) * 1e3;
|
|
1056
|
+
s && (Ne.current = X, B(
|
|
1045
1057
|
`[AUDIO] New segment detected at +${X.toFixed(
|
|
1046
1058
|
0
|
|
1047
1059
|
)}ms. Resetting segment offset.`
|
|
1048
|
-
)), t.forEach((
|
|
1049
|
-
const D =
|
|
1060
|
+
)), t.forEach((F, se) => {
|
|
1061
|
+
const D = F.symbol ?? "";
|
|
1050
1062
|
if (D) {
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
`[AUDIO] Viseme "${D}": segment_relative=${
|
|
1063
|
+
const ie = bn(D), fe = Math.round(F.start * 1e3), Ee = Math.round((F.duration ?? 0) * 1e3), At = Ne.current + fe;
|
|
1064
|
+
se < 3 && B(
|
|
1065
|
+
`[AUDIO] Viseme "${D}": segment_relative=${fe}ms, segment_offset=${Ne.current.toFixed(
|
|
1054
1066
|
0
|
|
1055
|
-
)}ms => vtime=${
|
|
1056
|
-
),
|
|
1067
|
+
)}ms => vtime=${At}ms`
|
|
1068
|
+
), ie.forEach((Lt) => {
|
|
1057
1069
|
v.current.push({
|
|
1058
|
-
viseme:
|
|
1059
|
-
weight:
|
|
1060
|
-
vtime:
|
|
1061
|
-
vduration:
|
|
1070
|
+
viseme: Lt.v,
|
|
1071
|
+
weight: Lt.w,
|
|
1072
|
+
vtime: At,
|
|
1073
|
+
vduration: Ee
|
|
1062
1074
|
});
|
|
1063
1075
|
});
|
|
1064
1076
|
}
|
|
1065
|
-
}),
|
|
1077
|
+
}), _("Speaking...");
|
|
1066
1078
|
} finally {
|
|
1067
|
-
if (
|
|
1079
|
+
if (W.current = !1, M.current.length > 0) {
|
|
1068
1080
|
const o = M.current.shift();
|
|
1069
|
-
o &&
|
|
1081
|
+
o && ot(o.audio, o.visemes, o.isNewSegment);
|
|
1070
1082
|
}
|
|
1071
1083
|
}
|
|
1072
1084
|
}
|
|
1073
|
-
},
|
|
1085
|
+
}, jt = async (e) => {
|
|
1074
1086
|
try {
|
|
1075
|
-
|
|
1076
|
-
const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n =
|
|
1087
|
+
m(!0), We(!1), Oe.current = "", N(""), _("Processing Voice...");
|
|
1088
|
+
const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = $t(o), a = new FileReader();
|
|
1077
1089
|
a.readAsDataURL(n), a.onloadend = async () => {
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
const
|
|
1090
|
+
const p = a.result.split(",")[1];
|
|
1091
|
+
ze(), ee(""), he.current = "", Ce.current = !1;
|
|
1092
|
+
const R = `${lt}/stt?token=${encodeURIComponent(
|
|
1081
1093
|
T
|
|
1082
|
-
)}`, S = await fetch(
|
|
1094
|
+
)}`, S = await fetch(R, {
|
|
1083
1095
|
method: "POST",
|
|
1084
1096
|
headers: { "Content-Type": "application/json" },
|
|
1085
1097
|
body: JSON.stringify({
|
|
1086
|
-
audio_base64:
|
|
1098
|
+
audio_base64: p,
|
|
1087
1099
|
audio_format: "wav"
|
|
1088
1100
|
})
|
|
1089
1101
|
});
|
|
1090
1102
|
if (S.status === 429) {
|
|
1091
1103
|
try {
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1104
|
+
const se = await S.text(), D = JSON.parse(se);
|
|
1105
|
+
B("[STT] 429 agent at capacity:", D?.detail);
|
|
1094
1106
|
} catch {
|
|
1095
1107
|
}
|
|
1096
|
-
|
|
1108
|
+
ee(""), _("Busy"), m(!1);
|
|
1097
1109
|
return;
|
|
1098
1110
|
}
|
|
1099
1111
|
if (!S.ok) {
|
|
1100
|
-
const
|
|
1112
|
+
const se = await S.text();
|
|
1101
1113
|
let D = "STT Failed";
|
|
1102
1114
|
try {
|
|
1103
|
-
D = JSON.parse(
|
|
1115
|
+
D = JSON.parse(se).error || D;
|
|
1104
1116
|
} catch {
|
|
1105
|
-
|
|
1117
|
+
se && (D = se.slice(0, 200));
|
|
1106
1118
|
}
|
|
1107
1119
|
throw new Error(D);
|
|
1108
1120
|
}
|
|
1109
1121
|
const x = S.body;
|
|
1110
|
-
if (
|
|
1111
|
-
|
|
1122
|
+
if (B("this is body" + x), !x) {
|
|
1123
|
+
_("STT Failed"), m(!1);
|
|
1112
1124
|
return;
|
|
1113
1125
|
}
|
|
1114
1126
|
const O = x.getReader();
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1127
|
+
ke.current = !1;
|
|
1128
|
+
const H = new TextDecoder();
|
|
1117
1129
|
let j = "", X = !1;
|
|
1118
|
-
const
|
|
1119
|
-
switch (
|
|
1130
|
+
const F = async (se, D) => {
|
|
1131
|
+
switch (se) {
|
|
1120
1132
|
case "transcript":
|
|
1121
|
-
D.transcript != null &&
|
|
1133
|
+
D.transcript != null && ee(String(D.transcript));
|
|
1122
1134
|
break;
|
|
1123
1135
|
case "text": {
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1136
|
+
const ie = D.delta ?? D.text ?? "";
|
|
1137
|
+
ie && wt(ie);
|
|
1126
1138
|
break;
|
|
1127
1139
|
}
|
|
1128
1140
|
case "audio": {
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1141
|
+
const ie = D.chunk, fe = D.visemes ?? [], Ee = !!D.is_new_segment;
|
|
1142
|
+
ie && await ot(ie, fe, Ee);
|
|
1131
1143
|
break;
|
|
1132
1144
|
}
|
|
1133
1145
|
case "done": {
|
|
1134
|
-
X = !0,
|
|
1146
|
+
X = !0, _("Ready"), m(!1);
|
|
1135
1147
|
break;
|
|
1136
1148
|
}
|
|
1137
1149
|
case "error": {
|
|
1138
|
-
X = !0,
|
|
1150
|
+
X = !0, _("STT Failed"), m(!1);
|
|
1139
1151
|
break;
|
|
1140
1152
|
}
|
|
1141
1153
|
default:
|
|
@@ -1143,32 +1155,32 @@ const bn = ({
|
|
|
1143
1155
|
}
|
|
1144
1156
|
};
|
|
1145
1157
|
for (; ; ) {
|
|
1146
|
-
const { done:
|
|
1147
|
-
D && (j +=
|
|
1148
|
-
const
|
|
1158
|
+
const { done: se, value: D } = await O.read();
|
|
1159
|
+
D && (j += H.decode(D, { stream: !0 }));
|
|
1160
|
+
const ie = j.split(`
|
|
1149
1161
|
|
|
1150
1162
|
`);
|
|
1151
|
-
j =
|
|
1152
|
-
for (const
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1163
|
+
j = ie.pop() ?? "";
|
|
1164
|
+
for (const fe of ie) {
|
|
1165
|
+
const Ee = Ye(fe);
|
|
1166
|
+
Ee && await F(Ee.event, Ee.data);
|
|
1155
1167
|
}
|
|
1156
|
-
if (
|
|
1168
|
+
if (se) {
|
|
1157
1169
|
if (j.trim()) {
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1170
|
+
const fe = Ye(j.trim());
|
|
1171
|
+
fe && await F(fe.event, fe.data);
|
|
1160
1172
|
}
|
|
1161
|
-
X || (
|
|
1173
|
+
X || (_("Ready"), m(!1));
|
|
1162
1174
|
break;
|
|
1163
1175
|
}
|
|
1164
1176
|
}
|
|
1165
1177
|
};
|
|
1166
1178
|
} catch (t) {
|
|
1167
|
-
console.error("Audio Submission Error:", t),
|
|
1179
|
+
console.error("Audio Submission Error:", t), _("STT Failed"), m(!1);
|
|
1168
1180
|
}
|
|
1169
|
-
},
|
|
1170
|
-
e && e.preventDefault(),
|
|
1171
|
-
},
|
|
1181
|
+
}, Jt = async (e) => {
|
|
1182
|
+
e && e.preventDefault(), We(!1), Oe.current = "", N(""), !(!E || ce) && await qt(E);
|
|
1183
|
+
}, Ye = (e) => {
|
|
1172
1184
|
const t = e.split(/\r?\n/);
|
|
1173
1185
|
let s = "", o = "";
|
|
1174
1186
|
for (const a of t)
|
|
@@ -1182,45 +1194,45 @@ const bn = ({
|
|
|
1182
1194
|
n = { raw: o };
|
|
1183
1195
|
}
|
|
1184
1196
|
return { event: s, data: n };
|
|
1185
|
-
},
|
|
1197
|
+
}, kt = (e, t) => {
|
|
1186
1198
|
switch (e) {
|
|
1187
1199
|
case "connected":
|
|
1188
|
-
|
|
1200
|
+
he.current = "", Ce.current = !1;
|
|
1189
1201
|
break;
|
|
1190
1202
|
case "text": {
|
|
1191
1203
|
const s = t.delta ?? "";
|
|
1192
|
-
s &&
|
|
1204
|
+
s && wt(s);
|
|
1193
1205
|
break;
|
|
1194
1206
|
}
|
|
1195
1207
|
case "audio": {
|
|
1196
1208
|
const s = t.chunk, o = t.visemes ?? [];
|
|
1197
|
-
s &&
|
|
1209
|
+
s && ot(s, o);
|
|
1198
1210
|
break;
|
|
1199
1211
|
}
|
|
1200
1212
|
case "done": {
|
|
1201
|
-
const s =
|
|
1213
|
+
const s = vt(), o = Oe.current.trim(), n = [
|
|
1202
1214
|
...s,
|
|
1203
1215
|
{ role: "user", content: E || "..." },
|
|
1204
1216
|
{ role: "assistant", content: o }
|
|
1205
1217
|
];
|
|
1206
|
-
|
|
1218
|
+
Ut(n), Ie.current = [...v.current], _("Ready"), m(!1), ee("");
|
|
1207
1219
|
break;
|
|
1208
1220
|
}
|
|
1209
1221
|
case "error": {
|
|
1210
1222
|
const s = t.message ?? "Unknown error";
|
|
1211
|
-
|
|
1223
|
+
Oe.current = s, N(s), _("Agent Failed"), m(!1);
|
|
1212
1224
|
break;
|
|
1213
1225
|
}
|
|
1214
1226
|
}
|
|
1215
|
-
},
|
|
1216
|
-
|
|
1217
|
-
const t = `${
|
|
1227
|
+
}, qt = async (e) => {
|
|
1228
|
+
m(!0), _("Thinking..."), Oe.current = "", he.current = "", Ce.current = !1, ze(), ve.current = 0, u(0);
|
|
1229
|
+
const t = `${lt}/agent/chat?token=${encodeURIComponent(
|
|
1218
1230
|
T
|
|
1219
1231
|
)}`;
|
|
1220
1232
|
try {
|
|
1221
|
-
const s =
|
|
1233
|
+
const s = vt();
|
|
1222
1234
|
let o = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
|
|
1223
|
-
o || (
|
|
1235
|
+
o || (nn(
|
|
1224
1236
|
"[CHAT] Session UID missing at send time! Generating emergency backup."
|
|
1225
1237
|
), o = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", o));
|
|
1226
1238
|
const n = {
|
|
@@ -1228,7 +1240,7 @@ const bn = ({
|
|
|
1228
1240
|
question: e,
|
|
1229
1241
|
lead_id: o
|
|
1230
1242
|
};
|
|
1231
|
-
|
|
1243
|
+
B("[CHAT] Sending payload:", n);
|
|
1232
1244
|
const a = await fetch(t, {
|
|
1233
1245
|
method: "POST",
|
|
1234
1246
|
headers: {
|
|
@@ -1240,72 +1252,72 @@ const bn = ({
|
|
|
1240
1252
|
if (a.status === 429) {
|
|
1241
1253
|
try {
|
|
1242
1254
|
const O = await a.json();
|
|
1243
|
-
|
|
1255
|
+
B("[CHAT] 429 agent at capacity:", O?.detail);
|
|
1244
1256
|
} catch {
|
|
1245
1257
|
}
|
|
1246
|
-
|
|
1258
|
+
ee(""), _("Busy"), m(!1);
|
|
1247
1259
|
return;
|
|
1248
1260
|
}
|
|
1249
1261
|
if (!a.ok)
|
|
1250
1262
|
throw new Error("Agent request failed");
|
|
1251
|
-
const
|
|
1252
|
-
if (!
|
|
1253
|
-
|
|
1263
|
+
const p = a.body;
|
|
1264
|
+
if (!p) {
|
|
1265
|
+
_("Agent Failed"), m(!1);
|
|
1254
1266
|
return;
|
|
1255
1267
|
}
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1268
|
+
const R = p.getReader();
|
|
1269
|
+
ke.current = !1;
|
|
1258
1270
|
const S = new TextDecoder();
|
|
1259
1271
|
let x = "";
|
|
1260
1272
|
for (; ; ) {
|
|
1261
|
-
const { done: O, value:
|
|
1262
|
-
|
|
1263
|
-
`[SSE] Chunk received. done=${O}, length=${
|
|
1264
|
-
),
|
|
1273
|
+
const { done: O, value: H } = await R.read();
|
|
1274
|
+
B(
|
|
1275
|
+
`[SSE] Chunk received. done=${O}, length=${H?.length || 0}`
|
|
1276
|
+
), H && (x += S.decode(H, { stream: !0 }));
|
|
1265
1277
|
const j = x.split(`
|
|
1266
1278
|
|
|
1267
1279
|
`);
|
|
1268
1280
|
x = j.pop() ?? "";
|
|
1269
1281
|
for (const X of j) {
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1282
|
+
B(`[SSE] Processing block: ${X.slice(0, 50)}...`);
|
|
1283
|
+
const F = Ye(X);
|
|
1284
|
+
F && (B(`[SSE] Event: ${F.event}`), kt(F.event, F.data));
|
|
1273
1285
|
}
|
|
1274
1286
|
if (O) {
|
|
1275
|
-
if (
|
|
1276
|
-
const X =
|
|
1277
|
-
X &&
|
|
1287
|
+
if (B("[SSE] Stream finished"), x.trim()) {
|
|
1288
|
+
const X = Ye(x.trim());
|
|
1289
|
+
X && kt(X.event, X.data);
|
|
1278
1290
|
}
|
|
1279
|
-
|
|
1291
|
+
_("Ready"), m(!1), ee("");
|
|
1280
1292
|
break;
|
|
1281
1293
|
}
|
|
1282
1294
|
}
|
|
1283
1295
|
} catch (s) {
|
|
1284
|
-
console.error("Chat Error:", s),
|
|
1296
|
+
console.error("Chat Error:", s), _("Agent Failed"), m(!1);
|
|
1285
1297
|
}
|
|
1286
|
-
},
|
|
1298
|
+
}, Rt = ae.trim(), at = Rt && Y ? Rt.slice(
|
|
1287
1299
|
0,
|
|
1288
1300
|
d != null && d > 0 ? d : 0
|
|
1289
1301
|
) : "";
|
|
1290
1302
|
P(() => {
|
|
1291
|
-
const e =
|
|
1292
|
-
e !== "exiting" && (
|
|
1293
|
-
}, [
|
|
1294
|
-
const
|
|
1295
|
-
const e =
|
|
1296
|
-
e === "entering" ?
|
|
1303
|
+
const e = Ze.current;
|
|
1304
|
+
e !== "exiting" && (at ? (Dt(at), e === "hidden" && Je("entering")) : (e === "visible" || e === "entering") && Je("exiting"));
|
|
1305
|
+
}, [at, ue]);
|
|
1306
|
+
const Gt = Qe(() => {
|
|
1307
|
+
const e = Ze.current;
|
|
1308
|
+
e === "entering" ? Je("visible") : e === "exiting" && Je("hidden");
|
|
1297
1309
|
}, []);
|
|
1298
|
-
return
|
|
1299
|
-
const e =
|
|
1310
|
+
return Zt(() => {
|
|
1311
|
+
const e = ht.current;
|
|
1300
1312
|
e && (e.scrollTop = e.scrollHeight);
|
|
1301
|
-
}, [
|
|
1302
|
-
/* @__PURE__ */
|
|
1303
|
-
|
|
1313
|
+
}, [mt]), /* @__PURE__ */ oe("div", { className: "avatar-widget-container", children: [
|
|
1314
|
+
/* @__PURE__ */ oe("div", { className: "avatar-input-area", children: [
|
|
1315
|
+
te !== "hidden" ? /* @__PURE__ */ l(
|
|
1304
1316
|
"div",
|
|
1305
1317
|
{
|
|
1306
|
-
className: `avatar-thinking-tab${
|
|
1307
|
-
onAnimationEnd:
|
|
1308
|
-
children:
|
|
1318
|
+
className: `avatar-thinking-tab${te === "exiting" ? " avatar-thinking-tab--exiting" : te === "entering" ? " avatar-thinking-tab--entering" : ""}`,
|
|
1319
|
+
onAnimationEnd: Ct,
|
|
1320
|
+
children: Le === It ? /* @__PURE__ */ l(
|
|
1309
1321
|
"a",
|
|
1310
1322
|
{
|
|
1311
1323
|
href: "https://leads.streamoji.com",
|
|
@@ -1313,7 +1325,7 @@ const bn = ({
|
|
|
1313
1325
|
rel: "noopener noreferrer",
|
|
1314
1326
|
children: "Made by Streamoji Leads"
|
|
1315
1327
|
}
|
|
1316
|
-
) :
|
|
1328
|
+
) : Le
|
|
1317
1329
|
}
|
|
1318
1330
|
) : null,
|
|
1319
1331
|
/* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
|
|
@@ -1325,15 +1337,15 @@ const bn = ({
|
|
|
1325
1337
|
width: "100%",
|
|
1326
1338
|
height: "100%"
|
|
1327
1339
|
},
|
|
1328
|
-
children:
|
|
1340
|
+
children: nt ? /* @__PURE__ */ oe("div", { className: "avatar-input-recording", children: [
|
|
1329
1341
|
/* @__PURE__ */ l(
|
|
1330
1342
|
"button",
|
|
1331
1343
|
{
|
|
1332
1344
|
type: "button",
|
|
1333
1345
|
className: "avatar-recording-cancel",
|
|
1334
|
-
onClick:
|
|
1346
|
+
onClick: Ht,
|
|
1335
1347
|
title: "Cancel",
|
|
1336
|
-
children: /* @__PURE__ */
|
|
1348
|
+
children: /* @__PURE__ */ oe(
|
|
1337
1349
|
"svg",
|
|
1338
1350
|
{
|
|
1339
1351
|
width: "18",
|
|
@@ -1353,7 +1365,7 @@ const bn = ({
|
|
|
1353
1365
|
)
|
|
1354
1366
|
}
|
|
1355
1367
|
),
|
|
1356
|
-
/* @__PURE__ */
|
|
1368
|
+
/* @__PURE__ */ oe(
|
|
1357
1369
|
"div",
|
|
1358
1370
|
{
|
|
1359
1371
|
style: {
|
|
@@ -1365,8 +1377,8 @@ const bn = ({
|
|
|
1365
1377
|
minWidth: 0
|
|
1366
1378
|
},
|
|
1367
1379
|
children: [
|
|
1368
|
-
/* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(
|
|
1369
|
-
/* @__PURE__ */
|
|
1380
|
+
/* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Tt, { analyser: Pt }) }),
|
|
1381
|
+
/* @__PURE__ */ oe(
|
|
1370
1382
|
"span",
|
|
1371
1383
|
{
|
|
1372
1384
|
style: {
|
|
@@ -1379,9 +1391,9 @@ const bn = ({
|
|
|
1379
1391
|
fontVariantNumeric: "tabular-nums"
|
|
1380
1392
|
},
|
|
1381
1393
|
children: [
|
|
1382
|
-
Math.floor(
|
|
1394
|
+
Math.floor(yt / 60),
|
|
1383
1395
|
":",
|
|
1384
|
-
String(
|
|
1396
|
+
String(yt % 60).padStart(2, "0")
|
|
1385
1397
|
]
|
|
1386
1398
|
}
|
|
1387
1399
|
)
|
|
@@ -1393,7 +1405,7 @@ const bn = ({
|
|
|
1393
1405
|
{
|
|
1394
1406
|
type: "button",
|
|
1395
1407
|
className: "avatar-recording-confirm",
|
|
1396
|
-
onClick:
|
|
1408
|
+
onClick: Vt,
|
|
1397
1409
|
title: "Send",
|
|
1398
1410
|
children: /* @__PURE__ */ l(
|
|
1399
1411
|
"svg",
|
|
@@ -1412,7 +1424,7 @@ const bn = ({
|
|
|
1412
1424
|
)
|
|
1413
1425
|
}
|
|
1414
1426
|
)
|
|
1415
|
-
] }) : Y && !
|
|
1427
|
+
] }) : Y && !tt ? /* @__PURE__ */ oe("div", { className: "avatar-input-speaking", children: [
|
|
1416
1428
|
/* @__PURE__ */ l(
|
|
1417
1429
|
"div",
|
|
1418
1430
|
{
|
|
@@ -1423,7 +1435,7 @@ const bn = ({
|
|
|
1423
1435
|
alignItems: "center",
|
|
1424
1436
|
paddingRight: "8px"
|
|
1425
1437
|
},
|
|
1426
|
-
children: /* @__PURE__ */ l(
|
|
1438
|
+
children: /* @__PURE__ */ l(Tt, { analyser: xt })
|
|
1427
1439
|
}
|
|
1428
1440
|
),
|
|
1429
1441
|
/* @__PURE__ */ l(
|
|
@@ -1431,12 +1443,12 @@ const bn = ({
|
|
|
1431
1443
|
{
|
|
1432
1444
|
type: "button",
|
|
1433
1445
|
className: "avatar-speaking-stop",
|
|
1434
|
-
onClick: () =>
|
|
1446
|
+
onClick: () => ze(!0),
|
|
1435
1447
|
title: "Stop",
|
|
1436
1448
|
children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
|
|
1437
1449
|
}
|
|
1438
1450
|
)
|
|
1439
|
-
] }) :
|
|
1451
|
+
] }) : ce ? /* @__PURE__ */ l(
|
|
1440
1452
|
"div",
|
|
1441
1453
|
{
|
|
1442
1454
|
style: {
|
|
@@ -1448,10 +1460,10 @@ const bn = ({
|
|
|
1448
1460
|
},
|
|
1449
1461
|
children: /* @__PURE__ */ l("div", { className: "avatar-input-loader" })
|
|
1450
1462
|
}
|
|
1451
|
-
) : /* @__PURE__ */
|
|
1463
|
+
) : /* @__PURE__ */ oe(
|
|
1452
1464
|
"form",
|
|
1453
1465
|
{
|
|
1454
|
-
onSubmit:
|
|
1466
|
+
onSubmit: Jt,
|
|
1455
1467
|
style: {
|
|
1456
1468
|
flex: 1,
|
|
1457
1469
|
display: "flex",
|
|
@@ -1465,14 +1477,14 @@ const bn = ({
|
|
|
1465
1477
|
id: "avatar-text-input",
|
|
1466
1478
|
type: "text",
|
|
1467
1479
|
value: E,
|
|
1468
|
-
onChange: (e) =>
|
|
1469
|
-
placeholder:
|
|
1470
|
-
disabled:
|
|
1480
|
+
onChange: (e) => ee(e.target.value),
|
|
1481
|
+
placeholder: U === "Busy" ? "Assisting another user" : He || "Ask me anything",
|
|
1482
|
+
disabled: ce || U === "Busy",
|
|
1471
1483
|
autoComplete: "off",
|
|
1472
1484
|
style: { width: "100%", height: "100%" }
|
|
1473
1485
|
}
|
|
1474
1486
|
),
|
|
1475
|
-
|
|
1487
|
+
U === "Busy" ? /* @__PURE__ */ l(
|
|
1476
1488
|
"button",
|
|
1477
1489
|
{
|
|
1478
1490
|
type: "button",
|
|
@@ -1504,10 +1516,10 @@ const bn = ({
|
|
|
1504
1516
|
{
|
|
1505
1517
|
type: "button",
|
|
1506
1518
|
className: "mic-button",
|
|
1507
|
-
onClick:
|
|
1508
|
-
disabled:
|
|
1519
|
+
onClick: Wt,
|
|
1520
|
+
disabled: ce,
|
|
1509
1521
|
style: { backgroundColor: "#1e4a5e" },
|
|
1510
|
-
children: /* @__PURE__ */
|
|
1522
|
+
children: /* @__PURE__ */ oe(
|
|
1511
1523
|
"svg",
|
|
1512
1524
|
{
|
|
1513
1525
|
width: "28",
|
|
@@ -1539,7 +1551,7 @@ const bn = ({
|
|
|
1539
1551
|
{
|
|
1540
1552
|
type: "submit",
|
|
1541
1553
|
className: "mic-button",
|
|
1542
|
-
disabled:
|
|
1554
|
+
disabled: ce,
|
|
1543
1555
|
style: { backgroundColor: "#1e4a5e" },
|
|
1544
1556
|
title: "Send",
|
|
1545
1557
|
children: /* @__PURE__ */ l(
|
|
@@ -1570,13 +1582,13 @@ const bn = ({
|
|
|
1570
1582
|
}
|
|
1571
1583
|
) })
|
|
1572
1584
|
] }),
|
|
1573
|
-
/* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */
|
|
1574
|
-
|
|
1585
|
+
/* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ oe("div", { className: "avatar-scene-wrapper", children: [
|
|
1586
|
+
ue !== "hidden" && /* @__PURE__ */ l(
|
|
1575
1587
|
"div",
|
|
1576
1588
|
{
|
|
1577
|
-
className: `avatar-bubble${
|
|
1578
|
-
onAnimationEnd:
|
|
1579
|
-
children: /* @__PURE__ */ l("div", { ref:
|
|
1589
|
+
className: `avatar-bubble${ue === "entering" ? " avatar-bubble--entering" : ue === "exiting" ? " avatar-bubble--exiting" : ""}`,
|
|
1590
|
+
onAnimationEnd: Gt,
|
|
1591
|
+
children: /* @__PURE__ */ l("div", { ref: ht, className: `avatar-bubble__content${tt ? " avatar-bubble__content--nudge" : ""}`, children: mt })
|
|
1580
1592
|
}
|
|
1581
1593
|
),
|
|
1582
1594
|
/* @__PURE__ */ l(
|
|
@@ -1584,8 +1596,8 @@ const bn = ({
|
|
|
1584
1596
|
{
|
|
1585
1597
|
className: "avatar-canvas-layer",
|
|
1586
1598
|
style: { width: C, height: C },
|
|
1587
|
-
children: /* @__PURE__ */
|
|
1588
|
-
|
|
1599
|
+
children: /* @__PURE__ */ oe(
|
|
1600
|
+
Qt,
|
|
1589
1601
|
{
|
|
1590
1602
|
shadows: !0,
|
|
1591
1603
|
camera: { position: [0.2, 1.4, 3], fov: 42 },
|
|
@@ -1593,29 +1605,29 @@ const bn = ({
|
|
|
1593
1605
|
dpr: 1.8,
|
|
1594
1606
|
style: { pointerEvents: "none", width: "100%", height: "100%" },
|
|
1595
1607
|
children: [
|
|
1596
|
-
/* @__PURE__ */ l(
|
|
1608
|
+
/* @__PURE__ */ l(_n, { target: fn }),
|
|
1597
1609
|
/* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
|
|
1598
1610
|
/* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
|
|
1599
|
-
/* @__PURE__ */ l(
|
|
1600
|
-
/* @__PURE__ */ l(
|
|
1601
|
-
|
|
1611
|
+
/* @__PURE__ */ l(zt, { preset: "city" }),
|
|
1612
|
+
/* @__PURE__ */ l(en, { fallback: null, children: V !== null && /* @__PURE__ */ l(
|
|
1613
|
+
wn,
|
|
1602
1614
|
{
|
|
1603
|
-
avatarUrl:
|
|
1604
|
-
isPlayingRef:
|
|
1615
|
+
avatarUrl: V,
|
|
1616
|
+
isPlayingRef: L,
|
|
1605
1617
|
visemeQueueRef: v,
|
|
1606
1618
|
audioContextRef: y,
|
|
1607
|
-
responseAudioStartTimeRef:
|
|
1608
|
-
adjustments:
|
|
1619
|
+
responseAudioStartTimeRef: we,
|
|
1620
|
+
adjustments: dn,
|
|
1609
1621
|
mood: r,
|
|
1610
1622
|
expression: G,
|
|
1611
|
-
agentResponse:
|
|
1623
|
+
agentResponse: ae,
|
|
1612
1624
|
isSpeaking: Y,
|
|
1613
|
-
nextStartTimeRef:
|
|
1614
|
-
stopPlayback:
|
|
1625
|
+
nextStartTimeRef: le,
|
|
1626
|
+
stopPlayback: ze,
|
|
1615
1627
|
setIsSpeaking: $,
|
|
1616
|
-
expressionUrl:
|
|
1617
|
-
onExpressionFinished:
|
|
1618
|
-
isNudgeResponse:
|
|
1628
|
+
expressionUrl: Ke,
|
|
1629
|
+
onExpressionFinished: Nt,
|
|
1630
|
+
isNudgeResponse: tt,
|
|
1619
1631
|
avatarGender: g
|
|
1620
1632
|
}
|
|
1621
1633
|
) })
|
|
@@ -1626,17 +1638,17 @@ const bn = ({
|
|
|
1626
1638
|
)
|
|
1627
1639
|
] }) })
|
|
1628
1640
|
] });
|
|
1629
|
-
},
|
|
1641
|
+
}, Ln = ({
|
|
1630
1642
|
token: f,
|
|
1631
|
-
onNavigationRequested:
|
|
1643
|
+
onNavigationRequested: A
|
|
1632
1644
|
}) => /* @__PURE__ */ l(
|
|
1633
|
-
|
|
1645
|
+
yn,
|
|
1634
1646
|
{
|
|
1635
1647
|
token: f,
|
|
1636
|
-
onNavigationRequested:
|
|
1648
|
+
onNavigationRequested: A
|
|
1637
1649
|
}
|
|
1638
1650
|
);
|
|
1639
1651
|
export {
|
|
1640
|
-
|
|
1652
|
+
Ln as AvatarWidget
|
|
1641
1653
|
};
|
|
1642
1654
|
//# sourceMappingURL=avatar-widget.js.map
|