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