@zeroweight/react 0.2.26 → 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/LiveKitAvatarProvider.d.ts.map +1 -1
- 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 +272 -258
- package/dist/zeroweight-renderer-react.es.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,136 +1,133 @@
|
|
|
1
|
-
import { useMemo as ve, useRef 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
|
|
4
|
-
import { useVoiceAssistant as xe, useLocalParticipant as we, useIsSpeaking as
|
|
3
|
+
import { jsxs as b, jsx as r, Fragment as P } 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
|
|
7
|
-
const Le = 3e4,
|
|
8
|
-
|
|
9
|
-
return `${u[Math.floor(Math.random() * u.length)]}${o[Math.floor(Math.random() * o.length)]}${t}`;
|
|
10
|
-
};
|
|
11
|
-
function $e(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:
|
|
17
|
-
sessionDuration:
|
|
18
|
-
inactivityTimeout:
|
|
19
|
-
} =
|
|
13
|
+
livekitUrl: g = ze,
|
|
14
|
+
sessionDuration: d = De,
|
|
15
|
+
inactivityTimeout: x = Le
|
|
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 (
|
|
24
|
-
const
|
|
25
|
-
`${
|
|
26
|
-
|
|
20
|
+
getBundle: async (p) => {
|
|
21
|
+
const k = await fetch(
|
|
22
|
+
`${Y}/avatars/bundle/${encodeURIComponent(
|
|
23
|
+
p
|
|
27
24
|
)}`,
|
|
28
25
|
{ headers: e }
|
|
29
26
|
);
|
|
30
|
-
if (!
|
|
27
|
+
if (!k.ok)
|
|
31
28
|
throw new Error(
|
|
32
|
-
`Failed to fetch avatar bundle (${
|
|
29
|
+
`Failed to fetch avatar bundle (${k.status} ${k.statusText})`
|
|
33
30
|
);
|
|
34
|
-
return
|
|
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,
|
|
57
|
-
}), [ie,
|
|
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
|
-
const
|
|
67
|
-
if (!
|
|
68
|
-
const
|
|
69
|
-
i.current =
|
|
70
|
-
const
|
|
71
|
-
|
|
63
|
+
const k = J();
|
|
64
|
+
if (!k) return;
|
|
65
|
+
const l = new ye();
|
|
66
|
+
i.current = l;
|
|
67
|
+
const W = new be((T, z) => {
|
|
68
|
+
l.play(T, z);
|
|
72
69
|
});
|
|
73
|
-
|
|
74
|
-
e ||
|
|
75
|
-
}),
|
|
76
|
-
e ||
|
|
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
|
-
}),
|
|
83
|
-
e ||
|
|
84
|
-
}),
|
|
85
|
-
e || (
|
|
79
|
+
}), l.on("allActionsLoaded", () => {
|
|
80
|
+
e || B(!1);
|
|
81
|
+
}), l.on("ready", () => {
|
|
82
|
+
e || (F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata()));
|
|
86
83
|
});
|
|
87
84
|
try {
|
|
88
|
-
|
|
89
|
-
const T = await
|
|
90
|
-
if (e || (await
|
|
91
|
-
|
|
85
|
+
B(!0);
|
|
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
|
-
e = !0, i.current?.destroy(), i.current = null,
|
|
93
|
+
e = !0, i.current?.destroy(), i.current = null, c.current = null;
|
|
97
94
|
};
|
|
98
|
-
}, [
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}, [
|
|
103
|
-
const se =
|
|
104
|
-
if (!(
|
|
105
|
-
|
|
95
|
+
}, [a, J, u]);
|
|
96
|
+
const Z = A(!1);
|
|
97
|
+
y(() => {
|
|
98
|
+
O && i.current && E.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
|
|
99
|
+
}, [O, E]);
|
|
100
|
+
const se = w(async () => {
|
|
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
|
-
|
|
116
|
-
}, [
|
|
117
|
-
|
|
118
|
-
K.current =
|
|
119
|
-
}, [
|
|
120
|
-
const ce =
|
|
121
|
-
Q(!0),
|
|
122
|
-
}, []), le =
|
|
123
|
-
|
|
124
|
-
|
|
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();
|
|
113
|
+
}, [d]);
|
|
114
|
+
y(() => {
|
|
115
|
+
K.current = N;
|
|
116
|
+
}, [N]);
|
|
117
|
+
const ce = w(() => {
|
|
118
|
+
Q(!0), U(!1);
|
|
119
|
+
}, []), le = w(() => {
|
|
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
|
-
}, [
|
|
127
|
-
const
|
|
128
|
-
return `${
|
|
123
|
+
}, [d]), de = w((e) => {
|
|
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
|
-
|
|
131
|
-
|
|
127
|
+
y(() => () => {
|
|
128
|
+
I.current && clearInterval(I.current);
|
|
132
129
|
}, []);
|
|
133
|
-
const ue =
|
|
130
|
+
const ue = w(
|
|
134
131
|
(e) => {
|
|
135
132
|
if (!e) {
|
|
136
133
|
C.current && (clearTimeout(C.current), C.current = null);
|
|
@@ -138,40 +135,40 @@ function $e(u) {
|
|
|
138
135
|
}
|
|
139
136
|
C.current || (C.current = setTimeout(() => {
|
|
140
137
|
C.current = null, K.current();
|
|
141
|
-
},
|
|
138
|
+
}, x));
|
|
142
139
|
},
|
|
143
|
-
[
|
|
144
|
-
), pe =
|
|
145
|
-
|
|
146
|
-
}, []), fe =
|
|
140
|
+
[x]
|
|
141
|
+
), pe = w(() => {
|
|
142
|
+
oe((e) => !e);
|
|
143
|
+
}, []), fe = w((e) => {
|
|
147
144
|
q(e);
|
|
148
|
-
}, []), ge =
|
|
145
|
+
}, []), ge = w(() => {
|
|
149
146
|
q((e) => e > 0 ? 0 : 1);
|
|
150
|
-
}, []), he =
|
|
147
|
+
}, []), he = w(() => {
|
|
151
148
|
i.current?.interrupt();
|
|
152
|
-
}, []), me =
|
|
149
|
+
}, []), me = w((e) => {
|
|
153
150
|
i.current?.play(e, "listening");
|
|
154
151
|
}, []);
|
|
155
152
|
return {
|
|
156
|
-
containerRef:
|
|
153
|
+
containerRef: h,
|
|
157
154
|
renderer: i.current,
|
|
158
|
-
actionQueue:
|
|
159
|
-
rendererState:
|
|
160
|
-
avatarDimensions:
|
|
161
|
-
loadedActions:
|
|
162
|
-
actionMetadata:
|
|
155
|
+
actionQueue: c.current,
|
|
156
|
+
rendererState: R,
|
|
157
|
+
avatarDimensions: n,
|
|
158
|
+
loadedActions: E,
|
|
159
|
+
actionMetadata: D,
|
|
163
160
|
isLoadingActions: te,
|
|
164
|
-
isEngineReady:
|
|
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
|
-
volume:
|
|
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 $e(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,10 +197,10 @@ const je = ({
|
|
|
200
197
|
justifyContent: "center",
|
|
201
198
|
alignItems: "center",
|
|
202
199
|
overflow: "hidden",
|
|
203
|
-
...
|
|
200
|
+
...a
|
|
204
201
|
},
|
|
205
202
|
children: [
|
|
206
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ r("style", { children: `
|
|
207
204
|
@keyframes zwr-spin {
|
|
208
205
|
from { transform: rotate(0deg); }
|
|
209
206
|
to { transform: rotate(360deg); }
|
|
@@ -213,17 +210,17 @@ const je = ({
|
|
|
213
210
|
50% { opacity: 0.5; }
|
|
214
211
|
}
|
|
215
212
|
` }),
|
|
216
|
-
/* @__PURE__ */
|
|
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 je = ({
|
|
|
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: {
|
|
@@ -246,8 +243,8 @@ const je = ({
|
|
|
246
243
|
gap: 16
|
|
247
244
|
},
|
|
248
245
|
children: [
|
|
249
|
-
/* @__PURE__ */
|
|
250
|
-
|
|
246
|
+
/* @__PURE__ */ r(
|
|
247
|
+
V,
|
|
251
248
|
{
|
|
252
249
|
style: {
|
|
253
250
|
width: 40,
|
|
@@ -257,7 +254,7 @@ const je = ({
|
|
|
257
254
|
}
|
|
258
255
|
}
|
|
259
256
|
),
|
|
260
|
-
/* @__PURE__ */
|
|
257
|
+
/* @__PURE__ */ r(
|
|
261
258
|
"div",
|
|
262
259
|
{
|
|
263
260
|
style: {
|
|
@@ -280,7 +277,7 @@ const je = ({
|
|
|
280
277
|
)
|
|
281
278
|
]
|
|
282
279
|
}
|
|
283
|
-
),
|
|
280
|
+
), G = {
|
|
284
281
|
flexShrink: 0,
|
|
285
282
|
borderRadius: 9999,
|
|
286
283
|
padding: 16,
|
|
@@ -305,41 +302,41 @@ const je = ({
|
|
|
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:
|
|
316
|
-
isConnecting:
|
|
317
|
-
isEngineReady:
|
|
312
|
+
isConnected: g,
|
|
313
|
+
isConnecting: d,
|
|
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
|
-
},
|
|
329
|
+
}, s = g ? {
|
|
333
330
|
...ee,
|
|
334
|
-
background:
|
|
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)"
|
|
336
333
|
} : {
|
|
337
334
|
...ee,
|
|
338
335
|
background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
|
|
339
336
|
boxShadow: "0 0 30px rgba(236,72,153,0.3)",
|
|
340
|
-
opacity:
|
|
337
|
+
opacity: c ? 0.9 : 1
|
|
341
338
|
};
|
|
342
|
-
return (
|
|
339
|
+
return (d || !o) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ b(
|
|
343
340
|
"div",
|
|
344
341
|
{
|
|
345
342
|
style: {
|
|
@@ -350,16 +347,16 @@ const je = ({
|
|
|
350
347
|
alignItems: "center",
|
|
351
348
|
gap: 16,
|
|
352
349
|
paddingBottom: 16,
|
|
353
|
-
...
|
|
350
|
+
...a
|
|
354
351
|
},
|
|
355
352
|
children: [
|
|
356
|
-
/* @__PURE__ */
|
|
353
|
+
/* @__PURE__ */ r("style", { children: `
|
|
357
354
|
@keyframes zwr-spin {
|
|
358
355
|
from { transform: rotate(0deg); }
|
|
359
356
|
to { transform: rotate(360deg); }
|
|
360
357
|
}
|
|
361
358
|
` }),
|
|
362
|
-
/* @__PURE__ */
|
|
359
|
+
/* @__PURE__ */ b(
|
|
363
360
|
"div",
|
|
364
361
|
{
|
|
365
362
|
style: {
|
|
@@ -372,39 +369,39 @@ const je = ({
|
|
|
372
369
|
pointerEvents: "auto"
|
|
373
370
|
},
|
|
374
371
|
children: [
|
|
375
|
-
/* @__PURE__ */
|
|
372
|
+
/* @__PURE__ */ r(
|
|
376
373
|
"button",
|
|
377
374
|
{
|
|
378
375
|
type: "button",
|
|
379
376
|
onClick: f,
|
|
380
377
|
onMouseEnter: () => i(!0),
|
|
381
378
|
onMouseLeave: () => i(!1),
|
|
382
|
-
style:
|
|
379
|
+
style: n,
|
|
383
380
|
title: t ? "Unmute mic" : "Mute mic",
|
|
384
|
-
children: t ? /* @__PURE__ */
|
|
381
|
+
children: t ? /* @__PURE__ */ r(Re, { size: 24 }) : /* @__PURE__ */ r(Ce, { size: 24 })
|
|
385
382
|
}
|
|
386
383
|
),
|
|
387
|
-
/* @__PURE__ */
|
|
384
|
+
/* @__PURE__ */ r(
|
|
388
385
|
"button",
|
|
389
386
|
{
|
|
390
387
|
type: "button",
|
|
391
|
-
onClick:
|
|
392
|
-
onMouseEnter: () =>
|
|
393
|
-
onMouseLeave: () =>
|
|
394
|
-
disabled: !
|
|
395
|
-
style:
|
|
396
|
-
children:
|
|
397
|
-
/* @__PURE__ */
|
|
398
|
-
/* @__PURE__ */
|
|
399
|
-
] }) : !
|
|
400
|
-
/* @__PURE__ */
|
|
401
|
-
/* @__PURE__ */
|
|
402
|
-
] }) :
|
|
403
|
-
/* @__PURE__ */
|
|
404
|
-
/* @__PURE__ */
|
|
405
|
-
] }) : /* @__PURE__ */
|
|
406
|
-
/* @__PURE__ */
|
|
407
|
-
/* @__PURE__ */
|
|
388
|
+
onClick: g ? h : u,
|
|
389
|
+
onMouseEnter: () => R(!0),
|
|
390
|
+
onMouseLeave: () => R(!1),
|
|
391
|
+
disabled: !g && (d || !o),
|
|
392
|
+
style: s,
|
|
393
|
+
children: d ? /* @__PURE__ */ b(P, { children: [
|
|
394
|
+
/* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
395
|
+
/* @__PURE__ */ r("span", { children: "Connecting..." })
|
|
396
|
+
] }) : !g && !o ? /* @__PURE__ */ b(P, { children: [
|
|
397
|
+
/* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
|
|
398
|
+
/* @__PURE__ */ r("span", { children: "Loading Avatar..." })
|
|
399
|
+
] }) : g ? /* @__PURE__ */ b(P, { children: [
|
|
400
|
+
/* @__PURE__ */ r(Me, { size: 20 }),
|
|
401
|
+
/* @__PURE__ */ r("span", { children: "End Session" })
|
|
402
|
+
] }) : /* @__PURE__ */ b(P, { children: [
|
|
403
|
+
/* @__PURE__ */ r(Ee, { size: 20 }),
|
|
404
|
+
/* @__PURE__ */ r("span", { children: "Start Session" })
|
|
408
405
|
] })
|
|
409
406
|
}
|
|
410
407
|
)
|
|
@@ -414,10 +411,10 @@ const je = ({
|
|
|
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,12 +424,12 @@ const je = ({
|
|
|
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)",
|
|
434
431
|
animation: "zwr-pulse 2s ease-in-out infinite"
|
|
435
|
-
} :
|
|
432
|
+
} : d ? {
|
|
436
433
|
background: "rgba(249,115,22,0.2)",
|
|
437
434
|
borderColor: "rgba(249,115,22,0.3)",
|
|
438
435
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
@@ -442,22 +439,22 @@ const je = ({
|
|
|
442
439
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
|
|
443
440
|
}
|
|
444
441
|
};
|
|
445
|
-
return /* @__PURE__ */
|
|
446
|
-
/* @__PURE__ */
|
|
442
|
+
return /* @__PURE__ */ b(P, { children: [
|
|
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__ */
|
|
453
|
-
/* @__PURE__ */
|
|
449
|
+
/* @__PURE__ */ b("div", { style: x, children: [
|
|
450
|
+
/* @__PURE__ */ r(
|
|
454
451
|
"div",
|
|
455
452
|
{
|
|
456
453
|
style: {
|
|
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
|
} : {
|
|
@@ -466,7 +463,7 @@ const je = ({
|
|
|
466
463
|
}
|
|
467
464
|
}
|
|
468
465
|
),
|
|
469
|
-
/* @__PURE__ */
|
|
466
|
+
/* @__PURE__ */ r(
|
|
470
467
|
"span",
|
|
471
468
|
{
|
|
472
469
|
style: {
|
|
@@ -476,103 +473,120 @@ const je = ({
|
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
}, [
|
|
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(() => {
|
|
486
|
+
R.current = x;
|
|
487
|
+
}, [x]), y(() => {
|
|
488
|
+
const n = m.localParticipant;
|
|
489
|
+
if (!a || !n) return;
|
|
490
|
+
const s = new TextEncoder();
|
|
491
|
+
return a.onOneshotComplete((L) => {
|
|
492
|
+
const D = s.encode(
|
|
493
|
+
JSON.stringify({
|
|
494
|
+
type: "ACTION_FINISHED",
|
|
495
|
+
action: L
|
|
496
|
+
})
|
|
497
|
+
);
|
|
498
|
+
n.publishData(D, {
|
|
499
|
+
reliable: !0
|
|
500
|
+
}).catch((F) => {
|
|
501
|
+
console.error("[LiveKitAvatarProvider] Failed to publish action completion:", F);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
}, [a, m.localParticipant]), y(() => {
|
|
491
505
|
if (!t) return;
|
|
492
|
-
const
|
|
506
|
+
const n = new Se({
|
|
493
507
|
threshold: 8e-3,
|
|
494
508
|
analyseIntervalMs: 30,
|
|
495
509
|
speechStartFrames: 1,
|
|
496
510
|
speechPauseFrames: 30,
|
|
497
511
|
turnEndFrames: 50
|
|
498
512
|
});
|
|
499
|
-
return
|
|
513
|
+
return c.current = n, n.on("speechStart", () => {
|
|
500
514
|
t.setTurnActive(!0), t.setSpeechState("speaking");
|
|
501
|
-
}),
|
|
515
|
+
}), n.on("turnEnd", () => {
|
|
502
516
|
t.setTurnActive(!1);
|
|
503
517
|
}), () => {
|
|
504
|
-
|
|
518
|
+
n.stop(), c.current = null;
|
|
505
519
|
};
|
|
506
|
-
}, [t]),
|
|
507
|
-
const
|
|
508
|
-
if (
|
|
509
|
-
if (
|
|
510
|
-
const
|
|
511
|
-
|
|
520
|
+
}, [t]), y(() => {
|
|
521
|
+
const n = c.current;
|
|
522
|
+
if (n)
|
|
523
|
+
if (h?.publication?.track) {
|
|
524
|
+
const s = h.publication.track.mediaStreamTrack;
|
|
525
|
+
s && n.start(s);
|
|
512
526
|
} else
|
|
513
|
-
|
|
514
|
-
}, [
|
|
515
|
-
const
|
|
516
|
-
return
|
|
527
|
+
n.stop();
|
|
528
|
+
}, [h?.publication?.track]);
|
|
529
|
+
const o = A(null);
|
|
530
|
+
return y(() => {
|
|
517
531
|
if (!t) return;
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
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);
|
|
521
535
|
}, 500)));
|
|
522
|
-
}, [
|
|
523
|
-
|
|
524
|
-
}, []),
|
|
536
|
+
}, [u, t]), y(() => () => {
|
|
537
|
+
o.current && clearTimeout(o.current);
|
|
538
|
+
}, []), ke((n) => {
|
|
525
539
|
try {
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
528
|
-
const
|
|
529
|
-
if (!
|
|
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))
|
|
530
544
|
return;
|
|
531
|
-
t?.dispatch(
|
|
545
|
+
t?.dispatch(D);
|
|
532
546
|
}
|
|
533
|
-
} catch (
|
|
534
|
-
console.error("[LiveKitAvatarProvider] Failed to parse data message:",
|
|
547
|
+
} catch (s) {
|
|
548
|
+
console.error("[LiveKitAvatarProvider] Failed to parse data message:", s);
|
|
535
549
|
}
|
|
536
|
-
}),
|
|
537
|
-
|
|
538
|
-
}, [i,
|
|
550
|
+
}), y(() => {
|
|
551
|
+
d(!(u === "speaking") && !i);
|
|
552
|
+
}, [i, d, u]), y(() => {
|
|
539
553
|
if (!t) return;
|
|
540
|
-
const
|
|
541
|
-
(!
|
|
542
|
-
}, [
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
console.error("[LiveKitAvatarProvider] Failed to set mic state:",
|
|
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;
|
|
558
|
+
n && n.setMicrophoneEnabled(!f).catch((s) => {
|
|
559
|
+
console.error("[LiveKitAvatarProvider] Failed to set mic state:", s);
|
|
546
560
|
});
|
|
547
|
-
}, [f,
|
|
548
|
-
},
|
|
549
|
-
avatarId:
|
|
550
|
-
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,
|
|
551
565
|
api: t,
|
|
552
566
|
livekitUrl: f,
|
|
553
|
-
sessionDuration:
|
|
554
|
-
inactivityTimeout:
|
|
555
|
-
style:
|
|
567
|
+
sessionDuration: g,
|
|
568
|
+
inactivityTimeout: d,
|
|
569
|
+
style: x,
|
|
556
570
|
className: M,
|
|
557
|
-
loadingContent:
|
|
558
|
-
customControls:
|
|
559
|
-
customStatusBadge:
|
|
571
|
+
loadingContent: u,
|
|
572
|
+
customControls: h,
|
|
573
|
+
customStatusBadge: m
|
|
560
574
|
}) => {
|
|
561
|
-
const i =
|
|
562
|
-
avatarId:
|
|
563
|
-
apiKey:
|
|
575
|
+
const i = Pe({
|
|
576
|
+
avatarId: S,
|
|
577
|
+
apiKey: a,
|
|
564
578
|
api: t,
|
|
565
579
|
livekitUrl: f,
|
|
566
|
-
sessionDuration:
|
|
567
|
-
inactivityTimeout:
|
|
580
|
+
sessionDuration: g,
|
|
581
|
+
inactivityTimeout: d
|
|
568
582
|
}), {
|
|
569
|
-
token:
|
|
570
|
-
isConnected:
|
|
571
|
-
avatarDimensions:
|
|
572
|
-
disconnect:
|
|
573
|
-
startSessionTimer:
|
|
583
|
+
token: c,
|
|
584
|
+
isConnected: R,
|
|
585
|
+
avatarDimensions: o,
|
|
586
|
+
disconnect: n,
|
|
587
|
+
startSessionTimer: s
|
|
574
588
|
} = i;
|
|
575
|
-
return /* @__PURE__ */
|
|
589
|
+
return /* @__PURE__ */ b(
|
|
576
590
|
"section",
|
|
577
591
|
{
|
|
578
592
|
className: M,
|
|
@@ -589,12 +603,12 @@ const je = ({
|
|
|
589
603
|
height: "80vh",
|
|
590
604
|
width: "auto",
|
|
591
605
|
maxWidth: "100%",
|
|
592
|
-
aspectRatio:
|
|
593
|
-
...
|
|
606
|
+
aspectRatio: o ? `${o.width} / ${o.height}` : "3 / 4",
|
|
607
|
+
...x
|
|
594
608
|
},
|
|
595
609
|
children: [
|
|
596
|
-
/* @__PURE__ */
|
|
597
|
-
/* @__PURE__ */
|
|
610
|
+
/* @__PURE__ */ r(Fe, { session: i, loadingContent: u }),
|
|
611
|
+
/* @__PURE__ */ b(
|
|
598
612
|
"div",
|
|
599
613
|
{
|
|
600
614
|
style: {
|
|
@@ -608,7 +622,7 @@ const je = ({
|
|
|
608
622
|
padding: 16
|
|
609
623
|
},
|
|
610
624
|
children: [
|
|
611
|
-
/* @__PURE__ */
|
|
625
|
+
/* @__PURE__ */ b(
|
|
612
626
|
"div",
|
|
613
627
|
{
|
|
614
628
|
style: {
|
|
@@ -618,28 +632,28 @@ const je = ({
|
|
|
618
632
|
justifyContent: "space-between"
|
|
619
633
|
},
|
|
620
634
|
children: [
|
|
621
|
-
|
|
622
|
-
/* @__PURE__ */
|
|
635
|
+
m ? m(i) : /* @__PURE__ */ r(_e, { session: i }),
|
|
636
|
+
/* @__PURE__ */ r("div", {})
|
|
623
637
|
]
|
|
624
638
|
}
|
|
625
639
|
),
|
|
626
|
-
|
|
640
|
+
h ? h(i) : /* @__PURE__ */ r(Ue, { session: i })
|
|
627
641
|
]
|
|
628
642
|
}
|
|
629
643
|
),
|
|
630
|
-
/* @__PURE__ */
|
|
631
|
-
|
|
644
|
+
/* @__PURE__ */ r("div", { style: { display: "none" }, children: c && f && /* @__PURE__ */ r(
|
|
645
|
+
Ie,
|
|
632
646
|
{
|
|
633
647
|
serverUrl: f,
|
|
634
|
-
token:
|
|
648
|
+
token: c,
|
|
635
649
|
connect: !0,
|
|
636
650
|
video: !1,
|
|
637
651
|
audio: !0,
|
|
638
652
|
onConnected: () => {
|
|
639
|
-
i.markConnected(),
|
|
653
|
+
i.markConnected(), s();
|
|
640
654
|
},
|
|
641
|
-
onDisconnected:
|
|
642
|
-
children: /* @__PURE__ */
|
|
655
|
+
onDisconnected: n,
|
|
656
|
+
children: /* @__PURE__ */ r(je, { session: i })
|
|
643
657
|
}
|
|
644
658
|
) })
|
|
645
659
|
]
|
|
@@ -647,11 +661,11 @@ const je = ({
|
|
|
647
661
|
);
|
|
648
662
|
};
|
|
649
663
|
export {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
664
|
+
Fe as AvatarCanvas,
|
|
665
|
+
Ue as AvatarControls,
|
|
666
|
+
_e as AvatarStatusBadge,
|
|
667
|
+
je as LiveKitAvatarProvider,
|
|
668
|
+
Be as LiveKitAvatarSession,
|
|
669
|
+
Pe as useAvatarSession
|
|
656
670
|
};
|
|
657
671
|
//# sourceMappingURL=zeroweight-renderer-react.es.js.map
|