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