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