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