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