@zeroweight/react 0.2.33 → 0.2.34
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,7 +1,7 @@
|
|
|
1
|
-
import { useMemo as be, useRef as k, useState as x, useCallback as S, useEffect as
|
|
1
|
+
import { useMemo as be, useRef as k, useState as x, useCallback as S, useEffect as g } from "react";
|
|
2
2
|
import { ZeroWeightRenderer as Se, ActionQueue as xe, VoiceActivityDetector as ke } from "@zeroweight/renderer";
|
|
3
|
-
import { jsxs as
|
|
4
|
-
import { useVoiceAssistant as
|
|
3
|
+
import { jsxs as A, jsx as r, Fragment as j } from "react/jsx-runtime";
|
|
4
|
+
import { useVoiceAssistant as Ae, useLocalParticipant as we, useIsSpeaking as Te, useDataChannel as Ie, RoomAudioRenderer as Ce, LiveKitRoom as Re } from "@livekit/components-react";
|
|
5
5
|
import "@livekit/components-styles";
|
|
6
6
|
import { Loader2 as J, MicOff as Me, Mic as Ee, Power as Le, Activity as De } from "lucide-react";
|
|
7
7
|
const ze = 3e4, Pe = 120, Fe = "wss://prod-project-pazuyq69.livekit.cloud", ne = "https://api.zeroweight.ai/api/v1";
|
|
@@ -9,93 +9,90 @@ function Ue(v) {
|
|
|
9
9
|
const {
|
|
10
10
|
avatarId: a,
|
|
11
11
|
apiKey: e = null,
|
|
12
|
-
api:
|
|
13
|
-
turnOffMicWhenAISpeaking:
|
|
14
|
-
livekitUrl:
|
|
15
|
-
sessionDuration:
|
|
12
|
+
api: l,
|
|
13
|
+
turnOffMicWhenAISpeaking: u = !0,
|
|
14
|
+
livekitUrl: w = Fe,
|
|
15
|
+
sessionDuration: d = Pe,
|
|
16
16
|
inactivityTimeout: C = ze
|
|
17
|
-
} = v, D =
|
|
18
|
-
if (
|
|
17
|
+
} = v, D = w, y = be(() => {
|
|
18
|
+
if (l) return l;
|
|
19
19
|
const t = e ? { "X-ZW-Api-Key": e } : void 0;
|
|
20
20
|
return {
|
|
21
|
-
getBundle: async (
|
|
22
|
-
const
|
|
21
|
+
getBundle: async (f) => {
|
|
22
|
+
const m = await fetch(
|
|
23
23
|
`${ne}/avatars/bundle/${encodeURIComponent(
|
|
24
|
-
|
|
24
|
+
f
|
|
25
25
|
)}`,
|
|
26
26
|
{ headers: t }
|
|
27
27
|
);
|
|
28
|
-
if (!
|
|
28
|
+
if (!m.ok)
|
|
29
29
|
throw new Error(
|
|
30
|
-
`Failed to fetch avatar bundle (${
|
|
30
|
+
`Failed to fetch avatar bundle (${m.status} ${m.statusText})`
|
|
31
31
|
);
|
|
32
|
-
return
|
|
32
|
+
return m.json();
|
|
33
33
|
},
|
|
34
|
-
getLiveKitToken: async (
|
|
35
|
-
const
|
|
36
|
-
avatar_id
|
|
37
|
-
name: "alice"
|
|
38
|
-
}), c = await fetch(
|
|
39
|
-
`${ne}/livekit/getToken?${T.toString()}`,
|
|
34
|
+
getLiveKitToken: async (f) => {
|
|
35
|
+
const m = await fetch(
|
|
36
|
+
`${ne}/livekit/getToken?avatar_id=${f}&name=anonymuous`,
|
|
40
37
|
{ headers: t }
|
|
41
38
|
);
|
|
42
|
-
if (!
|
|
39
|
+
if (!m.ok)
|
|
43
40
|
throw new Error(
|
|
44
|
-
`Failed to fetch LiveKit token (${
|
|
41
|
+
`Failed to fetch LiveKit token (${m.status} ${m.statusText})`
|
|
45
42
|
);
|
|
46
|
-
return
|
|
43
|
+
return m.json();
|
|
47
44
|
}
|
|
48
45
|
};
|
|
49
|
-
}, [
|
|
46
|
+
}, [l, e]), h = k(null), E = k(null), i = k(null), c = k(null), [b, R] = x("idle"), [p, P] = x(null), [s, U] = x(
|
|
50
47
|
/* @__PURE__ */ new Set(["listening"])
|
|
51
48
|
), [n, o] = x({
|
|
52
49
|
listening: { kind: "looped" },
|
|
53
50
|
speaking: { kind: "looped" }
|
|
54
|
-
}), [O, z] = x(!1), [F, $] = x(null), [W, K] = x(!1), [N, Z] = x(!1), [ae, V] = x(
|
|
51
|
+
}), [O, z] = x(!1), [F, $] = x(null), [W, K] = x(!1), [N, Z] = x(!1), [ae, V] = x(d), M = k(null), B = k(() => {
|
|
55
52
|
}), [oe, X] = x(!1), [se, Y] = x(0.8), L = k(null), H = b === "ready", G = S(() => {
|
|
56
|
-
const t =
|
|
53
|
+
const t = h.current;
|
|
57
54
|
if (!t) return null;
|
|
58
|
-
let
|
|
59
|
-
return
|
|
55
|
+
let f = t.querySelector("canvas");
|
|
56
|
+
return f || (f = document.createElement("canvas"), f.style.width = "100%", f.style.height = "100%", f.style.display = "block", t.appendChild(f)), E.current = f, f;
|
|
60
57
|
}, []);
|
|
61
|
-
|
|
58
|
+
g(() => {
|
|
62
59
|
let t = !1;
|
|
63
60
|
return (async () => {
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
const
|
|
67
|
-
i.current =
|
|
61
|
+
const m = G();
|
|
62
|
+
if (!m) return;
|
|
63
|
+
const T = new Se();
|
|
64
|
+
i.current = T;
|
|
68
65
|
const q = new xe((I, _) => {
|
|
69
|
-
|
|
66
|
+
T.play(I, _);
|
|
70
67
|
});
|
|
71
|
-
|
|
68
|
+
c.current = q, T.on("stateChanged", (I) => {
|
|
72
69
|
t || R(I);
|
|
73
|
-
}),
|
|
70
|
+
}), T.on("dimensions", (I, _) => {
|
|
74
71
|
t || P({ width: I, height: _ });
|
|
75
|
-
}),
|
|
72
|
+
}), T.on("actionLoaded", (I) => {
|
|
76
73
|
t || U((_) => {
|
|
77
74
|
const te = new Set(_);
|
|
78
75
|
return te.add(I), te;
|
|
79
76
|
});
|
|
80
|
-
}),
|
|
77
|
+
}), T.on("allActionsLoaded", () => {
|
|
81
78
|
t || z(!1);
|
|
82
|
-
}),
|
|
83
|
-
t || (o(
|
|
79
|
+
}), T.on("ready", () => {
|
|
80
|
+
t || (o(T.getActionMetadata()), q.setActionMetadata(T.getActionMetadata()));
|
|
84
81
|
});
|
|
85
82
|
try {
|
|
86
83
|
z(!0);
|
|
87
84
|
const I = await y.getBundle(a);
|
|
88
|
-
if (t || (await
|
|
89
|
-
o(
|
|
85
|
+
if (t || (await T.init(m, { payload: I.payload }), t)) return;
|
|
86
|
+
o(T.getActionMetadata()), q.setActionMetadata(T.getActionMetadata());
|
|
90
87
|
} catch (I) {
|
|
91
88
|
console.error("[useAvatarSession] Init failed:", I);
|
|
92
89
|
}
|
|
93
90
|
})(), () => {
|
|
94
|
-
t = !0, i.current?.destroy(), i.current = null,
|
|
91
|
+
t = !0, i.current?.destroy(), i.current = null, c.current = null;
|
|
95
92
|
};
|
|
96
93
|
}, [a, G, y]);
|
|
97
94
|
const ee = k(!1);
|
|
98
|
-
|
|
95
|
+
g(() => {
|
|
99
96
|
H && i.current && s.has("wave_hand") && !ee.current && (i.current.play("wave_hand", "listening"), ee.current = !0);
|
|
100
97
|
}, [H, s]);
|
|
101
98
|
const ce = S(async () => {
|
|
@@ -110,22 +107,22 @@ function Ue(v) {
|
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
}, [W, N, a, y]), Q = S(() => {
|
|
113
|
-
M.current && (clearInterval(M.current), M.current = null), V(
|
|
114
|
-
}, [
|
|
115
|
-
|
|
110
|
+
M.current && (clearInterval(M.current), M.current = null), V(d), L.current && (clearTimeout(L.current), L.current = null), $(null), Z(!1), K(!1), c.current?.forceListening();
|
|
111
|
+
}, [d]);
|
|
112
|
+
g(() => {
|
|
116
113
|
B.current = Q;
|
|
117
114
|
}, [Q]);
|
|
118
115
|
const le = S(() => {
|
|
119
116
|
Z(!0), K(!1);
|
|
120
117
|
}, []), ue = S(() => {
|
|
121
|
-
M.current && clearInterval(M.current), V(
|
|
118
|
+
M.current && clearInterval(M.current), V(d), M.current = setInterval(() => {
|
|
122
119
|
V((t) => t <= 1 ? (clearInterval(M.current), M.current = null, setTimeout(() => B.current(), 0), 0) : t - 1);
|
|
123
120
|
}, 1e3);
|
|
124
|
-
}, [
|
|
125
|
-
const
|
|
126
|
-
return `${
|
|
121
|
+
}, [d]), de = S((t) => {
|
|
122
|
+
const f = Math.floor(t / 60).toString().padStart(2, "0"), m = (t % 60).toString().padStart(2, "0");
|
|
123
|
+
return `${f}:${m}`;
|
|
127
124
|
}, []);
|
|
128
|
-
|
|
125
|
+
g(() => () => {
|
|
129
126
|
M.current && clearInterval(M.current);
|
|
130
127
|
}, []);
|
|
131
128
|
const pe = S(
|
|
@@ -153,11 +150,11 @@ function Ue(v) {
|
|
|
153
150
|
i.current?.play(t, "listening");
|
|
154
151
|
}, []);
|
|
155
152
|
return {
|
|
156
|
-
containerRef:
|
|
153
|
+
containerRef: h,
|
|
157
154
|
renderer: i.current,
|
|
158
|
-
actionQueue:
|
|
155
|
+
actionQueue: c.current,
|
|
159
156
|
rendererState: b,
|
|
160
|
-
avatarDimensions:
|
|
157
|
+
avatarDimensions: p,
|
|
161
158
|
loadedActions: s,
|
|
162
159
|
actionMetadata: n,
|
|
163
160
|
isLoadingActions: O,
|
|
@@ -170,7 +167,7 @@ function Ue(v) {
|
|
|
170
167
|
formatTime: de,
|
|
171
168
|
micMuted: oe,
|
|
172
169
|
volume: se,
|
|
173
|
-
turnOffMicWhenAISpeaking:
|
|
170
|
+
turnOffMicWhenAISpeaking: u,
|
|
174
171
|
connect: ce,
|
|
175
172
|
disconnect: Q,
|
|
176
173
|
toggleMic: fe,
|
|
@@ -188,7 +185,7 @@ const _e = ({
|
|
|
188
185
|
session: v,
|
|
189
186
|
style: a,
|
|
190
187
|
loadingContent: e
|
|
191
|
-
}) => /* @__PURE__ */
|
|
188
|
+
}) => /* @__PURE__ */ A(
|
|
192
189
|
"div",
|
|
193
190
|
{
|
|
194
191
|
style: {
|
|
@@ -238,7 +235,7 @@ const _e = ({
|
|
|
238
235
|
backdropFilter: "blur(4px)",
|
|
239
236
|
zIndex: 10
|
|
240
237
|
},
|
|
241
|
-
children: e || /* @__PURE__ */
|
|
238
|
+
children: e || /* @__PURE__ */ A(
|
|
242
239
|
"div",
|
|
243
240
|
{
|
|
244
241
|
style: {
|
|
@@ -313,25 +310,25 @@ const _e = ({
|
|
|
313
310
|
}) => {
|
|
314
311
|
const {
|
|
315
312
|
micMuted: e,
|
|
316
|
-
toggleMic:
|
|
317
|
-
isConnected:
|
|
318
|
-
isConnecting:
|
|
319
|
-
isEngineReady:
|
|
313
|
+
toggleMic: l,
|
|
314
|
+
isConnected: u,
|
|
315
|
+
isConnecting: w,
|
|
316
|
+
isEngineReady: d,
|
|
320
317
|
loadedActions: C,
|
|
321
318
|
connect: D,
|
|
322
319
|
disconnect: y
|
|
323
|
-
} = v, [
|
|
320
|
+
} = v, [h, E] = x(!1), [i, c] = x(!1), b = d && C.has("listening") && C.has("speaking"), R = e ? {
|
|
324
321
|
...re,
|
|
325
322
|
background: "rgba(239,68,68,0.1)",
|
|
326
323
|
color: "#f87171",
|
|
327
324
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
|
|
328
|
-
...
|
|
325
|
+
...h ? { background: "rgba(239,68,68,0.2)" } : {}
|
|
329
326
|
} : {
|
|
330
327
|
...re,
|
|
331
|
-
background:
|
|
328
|
+
background: h ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
|
|
332
329
|
color: "#fff",
|
|
333
330
|
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
|
|
334
|
-
},
|
|
331
|
+
}, p = u ? {
|
|
335
332
|
...ie,
|
|
336
333
|
background: i ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
|
|
337
334
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
|
|
@@ -341,7 +338,7 @@ const _e = ({
|
|
|
341
338
|
boxShadow: "0 0 30px rgba(236,72,153,0.3)",
|
|
342
339
|
opacity: i ? 0.9 : 1
|
|
343
340
|
};
|
|
344
|
-
return (
|
|
341
|
+
return (w || !b) && (p.opacity = 0.5, p.cursor = "not-allowed"), /* @__PURE__ */ A(
|
|
345
342
|
"div",
|
|
346
343
|
{
|
|
347
344
|
style: {
|
|
@@ -361,7 +358,7 @@ const _e = ({
|
|
|
361
358
|
to { transform: rotate(360deg); }
|
|
362
359
|
}
|
|
363
360
|
` }),
|
|
364
|
-
/* @__PURE__ */
|
|
361
|
+
/* @__PURE__ */ A(
|
|
365
362
|
"div",
|
|
366
363
|
{
|
|
367
364
|
style: {
|
|
@@ -378,7 +375,7 @@ const _e = ({
|
|
|
378
375
|
"button",
|
|
379
376
|
{
|
|
380
377
|
type: "button",
|
|
381
|
-
onClick:
|
|
378
|
+
onClick: l,
|
|
382
379
|
onMouseEnter: () => E(!0),
|
|
383
380
|
onMouseLeave: () => E(!1),
|
|
384
381
|
style: R,
|
|
@@ -390,21 +387,21 @@ const _e = ({
|
|
|
390
387
|
"button",
|
|
391
388
|
{
|
|
392
389
|
type: "button",
|
|
393
|
-
onClick:
|
|
394
|
-
onMouseEnter: () =>
|
|
395
|
-
onMouseLeave: () =>
|
|
396
|
-
disabled: !
|
|
397
|
-
style:
|
|
398
|
-
children:
|
|
390
|
+
onClick: u ? y : D,
|
|
391
|
+
onMouseEnter: () => c(!0),
|
|
392
|
+
onMouseLeave: () => c(!1),
|
|
393
|
+
disabled: !u && (w || !b),
|
|
394
|
+
style: p,
|
|
395
|
+
children: w ? /* @__PURE__ */ A(j, { children: [
|
|
399
396
|
/* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
400
397
|
/* @__PURE__ */ r("span", { children: "Connecting..." })
|
|
401
|
-
] }) : !
|
|
398
|
+
] }) : !u && !b ? /* @__PURE__ */ A(j, { children: [
|
|
402
399
|
/* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
403
400
|
/* @__PURE__ */ r("span", { children: "Loading Avatar..." })
|
|
404
|
-
] }) :
|
|
401
|
+
] }) : u ? /* @__PURE__ */ A(j, { children: [
|
|
405
402
|
/* @__PURE__ */ r(Le, { size: 20 }),
|
|
406
403
|
/* @__PURE__ */ r("span", { children: "End Session" })
|
|
407
|
-
] }) : /* @__PURE__ */
|
|
404
|
+
] }) : /* @__PURE__ */ A(j, { children: [
|
|
408
405
|
/* @__PURE__ */ r(De, { size: 20 }),
|
|
409
406
|
/* @__PURE__ */ r("span", { children: "Start Session" })
|
|
410
407
|
] })
|
|
@@ -419,7 +416,7 @@ const _e = ({
|
|
|
419
416
|
}, Oe = ({
|
|
420
417
|
session: v
|
|
421
418
|
}) => {
|
|
422
|
-
const { isConnected: a, timeRemaining: e, formatTime:
|
|
419
|
+
const { isConnected: a, timeRemaining: e, formatTime: l } = v, u = a && e <= 30, w = a && e > 30 && e <= 60, d = {
|
|
423
420
|
display: "flex",
|
|
424
421
|
alignItems: "center",
|
|
425
422
|
gap: 8,
|
|
@@ -429,12 +426,12 @@ const _e = ({
|
|
|
429
426
|
border: "1px solid",
|
|
430
427
|
pointerEvents: "auto",
|
|
431
428
|
transition: "all 0.3s",
|
|
432
|
-
...
|
|
429
|
+
...u ? {
|
|
433
430
|
background: "rgba(239,68,68,0.3)",
|
|
434
431
|
borderColor: "rgba(239,68,68,0.4)",
|
|
435
432
|
boxShadow: "0 0 15px rgba(239,68,68,0.3)",
|
|
436
433
|
animation: "zwr-pulse 2s ease-in-out infinite"
|
|
437
|
-
} :
|
|
434
|
+
} : w ? {
|
|
438
435
|
background: "rgba(249,115,22,0.2)",
|
|
439
436
|
borderColor: "rgba(249,115,22,0.3)",
|
|
440
437
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
@@ -444,14 +441,14 @@ const _e = ({
|
|
|
444
441
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
445
442
|
}
|
|
446
443
|
};
|
|
447
|
-
return /* @__PURE__ */
|
|
444
|
+
return /* @__PURE__ */ A(j, { children: [
|
|
448
445
|
/* @__PURE__ */ r("style", { children: `
|
|
449
446
|
@keyframes zwr-pulse {
|
|
450
447
|
0%, 100% { opacity: 1; }
|
|
451
448
|
50% { opacity: 0.5; }
|
|
452
449
|
}
|
|
453
450
|
` }),
|
|
454
|
-
/* @__PURE__ */
|
|
451
|
+
/* @__PURE__ */ A("div", { style: d, children: [
|
|
455
452
|
/* @__PURE__ */ r(
|
|
456
453
|
"div",
|
|
457
454
|
{
|
|
@@ -478,7 +475,7 @@ const _e = ({
|
|
|
478
475
|
color: "rgba(255,255,255,0.7)",
|
|
479
476
|
textTransform: "uppercase"
|
|
480
477
|
},
|
|
481
|
-
children: a ? `Online ${
|
|
478
|
+
children: a ? `Online ${l(e)}` : "Offline"
|
|
482
479
|
}
|
|
483
480
|
)
|
|
484
481
|
] })
|
|
@@ -489,16 +486,16 @@ const _e = ({
|
|
|
489
486
|
const {
|
|
490
487
|
renderer: a,
|
|
491
488
|
actionQueue: e,
|
|
492
|
-
micMuted:
|
|
493
|
-
volume:
|
|
494
|
-
setInactivityActive:
|
|
495
|
-
loadedActions:
|
|
489
|
+
micMuted: l,
|
|
490
|
+
volume: u,
|
|
491
|
+
setInactivityActive: w,
|
|
492
|
+
loadedActions: d,
|
|
496
493
|
token: C,
|
|
497
494
|
isConnected: D
|
|
498
|
-
} = v, { turnOffMicWhenAISpeaking: y, setMicMuted:
|
|
499
|
-
|
|
500
|
-
P.current =
|
|
501
|
-
}, [
|
|
495
|
+
} = v, { turnOffMicWhenAISpeaking: y, setMicMuted: h } = v, E = k(!1), { state: i, audioTrack: c } = Ae(), b = we(), R = Te(b.localParticipant), p = k(null), P = k(d);
|
|
496
|
+
g(() => {
|
|
497
|
+
P.current = d;
|
|
498
|
+
}, [d]), g(() => {
|
|
502
499
|
const n = b.localParticipant;
|
|
503
500
|
if (!a || !n) return;
|
|
504
501
|
const o = new TextEncoder();
|
|
@@ -515,7 +512,7 @@ const _e = ({
|
|
|
515
512
|
console.error("[LiveKitAvatarProvider] Failed to publish action completion:", $);
|
|
516
513
|
});
|
|
517
514
|
});
|
|
518
|
-
}, [a, b.localParticipant]),
|
|
515
|
+
}, [a, b.localParticipant]), g(() => {
|
|
519
516
|
if (!e) return;
|
|
520
517
|
const n = new ke({
|
|
521
518
|
threshold: 8e-3,
|
|
@@ -524,50 +521,50 @@ const _e = ({
|
|
|
524
521
|
speechPauseFrames: 30,
|
|
525
522
|
turnEndFrames: 50
|
|
526
523
|
});
|
|
527
|
-
return
|
|
524
|
+
return p.current = n, n.on("speechStart", () => {
|
|
528
525
|
e.setTurnActive(!0), e.setSpeechState("speaking");
|
|
529
526
|
}), n.on("turnEnd", () => {
|
|
530
527
|
e.setTurnActive(!1);
|
|
531
528
|
}), () => {
|
|
532
|
-
n.stop(),
|
|
529
|
+
n.stop(), p.current = null;
|
|
533
530
|
};
|
|
534
|
-
}, [e]),
|
|
535
|
-
const n =
|
|
531
|
+
}, [e]), g(() => {
|
|
532
|
+
const n = p.current;
|
|
536
533
|
if (n)
|
|
537
|
-
if (
|
|
538
|
-
const o =
|
|
534
|
+
if (c?.publication?.track) {
|
|
535
|
+
const o = c.publication.track.mediaStreamTrack;
|
|
539
536
|
o && n.start(o);
|
|
540
537
|
} else
|
|
541
538
|
n.stop();
|
|
542
|
-
}, [
|
|
539
|
+
}, [c?.publication?.track]);
|
|
543
540
|
const s = k(null), U = k(!1);
|
|
544
|
-
return
|
|
541
|
+
return g(() => {
|
|
545
542
|
if (!e) return;
|
|
546
543
|
const n = i;
|
|
547
544
|
if (!C || !D || n === "disconnected") {
|
|
548
|
-
s.current && (clearTimeout(s.current), s.current = null),
|
|
545
|
+
s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.forceListening();
|
|
549
546
|
return;
|
|
550
547
|
}
|
|
551
|
-
n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null),
|
|
552
|
-
s.current = null,
|
|
548
|
+
n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.setTurnActive(!1)) : n === "thinking" && (s.current || (s.current = setTimeout(() => {
|
|
549
|
+
s.current = null, p.current?.endTurn(), e.setTurnActive(!1);
|
|
553
550
|
}, 500)));
|
|
554
|
-
}, [e, D, i, C]),
|
|
551
|
+
}, [e, D, i, C]), g(() => {
|
|
555
552
|
const n = i === "speaking";
|
|
556
553
|
if (!y) {
|
|
557
554
|
U.current = n;
|
|
558
555
|
return;
|
|
559
556
|
}
|
|
560
557
|
const o = U.current;
|
|
561
|
-
!o && n ?
|
|
562
|
-
}, [
|
|
558
|
+
!o && n ? l || h(!0) : o && !n && l && h(!1), U.current = n;
|
|
559
|
+
}, [l, h, i, y]), g(() => {
|
|
563
560
|
if (!y || !e) return;
|
|
564
561
|
const n = (o) => {
|
|
565
|
-
o ||
|
|
562
|
+
o || h(!1);
|
|
566
563
|
};
|
|
567
564
|
return e.on("turnChanged", n), () => {
|
|
568
565
|
e.off("turnChanged", n);
|
|
569
566
|
};
|
|
570
|
-
}, [e,
|
|
567
|
+
}, [e, h, y]), g(() => () => {
|
|
571
568
|
s.current && clearTimeout(s.current);
|
|
572
569
|
}, []), Ie((n) => {
|
|
573
570
|
try {
|
|
@@ -581,48 +578,48 @@ const _e = ({
|
|
|
581
578
|
} catch (o) {
|
|
582
579
|
console.error("[LiveKitAvatarProvider] Failed to parse data message:", o);
|
|
583
580
|
}
|
|
584
|
-
}),
|
|
585
|
-
|
|
586
|
-
}, [R,
|
|
581
|
+
}), g(() => {
|
|
582
|
+
w(!(i === "speaking") && !R);
|
|
583
|
+
}, [R, w, i]), g(() => {
|
|
587
584
|
if (!e) return;
|
|
588
|
-
const n = !!
|
|
589
|
-
(!n || i === "disconnected") && (
|
|
590
|
-
}, [
|
|
585
|
+
const n = !!c;
|
|
586
|
+
(!n || i === "disconnected") && (p.current?.endTurn(), e.forceListening()), E.current = n;
|
|
587
|
+
}, [c, i, e]), g(() => {
|
|
591
588
|
const n = b.localParticipant;
|
|
592
|
-
n && n.setMicrophoneEnabled(!
|
|
589
|
+
n && n.setMicrophoneEnabled(!l).catch((o) => {
|
|
593
590
|
console.error("[LiveKitAvatarProvider] Failed to set mic state:", o);
|
|
594
591
|
});
|
|
595
|
-
}, [
|
|
592
|
+
}, [l, b.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Ce, { volume: u }) });
|
|
596
593
|
}, Qe = ({
|
|
597
594
|
avatarId: v,
|
|
598
595
|
apiKey: a,
|
|
599
596
|
api: e,
|
|
600
|
-
turnOffMicWhenAISpeaking:
|
|
601
|
-
livekitUrl:
|
|
602
|
-
sessionDuration:
|
|
603
|
-
inactivityTimeout:
|
|
597
|
+
turnOffMicWhenAISpeaking: l,
|
|
598
|
+
livekitUrl: u,
|
|
599
|
+
sessionDuration: w,
|
|
600
|
+
inactivityTimeout: d,
|
|
604
601
|
style: C,
|
|
605
602
|
className: D,
|
|
606
603
|
loadingContent: y,
|
|
607
|
-
customControls:
|
|
604
|
+
customControls: h,
|
|
608
605
|
customStatusBadge: E
|
|
609
606
|
}) => {
|
|
610
607
|
const i = Ue({
|
|
611
608
|
avatarId: v,
|
|
612
609
|
apiKey: a,
|
|
613
610
|
api: e,
|
|
614
|
-
turnOffMicWhenAISpeaking:
|
|
615
|
-
livekitUrl:
|
|
616
|
-
sessionDuration:
|
|
617
|
-
inactivityTimeout:
|
|
611
|
+
turnOffMicWhenAISpeaking: l,
|
|
612
|
+
livekitUrl: u,
|
|
613
|
+
sessionDuration: w,
|
|
614
|
+
inactivityTimeout: d
|
|
618
615
|
}), {
|
|
619
|
-
token:
|
|
616
|
+
token: c,
|
|
620
617
|
isConnected: b,
|
|
621
618
|
avatarDimensions: R,
|
|
622
|
-
disconnect:
|
|
619
|
+
disconnect: p,
|
|
623
620
|
startSessionTimer: P
|
|
624
621
|
} = i;
|
|
625
|
-
return /* @__PURE__ */
|
|
622
|
+
return /* @__PURE__ */ A(
|
|
626
623
|
"section",
|
|
627
624
|
{
|
|
628
625
|
className: D,
|
|
@@ -644,7 +641,7 @@ const _e = ({
|
|
|
644
641
|
},
|
|
645
642
|
children: [
|
|
646
643
|
/* @__PURE__ */ r(_e, { session: i, loadingContent: y }),
|
|
647
|
-
/* @__PURE__ */
|
|
644
|
+
/* @__PURE__ */ A(
|
|
648
645
|
"div",
|
|
649
646
|
{
|
|
650
647
|
style: {
|
|
@@ -658,7 +655,7 @@ const _e = ({
|
|
|
658
655
|
padding: 16
|
|
659
656
|
},
|
|
660
657
|
children: [
|
|
661
|
-
/* @__PURE__ */
|
|
658
|
+
/* @__PURE__ */ A(
|
|
662
659
|
"div",
|
|
663
660
|
{
|
|
664
661
|
style: {
|
|
@@ -673,22 +670,22 @@ const _e = ({
|
|
|
673
670
|
]
|
|
674
671
|
}
|
|
675
672
|
),
|
|
676
|
-
|
|
673
|
+
h ? h(i) : /* @__PURE__ */ r(je, { session: i })
|
|
677
674
|
]
|
|
678
675
|
}
|
|
679
676
|
),
|
|
680
|
-
/* @__PURE__ */ r("div", { style: { display: "none" }, children:
|
|
677
|
+
/* @__PURE__ */ r("div", { style: { display: "none" }, children: c && u && /* @__PURE__ */ r(
|
|
681
678
|
Re,
|
|
682
679
|
{
|
|
683
|
-
serverUrl:
|
|
684
|
-
token:
|
|
680
|
+
serverUrl: u,
|
|
681
|
+
token: c,
|
|
685
682
|
connect: !0,
|
|
686
683
|
video: !1,
|
|
687
684
|
audio: !0,
|
|
688
685
|
onConnected: () => {
|
|
689
686
|
i.markConnected(), P();
|
|
690
687
|
},
|
|
691
|
-
onDisconnected:
|
|
688
|
+
onDisconnected: p,
|
|
692
689
|
children: /* @__PURE__ */ r($e, { session: i })
|
|
693
690
|
}
|
|
694
691
|
) })
|