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