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