orb-ui 0.6.0 → 0.6.1
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 -4
- package/dist/adapters/audio-level.d.ts +5 -0
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/livekit/browser.d.ts +5 -0
- package/dist/adapters/livekit/index.d.ts +9 -2
- package/dist/adapters/pipecat/index.d.ts +16 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +260 -241
- package/dist/livekit-CukEeYFK.js +316 -0
- package/dist/livekit-Dt-QZ6Gs.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -1
- package/dist/livekit-adapter.js +4 -2
- package/package.json +1 -1
- package/dist/livekit-Dasur3lv.js +0 -240
- package/dist/livekit-Ro6A52eb.cjs +0 -1
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
//#region src/adapters/types.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = Math.min(e / .5, 1);
|
|
4
|
+
return t **= 1.3, t;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/adapters/audio-level.ts
|
|
8
|
+
var t = {
|
|
9
|
+
noiseFloor: 0,
|
|
10
|
+
gain: 4,
|
|
11
|
+
exponent: .8,
|
|
12
|
+
attack: 1,
|
|
13
|
+
release: 1
|
|
14
|
+
};
|
|
15
|
+
function n(e, t, n) {
|
|
16
|
+
return Math.min(n, Math.max(t, e));
|
|
17
|
+
}
|
|
18
|
+
function r(e, t) {
|
|
19
|
+
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
20
|
+
}
|
|
21
|
+
function i(e) {
|
|
22
|
+
let i = typeof e == "function" ? e() : e;
|
|
23
|
+
return {
|
|
24
|
+
noiseFloor: n(r(i?.noiseFloor, t.noiseFloor), 0, 1),
|
|
25
|
+
gain: Math.max(0, r(i?.gain, t.gain)),
|
|
26
|
+
exponent: Math.max(.01, r(i?.exponent, t.exponent)),
|
|
27
|
+
attack: n(r(i?.attack, t.attack), 0, 1),
|
|
28
|
+
release: n(r(i?.release, t.release), 0, 1)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function a(e, t, r) {
|
|
32
|
+
let a = Number.isFinite(e) ? n(e, 0, 1) : 0, o = i(r), s = n((a <= o.noiseFloor ? 0 : a - o.noiseFloor) * o.gain, 0, 1) ** +o.exponent, c = s > t ? o.attack : o.release;
|
|
33
|
+
return {
|
|
34
|
+
raw: a,
|
|
35
|
+
shaped: s,
|
|
36
|
+
normalized: n(t + (s - t) * c, 0, 1)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function o(e, t, n) {
|
|
40
|
+
let r;
|
|
41
|
+
try {
|
|
42
|
+
if (r = t(), !r) return;
|
|
43
|
+
let i = r;
|
|
44
|
+
i.state === "suspended" && i.resume().catch(() => void 0);
|
|
45
|
+
let a = i.createMediaStreamSource(new MediaStream([e])), o = i.createAnalyser();
|
|
46
|
+
o.fftSize = 512, o.smoothingTimeConstant = .25, a.connect(o);
|
|
47
|
+
let s = new Float32Array(o.fftSize), c = setInterval(() => {
|
|
48
|
+
o.getFloatTimeDomainData(s);
|
|
49
|
+
let e = 0;
|
|
50
|
+
for (let t of s) e += t * t;
|
|
51
|
+
n(Math.sqrt(e / s.length));
|
|
52
|
+
}, 33);
|
|
53
|
+
return { async stop() {
|
|
54
|
+
clearInterval(c);
|
|
55
|
+
try {
|
|
56
|
+
a.disconnect(), o.disconnect();
|
|
57
|
+
} finally {
|
|
58
|
+
i.state !== "closed" && await i.close();
|
|
59
|
+
}
|
|
60
|
+
} };
|
|
61
|
+
} catch {
|
|
62
|
+
r?.state !== "closed" && r?.close().catch(() => void 0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/adapters/livekit/index.ts
|
|
68
|
+
var s = 4, c = {
|
|
69
|
+
fftSize: 512,
|
|
70
|
+
smoothingTimeConstant: .25,
|
|
71
|
+
minDecibels: -85,
|
|
72
|
+
maxDecibels: -20
|
|
73
|
+
}, l = {
|
|
74
|
+
noiseFloor: .015,
|
|
75
|
+
gain: 4.6,
|
|
76
|
+
exponent: 1.15,
|
|
77
|
+
attack: .1,
|
|
78
|
+
release: .48
|
|
79
|
+
};
|
|
80
|
+
function u(e) {
|
|
81
|
+
switch (e) {
|
|
82
|
+
case "speaking": return "speaking";
|
|
83
|
+
case "thinking": return "thinking";
|
|
84
|
+
case "listening":
|
|
85
|
+
case "idle": return "listening";
|
|
86
|
+
case "connecting":
|
|
87
|
+
case "pre-connect-buffering":
|
|
88
|
+
case "initializing": return "connecting";
|
|
89
|
+
case "disconnected": return "idle";
|
|
90
|
+
case "failed": return "error";
|
|
91
|
+
default: return "idle";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function d(e) {
|
|
95
|
+
return "RoomClass" in e;
|
|
96
|
+
}
|
|
97
|
+
function f(e) {
|
|
98
|
+
return typeof e == "function" ? e() : e;
|
|
99
|
+
}
|
|
100
|
+
function p(e) {
|
|
101
|
+
if (!e) return {};
|
|
102
|
+
let t = {}, n = (e, n) => {
|
|
103
|
+
n !== void 0 && (t[e] = n);
|
|
104
|
+
};
|
|
105
|
+
return n("roomName", f(e.roomName)), n("participantName", f(e.participantName)), n("participantIdentity", f(e.participantIdentity)), n("participantMetadata", f(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", f(e.agentName)), n("agentMetadata", f(e.agentMetadata)), n("deployment", f(e.deployment)), t;
|
|
106
|
+
}
|
|
107
|
+
function m(e) {
|
|
108
|
+
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
109
|
+
return e;
|
|
110
|
+
}
|
|
111
|
+
async function h(e) {
|
|
112
|
+
let t = p(e.tokenOptions);
|
|
113
|
+
return typeof e.getConnectionDetails == "function" ? m(await e.getConnectionDetails(t)) : e.tokenSource ? m(await e.tokenSource.fetch(t)) : m({
|
|
114
|
+
serverUrl: e.serverUrl,
|
|
115
|
+
participantToken: e.participantToken
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function g(e) {
|
|
119
|
+
for (let [, t] of e.remoteParticipants) if (!t.isLocal && (t.kind === s || t.attributes?.["lk.agent.state"] !== void 0)) return t;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
function _(e, t, n) {
|
|
123
|
+
let r = e.off;
|
|
124
|
+
if (r) {
|
|
125
|
+
r.call(e, t, n);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
e.removeListener?.call(e, t, n);
|
|
129
|
+
}
|
|
130
|
+
function v(e, t, n) {
|
|
131
|
+
e.on.call(e, t, n);
|
|
132
|
+
}
|
|
133
|
+
function y(t) {
|
|
134
|
+
let n = d(t), r = t.createAudioAnalyser, i = { current: n ? null : t.room }, o = /* @__PURE__ */ new Set(), f = {
|
|
135
|
+
state: "idle",
|
|
136
|
+
volume: 0,
|
|
137
|
+
inputVolume: 0,
|
|
138
|
+
outputVolume: 0
|
|
139
|
+
}, p = "idle", m = null, y = null, b = null, x = null, S = null, C = null, w = null, T = 0, E = null;
|
|
140
|
+
function D(e) {
|
|
141
|
+
f = e, o.forEach((t) => t(e));
|
|
142
|
+
}
|
|
143
|
+
function O(e) {
|
|
144
|
+
D({
|
|
145
|
+
...f,
|
|
146
|
+
...e,
|
|
147
|
+
state: e.state ?? f.state
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function k() {
|
|
151
|
+
let e = typeof t.outputVolumeCalibration == "function" ? t.outputVolumeCalibration() : t.outputVolumeCalibration;
|
|
152
|
+
return {
|
|
153
|
+
...l,
|
|
154
|
+
...e
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function A(e) {
|
|
158
|
+
let n = a(e, T, k);
|
|
159
|
+
return T = n.normalized, t.onOutputVolumeSample?.(n), n.normalized;
|
|
160
|
+
}
|
|
161
|
+
function j() {
|
|
162
|
+
T = 0, O({
|
|
163
|
+
volume: 0,
|
|
164
|
+
outputVolume: 0
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function M({ emitZero: e = !0 } = {}) {
|
|
168
|
+
S &&= (clearInterval(S), null), x &&= (x.cleanup().catch(() => {}), null), e && O({
|
|
169
|
+
volume: 0,
|
|
170
|
+
inputVolume: 0
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function N(t) {
|
|
174
|
+
if (!(m === t && x)) {
|
|
175
|
+
M({ emitZero: !1 }), m = t;
|
|
176
|
+
try {
|
|
177
|
+
x = r(t, c);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
S = setInterval(() => {
|
|
183
|
+
if (!x || p !== "listening") return;
|
|
184
|
+
let t = e(x.calculateVolume());
|
|
185
|
+
O({
|
|
186
|
+
volume: t,
|
|
187
|
+
inputVolume: t,
|
|
188
|
+
outputVolume: 0
|
|
189
|
+
});
|
|
190
|
+
}, 33);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function P({ emitZero: e = !0 } = {}) {
|
|
194
|
+
w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), T = 0, e && O({
|
|
195
|
+
volume: 0,
|
|
196
|
+
outputVolume: 0
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function F(e) {
|
|
200
|
+
P();
|
|
201
|
+
try {
|
|
202
|
+
C = r(e, c);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
w = setInterval(() => {
|
|
208
|
+
if (!C || p !== "speaking") return;
|
|
209
|
+
let e = A(C.calculateVolume());
|
|
210
|
+
O({
|
|
211
|
+
volume: e,
|
|
212
|
+
inputVolume: 0,
|
|
213
|
+
outputVolume: e
|
|
214
|
+
});
|
|
215
|
+
}, 33);
|
|
216
|
+
}
|
|
217
|
+
function I(e) {
|
|
218
|
+
p = e, O({
|
|
219
|
+
state: e,
|
|
220
|
+
volume: 0,
|
|
221
|
+
inputVolume: 0,
|
|
222
|
+
outputVolume: 0
|
|
223
|
+
}), e === "speaking" && y ? F(y) : e !== "speaking" && P({ emitZero: !1 });
|
|
224
|
+
}
|
|
225
|
+
function L(e) {
|
|
226
|
+
b || typeof document > "u" || (b = e.attach(), b.id = "orb-ui-livekit-agent-audio", document.body.appendChild(b));
|
|
227
|
+
}
|
|
228
|
+
function R() {
|
|
229
|
+
b &&= (b.remove(), null);
|
|
230
|
+
}
|
|
231
|
+
function z(e) {
|
|
232
|
+
y = e, L(e), p === "speaking" && F(e);
|
|
233
|
+
}
|
|
234
|
+
function B(e) {
|
|
235
|
+
N(e);
|
|
236
|
+
}
|
|
237
|
+
function V(e) {
|
|
238
|
+
let t = e.getTrackPublication?.("microphone");
|
|
239
|
+
t?.track && B(t.track);
|
|
240
|
+
}
|
|
241
|
+
function H(e) {
|
|
242
|
+
let t = u(e);
|
|
243
|
+
t !== p && I(t);
|
|
244
|
+
}
|
|
245
|
+
function U(e) {
|
|
246
|
+
let t = e.attributes?.["lk.agent.state"];
|
|
247
|
+
t && H(t);
|
|
248
|
+
let n = e.getTrackPublication("microphone");
|
|
249
|
+
n?.track && z(n.track);
|
|
250
|
+
}
|
|
251
|
+
function W(e) {
|
|
252
|
+
if (E) return;
|
|
253
|
+
let t = (e, t) => {
|
|
254
|
+
if (t.isLocal) return;
|
|
255
|
+
let n = e["lk.agent.state"];
|
|
256
|
+
n && H(n);
|
|
257
|
+
}, n = (e, t, n) => {
|
|
258
|
+
n.isLocal || !(n.kind === s || n.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || z(e);
|
|
259
|
+
}, r = (e) => {
|
|
260
|
+
y === e && (y = null, R(), P());
|
|
261
|
+
}, i = (e) => {
|
|
262
|
+
e.source !== "microphone" || !e.track || B(e.track);
|
|
263
|
+
}, a = (e) => {
|
|
264
|
+
e.source === "microphone" && (m = null, M());
|
|
265
|
+
}, o = () => {
|
|
266
|
+
m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), I("idle");
|
|
267
|
+
};
|
|
268
|
+
if (v(e, "participantAttributesChanged", t), v(e, "trackSubscribed", n), v(e, "trackUnsubscribed", r), v(e, "localTrackPublished", i), v(e, "localTrackUnpublished", a), v(e, "disconnected", o), E = () => {
|
|
269
|
+
_(e, "participantAttributesChanged", t), _(e, "trackSubscribed", n), _(e, "trackUnsubscribed", r), _(e, "localTrackPublished", i), _(e, "localTrackUnpublished", a), _(e, "disconnected", o);
|
|
270
|
+
}, V(e.localParticipant), e.state === "connected") {
|
|
271
|
+
let t = g(e);
|
|
272
|
+
t ? U(t) : I("connecting");
|
|
273
|
+
} else I("idle");
|
|
274
|
+
}
|
|
275
|
+
function G() {
|
|
276
|
+
E?.(), E = null, m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), O({
|
|
277
|
+
volume: 0,
|
|
278
|
+
inputVolume: 0,
|
|
279
|
+
outputVolume: 0
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
let K = (e) => {
|
|
283
|
+
o.add(e), e(f);
|
|
284
|
+
let t = i.current;
|
|
285
|
+
return t && W(t), () => {
|
|
286
|
+
o.delete(e), o.size === 0 && G();
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
return n ? {
|
|
290
|
+
subscribe: K,
|
|
291
|
+
async start() {
|
|
292
|
+
if (i.current) return;
|
|
293
|
+
let e = t, n = new e.RoomClass();
|
|
294
|
+
I("connecting");
|
|
295
|
+
try {
|
|
296
|
+
let t = await h(e);
|
|
297
|
+
if (await n.connect(t.serverUrl, t.participantToken, e.connectOptions), i.current = n, W(n), e.enableMicrophone !== !1) {
|
|
298
|
+
let e = (await n.localParticipant.setMicrophoneEnabled(!0))?.track ?? n.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
299
|
+
e && B(e);
|
|
300
|
+
}
|
|
301
|
+
} catch (e) {
|
|
302
|
+
throw console.error("[orb-ui/livekit] connect failed:", e), i.current === n && G(), n.disconnect(), i.current = null, I("error"), j(), O({ error: e }), e;
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
async stop() {
|
|
306
|
+
let e = i.current;
|
|
307
|
+
if (!e) {
|
|
308
|
+
I("idle");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
G(), e.disconnect(), i.current = null, I("idle");
|
|
312
|
+
}
|
|
313
|
+
} : { subscribe: K };
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
export { o as i, t as n, a as r, y as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t={noiseFloor:0,gain:4,exponent:.8,attack:1,release:1};function n(e,t,n){return Math.min(n,Math.max(t,e))}function r(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function i(e){let i=typeof e==`function`?e():e;return{noiseFloor:n(r(i?.noiseFloor,t.noiseFloor),0,1),gain:Math.max(0,r(i?.gain,t.gain)),exponent:Math.max(.01,r(i?.exponent,t.exponent)),attack:n(r(i?.attack,t.attack),0,1),release:n(r(i?.release,t.release),0,1)}}function a(e,t,r){let a=Number.isFinite(e)?n(e,0,1):0,o=i(r),s=n((a<=o.noiseFloor?0:a-o.noiseFloor)*o.gain,0,1)**+o.exponent,c=s>t?o.attack:o.release;return{raw:a,shaped:s,normalized:n(t+(s-t)*c,0,1)}}function o(e,t,n){let r;try{if(r=t(),!r)return;let i=r;i.state===`suspended`&&i.resume().catch(()=>void 0);let a=i.createMediaStreamSource(new MediaStream([e])),o=i.createAnalyser();o.fftSize=512,o.smoothingTimeConstant=.25,a.connect(o);let s=new Float32Array(o.fftSize),c=setInterval(()=>{o.getFloatTimeDomainData(s);let e=0;for(let t of s)e+=t*t;n(Math.sqrt(e/s.length))},33);return{async stop(){clearInterval(c);try{a.disconnect(),o.disconnect()}finally{i.state!==`closed`&&await i.close()}}}}catch{r?.state!==`closed`&&r?.close().catch(()=>void 0);return}}var s=4,c={fftSize:512,smoothingTimeConstant:.25,minDecibels:-85,maxDecibels:-20},l={noiseFloor:.015,gain:4.6,exponent:1.15,attack:.1,release:.48};function u(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function d(e){return`RoomClass`in e}function f(e){return typeof e==`function`?e():e}function p(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,f(e.roomName)),n(`participantName`,f(e.participantName)),n(`participantIdentity`,f(e.participantIdentity)),n(`participantMetadata`,f(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,f(e.agentName)),n(`agentMetadata`,f(e.agentMetadata)),n(`deployment`,f(e.deployment)),t}function m(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function h(e){let t=p(e.tokenOptions);return typeof e.getConnectionDetails==`function`?m(await e.getConnectionDetails(t)):e.tokenSource?m(await e.tokenSource.fetch(t)):m({serverUrl:e.serverUrl,participantToken:e.participantToken})}function g(e){for(let[,t]of e.remoteParticipants)if(!t.isLocal&&(t.kind===s||t.attributes?.[`lk.agent.state`]!==void 0))return t;return null}function _(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function v(e,t,n){e.on.call(e,t,n)}function y(t){let n=d(t),r=t.createAudioAnalyser,i={current:n?null:t.room},o=new Set,f={state:`idle`,volume:0,inputVolume:0,outputVolume:0},p=`idle`,m=null,y=null,b=null,x=null,S=null,C=null,w=null,T=0,E=null;function D(e){f=e,o.forEach(t=>t(e))}function O(e){D({...f,...e,state:e.state??f.state})}function k(){let e=typeof t.outputVolumeCalibration==`function`?t.outputVolumeCalibration():t.outputVolumeCalibration;return{...l,...e}}function A(e){let n=a(e,T,k);return T=n.normalized,t.onOutputVolumeSample?.(n),n.normalized}function j(){T=0,O({volume:0,outputVolume:0})}function M({emitZero:e=!0}={}){S&&=(clearInterval(S),null),x&&=(x.cleanup().catch(()=>{}),null),e&&O({volume:0,inputVolume:0})}function N(t){if(!(m===t&&x)){M({emitZero:!1}),m=t;try{x=r(t,c)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}S=setInterval(()=>{if(!x||p!==`listening`)return;let t=e(x.calculateVolume());O({volume:t,inputVolume:t,outputVolume:0})},33)}}function P({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),T=0,e&&O({volume:0,outputVolume:0})}function F(e){P();try{C=r(e,c)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||p!==`speaking`)return;let e=A(C.calculateVolume());O({volume:e,inputVolume:0,outputVolume:e})},33)}function I(e){p=e,O({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&y?F(y):e!==`speaking`&&P({emitZero:!1})}function L(e){b||typeof document>`u`||(b=e.attach(),b.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(b))}function R(){b&&=(b.remove(),null)}function z(e){y=e,L(e),p===`speaking`&&F(e)}function B(e){N(e)}function V(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&B(t.track)}function H(e){let t=u(e);t!==p&&I(t)}function U(e){let t=e.attributes?.[`lk.agent.state`];t&&H(t);let n=e.getTrackPublication(`microphone`);n?.track&&z(n.track)}function W(e){if(E)return;let t=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&H(n)},n=(e,t,n)=>{n.isLocal||!(n.kind===s||n.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||z(e)},r=e=>{y===e&&(y=null,R(),P())},i=e=>{e.source!==`microphone`||!e.track||B(e.track)},a=e=>{e.source===`microphone`&&(m=null,M())},o=()=>{m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),I(`idle`)};if(v(e,`participantAttributesChanged`,t),v(e,`trackSubscribed`,n),v(e,`trackUnsubscribed`,r),v(e,`localTrackPublished`,i),v(e,`localTrackUnpublished`,a),v(e,`disconnected`,o),E=()=>{_(e,`participantAttributesChanged`,t),_(e,`trackSubscribed`,n),_(e,`trackUnsubscribed`,r),_(e,`localTrackPublished`,i),_(e,`localTrackUnpublished`,a),_(e,`disconnected`,o)},V(e.localParticipant),e.state===`connected`){let t=g(e);t?U(t):I(`connecting`)}else I(`idle`)}function G(){E?.(),E=null,m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),O({volume:0,inputVolume:0,outputVolume:0})}let K=e=>{o.add(e),e(f);let t=i.current;return t&&W(t),()=>{o.delete(e),o.size===0&&G()}};return n?{subscribe:K,async start(){if(i.current)return;let e=t,n=new e.RoomClass;I(`connecting`);try{let t=await h(e);if(await n.connect(t.serverUrl,t.participantToken,e.connectOptions),i.current=n,W(n),e.enableMicrophone!==!1){let e=(await n.localParticipant.setMicrophoneEnabled(!0))?.track??n.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&B(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),i.current===n&&G(),n.disconnect(),i.current=null,I(`error`),j(),O({error:e}),e}},async stop(){let e=i.current;if(!e){I(`idle`);return}G(),e.disconnect(),i.current=null,I(`idle`)}}:{subscribe:K}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});
|
package/dist/livekit-adapter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-Dt-QZ6Gs.cjs");let t=require("livekit-client");function n(){return`orb-${globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random().toString(36).slice(2)}`}`}function r(r){let{agentMetadata:i,agentName:a,connectOptions:o,deployment:s,enableMicrophone:c,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p=n,outputVolumeCalibration:m,onOutputVolumeSample:h}=r;return e.t({tokenSource:r.tokenEndpoint===void 0?t.TokenSource.sandboxTokenServer(r.sandboxId,r.sandboxOptions):t.TokenSource.endpoint(r.tokenEndpoint,r.tokenEndpointOptions),tokenOptions:{agentMetadata:i,agentName:a,deployment:s,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p},connectOptions:o,enableMicrophone:c,outputVolumeCalibration:m,onOutputVolumeSample:h,createAudioAnalyser:t.createAudioAnalyser,RoomClass:t.Room})}exports.createLiveKitAdapter=r;
|
package/dist/livekit-adapter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as e } from "./livekit-
|
|
1
|
+
import { t as e } from "./livekit-CukEeYFK.js";
|
|
2
2
|
import { Room as t, TokenSource as n, createAudioAnalyser as r } from "livekit-client";
|
|
3
3
|
//#region src/adapters/livekit/browser.ts
|
|
4
4
|
function i() {
|
|
5
5
|
return `orb-${globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`}`;
|
|
6
6
|
}
|
|
7
7
|
function a(a) {
|
|
8
|
-
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i } = a;
|
|
8
|
+
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i, outputVolumeCalibration: g, onOutputVolumeSample: _ } = a;
|
|
9
9
|
return e({
|
|
10
10
|
tokenSource: a.tokenEndpoint === void 0 ? n.sandboxTokenServer(a.sandboxId, a.sandboxOptions) : n.endpoint(a.tokenEndpoint, a.tokenEndpointOptions),
|
|
11
11
|
tokenOptions: {
|
|
@@ -20,6 +20,8 @@ function a(a) {
|
|
|
20
20
|
},
|
|
21
21
|
connectOptions: c,
|
|
22
22
|
enableMicrophone: u,
|
|
23
|
+
outputVolumeCalibration: g,
|
|
24
|
+
onOutputVolumeSample: _,
|
|
23
25
|
createAudioAnalyser: r,
|
|
24
26
|
RoomClass: t
|
|
25
27
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orb-ui",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "React voice agent UI components with audio-reactive adapters for Vapi, ElevenLabs, LiveKit, Pipecat, OpenAI Realtime, Gemini Live, and custom voice AI apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/orb-ui.cjs",
|
package/dist/livekit-Dasur3lv.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
//#region src/adapters/types.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
let t = Math.min(e / .5, 1);
|
|
4
|
-
return t **= 1.3, t;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/adapters/livekit/index.ts
|
|
8
|
-
var t = 4, n = .03, r = 1.5, i = .6, a = .2, o = .35;
|
|
9
|
-
function s(e) {
|
|
10
|
-
switch (e) {
|
|
11
|
-
case "speaking": return "speaking";
|
|
12
|
-
case "thinking": return "thinking";
|
|
13
|
-
case "listening":
|
|
14
|
-
case "idle": return "listening";
|
|
15
|
-
case "connecting":
|
|
16
|
-
case "pre-connect-buffering":
|
|
17
|
-
case "initializing": return "connecting";
|
|
18
|
-
case "disconnected": return "idle";
|
|
19
|
-
case "failed": return "error";
|
|
20
|
-
default: return "idle";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function c(e) {
|
|
24
|
-
return "RoomClass" in e;
|
|
25
|
-
}
|
|
26
|
-
function l(e) {
|
|
27
|
-
return typeof e == "function" ? e() : e;
|
|
28
|
-
}
|
|
29
|
-
function u(e) {
|
|
30
|
-
if (!e) return {};
|
|
31
|
-
let t = {}, n = (e, n) => {
|
|
32
|
-
n !== void 0 && (t[e] = n);
|
|
33
|
-
};
|
|
34
|
-
return n("roomName", l(e.roomName)), n("participantName", l(e.participantName)), n("participantIdentity", l(e.participantIdentity)), n("participantMetadata", l(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", l(e.agentName)), n("agentMetadata", l(e.agentMetadata)), n("deployment", l(e.deployment)), t;
|
|
35
|
-
}
|
|
36
|
-
function d(e) {
|
|
37
|
-
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
38
|
-
return e;
|
|
39
|
-
}
|
|
40
|
-
async function f(e) {
|
|
41
|
-
let t = u(e.tokenOptions);
|
|
42
|
-
return typeof e.getConnectionDetails == "function" ? d(await e.getConnectionDetails(t)) : e.tokenSource ? d(await e.tokenSource.fetch(t)) : d({
|
|
43
|
-
serverUrl: e.serverUrl,
|
|
44
|
-
participantToken: e.participantToken
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function p(e) {
|
|
48
|
-
for (let [, n] of e.remoteParticipants) if (!n.isLocal && (n.kind === t || n.attributes?.["lk.agent.state"] !== void 0)) return n;
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
function m(e, t, n) {
|
|
52
|
-
let r = e.off;
|
|
53
|
-
if (r) {
|
|
54
|
-
r.call(e, t, n);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
e.removeListener?.call(e, t, n);
|
|
58
|
-
}
|
|
59
|
-
function h(e, t, n) {
|
|
60
|
-
e.on.call(e, t, n);
|
|
61
|
-
}
|
|
62
|
-
function g(l) {
|
|
63
|
-
let u = c(l), d = l.createAudioAnalyser, g = { current: u ? null : l.room }, _ = /* @__PURE__ */ new Set(), v = {
|
|
64
|
-
state: "idle",
|
|
65
|
-
volume: 0,
|
|
66
|
-
inputVolume: 0,
|
|
67
|
-
outputVolume: 0
|
|
68
|
-
}, y = "idle", b = null, x = null, S = null, C = null, w = null, T = null, E = null, D = 0, O = null;
|
|
69
|
-
function k(e) {
|
|
70
|
-
v = e, _.forEach((t) => t(e));
|
|
71
|
-
}
|
|
72
|
-
function A(e) {
|
|
73
|
-
k({
|
|
74
|
-
...v,
|
|
75
|
-
...e,
|
|
76
|
-
state: e.state ?? v.state
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function j(e) {
|
|
80
|
-
let t = e < n ? 0 : e, s = t > D ? i : a;
|
|
81
|
-
D += (t - D) * s;
|
|
82
|
-
let c = Math.min(D * r, 1);
|
|
83
|
-
return c / (c + o);
|
|
84
|
-
}
|
|
85
|
-
function M() {
|
|
86
|
-
D = 0, A({
|
|
87
|
-
volume: 0,
|
|
88
|
-
outputVolume: 0
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function N({ emitZero: e = !0 } = {}) {
|
|
92
|
-
w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), e && A({
|
|
93
|
-
volume: 0,
|
|
94
|
-
inputVolume: 0
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function P(t) {
|
|
98
|
-
if (!(b === t && C)) {
|
|
99
|
-
N({ emitZero: !1 }), b = t;
|
|
100
|
-
try {
|
|
101
|
-
C = d(t);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
w = setInterval(() => {
|
|
107
|
-
if (!C || y !== "listening") return;
|
|
108
|
-
let t = e(C.calculateVolume());
|
|
109
|
-
A({
|
|
110
|
-
volume: t,
|
|
111
|
-
inputVolume: t,
|
|
112
|
-
outputVolume: 0
|
|
113
|
-
});
|
|
114
|
-
}, 33);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function F({ emitZero: e = !0 } = {}) {
|
|
118
|
-
E &&= (clearInterval(E), null), T &&= (T.cleanup().catch(() => {}), null), D = 0, e && A({
|
|
119
|
-
volume: 0,
|
|
120
|
-
outputVolume: 0
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function I(e) {
|
|
124
|
-
F();
|
|
125
|
-
try {
|
|
126
|
-
T = d(e);
|
|
127
|
-
} catch (e) {
|
|
128
|
-
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
E = setInterval(() => {
|
|
132
|
-
if (!T || y !== "speaking") return;
|
|
133
|
-
let e = j(T.calculateVolume());
|
|
134
|
-
A({
|
|
135
|
-
volume: e,
|
|
136
|
-
inputVolume: 0,
|
|
137
|
-
outputVolume: e
|
|
138
|
-
});
|
|
139
|
-
}, 33);
|
|
140
|
-
}
|
|
141
|
-
function L(e) {
|
|
142
|
-
y = e, A({
|
|
143
|
-
state: e,
|
|
144
|
-
volume: 0,
|
|
145
|
-
inputVolume: 0,
|
|
146
|
-
outputVolume: 0
|
|
147
|
-
}), e === "speaking" && x ? I(x) : e !== "speaking" && F({ emitZero: !1 });
|
|
148
|
-
}
|
|
149
|
-
function R(e) {
|
|
150
|
-
S || typeof document > "u" || (S = e.attach(), S.id = "orb-ui-livekit-agent-audio", document.body.appendChild(S));
|
|
151
|
-
}
|
|
152
|
-
function z() {
|
|
153
|
-
S &&= (S.remove(), null);
|
|
154
|
-
}
|
|
155
|
-
function B(e) {
|
|
156
|
-
x = e, R(e), y === "speaking" && I(e);
|
|
157
|
-
}
|
|
158
|
-
function V(e) {
|
|
159
|
-
P(e);
|
|
160
|
-
}
|
|
161
|
-
function H(e) {
|
|
162
|
-
let t = e.getTrackPublication?.("microphone");
|
|
163
|
-
t?.track && V(t.track);
|
|
164
|
-
}
|
|
165
|
-
function U(e) {
|
|
166
|
-
let t = s(e);
|
|
167
|
-
t !== y && L(t);
|
|
168
|
-
}
|
|
169
|
-
function W(e) {
|
|
170
|
-
let t = e.attributes?.["lk.agent.state"];
|
|
171
|
-
t && U(t);
|
|
172
|
-
let n = e.getTrackPublication("microphone");
|
|
173
|
-
n?.track && B(n.track);
|
|
174
|
-
}
|
|
175
|
-
function G(e) {
|
|
176
|
-
if (O) return;
|
|
177
|
-
let n = (e, t) => {
|
|
178
|
-
if (t.isLocal) return;
|
|
179
|
-
let n = e["lk.agent.state"];
|
|
180
|
-
n && U(n);
|
|
181
|
-
}, r = (e, n, r) => {
|
|
182
|
-
r.isLocal || !(r.kind === t || r.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || B(e);
|
|
183
|
-
}, i = (e) => {
|
|
184
|
-
x === e && (x = null, z(), F());
|
|
185
|
-
}, a = (e) => {
|
|
186
|
-
e.source !== "microphone" || !e.track || V(e.track);
|
|
187
|
-
}, o = (e) => {
|
|
188
|
-
e.source === "microphone" && (b = null, N());
|
|
189
|
-
}, s = () => {
|
|
190
|
-
b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), L("idle");
|
|
191
|
-
};
|
|
192
|
-
if (h(e, "participantAttributesChanged", n), h(e, "trackSubscribed", r), h(e, "trackUnsubscribed", i), h(e, "localTrackPublished", a), h(e, "localTrackUnpublished", o), h(e, "disconnected", s), O = () => {
|
|
193
|
-
m(e, "participantAttributesChanged", n), m(e, "trackSubscribed", r), m(e, "trackUnsubscribed", i), m(e, "localTrackPublished", a), m(e, "localTrackUnpublished", o), m(e, "disconnected", s);
|
|
194
|
-
}, H(e.localParticipant), e.state === "connected") {
|
|
195
|
-
let t = p(e);
|
|
196
|
-
t ? W(t) : L("connecting");
|
|
197
|
-
} else L("idle");
|
|
198
|
-
}
|
|
199
|
-
function K() {
|
|
200
|
-
O?.(), O = null, b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), A({
|
|
201
|
-
volume: 0,
|
|
202
|
-
inputVolume: 0,
|
|
203
|
-
outputVolume: 0
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
let q = (e) => {
|
|
207
|
-
_.add(e), e(v);
|
|
208
|
-
let t = g.current;
|
|
209
|
-
return t && G(t), () => {
|
|
210
|
-
_.delete(e), _.size === 0 && K();
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
return u ? {
|
|
214
|
-
subscribe: q,
|
|
215
|
-
async start() {
|
|
216
|
-
if (g.current) return;
|
|
217
|
-
let e = l, t = new e.RoomClass();
|
|
218
|
-
L("connecting");
|
|
219
|
-
try {
|
|
220
|
-
let n = await f(e);
|
|
221
|
-
if (await t.connect(n.serverUrl, n.participantToken, e.connectOptions), g.current = t, G(t), e.enableMicrophone !== !1) {
|
|
222
|
-
let e = (await t.localParticipant.setMicrophoneEnabled(!0))?.track ?? t.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
223
|
-
e && V(e);
|
|
224
|
-
}
|
|
225
|
-
} catch (e) {
|
|
226
|
-
throw console.error("[orb-ui/livekit] connect failed:", e), g.current === t && K(), t.disconnect(), g.current = null, L("error"), M(), A({ error: e }), e;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
async stop() {
|
|
230
|
-
let e = g.current;
|
|
231
|
-
if (!e) {
|
|
232
|
-
L("idle");
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
K(), e.disconnect(), g.current = null, L("idle");
|
|
236
|
-
}
|
|
237
|
-
} : { subscribe: q };
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
export { g as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t=4,n=.03,r=1.5,i=.6,a=.2,o=.35;function s(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function c(e){return`RoomClass`in e}function l(e){return typeof e==`function`?e():e}function u(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,l(e.roomName)),n(`participantName`,l(e.participantName)),n(`participantIdentity`,l(e.participantIdentity)),n(`participantMetadata`,l(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,l(e.agentName)),n(`agentMetadata`,l(e.agentMetadata)),n(`deployment`,l(e.deployment)),t}function d(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function f(e){let t=u(e.tokenOptions);return typeof e.getConnectionDetails==`function`?d(await e.getConnectionDetails(t)):e.tokenSource?d(await e.tokenSource.fetch(t)):d({serverUrl:e.serverUrl,participantToken:e.participantToken})}function p(e){for(let[,n]of e.remoteParticipants)if(!n.isLocal&&(n.kind===t||n.attributes?.[`lk.agent.state`]!==void 0))return n;return null}function m(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function h(e,t,n){e.on.call(e,t,n)}function g(l){let u=c(l),d=l.createAudioAnalyser,g={current:u?null:l.room},_=new Set,v={state:`idle`,volume:0,inputVolume:0,outputVolume:0},y=`idle`,b=null,x=null,S=null,C=null,w=null,T=null,E=null,D=0,O=null;function k(e){v=e,_.forEach(t=>t(e))}function A(e){k({...v,...e,state:e.state??v.state})}function j(e){let t=e<n?0:e,s=t>D?i:a;D+=(t-D)*s;let c=Math.min(D*r,1);return c/(c+o)}function M(){D=0,A({volume:0,outputVolume:0})}function N({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),e&&A({volume:0,inputVolume:0})}function P(t){if(!(b===t&&C)){N({emitZero:!1}),b=t;try{C=d(t)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||y!==`listening`)return;let t=e(C.calculateVolume());A({volume:t,inputVolume:t,outputVolume:0})},33)}}function F({emitZero:e=!0}={}){E&&=(clearInterval(E),null),T&&=(T.cleanup().catch(()=>{}),null),D=0,e&&A({volume:0,outputVolume:0})}function I(e){F();try{T=d(e)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}E=setInterval(()=>{if(!T||y!==`speaking`)return;let e=j(T.calculateVolume());A({volume:e,inputVolume:0,outputVolume:e})},33)}function L(e){y=e,A({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&x?I(x):e!==`speaking`&&F({emitZero:!1})}function R(e){S||typeof document>`u`||(S=e.attach(),S.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(S))}function z(){S&&=(S.remove(),null)}function B(e){x=e,R(e),y===`speaking`&&I(e)}function V(e){P(e)}function H(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&V(t.track)}function U(e){let t=s(e);t!==y&&L(t)}function W(e){let t=e.attributes?.[`lk.agent.state`];t&&U(t);let n=e.getTrackPublication(`microphone`);n?.track&&B(n.track)}function G(e){if(O)return;let n=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&U(n)},r=(e,n,r)=>{r.isLocal||!(r.kind===t||r.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||B(e)},i=e=>{x===e&&(x=null,z(),F())},a=e=>{e.source!==`microphone`||!e.track||V(e.track)},o=e=>{e.source===`microphone`&&(b=null,N())},s=()=>{b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),L(`idle`)};if(h(e,`participantAttributesChanged`,n),h(e,`trackSubscribed`,r),h(e,`trackUnsubscribed`,i),h(e,`localTrackPublished`,a),h(e,`localTrackUnpublished`,o),h(e,`disconnected`,s),O=()=>{m(e,`participantAttributesChanged`,n),m(e,`trackSubscribed`,r),m(e,`trackUnsubscribed`,i),m(e,`localTrackPublished`,a),m(e,`localTrackUnpublished`,o),m(e,`disconnected`,s)},H(e.localParticipant),e.state===`connected`){let t=p(e);t?W(t):L(`connecting`)}else L(`idle`)}function K(){O?.(),O=null,b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),A({volume:0,inputVolume:0,outputVolume:0})}let q=e=>{_.add(e),e(v);let t=g.current;return t&&G(t),()=>{_.delete(e),_.size===0&&K()}};return u?{subscribe:q,async start(){if(g.current)return;let e=l,t=new e.RoomClass;L(`connecting`);try{let n=await f(e);if(await t.connect(n.serverUrl,n.participantToken,e.connectOptions),g.current=t,G(t),e.enableMicrophone!==!1){let e=(await t.localParticipant.setMicrophoneEnabled(!0))?.track??t.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&V(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),g.current===t&&K(),t.disconnect(),g.current=null,L(`error`),M(),A({error:e}),e}},async stop(){let e=g.current;if(!e){L(`idle`);return}K(),e.disconnect(),g.current=null,L(`idle`)}}:{subscribe:q}}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return g}});
|