@zeroweight/react 0.2.27 → 0.2.28
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/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useAvatarSession.d.ts.map +1 -1
- package/dist/zeroweight-renderer-react.cjs.js +4 -4
- package/dist/zeroweight-renderer-react.cjs.js.map +1 -1
- package/dist/zeroweight-renderer-react.es.js +178 -181
- package/dist/zeroweight-renderer-react.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import { useMemo as ve, useRef as A, useState as
|
|
1
|
+
import { useMemo as ve, useRef as A, useState as v, useCallback as w, useEffect as y } from "react";
|
|
2
2
|
import { ZeroWeightRenderer as ye, ActionQueue as be, VoiceActivityDetector as Se } from "@zeroweight/renderer";
|
|
3
|
-
import { jsxs as
|
|
3
|
+
import { jsxs as b, jsx as r, Fragment as P } from "react/jsx-runtime";
|
|
4
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
|
|
7
|
-
const Le = 3e4, De = 120, ze = "wss://prod-project-pazuyq69.livekit.cloud",
|
|
8
|
-
|
|
9
|
-
return `${u[Math.floor(Math.random() * u.length)]}${o[Math.floor(Math.random() * o.length)]}${t}`;
|
|
10
|
-
};
|
|
11
|
-
function Ue(u) {
|
|
6
|
+
import { Loader2 as V, 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", Y = "https://api.zeroweight.ai";
|
|
8
|
+
function Pe(S) {
|
|
12
9
|
const {
|
|
13
|
-
avatarId:
|
|
10
|
+
avatarId: a,
|
|
14
11
|
apiKey: t = null,
|
|
15
12
|
api: f,
|
|
16
|
-
livekitUrl:
|
|
13
|
+
livekitUrl: g = ze,
|
|
17
14
|
sessionDuration: d = De,
|
|
18
15
|
inactivityTimeout: x = Le
|
|
19
|
-
} =
|
|
16
|
+
} = S, M = g, u = ve(() => {
|
|
20
17
|
if (f) return f;
|
|
21
18
|
const e = t ? { "X-ZW-Api-Key": t } : void 0;
|
|
22
19
|
return {
|
|
23
|
-
getBundle: async (
|
|
20
|
+
getBundle: async (p) => {
|
|
24
21
|
const k = await fetch(
|
|
25
|
-
`${
|
|
26
|
-
|
|
22
|
+
`${Y}/avatars/bundle/${encodeURIComponent(
|
|
23
|
+
p
|
|
27
24
|
)}`,
|
|
28
25
|
{ headers: e }
|
|
29
26
|
);
|
|
@@ -33,101 +30,101 @@ function Ue(u) {
|
|
|
33
30
|
);
|
|
34
31
|
return k.json();
|
|
35
32
|
},
|
|
36
|
-
getLiveKitToken: async (
|
|
37
|
-
const
|
|
38
|
-
avatar_id:
|
|
39
|
-
name:
|
|
40
|
-
}),
|
|
41
|
-
`${
|
|
33
|
+
getLiveKitToken: async (p) => {
|
|
34
|
+
const k = new URLSearchParams({
|
|
35
|
+
avatar_id: p,
|
|
36
|
+
name: "anonymuous"
|
|
37
|
+
}), l = await fetch(
|
|
38
|
+
`${Y}/livekit/token?${k.toString()}`,
|
|
42
39
|
{ headers: e }
|
|
43
40
|
);
|
|
44
|
-
if (!
|
|
41
|
+
if (!l.ok)
|
|
45
42
|
throw new Error(
|
|
46
|
-
`Failed to fetch LiveKit token (${
|
|
43
|
+
`Failed to fetch LiveKit token (${l.status} ${l.statusText})`
|
|
47
44
|
);
|
|
48
|
-
return
|
|
45
|
+
return l.json();
|
|
49
46
|
}
|
|
50
47
|
};
|
|
51
|
-
}, [f, t]),
|
|
48
|
+
}, [f, t]), h = A(null), m = A(null), i = A(null), c = A(null), [R, o] = v("idle"), [n, s] = v(null), [E, L] = v(
|
|
52
49
|
/* @__PURE__ */ new Set(["listening"])
|
|
53
|
-
), [
|
|
50
|
+
), [D, F] = v({
|
|
54
51
|
listening: { kind: "looped" },
|
|
55
52
|
speaking: { kind: "looped" }
|
|
56
|
-
}), [te, B] =
|
|
57
|
-
}), [ie, oe] =
|
|
58
|
-
const e =
|
|
53
|
+
}), [te, B] = v(!1), [ne, H] = v(null), [_, U] = v(!1), [j, Q] = v(!1), [re, $] = v(d), I = A(null), K = A(() => {
|
|
54
|
+
}), [ie, oe] = v(!1), [ae, q] = v(0.8), C = A(null), O = R === "ready", J = w(() => {
|
|
55
|
+
const e = h.current;
|
|
59
56
|
if (!e) return null;
|
|
60
|
-
let
|
|
61
|
-
return
|
|
57
|
+
let p = e.querySelector("canvas");
|
|
58
|
+
return p || (p = document.createElement("canvas"), p.style.width = "100%", p.style.height = "100%", p.style.display = "block", e.appendChild(p)), m.current = p, p;
|
|
62
59
|
}, []);
|
|
63
|
-
|
|
60
|
+
y(() => {
|
|
64
61
|
let e = !1;
|
|
65
62
|
return (async () => {
|
|
66
63
|
const k = J();
|
|
67
64
|
if (!k) return;
|
|
68
|
-
const
|
|
69
|
-
i.current =
|
|
70
|
-
const
|
|
71
|
-
|
|
65
|
+
const l = new ye();
|
|
66
|
+
i.current = l;
|
|
67
|
+
const W = new be((T, z) => {
|
|
68
|
+
l.play(T, z);
|
|
72
69
|
});
|
|
73
|
-
c.current =
|
|
74
|
-
e ||
|
|
75
|
-
}),
|
|
76
|
-
e || s({ width: T, height:
|
|
77
|
-
}),
|
|
78
|
-
e ||
|
|
79
|
-
const
|
|
80
|
-
return
|
|
70
|
+
c.current = W, l.on("stateChanged", (T) => {
|
|
71
|
+
e || o(T);
|
|
72
|
+
}), l.on("dimensions", (T, z) => {
|
|
73
|
+
e || s({ width: T, height: z });
|
|
74
|
+
}), l.on("actionLoaded", (T) => {
|
|
75
|
+
e || L((z) => {
|
|
76
|
+
const X = new Set(z);
|
|
77
|
+
return X.add(T), X;
|
|
81
78
|
});
|
|
82
|
-
}),
|
|
79
|
+
}), l.on("allActionsLoaded", () => {
|
|
83
80
|
e || B(!1);
|
|
84
|
-
}),
|
|
85
|
-
e || (
|
|
81
|
+
}), l.on("ready", () => {
|
|
82
|
+
e || (F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata()));
|
|
86
83
|
});
|
|
87
84
|
try {
|
|
88
85
|
B(!0);
|
|
89
|
-
const T = await
|
|
90
|
-
if (e || (await
|
|
91
|
-
|
|
86
|
+
const T = await u.getBundle(a);
|
|
87
|
+
if (e || (await l.init(k, { payload: T.payload }), e)) return;
|
|
88
|
+
F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata());
|
|
92
89
|
} catch (T) {
|
|
93
90
|
console.error("[useAvatarSession] Init failed:", T);
|
|
94
91
|
}
|
|
95
92
|
})(), () => {
|
|
96
93
|
e = !0, i.current?.destroy(), i.current = null, c.current = null;
|
|
97
94
|
};
|
|
98
|
-
}, [
|
|
95
|
+
}, [a, J, u]);
|
|
99
96
|
const Z = A(!1);
|
|
100
|
-
|
|
101
|
-
O && i.current &&
|
|
102
|
-
}, [O,
|
|
97
|
+
y(() => {
|
|
98
|
+
O && i.current && E.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
|
|
99
|
+
}, [O, E]);
|
|
103
100
|
const se = w(async () => {
|
|
104
|
-
if (!(
|
|
105
|
-
|
|
101
|
+
if (!(_ || j)) {
|
|
102
|
+
U(!0);
|
|
106
103
|
try {
|
|
107
104
|
await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
108
|
-
const e =
|
|
109
|
-
H(
|
|
105
|
+
const e = await u.getLiveKitToken(a);
|
|
106
|
+
H(e.token);
|
|
110
107
|
} catch (e) {
|
|
111
|
-
console.error("[useAvatarSession] Failed to connect:", e),
|
|
108
|
+
console.error("[useAvatarSession] Failed to connect:", e), U(!1);
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
|
-
}, [
|
|
115
|
-
I.current && (clearInterval(I.current), I.current = null),
|
|
111
|
+
}, [_, j, a, u]), N = w(() => {
|
|
112
|
+
I.current && (clearInterval(I.current), I.current = null), $(d), C.current && (clearTimeout(C.current), C.current = null), H(null), Q(!1), U(!1), c.current?.forceListening();
|
|
116
113
|
}, [d]);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}, [
|
|
114
|
+
y(() => {
|
|
115
|
+
K.current = N;
|
|
116
|
+
}, [N]);
|
|
120
117
|
const ce = w(() => {
|
|
121
|
-
Q(!0),
|
|
118
|
+
Q(!0), U(!1);
|
|
122
119
|
}, []), le = w(() => {
|
|
123
|
-
I.current && clearInterval(I.current),
|
|
124
|
-
|
|
120
|
+
I.current && clearInterval(I.current), $(d), I.current = setInterval(() => {
|
|
121
|
+
$((e) => e <= 1 ? (clearInterval(I.current), I.current = null, setTimeout(() => K.current(), 0), 0) : e - 1);
|
|
125
122
|
}, 1e3);
|
|
126
123
|
}, [d]), de = w((e) => {
|
|
127
|
-
const
|
|
128
|
-
return `${
|
|
124
|
+
const p = Math.floor(e / 60).toString().padStart(2, "0"), k = (e % 60).toString().padStart(2, "0");
|
|
125
|
+
return `${p}:${k}`;
|
|
129
126
|
}, []);
|
|
130
|
-
|
|
127
|
+
y(() => () => {
|
|
131
128
|
I.current && clearInterval(I.current);
|
|
132
129
|
}, []);
|
|
133
130
|
const ue = w(
|
|
@@ -137,7 +134,7 @@ function Ue(u) {
|
|
|
137
134
|
return;
|
|
138
135
|
}
|
|
139
136
|
C.current || (C.current = setTimeout(() => {
|
|
140
|
-
C.current = null,
|
|
137
|
+
C.current = null, K.current();
|
|
141
138
|
}, x));
|
|
142
139
|
},
|
|
143
140
|
[x]
|
|
@@ -153,25 +150,25 @@ function Ue(u) {
|
|
|
153
150
|
i.current?.play(e, "listening");
|
|
154
151
|
}, []);
|
|
155
152
|
return {
|
|
156
|
-
containerRef:
|
|
153
|
+
containerRef: h,
|
|
157
154
|
renderer: i.current,
|
|
158
155
|
actionQueue: c.current,
|
|
159
156
|
rendererState: R,
|
|
160
157
|
avatarDimensions: n,
|
|
161
|
-
loadedActions:
|
|
162
|
-
actionMetadata:
|
|
158
|
+
loadedActions: E,
|
|
159
|
+
actionMetadata: D,
|
|
163
160
|
isLoadingActions: te,
|
|
164
161
|
isEngineReady: O,
|
|
165
162
|
token: ne,
|
|
166
|
-
isConnecting:
|
|
167
|
-
isConnected:
|
|
163
|
+
isConnecting: _,
|
|
164
|
+
isConnected: j,
|
|
168
165
|
livekitUrl: M,
|
|
169
166
|
timeRemaining: re,
|
|
170
167
|
formatTime: de,
|
|
171
168
|
micMuted: ie,
|
|
172
169
|
volume: ae,
|
|
173
170
|
connect: se,
|
|
174
|
-
disconnect:
|
|
171
|
+
disconnect: N,
|
|
175
172
|
toggleMic: pe,
|
|
176
173
|
setVolume: fe,
|
|
177
174
|
toggleVolume: ge,
|
|
@@ -182,11 +179,11 @@ function Ue(u) {
|
|
|
182
179
|
setInactivityActive: ue
|
|
183
180
|
};
|
|
184
181
|
}
|
|
185
|
-
const
|
|
186
|
-
session:
|
|
187
|
-
style:
|
|
182
|
+
const Fe = ({
|
|
183
|
+
session: S,
|
|
184
|
+
style: a,
|
|
188
185
|
loadingContent: t
|
|
189
|
-
}) => /* @__PURE__ */
|
|
186
|
+
}) => /* @__PURE__ */ b(
|
|
190
187
|
"div",
|
|
191
188
|
{
|
|
192
189
|
style: {
|
|
@@ -200,7 +197,7 @@ const $e = ({
|
|
|
200
197
|
justifyContent: "center",
|
|
201
198
|
alignItems: "center",
|
|
202
199
|
overflow: "hidden",
|
|
203
|
-
...
|
|
200
|
+
...a
|
|
204
201
|
},
|
|
205
202
|
children: [
|
|
206
203
|
/* @__PURE__ */ r("style", { children: `
|
|
@@ -216,14 +213,14 @@ const $e = ({
|
|
|
216
213
|
/* @__PURE__ */ r(
|
|
217
214
|
"div",
|
|
218
215
|
{
|
|
219
|
-
ref:
|
|
216
|
+
ref: S.containerRef,
|
|
220
217
|
style: {
|
|
221
218
|
position: "relative",
|
|
222
219
|
width: "100%",
|
|
223
220
|
height: "100%",
|
|
224
221
|
transition: "all 0.5s ease-in-out"
|
|
225
222
|
},
|
|
226
|
-
children: !
|
|
223
|
+
children: !S.isEngineReady && /* @__PURE__ */ r(
|
|
227
224
|
"div",
|
|
228
225
|
{
|
|
229
226
|
style: {
|
|
@@ -236,7 +233,7 @@ const $e = ({
|
|
|
236
233
|
backdropFilter: "blur(4px)",
|
|
237
234
|
zIndex: 10
|
|
238
235
|
},
|
|
239
|
-
children: t || /* @__PURE__ */
|
|
236
|
+
children: t || /* @__PURE__ */ b(
|
|
240
237
|
"div",
|
|
241
238
|
{
|
|
242
239
|
style: {
|
|
@@ -247,7 +244,7 @@ const $e = ({
|
|
|
247
244
|
},
|
|
248
245
|
children: [
|
|
249
246
|
/* @__PURE__ */ r(
|
|
250
|
-
|
|
247
|
+
V,
|
|
251
248
|
{
|
|
252
249
|
style: {
|
|
253
250
|
width: 40,
|
|
@@ -280,7 +277,7 @@ const $e = ({
|
|
|
280
277
|
)
|
|
281
278
|
]
|
|
282
279
|
}
|
|
283
|
-
),
|
|
280
|
+
), G = {
|
|
284
281
|
flexShrink: 0,
|
|
285
282
|
borderRadius: 9999,
|
|
286
283
|
padding: 16,
|
|
@@ -305,31 +302,31 @@ const $e = ({
|
|
|
305
302
|
transition: "all 0.3s",
|
|
306
303
|
border: "none",
|
|
307
304
|
cursor: "pointer"
|
|
308
|
-
},
|
|
309
|
-
session:
|
|
310
|
-
style:
|
|
305
|
+
}, Ue = ({
|
|
306
|
+
session: S,
|
|
307
|
+
style: a
|
|
311
308
|
}) => {
|
|
312
309
|
const {
|
|
313
310
|
micMuted: t,
|
|
314
311
|
toggleMic: f,
|
|
315
|
-
isConnected:
|
|
312
|
+
isConnected: g,
|
|
316
313
|
isConnecting: d,
|
|
317
314
|
isEngineReady: x,
|
|
318
315
|
loadedActions: M,
|
|
319
|
-
connect:
|
|
320
|
-
disconnect:
|
|
321
|
-
} =
|
|
322
|
-
...
|
|
316
|
+
connect: u,
|
|
317
|
+
disconnect: h
|
|
318
|
+
} = S, [m, i] = v(!1), [c, R] = v(!1), o = x && M.has("listening") && M.has("speaking"), n = t ? {
|
|
319
|
+
...G,
|
|
323
320
|
background: "rgba(239,68,68,0.1)",
|
|
324
321
|
color: "#f87171",
|
|
325
322
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
|
|
326
|
-
...
|
|
323
|
+
...m ? { background: "rgba(239,68,68,0.2)" } : {}
|
|
327
324
|
} : {
|
|
328
|
-
...
|
|
329
|
-
background:
|
|
325
|
+
...G,
|
|
326
|
+
background: m ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
|
|
330
327
|
color: "#fff",
|
|
331
328
|
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
|
|
332
|
-
}, s =
|
|
329
|
+
}, s = g ? {
|
|
333
330
|
...ee,
|
|
334
331
|
background: c ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
|
|
335
332
|
boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
|
|
@@ -339,7 +336,7 @@ const $e = ({
|
|
|
339
336
|
boxShadow: "0 0 30px rgba(236,72,153,0.3)",
|
|
340
337
|
opacity: c ? 0.9 : 1
|
|
341
338
|
};
|
|
342
|
-
return (d || !
|
|
339
|
+
return (d || !o) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ b(
|
|
343
340
|
"div",
|
|
344
341
|
{
|
|
345
342
|
style: {
|
|
@@ -350,7 +347,7 @@ const $e = ({
|
|
|
350
347
|
alignItems: "center",
|
|
351
348
|
gap: 16,
|
|
352
349
|
paddingBottom: 16,
|
|
353
|
-
...
|
|
350
|
+
...a
|
|
354
351
|
},
|
|
355
352
|
children: [
|
|
356
353
|
/* @__PURE__ */ r("style", { children: `
|
|
@@ -359,7 +356,7 @@ const $e = ({
|
|
|
359
356
|
to { transform: rotate(360deg); }
|
|
360
357
|
}
|
|
361
358
|
` }),
|
|
362
|
-
/* @__PURE__ */
|
|
359
|
+
/* @__PURE__ */ b(
|
|
363
360
|
"div",
|
|
364
361
|
{
|
|
365
362
|
style: {
|
|
@@ -388,21 +385,21 @@ const $e = ({
|
|
|
388
385
|
"button",
|
|
389
386
|
{
|
|
390
387
|
type: "button",
|
|
391
|
-
onClick:
|
|
388
|
+
onClick: g ? h : u,
|
|
392
389
|
onMouseEnter: () => R(!0),
|
|
393
390
|
onMouseLeave: () => R(!1),
|
|
394
|
-
disabled: !
|
|
391
|
+
disabled: !g && (d || !o),
|
|
395
392
|
style: s,
|
|
396
|
-
children: d ? /* @__PURE__ */
|
|
397
|
-
/* @__PURE__ */ r(
|
|
393
|
+
children: d ? /* @__PURE__ */ b(P, { children: [
|
|
394
|
+
/* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
398
395
|
/* @__PURE__ */ r("span", { children: "Connecting..." })
|
|
399
|
-
] }) : !
|
|
400
|
-
/* @__PURE__ */ r(
|
|
396
|
+
] }) : !g && !o ? /* @__PURE__ */ b(P, { children: [
|
|
397
|
+
/* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
401
398
|
/* @__PURE__ */ r("span", { children: "Loading Avatar..." })
|
|
402
|
-
] }) :
|
|
399
|
+
] }) : g ? /* @__PURE__ */ b(P, { children: [
|
|
403
400
|
/* @__PURE__ */ r(Me, { size: 20 }),
|
|
404
401
|
/* @__PURE__ */ r("span", { children: "End Session" })
|
|
405
|
-
] }) : /* @__PURE__ */
|
|
402
|
+
] }) : /* @__PURE__ */ b(P, { children: [
|
|
406
403
|
/* @__PURE__ */ r(Ee, { size: 20 }),
|
|
407
404
|
/* @__PURE__ */ r("span", { children: "Start Session" })
|
|
408
405
|
] })
|
|
@@ -414,10 +411,10 @@ const $e = ({
|
|
|
414
411
|
]
|
|
415
412
|
}
|
|
416
413
|
);
|
|
417
|
-
},
|
|
418
|
-
session:
|
|
414
|
+
}, _e = ({
|
|
415
|
+
session: S
|
|
419
416
|
}) => {
|
|
420
|
-
const { isConnected:
|
|
417
|
+
const { isConnected: a, timeRemaining: t, formatTime: f } = S, g = a && t <= 30, d = a && t > 30 && t <= 60, x = {
|
|
421
418
|
display: "flex",
|
|
422
419
|
alignItems: "center",
|
|
423
420
|
gap: 8,
|
|
@@ -427,7 +424,7 @@ const $e = ({
|
|
|
427
424
|
border: "1px solid",
|
|
428
425
|
pointerEvents: "auto",
|
|
429
426
|
transition: "all 0.3s",
|
|
430
|
-
...
|
|
427
|
+
...g ? {
|
|
431
428
|
background: "rgba(239,68,68,0.3)",
|
|
432
429
|
borderColor: "rgba(239,68,68,0.4)",
|
|
433
430
|
boxShadow: "0 0 15px rgba(239,68,68,0.3)",
|
|
@@ -442,14 +439,14 @@ const $e = ({
|
|
|
442
439
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
443
440
|
}
|
|
444
441
|
};
|
|
445
|
-
return /* @__PURE__ */
|
|
442
|
+
return /* @__PURE__ */ b(P, { children: [
|
|
446
443
|
/* @__PURE__ */ r("style", { children: `
|
|
447
444
|
@keyframes zwr-pulse {
|
|
448
445
|
0%, 100% { opacity: 1; }
|
|
449
446
|
50% { opacity: 0.5; }
|
|
450
447
|
}
|
|
451
448
|
` }),
|
|
452
|
-
/* @__PURE__ */
|
|
449
|
+
/* @__PURE__ */ b("div", { style: x, children: [
|
|
453
450
|
/* @__PURE__ */ r(
|
|
454
451
|
"div",
|
|
455
452
|
{
|
|
@@ -457,7 +454,7 @@ const $e = ({
|
|
|
457
454
|
height: 8,
|
|
458
455
|
width: 8,
|
|
459
456
|
borderRadius: "50%",
|
|
460
|
-
...
|
|
457
|
+
...a ? {
|
|
461
458
|
background: "#22c55e",
|
|
462
459
|
boxShadow: "0 0 10px rgba(34,197,94,0.5)"
|
|
463
460
|
} : {
|
|
@@ -476,35 +473,35 @@ const $e = ({
|
|
|
476
473
|
color: "rgba(255,255,255,0.7)",
|
|
477
474
|
textTransform: "uppercase"
|
|
478
475
|
},
|
|
479
|
-
children:
|
|
476
|
+
children: a ? `Online ${f(t)}` : "Offline"
|
|
480
477
|
}
|
|
481
478
|
)
|
|
482
479
|
] })
|
|
483
480
|
] });
|
|
484
|
-
},
|
|
485
|
-
session:
|
|
481
|
+
}, je = ({
|
|
482
|
+
session: S
|
|
486
483
|
}) => {
|
|
487
|
-
const { renderer:
|
|
488
|
-
|
|
484
|
+
const { renderer: a, actionQueue: t, micMuted: f, volume: g, setInactivityActive: d, loadedActions: x } = S, M = A(!1), { state: u, audioTrack: h } = xe(), m = we(), i = Ae(m.localParticipant), c = A(null), R = A(x);
|
|
485
|
+
y(() => {
|
|
489
486
|
R.current = x;
|
|
490
|
-
}, [x]),
|
|
491
|
-
const n =
|
|
492
|
-
if (!
|
|
487
|
+
}, [x]), y(() => {
|
|
488
|
+
const n = m.localParticipant;
|
|
489
|
+
if (!a || !n) return;
|
|
493
490
|
const s = new TextEncoder();
|
|
494
|
-
return
|
|
495
|
-
const
|
|
491
|
+
return a.onOneshotComplete((L) => {
|
|
492
|
+
const D = s.encode(
|
|
496
493
|
JSON.stringify({
|
|
497
494
|
type: "ACTION_FINISHED",
|
|
498
|
-
action:
|
|
495
|
+
action: L
|
|
499
496
|
})
|
|
500
497
|
);
|
|
501
|
-
n.publishData(
|
|
498
|
+
n.publishData(D, {
|
|
502
499
|
reliable: !0
|
|
503
|
-
}).catch((
|
|
504
|
-
console.error("[LiveKitAvatarProvider] Failed to publish action completion:",
|
|
500
|
+
}).catch((F) => {
|
|
501
|
+
console.error("[LiveKitAvatarProvider] Failed to publish action completion:", F);
|
|
505
502
|
});
|
|
506
503
|
});
|
|
507
|
-
}, [
|
|
504
|
+
}, [a, m.localParticipant]), y(() => {
|
|
508
505
|
if (!t) return;
|
|
509
506
|
const n = new Se({
|
|
510
507
|
threshold: 8e-3,
|
|
@@ -520,76 +517,76 @@ const $e = ({
|
|
|
520
517
|
}), () => {
|
|
521
518
|
n.stop(), c.current = null;
|
|
522
519
|
};
|
|
523
|
-
}, [t]),
|
|
520
|
+
}, [t]), y(() => {
|
|
524
521
|
const n = c.current;
|
|
525
522
|
if (n)
|
|
526
|
-
if (
|
|
527
|
-
const s =
|
|
523
|
+
if (h?.publication?.track) {
|
|
524
|
+
const s = h.publication.track.mediaStreamTrack;
|
|
528
525
|
s && n.start(s);
|
|
529
526
|
} else
|
|
530
527
|
n.stop();
|
|
531
|
-
}, [
|
|
532
|
-
const
|
|
533
|
-
return
|
|
528
|
+
}, [h?.publication?.track]);
|
|
529
|
+
const o = A(null);
|
|
530
|
+
return y(() => {
|
|
534
531
|
if (!t) return;
|
|
535
|
-
const n =
|
|
536
|
-
n === "speaking" ? (
|
|
537
|
-
|
|
532
|
+
const n = u;
|
|
533
|
+
n === "speaking" ? (o.current && (clearTimeout(o.current), o.current = null), t.setTurnActive(!0), t.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (o.current && (clearTimeout(o.current), o.current = null), c.current?.endTurn(), t.setTurnActive(!1)) : n === "thinking" && (o.current || (o.current = setTimeout(() => {
|
|
534
|
+
o.current = null, c.current?.endTurn(), t.setTurnActive(!1);
|
|
538
535
|
}, 500)));
|
|
539
|
-
}, [
|
|
540
|
-
|
|
536
|
+
}, [u, t]), y(() => () => {
|
|
537
|
+
o.current && clearTimeout(o.current);
|
|
541
538
|
}, []), ke((n) => {
|
|
542
539
|
try {
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
-
const
|
|
546
|
-
if (!R.current.has(
|
|
540
|
+
const E = new TextDecoder().decode(n.payload), L = JSON.parse(E);
|
|
541
|
+
if (L.type === "AVATAR_UPDATE") {
|
|
542
|
+
const D = L.action;
|
|
543
|
+
if (!R.current.has(D))
|
|
547
544
|
return;
|
|
548
|
-
t?.dispatch(
|
|
545
|
+
t?.dispatch(D);
|
|
549
546
|
}
|
|
550
547
|
} catch (s) {
|
|
551
548
|
console.error("[LiveKitAvatarProvider] Failed to parse data message:", s);
|
|
552
549
|
}
|
|
553
|
-
}),
|
|
554
|
-
d(!(
|
|
555
|
-
}, [i, d,
|
|
550
|
+
}), y(() => {
|
|
551
|
+
d(!(u === "speaking") && !i);
|
|
552
|
+
}, [i, d, u]), y(() => {
|
|
556
553
|
if (!t) return;
|
|
557
|
-
const n = !!
|
|
558
|
-
(!n ||
|
|
559
|
-
}, [
|
|
560
|
-
const n =
|
|
554
|
+
const n = !!h;
|
|
555
|
+
(!n || u === "disconnected") && (c.current?.endTurn(), t.forceListening()), M.current = n;
|
|
556
|
+
}, [h, u, t]), y(() => {
|
|
557
|
+
const n = m.localParticipant;
|
|
561
558
|
n && n.setMicrophoneEnabled(!f).catch((s) => {
|
|
562
559
|
console.error("[LiveKitAvatarProvider] Failed to set mic state:", s);
|
|
563
560
|
});
|
|
564
|
-
}, [f,
|
|
565
|
-
},
|
|
566
|
-
avatarId:
|
|
567
|
-
apiKey:
|
|
561
|
+
}, [f, m.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Te, { volume: g }) });
|
|
562
|
+
}, Be = ({
|
|
563
|
+
avatarId: S,
|
|
564
|
+
apiKey: a,
|
|
568
565
|
api: t,
|
|
569
566
|
livekitUrl: f,
|
|
570
|
-
sessionDuration:
|
|
567
|
+
sessionDuration: g,
|
|
571
568
|
inactivityTimeout: d,
|
|
572
569
|
style: x,
|
|
573
570
|
className: M,
|
|
574
|
-
loadingContent:
|
|
575
|
-
customControls:
|
|
576
|
-
customStatusBadge:
|
|
571
|
+
loadingContent: u,
|
|
572
|
+
customControls: h,
|
|
573
|
+
customStatusBadge: m
|
|
577
574
|
}) => {
|
|
578
|
-
const i =
|
|
579
|
-
avatarId:
|
|
580
|
-
apiKey:
|
|
575
|
+
const i = Pe({
|
|
576
|
+
avatarId: S,
|
|
577
|
+
apiKey: a,
|
|
581
578
|
api: t,
|
|
582
579
|
livekitUrl: f,
|
|
583
|
-
sessionDuration:
|
|
580
|
+
sessionDuration: g,
|
|
584
581
|
inactivityTimeout: d
|
|
585
582
|
}), {
|
|
586
583
|
token: c,
|
|
587
584
|
isConnected: R,
|
|
588
|
-
avatarDimensions:
|
|
585
|
+
avatarDimensions: o,
|
|
589
586
|
disconnect: n,
|
|
590
587
|
startSessionTimer: s
|
|
591
588
|
} = i;
|
|
592
|
-
return /* @__PURE__ */
|
|
589
|
+
return /* @__PURE__ */ b(
|
|
593
590
|
"section",
|
|
594
591
|
{
|
|
595
592
|
className: M,
|
|
@@ -606,12 +603,12 @@ const $e = ({
|
|
|
606
603
|
height: "80vh",
|
|
607
604
|
width: "auto",
|
|
608
605
|
maxWidth: "100%",
|
|
609
|
-
aspectRatio:
|
|
606
|
+
aspectRatio: o ? `${o.width} / ${o.height}` : "3 / 4",
|
|
610
607
|
...x
|
|
611
608
|
},
|
|
612
609
|
children: [
|
|
613
|
-
/* @__PURE__ */ r(
|
|
614
|
-
/* @__PURE__ */
|
|
610
|
+
/* @__PURE__ */ r(Fe, { session: i, loadingContent: u }),
|
|
611
|
+
/* @__PURE__ */ b(
|
|
615
612
|
"div",
|
|
616
613
|
{
|
|
617
614
|
style: {
|
|
@@ -625,7 +622,7 @@ const $e = ({
|
|
|
625
622
|
padding: 16
|
|
626
623
|
},
|
|
627
624
|
children: [
|
|
628
|
-
/* @__PURE__ */
|
|
625
|
+
/* @__PURE__ */ b(
|
|
629
626
|
"div",
|
|
630
627
|
{
|
|
631
628
|
style: {
|
|
@@ -635,12 +632,12 @@ const $e = ({
|
|
|
635
632
|
justifyContent: "space-between"
|
|
636
633
|
},
|
|
637
634
|
children: [
|
|
638
|
-
|
|
635
|
+
m ? m(i) : /* @__PURE__ */ r(_e, { session: i }),
|
|
639
636
|
/* @__PURE__ */ r("div", {})
|
|
640
637
|
]
|
|
641
638
|
}
|
|
642
639
|
),
|
|
643
|
-
|
|
640
|
+
h ? h(i) : /* @__PURE__ */ r(Ue, { session: i })
|
|
644
641
|
]
|
|
645
642
|
}
|
|
646
643
|
),
|
|
@@ -656,7 +653,7 @@ const $e = ({
|
|
|
656
653
|
i.markConnected(), s();
|
|
657
654
|
},
|
|
658
655
|
onDisconnected: n,
|
|
659
|
-
children: /* @__PURE__ */ r(
|
|
656
|
+
children: /* @__PURE__ */ r(je, { session: i })
|
|
660
657
|
}
|
|
661
658
|
) })
|
|
662
659
|
]
|
|
@@ -664,11 +661,11 @@ const $e = ({
|
|
|
664
661
|
);
|
|
665
662
|
};
|
|
666
663
|
export {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
664
|
+
Fe as AvatarCanvas,
|
|
665
|
+
Ue as AvatarControls,
|
|
666
|
+
_e as AvatarStatusBadge,
|
|
667
|
+
je as LiveKitAvatarProvider,
|
|
668
|
+
Be as LiveKitAvatarSession,
|
|
669
|
+
Pe as useAvatarSession
|
|
673
670
|
};
|
|
674
671
|
//# sourceMappingURL=zeroweight-renderer-react.es.js.map
|