@zeroweight/react 0.2.25 → 0.2.27
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,42 +1,42 @@
|
|
|
1
|
-
import { useMemo as ve, useRef as
|
|
1
|
+
import { useMemo as ve, useRef as A, useState as y, useCallback as w, useEffect as b } from "react";
|
|
2
2
|
import { ZeroWeightRenderer as ye, ActionQueue as be, VoiceActivityDetector as Se } from "@zeroweight/renderer";
|
|
3
|
-
import { jsxs as
|
|
4
|
-
import { useVoiceAssistant as xe, useLocalParticipant as we, useIsSpeaking as
|
|
3
|
+
import { jsxs as S, jsx as r, Fragment as U } from "react/jsx-runtime";
|
|
4
|
+
import { useVoiceAssistant as xe, useLocalParticipant as we, useIsSpeaking as Ae, useDataChannel as ke, RoomAudioRenderer as Te, LiveKitRoom as Ie } from "@livekit/components-react";
|
|
5
5
|
import "@livekit/components-styles";
|
|
6
|
-
import { Loader2 as W, MicOff as
|
|
7
|
-
const Le = 3e4,
|
|
6
|
+
import { Loader2 as W, MicOff as Re, Mic as Ce, Power as Me, Activity as Ee } from "lucide-react";
|
|
7
|
+
const Le = 3e4, De = 120, ze = "wss://prod-project-pazuyq69.livekit.cloud", X = "https://api.zeroweight.ai", Pe = () => {
|
|
8
8
|
const u = ["Happy", "Swift", "Bright", "Cool", "Smart"], o = ["User", "Guest", "Visitor", "Agent", "Caller"], t = Math.floor(Math.random() * 1e3);
|
|
9
9
|
return `${u[Math.floor(Math.random() * u.length)]}${o[Math.floor(Math.random() * o.length)]}${t}`;
|
|
10
10
|
};
|
|
11
|
-
function
|
|
11
|
+
function Ue(u) {
|
|
12
12
|
const {
|
|
13
13
|
avatarId: o,
|
|
14
14
|
apiKey: t = null,
|
|
15
15
|
api: f,
|
|
16
|
-
livekitUrl: h =
|
|
17
|
-
sessionDuration:
|
|
18
|
-
inactivityTimeout:
|
|
16
|
+
livekitUrl: h = ze,
|
|
17
|
+
sessionDuration: d = De,
|
|
18
|
+
inactivityTimeout: x = Le
|
|
19
19
|
} = u, M = h, p = ve(() => {
|
|
20
20
|
if (f) return f;
|
|
21
21
|
const e = t ? { "X-ZW-Api-Key": t } : void 0;
|
|
22
22
|
return {
|
|
23
|
-
getBundle: async (
|
|
24
|
-
const
|
|
23
|
+
getBundle: async (l) => {
|
|
24
|
+
const k = await fetch(
|
|
25
25
|
`${X}/avatars/bundle/${encodeURIComponent(
|
|
26
|
-
|
|
26
|
+
l
|
|
27
27
|
)}`,
|
|
28
28
|
{ headers: e }
|
|
29
29
|
);
|
|
30
|
-
if (!
|
|
30
|
+
if (!k.ok)
|
|
31
31
|
throw new Error(
|
|
32
|
-
`Failed to fetch avatar bundle (${
|
|
32
|
+
`Failed to fetch avatar bundle (${k.status} ${k.statusText})`
|
|
33
33
|
);
|
|
34
|
-
return
|
|
34
|
+
return k.json();
|
|
35
35
|
},
|
|
36
|
-
getLiveKitToken: async (
|
|
36
|
+
getLiveKitToken: async (l, k) => {
|
|
37
37
|
const g = new URLSearchParams({
|
|
38
|
-
avatar_id:
|
|
39
|
-
name:
|
|
38
|
+
avatar_id: l,
|
|
39
|
+
name: k
|
|
40
40
|
}), E = await fetch(
|
|
41
41
|
`${X}/livekit/token?${g.toString()}`,
|
|
42
42
|
{ headers: e }
|
|
@@ -48,128 +48,128 @@ function $e(u) {
|
|
|
48
48
|
return E.json();
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
}, [f, t]), m =
|
|
51
|
+
}, [f, t]), m = A(null), v = A(null), i = A(null), c = A(null), [R, a] = y("idle"), [n, s] = y(null), [L, D] = y(
|
|
52
52
|
/* @__PURE__ */ new Set(["listening"])
|
|
53
|
-
), [
|
|
53
|
+
), [z, $] = y({
|
|
54
54
|
listening: { kind: "looped" },
|
|
55
55
|
speaking: { kind: "looped" }
|
|
56
|
-
}), [te,
|
|
57
|
-
}), [ie,
|
|
56
|
+
}), [te, B] = y(!1), [ne, H] = y(null), [j, F] = y(!1), [_, Q] = y(!1), [re, K] = y(d), I = A(null), N = A(() => {
|
|
57
|
+
}), [ie, oe] = y(!1), [ae, q] = y(0.8), C = A(null), O = R === "ready", J = w(() => {
|
|
58
58
|
const e = m.current;
|
|
59
59
|
if (!e) return null;
|
|
60
|
-
let
|
|
61
|
-
return
|
|
60
|
+
let l = e.querySelector("canvas");
|
|
61
|
+
return l || (l = document.createElement("canvas"), l.style.width = "100%", l.style.height = "100%", l.style.display = "block", e.appendChild(l)), v.current = l, l;
|
|
62
62
|
}, []);
|
|
63
|
-
|
|
63
|
+
b(() => {
|
|
64
64
|
let e = !1;
|
|
65
65
|
return (async () => {
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
66
|
+
const k = J();
|
|
67
|
+
if (!k) return;
|
|
68
68
|
const g = new ye();
|
|
69
69
|
i.current = g;
|
|
70
|
-
const E = new be((T,
|
|
71
|
-
g.play(T,
|
|
70
|
+
const E = new be((T, P) => {
|
|
71
|
+
g.play(T, P);
|
|
72
72
|
});
|
|
73
|
-
|
|
73
|
+
c.current = E, g.on("stateChanged", (T) => {
|
|
74
74
|
e || a(T);
|
|
75
|
-
}), g.on("dimensions", (T,
|
|
76
|
-
e ||
|
|
75
|
+
}), g.on("dimensions", (T, P) => {
|
|
76
|
+
e || s({ width: T, height: P });
|
|
77
77
|
}), g.on("actionLoaded", (T) => {
|
|
78
|
-
e ||
|
|
79
|
-
const
|
|
80
|
-
return
|
|
78
|
+
e || D((P) => {
|
|
79
|
+
const G = new Set(P);
|
|
80
|
+
return G.add(T), G;
|
|
81
81
|
});
|
|
82
82
|
}), g.on("allActionsLoaded", () => {
|
|
83
|
-
e ||
|
|
83
|
+
e || B(!1);
|
|
84
84
|
}), g.on("ready", () => {
|
|
85
|
-
e || (
|
|
85
|
+
e || ($(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata()));
|
|
86
86
|
});
|
|
87
87
|
try {
|
|
88
|
-
|
|
88
|
+
B(!0);
|
|
89
89
|
const T = await p.getBundle(o);
|
|
90
|
-
if (e || (await g.init(
|
|
91
|
-
|
|
90
|
+
if (e || (await g.init(k, { payload: T.payload }), e)) return;
|
|
91
|
+
$(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata());
|
|
92
92
|
} catch (T) {
|
|
93
93
|
console.error("[useAvatarSession] Init failed:", T);
|
|
94
94
|
}
|
|
95
95
|
})(), () => {
|
|
96
|
-
e = !0, i.current?.destroy(), i.current = null,
|
|
96
|
+
e = !0, i.current?.destroy(), i.current = null, c.current = null;
|
|
97
97
|
};
|
|
98
|
-
}, [o,
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}, [
|
|
103
|
-
const se =
|
|
104
|
-
if (!(
|
|
105
|
-
|
|
98
|
+
}, [o, J, p]);
|
|
99
|
+
const Z = A(!1);
|
|
100
|
+
b(() => {
|
|
101
|
+
O && i.current && L.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
|
|
102
|
+
}, [O, L]);
|
|
103
|
+
const se = w(async () => {
|
|
104
|
+
if (!(j || _)) {
|
|
105
|
+
F(!0);
|
|
106
106
|
try {
|
|
107
107
|
await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
108
|
-
const e =
|
|
109
|
-
H(
|
|
108
|
+
const e = Pe(), l = await p.getLiveKitToken(o, e);
|
|
109
|
+
H(l.token);
|
|
110
110
|
} catch (e) {
|
|
111
|
-
console.error("[useAvatarSession] Failed to connect:", e),
|
|
111
|
+
console.error("[useAvatarSession] Failed to connect:", e), F(!1);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
}, [
|
|
115
|
-
|
|
116
|
-
}, [
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
}, [j, _, o, p]), V = w(() => {
|
|
115
|
+
I.current && (clearInterval(I.current), I.current = null), K(d), C.current && (clearTimeout(C.current), C.current = null), H(null), Q(!1), F(!1), c.current?.forceListening();
|
|
116
|
+
}, [d]);
|
|
117
|
+
b(() => {
|
|
118
|
+
N.current = V;
|
|
119
119
|
}, [V]);
|
|
120
|
-
const ce =
|
|
121
|
-
Q(!0),
|
|
122
|
-
}, []), le =
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
const ce = w(() => {
|
|
121
|
+
Q(!0), F(!1);
|
|
122
|
+
}, []), le = w(() => {
|
|
123
|
+
I.current && clearInterval(I.current), K(d), I.current = setInterval(() => {
|
|
124
|
+
K((e) => e <= 1 ? (clearInterval(I.current), I.current = null, setTimeout(() => N.current(), 0), 0) : e - 1);
|
|
125
125
|
}, 1e3);
|
|
126
|
-
}, [
|
|
127
|
-
const
|
|
128
|
-
return `${
|
|
126
|
+
}, [d]), de = w((e) => {
|
|
127
|
+
const l = Math.floor(e / 60).toString().padStart(2, "0"), k = (e % 60).toString().padStart(2, "0");
|
|
128
|
+
return `${l}:${k}`;
|
|
129
129
|
}, []);
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
b(() => () => {
|
|
131
|
+
I.current && clearInterval(I.current);
|
|
132
132
|
}, []);
|
|
133
|
-
const ue =
|
|
133
|
+
const ue = w(
|
|
134
134
|
(e) => {
|
|
135
135
|
if (!e) {
|
|
136
136
|
C.current && (clearTimeout(C.current), C.current = null);
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
C.current || (C.current = setTimeout(() => {
|
|
140
|
-
C.current = null,
|
|
141
|
-
},
|
|
140
|
+
C.current = null, N.current();
|
|
141
|
+
}, x));
|
|
142
142
|
},
|
|
143
|
-
[
|
|
144
|
-
), pe =
|
|
145
|
-
|
|
146
|
-
}, []), fe =
|
|
143
|
+
[x]
|
|
144
|
+
), pe = w(() => {
|
|
145
|
+
oe((e) => !e);
|
|
146
|
+
}, []), fe = w((e) => {
|
|
147
147
|
q(e);
|
|
148
|
-
}, []), ge =
|
|
148
|
+
}, []), ge = w(() => {
|
|
149
149
|
q((e) => e > 0 ? 0 : 1);
|
|
150
|
-
}, []), he =
|
|
150
|
+
}, []), he = w(() => {
|
|
151
151
|
i.current?.interrupt();
|
|
152
|
-
}, []), me =
|
|
153
|
-
|
|
152
|
+
}, []), me = w((e) => {
|
|
153
|
+
i.current?.play(e, "listening");
|
|
154
154
|
}, []);
|
|
155
155
|
return {
|
|
156
156
|
containerRef: m,
|
|
157
157
|
renderer: i.current,
|
|
158
|
-
actionQueue:
|
|
159
|
-
rendererState:
|
|
160
|
-
avatarDimensions:
|
|
158
|
+
actionQueue: c.current,
|
|
159
|
+
rendererState: R,
|
|
160
|
+
avatarDimensions: n,
|
|
161
161
|
loadedActions: L,
|
|
162
|
-
actionMetadata:
|
|
162
|
+
actionMetadata: z,
|
|
163
163
|
isLoadingActions: te,
|
|
164
|
-
isEngineReady:
|
|
164
|
+
isEngineReady: O,
|
|
165
165
|
token: ne,
|
|
166
|
-
isConnecting:
|
|
167
|
-
isConnected:
|
|
166
|
+
isConnecting: j,
|
|
167
|
+
isConnected: _,
|
|
168
168
|
livekitUrl: M,
|
|
169
169
|
timeRemaining: re,
|
|
170
170
|
formatTime: de,
|
|
171
171
|
micMuted: ie,
|
|
172
|
-
volume:
|
|
172
|
+
volume: ae,
|
|
173
173
|
connect: se,
|
|
174
174
|
disconnect: V,
|
|
175
175
|
toggleMic: pe,
|
|
@@ -182,11 +182,11 @@ function $e(u) {
|
|
|
182
182
|
setInactivityActive: ue
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
|
-
const
|
|
185
|
+
const $e = ({
|
|
186
186
|
session: u,
|
|
187
187
|
style: o,
|
|
188
188
|
loadingContent: t
|
|
189
|
-
}) => /* @__PURE__ */
|
|
189
|
+
}) => /* @__PURE__ */ S(
|
|
190
190
|
"div",
|
|
191
191
|
{
|
|
192
192
|
style: {
|
|
@@ -203,7 +203,7 @@ const je = ({
|
|
|
203
203
|
...o
|
|
204
204
|
},
|
|
205
205
|
children: [
|
|
206
|
-
/* @__PURE__ */
|
|
206
|
+
/* @__PURE__ */ r("style", { children: `
|
|
207
207
|
@keyframes zwr-spin {
|
|
208
208
|
from { transform: rotate(0deg); }
|
|
209
209
|
to { transform: rotate(360deg); }
|
|
@@ -213,7 +213,7 @@ const je = ({
|
|
|
213
213
|
50% { opacity: 0.5; }
|
|
214
214
|
}
|
|
215
215
|
` }),
|
|
216
|
-
/* @__PURE__ */
|
|
216
|
+
/* @__PURE__ */ r(
|
|
217
217
|
"div",
|
|
218
218
|
{
|
|
219
219
|
ref: u.containerRef,
|
|
@@ -223,7 +223,7 @@ const je = ({
|
|
|
223
223
|
height: "100%",
|
|
224
224
|
transition: "all 0.5s ease-in-out"
|
|
225
225
|
},
|
|
226
|
-
children: !u.isEngineReady && /* @__PURE__ */
|
|
226
|
+
children: !u.isEngineReady && /* @__PURE__ */ r(
|
|
227
227
|
"div",
|
|
228
228
|
{
|
|
229
229
|
style: {
|
|
@@ -236,7 +236,7 @@ const je = ({
|
|
|
236
236
|
backdropFilter: "blur(4px)",
|
|
237
237
|
zIndex: 10
|
|
238
238
|
},
|
|
239
|
-
children: t || /* @__PURE__ */
|
|
239
|
+
children: t || /* @__PURE__ */ S(
|
|
240
240
|
"div",
|
|
241
241
|
{
|
|
242
242
|
style: {
|
|
@@ -246,7 +246,7 @@ const je = ({
|
|
|
246
246
|
gap: 16
|
|
247
247
|
},
|
|
248
248
|
children: [
|
|
249
|
-
/* @__PURE__ */
|
|
249
|
+
/* @__PURE__ */ r(
|
|
250
250
|
W,
|
|
251
251
|
{
|
|
252
252
|
style: {
|
|
@@ -257,7 +257,7 @@ const je = ({
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
),
|
|
260
|
-
/* @__PURE__ */
|
|
260
|
+
/* @__PURE__ */ r(
|
|
261
261
|
"div",
|
|
262
262
|
{
|
|
263
263
|
style: {
|
|
@@ -305,7 +305,7 @@ const je = ({
|
|
|
305
305
|
transition: "all 0.3s",
|
|
306
306
|
border: "none",
|
|
307
307
|
cursor: "pointer"
|
|
308
|
-
},
|
|
308
|
+
}, Fe = ({
|
|
309
309
|
session: u,
|
|
310
310
|
style: o
|
|
311
311
|
}) => {
|
|
@@ -313,33 +313,33 @@ const je = ({
|
|
|
313
313
|
micMuted: t,
|
|
314
314
|
toggleMic: f,
|
|
315
315
|
isConnected: h,
|
|
316
|
-
isConnecting:
|
|
317
|
-
isEngineReady:
|
|
316
|
+
isConnecting: d,
|
|
317
|
+
isEngineReady: x,
|
|
318
318
|
loadedActions: M,
|
|
319
319
|
connect: p,
|
|
320
320
|
disconnect: m
|
|
321
|
-
} = u, [
|
|
321
|
+
} = u, [v, i] = y(!1), [c, R] = y(!1), a = x && M.has("listening") && M.has("speaking"), n = t ? {
|
|
322
322
|
...Y,
|
|
323
323
|
background: "rgba(239,68,68,0.1)",
|
|
324
324
|
color: "#f87171",
|
|
325
325
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
|
|
326
|
-
...
|
|
326
|
+
...v ? { background: "rgba(239,68,68,0.2)" } : {}
|
|
327
327
|
} : {
|
|
328
328
|
...Y,
|
|
329
|
-
background:
|
|
329
|
+
background: v ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
|
|
330
330
|
color: "#fff",
|
|
331
331
|
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
|
|
332
|
-
},
|
|
332
|
+
}, s = h ? {
|
|
333
333
|
...ee,
|
|
334
|
-
background:
|
|
334
|
+
background: c ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
|
|
335
335
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
|
|
336
336
|
} : {
|
|
337
337
|
...ee,
|
|
338
338
|
background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
|
|
339
339
|
boxShadow: "0 0 30px rgba(236,72,153,0.3)",
|
|
340
|
-
opacity:
|
|
340
|
+
opacity: c ? 0.9 : 1
|
|
341
341
|
};
|
|
342
|
-
return (
|
|
342
|
+
return (d || !a) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ S(
|
|
343
343
|
"div",
|
|
344
344
|
{
|
|
345
345
|
style: {
|
|
@@ -353,13 +353,13 @@ const je = ({
|
|
|
353
353
|
...o
|
|
354
354
|
},
|
|
355
355
|
children: [
|
|
356
|
-
/* @__PURE__ */
|
|
356
|
+
/* @__PURE__ */ r("style", { children: `
|
|
357
357
|
@keyframes zwr-spin {
|
|
358
358
|
from { transform: rotate(0deg); }
|
|
359
359
|
to { transform: rotate(360deg); }
|
|
360
360
|
}
|
|
361
361
|
` }),
|
|
362
|
-
/* @__PURE__ */
|
|
362
|
+
/* @__PURE__ */ S(
|
|
363
363
|
"div",
|
|
364
364
|
{
|
|
365
365
|
style: {
|
|
@@ -372,39 +372,39 @@ const je = ({
|
|
|
372
372
|
pointerEvents: "auto"
|
|
373
373
|
},
|
|
374
374
|
children: [
|
|
375
|
-
/* @__PURE__ */
|
|
375
|
+
/* @__PURE__ */ r(
|
|
376
376
|
"button",
|
|
377
377
|
{
|
|
378
378
|
type: "button",
|
|
379
379
|
onClick: f,
|
|
380
380
|
onMouseEnter: () => i(!0),
|
|
381
381
|
onMouseLeave: () => i(!1),
|
|
382
|
-
style:
|
|
382
|
+
style: n,
|
|
383
383
|
title: t ? "Unmute mic" : "Mute mic",
|
|
384
|
-
children: t ? /* @__PURE__ */
|
|
384
|
+
children: t ? /* @__PURE__ */ r(Re, { size: 24 }) : /* @__PURE__ */ r(Ce, { size: 24 })
|
|
385
385
|
}
|
|
386
386
|
),
|
|
387
|
-
/* @__PURE__ */
|
|
387
|
+
/* @__PURE__ */ r(
|
|
388
388
|
"button",
|
|
389
389
|
{
|
|
390
390
|
type: "button",
|
|
391
391
|
onClick: h ? m : p,
|
|
392
|
-
onMouseEnter: () =>
|
|
393
|
-
onMouseLeave: () =>
|
|
394
|
-
disabled: !h && (
|
|
395
|
-
style:
|
|
396
|
-
children:
|
|
397
|
-
/* @__PURE__ */
|
|
398
|
-
/* @__PURE__ */
|
|
399
|
-
] }) : !h && !a ? /* @__PURE__ */
|
|
400
|
-
/* @__PURE__ */
|
|
401
|
-
/* @__PURE__ */
|
|
402
|
-
] }) : h ? /* @__PURE__ */
|
|
403
|
-
/* @__PURE__ */
|
|
404
|
-
/* @__PURE__ */
|
|
405
|
-
] }) : /* @__PURE__ */
|
|
406
|
-
/* @__PURE__ */
|
|
407
|
-
/* @__PURE__ */
|
|
392
|
+
onMouseEnter: () => R(!0),
|
|
393
|
+
onMouseLeave: () => R(!1),
|
|
394
|
+
disabled: !h && (d || !a),
|
|
395
|
+
style: s,
|
|
396
|
+
children: d ? /* @__PURE__ */ S(U, { children: [
|
|
397
|
+
/* @__PURE__ */ r(W, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
398
|
+
/* @__PURE__ */ r("span", { children: "Connecting..." })
|
|
399
|
+
] }) : !h && !a ? /* @__PURE__ */ S(U, { children: [
|
|
400
|
+
/* @__PURE__ */ r(W, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
401
|
+
/* @__PURE__ */ r("span", { children: "Loading Avatar..." })
|
|
402
|
+
] }) : h ? /* @__PURE__ */ S(U, { children: [
|
|
403
|
+
/* @__PURE__ */ r(Me, { size: 20 }),
|
|
404
|
+
/* @__PURE__ */ r("span", { children: "End Session" })
|
|
405
|
+
] }) : /* @__PURE__ */ S(U, { children: [
|
|
406
|
+
/* @__PURE__ */ r(Ee, { size: 20 }),
|
|
407
|
+
/* @__PURE__ */ r("span", { children: "Start Session" })
|
|
408
408
|
] })
|
|
409
409
|
}
|
|
410
410
|
)
|
|
@@ -414,10 +414,10 @@ const je = ({
|
|
|
414
414
|
]
|
|
415
415
|
}
|
|
416
416
|
);
|
|
417
|
-
},
|
|
417
|
+
}, je = ({
|
|
418
418
|
session: u
|
|
419
419
|
}) => {
|
|
420
|
-
const { isConnected: o, timeRemaining: t, formatTime: f } = u, h = o && t <= 30,
|
|
420
|
+
const { isConnected: o, timeRemaining: t, formatTime: f } = u, h = o && t <= 30, d = o && t > 30 && t <= 60, x = {
|
|
421
421
|
display: "flex",
|
|
422
422
|
alignItems: "center",
|
|
423
423
|
gap: 8,
|
|
@@ -432,7 +432,7 @@ const je = ({
|
|
|
432
432
|
borderColor: "rgba(239,68,68,0.4)",
|
|
433
433
|
boxShadow: "0 0 15px rgba(239,68,68,0.3)",
|
|
434
434
|
animation: "zwr-pulse 2s ease-in-out infinite"
|
|
435
|
-
} :
|
|
435
|
+
} : d ? {
|
|
436
436
|
background: "rgba(249,115,22,0.2)",
|
|
437
437
|
borderColor: "rgba(249,115,22,0.3)",
|
|
438
438
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
@@ -442,15 +442,15 @@ const je = ({
|
|
|
442
442
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
443
443
|
}
|
|
444
444
|
};
|
|
445
|
-
return /* @__PURE__ */
|
|
446
|
-
/* @__PURE__ */
|
|
445
|
+
return /* @__PURE__ */ S(U, { children: [
|
|
446
|
+
/* @__PURE__ */ r("style", { children: `
|
|
447
447
|
@keyframes zwr-pulse {
|
|
448
448
|
0%, 100% { opacity: 1; }
|
|
449
449
|
50% { opacity: 0.5; }
|
|
450
450
|
}
|
|
451
451
|
` }),
|
|
452
|
-
/* @__PURE__ */
|
|
453
|
-
/* @__PURE__ */
|
|
452
|
+
/* @__PURE__ */ S("div", { style: x, children: [
|
|
453
|
+
/* @__PURE__ */ r(
|
|
454
454
|
"div",
|
|
455
455
|
{
|
|
456
456
|
style: {
|
|
@@ -466,7 +466,7 @@ const je = ({
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
),
|
|
469
|
-
/* @__PURE__ */
|
|
469
|
+
/* @__PURE__ */ r(
|
|
470
470
|
"span",
|
|
471
471
|
{
|
|
472
472
|
style: {
|
|
@@ -484,95 +484,112 @@ const je = ({
|
|
|
484
484
|
}, _e = ({
|
|
485
485
|
session: u
|
|
486
486
|
}) => {
|
|
487
|
-
const { renderer: o, actionQueue: t, micMuted: f, volume: h, setInactivityActive:
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}, [
|
|
487
|
+
const { renderer: o, actionQueue: t, micMuted: f, volume: h, setInactivityActive: d, loadedActions: x } = u, M = A(!1), { state: p, audioTrack: m } = xe(), v = we(), i = Ae(v.localParticipant), c = A(null), R = A(x);
|
|
488
|
+
b(() => {
|
|
489
|
+
R.current = x;
|
|
490
|
+
}, [x]), b(() => {
|
|
491
|
+
const n = v.localParticipant;
|
|
492
|
+
if (!o || !n) return;
|
|
493
|
+
const s = new TextEncoder();
|
|
494
|
+
return o.onOneshotComplete((D) => {
|
|
495
|
+
const z = s.encode(
|
|
496
|
+
JSON.stringify({
|
|
497
|
+
type: "ACTION_FINISHED",
|
|
498
|
+
action: D
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
n.publishData(z, {
|
|
502
|
+
reliable: !0
|
|
503
|
+
}).catch(($) => {
|
|
504
|
+
console.error("[LiveKitAvatarProvider] Failed to publish action completion:", $);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
}, [o, v.localParticipant]), b(() => {
|
|
491
508
|
if (!t) return;
|
|
492
|
-
const
|
|
509
|
+
const n = new Se({
|
|
493
510
|
threshold: 8e-3,
|
|
494
511
|
analyseIntervalMs: 30,
|
|
495
512
|
speechStartFrames: 1,
|
|
496
513
|
speechPauseFrames: 30,
|
|
497
514
|
turnEndFrames: 50
|
|
498
515
|
});
|
|
499
|
-
return
|
|
516
|
+
return c.current = n, n.on("speechStart", () => {
|
|
500
517
|
t.setTurnActive(!0), t.setSpeechState("speaking");
|
|
501
|
-
}),
|
|
518
|
+
}), n.on("turnEnd", () => {
|
|
502
519
|
t.setTurnActive(!1);
|
|
503
520
|
}), () => {
|
|
504
|
-
|
|
521
|
+
n.stop(), c.current = null;
|
|
505
522
|
};
|
|
506
|
-
}, [t]),
|
|
507
|
-
const
|
|
508
|
-
if (
|
|
523
|
+
}, [t]), b(() => {
|
|
524
|
+
const n = c.current;
|
|
525
|
+
if (n)
|
|
509
526
|
if (m?.publication?.track) {
|
|
510
|
-
const
|
|
511
|
-
|
|
527
|
+
const s = m.publication.track.mediaStreamTrack;
|
|
528
|
+
s && n.start(s);
|
|
512
529
|
} else
|
|
513
|
-
|
|
530
|
+
n.stop();
|
|
514
531
|
}, [m?.publication?.track]);
|
|
515
|
-
const a =
|
|
516
|
-
return
|
|
532
|
+
const a = A(null);
|
|
533
|
+
return b(() => {
|
|
517
534
|
if (!t) return;
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
a.current = null,
|
|
535
|
+
const n = p;
|
|
536
|
+
n === "speaking" ? (a.current && (clearTimeout(a.current), a.current = null), t.setTurnActive(!0), t.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (a.current && (clearTimeout(a.current), a.current = null), c.current?.endTurn(), t.setTurnActive(!1)) : n === "thinking" && (a.current || (a.current = setTimeout(() => {
|
|
537
|
+
a.current = null, c.current?.endTurn(), t.setTurnActive(!1);
|
|
521
538
|
}, 500)));
|
|
522
|
-
}, [p, t]),
|
|
539
|
+
}, [p, t]), b(() => () => {
|
|
523
540
|
a.current && clearTimeout(a.current);
|
|
524
|
-
}, []),
|
|
541
|
+
}, []), ke((n) => {
|
|
525
542
|
try {
|
|
526
|
-
const L = new TextDecoder().decode(
|
|
527
|
-
if (
|
|
528
|
-
const
|
|
529
|
-
if (!
|
|
543
|
+
const L = new TextDecoder().decode(n.payload), D = JSON.parse(L);
|
|
544
|
+
if (D.type === "AVATAR_UPDATE") {
|
|
545
|
+
const z = D.action;
|
|
546
|
+
if (!R.current.has(z))
|
|
530
547
|
return;
|
|
531
|
-
t?.dispatch(
|
|
548
|
+
t?.dispatch(z);
|
|
532
549
|
}
|
|
533
|
-
} catch (
|
|
534
|
-
console.error("[LiveKitAvatarProvider] Failed to parse data message:",
|
|
550
|
+
} catch (s) {
|
|
551
|
+
console.error("[LiveKitAvatarProvider] Failed to parse data message:", s);
|
|
535
552
|
}
|
|
536
|
-
}),
|
|
537
|
-
|
|
538
|
-
}, [i,
|
|
553
|
+
}), b(() => {
|
|
554
|
+
d(!(p === "speaking") && !i);
|
|
555
|
+
}, [i, d, p]), b(() => {
|
|
539
556
|
if (!t) return;
|
|
540
|
-
const
|
|
541
|
-
(!
|
|
542
|
-
}, [m, p, t]),
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
console.error("[LiveKitAvatarProvider] Failed to set mic state:",
|
|
557
|
+
const n = !!m;
|
|
558
|
+
(!n || p === "disconnected") && (c.current?.endTurn(), t.forceListening()), M.current = n;
|
|
559
|
+
}, [m, p, t]), b(() => {
|
|
560
|
+
const n = v.localParticipant;
|
|
561
|
+
n && n.setMicrophoneEnabled(!f).catch((s) => {
|
|
562
|
+
console.error("[LiveKitAvatarProvider] Failed to set mic state:", s);
|
|
546
563
|
});
|
|
547
|
-
}, [f,
|
|
564
|
+
}, [f, v.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Te, { volume: h }) });
|
|
548
565
|
}, He = ({
|
|
549
566
|
avatarId: u,
|
|
550
567
|
apiKey: o,
|
|
551
568
|
api: t,
|
|
552
569
|
livekitUrl: f,
|
|
553
570
|
sessionDuration: h,
|
|
554
|
-
inactivityTimeout:
|
|
555
|
-
style:
|
|
571
|
+
inactivityTimeout: d,
|
|
572
|
+
style: x,
|
|
556
573
|
className: M,
|
|
557
574
|
loadingContent: p,
|
|
558
575
|
customControls: m,
|
|
559
|
-
customStatusBadge:
|
|
576
|
+
customStatusBadge: v
|
|
560
577
|
}) => {
|
|
561
|
-
const i =
|
|
578
|
+
const i = Ue({
|
|
562
579
|
avatarId: u,
|
|
563
580
|
apiKey: o,
|
|
564
581
|
api: t,
|
|
565
582
|
livekitUrl: f,
|
|
566
583
|
sessionDuration: h,
|
|
567
|
-
inactivityTimeout:
|
|
584
|
+
inactivityTimeout: d
|
|
568
585
|
}), {
|
|
569
|
-
token:
|
|
570
|
-
isConnected:
|
|
586
|
+
token: c,
|
|
587
|
+
isConnected: R,
|
|
571
588
|
avatarDimensions: a,
|
|
572
|
-
disconnect:
|
|
573
|
-
startSessionTimer:
|
|
589
|
+
disconnect: n,
|
|
590
|
+
startSessionTimer: s
|
|
574
591
|
} = i;
|
|
575
|
-
return /* @__PURE__ */
|
|
592
|
+
return /* @__PURE__ */ S(
|
|
576
593
|
"section",
|
|
577
594
|
{
|
|
578
595
|
className: M,
|
|
@@ -590,11 +607,11 @@ const je = ({
|
|
|
590
607
|
width: "auto",
|
|
591
608
|
maxWidth: "100%",
|
|
592
609
|
aspectRatio: a ? `${a.width} / ${a.height}` : "3 / 4",
|
|
593
|
-
...
|
|
610
|
+
...x
|
|
594
611
|
},
|
|
595
612
|
children: [
|
|
596
|
-
/* @__PURE__ */
|
|
597
|
-
/* @__PURE__ */
|
|
613
|
+
/* @__PURE__ */ r($e, { session: i, loadingContent: p }),
|
|
614
|
+
/* @__PURE__ */ S(
|
|
598
615
|
"div",
|
|
599
616
|
{
|
|
600
617
|
style: {
|
|
@@ -608,7 +625,7 @@ const je = ({
|
|
|
608
625
|
padding: 16
|
|
609
626
|
},
|
|
610
627
|
children: [
|
|
611
|
-
/* @__PURE__ */
|
|
628
|
+
/* @__PURE__ */ S(
|
|
612
629
|
"div",
|
|
613
630
|
{
|
|
614
631
|
style: {
|
|
@@ -618,28 +635,28 @@ const je = ({
|
|
|
618
635
|
justifyContent: "space-between"
|
|
619
636
|
},
|
|
620
637
|
children: [
|
|
621
|
-
|
|
622
|
-
/* @__PURE__ */
|
|
638
|
+
v ? v(i) : /* @__PURE__ */ r(je, { session: i }),
|
|
639
|
+
/* @__PURE__ */ r("div", {})
|
|
623
640
|
]
|
|
624
641
|
}
|
|
625
642
|
),
|
|
626
|
-
m ? m(i) : /* @__PURE__ */
|
|
643
|
+
m ? m(i) : /* @__PURE__ */ r(Fe, { session: i })
|
|
627
644
|
]
|
|
628
645
|
}
|
|
629
646
|
),
|
|
630
|
-
/* @__PURE__ */
|
|
631
|
-
|
|
647
|
+
/* @__PURE__ */ r("div", { style: { display: "none" }, children: c && f && /* @__PURE__ */ r(
|
|
648
|
+
Ie,
|
|
632
649
|
{
|
|
633
650
|
serverUrl: f,
|
|
634
|
-
token:
|
|
651
|
+
token: c,
|
|
635
652
|
connect: !0,
|
|
636
653
|
video: !1,
|
|
637
654
|
audio: !0,
|
|
638
655
|
onConnected: () => {
|
|
639
|
-
i.markConnected(),
|
|
656
|
+
i.markConnected(), s();
|
|
640
657
|
},
|
|
641
|
-
onDisconnected:
|
|
642
|
-
children: /* @__PURE__ */
|
|
658
|
+
onDisconnected: n,
|
|
659
|
+
children: /* @__PURE__ */ r(_e, { session: i })
|
|
643
660
|
}
|
|
644
661
|
) })
|
|
645
662
|
]
|
|
@@ -647,11 +664,11 @@ const je = ({
|
|
|
647
664
|
);
|
|
648
665
|
};
|
|
649
666
|
export {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
667
|
+
$e as AvatarCanvas,
|
|
668
|
+
Fe as AvatarControls,
|
|
669
|
+
je as AvatarStatusBadge,
|
|
653
670
|
_e as LiveKitAvatarProvider,
|
|
654
671
|
He as LiveKitAvatarSession,
|
|
655
|
-
|
|
672
|
+
Ue as useAvatarSession
|
|
656
673
|
};
|
|
657
674
|
//# sourceMappingURL=zeroweight-renderer-react.es.js.map
|