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