@d-id/client-sdk 3.0.0-staging.412 → 3.0.0-staging.414
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/{index-BLrKDuV_.js → index-DBWnR72S.js} +1628 -1615
- package/dist/index.js +20 -20
- package/dist/index.umd.cjs +7 -7
- package/dist/livekit-manager-BM3JMzT5.js +531 -0
- package/dist/src/api/agents.d.ts +5 -5
- package/dist/src/api/streams/streamApi.test.d.ts +1 -0
- package/dist/src/index.d.ts +6 -6
- package/dist/src/services/streaming-manager/common.d.ts +4 -4
- package/dist/src/types/entities/agents/chat.d.ts +9 -9
- package/dist/src/types/entities/agents/manager.d.ts +31 -30
- package/dist/src/types/stream/data-channel.d.ts +2 -2
- package/dist/src/types/stream/rtc.d.ts +14 -3
- package/dist/src/types/stream/stream.d.ts +114 -43
- package/dist/src/types/stream-script.d.ts +5 -5
- package/dist/src/types/voice/stt.d.ts +2 -2
- package/dist/src/types/voice/tts.d.ts +1 -1
- package/package.json +1 -1
- package/dist/livekit-manager-Cfb9x2ei.js +0 -506
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
import { c as Qe, C as J, S as l, a as We, b as qe, A as C, d as Ge, l as pe, e as He, t as Xe, f as E, g as U, h as Ze, D as me, i as Ye, j as b, n as en } from "./index-BLrKDuV_.js";
|
|
2
|
-
function nn() {
|
|
3
|
-
try {
|
|
4
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
5
|
-
} catch {
|
|
6
|
-
return "";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
function tn() {
|
|
10
|
-
if (typeof navigator > "u")
|
|
11
|
-
return "";
|
|
12
|
-
const f = navigator.userAgent ?? "", S = (navigator.platform ?? "").toLowerCase();
|
|
13
|
-
let u = "Unknown";
|
|
14
|
-
/android/i.test(f) ? u = "Android" : /iphone|ipad|ipod/i.test(f) ? u = "iOS" : S.includes("win") ? u = "Windows" : S.includes("mac") ? u = "Mac OS X" : S.includes("linux") && (u = "Linux");
|
|
15
|
-
const i = u === "Android" || u === "iOS" || /Mobi/i.test(f);
|
|
16
|
-
return `${u}, ${i ? "Mobile" : "Desktop"}`;
|
|
17
|
-
}
|
|
18
|
-
function on() {
|
|
19
|
-
const f = {}, S = nn();
|
|
20
|
-
S && (f.timezone = S);
|
|
21
|
-
const u = tn();
|
|
22
|
-
return u && (f.device = u), f;
|
|
23
|
-
}
|
|
24
|
-
function rn(f, S, u, i) {
|
|
25
|
-
const k = Qe(f, `${S}/v2/agents/${u}`, i);
|
|
26
|
-
return {
|
|
27
|
-
async createStream(g) {
|
|
28
|
-
return k.post("/sessions", g);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const an = {
|
|
33
|
-
[l.ChatAnswer]: J.Answer,
|
|
34
|
-
[l.ChatPartial]: J.Partial
|
|
35
|
-
}, Ce = 2e4, cn = [];
|
|
36
|
-
async function sn() {
|
|
37
|
-
try {
|
|
38
|
-
return await import("./index-BLrKDuV_.js").then((f) => f.y);
|
|
39
|
-
} catch {
|
|
40
|
-
throw new Error(
|
|
41
|
-
"LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const un = {
|
|
46
|
-
excellent: U.Strong,
|
|
47
|
-
good: U.Strong,
|
|
48
|
-
poor: U.Weak,
|
|
49
|
-
lost: U.Unknown,
|
|
50
|
-
unknown: U.Unknown
|
|
51
|
-
}, j = (f = "Stream Error") => new He(f);
|
|
52
|
-
function Se(f, S, u) {
|
|
53
|
-
var i, k;
|
|
54
|
-
throw S("Failed to connect to LiveKit room:", f), (i = u.onConnectionStateChange) == null || i.call(u, E.Fail, "internal:init-error"), (k = u.onError) == null || k.call(u, f, { sessionId: "" }), f;
|
|
55
|
-
}
|
|
56
|
-
async function ln(f, S, u) {
|
|
57
|
-
var de;
|
|
58
|
-
const i = We(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: g, ConnectionState: I, Track: ee } = await sn(), { callbacks: n, auth: Te, baseURL: ye, analytics: ne } = u;
|
|
59
|
-
let a = null, w = !1;
|
|
60
|
-
const te = qe.Fluent;
|
|
61
|
-
let L = null;
|
|
62
|
-
const P = { isPublishing: !1, publication: null }, Q = { isPublishing: !1, publication: null };
|
|
63
|
-
let p = null, T = null, O = null, K = !1;
|
|
64
|
-
a = new k({
|
|
65
|
-
adaptiveStream: !1,
|
|
66
|
-
// Must be false to use mediaStreamTrack directly
|
|
67
|
-
dynacast: !0
|
|
68
|
-
});
|
|
69
|
-
for (const [e, t] of u.rpcMethods ?? [])
|
|
70
|
-
a.registerRpcMethod(e, t);
|
|
71
|
-
let R = null, M = C.Idle, W = !0;
|
|
72
|
-
const y = /* @__PURE__ */ new Map();
|
|
73
|
-
let x = null, q = null;
|
|
74
|
-
const ve = rn(Te, ye || Ge, f, n.onError);
|
|
75
|
-
let v, _, $, ie = !0;
|
|
76
|
-
try {
|
|
77
|
-
const e = await ve.createStream({
|
|
78
|
-
transport: S.transport,
|
|
79
|
-
chat_persist: S.chat_persist ?? !1,
|
|
80
|
-
verbose: u.verbose ?? !1
|
|
81
|
-
}), { id: t, session_token: o, session_url: r, interrupt_enabled: c } = e;
|
|
82
|
-
(de = n.onStreamCreated) == null || de.call(n, { session_id: t, stream_id: t, agent_id: f }), v = t, _ = o, $ = r, ie = c ?? !0, await a.prepareConnection($, _);
|
|
83
|
-
} catch (e) {
|
|
84
|
-
Se(e, i, n);
|
|
85
|
-
}
|
|
86
|
-
if (!$ || !_ || !v)
|
|
87
|
-
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
88
|
-
a.on(g.ConnectionStateChanged, Ee).on(g.ConnectionQualityChanged, Re).on(g.ParticipantConnected, be).on(g.ParticipantDisconnected, Le).on(g.TrackSubscribed, Me).on(g.TrackUnsubscribed, ke).on(g.DataReceived, Ve).on(g.MediaDevicesError, Fe).on(g.TranscriptionReceived, we).on(g.EncryptionError, Ue).on(g.TrackSubscriptionFailed, je);
|
|
89
|
-
function we(e, t) {
|
|
90
|
-
t != null && t.isLocal && pe.update();
|
|
91
|
-
}
|
|
92
|
-
async function Ae() {
|
|
93
|
-
const e = on();
|
|
94
|
-
if (!(!a || Object.keys(e).length === 0))
|
|
95
|
-
try {
|
|
96
|
-
await a.localParticipant.setAttributes(e);
|
|
97
|
-
} catch (t) {
|
|
98
|
-
i("Failed to set user context attributes", t);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
await a.connect($, _), i("LiveKit room joined successfully"), Ae(), R = setTimeout(() => {
|
|
103
|
-
var t;
|
|
104
|
-
i(
|
|
105
|
-
`Track subscription timeout - no track subscribed within ${Ce / 1e3} seconds after connect`
|
|
106
|
-
), R = null;
|
|
107
|
-
const e = j("Track subscription timeout");
|
|
108
|
-
ne.track("connectivity-error", {
|
|
109
|
-
error: Xe(e),
|
|
110
|
-
sessionId: v
|
|
111
|
-
}), (t = n.onError) == null || t.call(n, e, { sessionId: v }), Y("internal:track-subscription-timeout");
|
|
112
|
-
}, Ce);
|
|
113
|
-
} catch (e) {
|
|
114
|
-
Se(e, i, n);
|
|
115
|
-
}
|
|
116
|
-
ne.enrich({
|
|
117
|
-
"stream-type": te
|
|
118
|
-
});
|
|
119
|
-
function Ee(e) {
|
|
120
|
-
var t, o, r, c;
|
|
121
|
-
switch (i("Connection state changed:", e), e) {
|
|
122
|
-
case I.Connecting:
|
|
123
|
-
i("CALLBACK: onConnectionStateChange(Connecting)"), (t = n.onConnectionStateChange) == null || t.call(n, E.Connecting, "livekit:connecting");
|
|
124
|
-
break;
|
|
125
|
-
case I.Connected:
|
|
126
|
-
i("LiveKit room connected successfully"), w = !0;
|
|
127
|
-
break;
|
|
128
|
-
case I.Disconnected:
|
|
129
|
-
i("LiveKit room disconnected"), w = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(
|
|
130
|
-
n,
|
|
131
|
-
E.Disconnected,
|
|
132
|
-
q ?? "livekit:disconnected"
|
|
133
|
-
);
|
|
134
|
-
break;
|
|
135
|
-
case I.Reconnecting:
|
|
136
|
-
i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, E.Connecting, "livekit:reconnecting");
|
|
137
|
-
break;
|
|
138
|
-
case I.SignalReconnecting:
|
|
139
|
-
i("LiveKit room signal reconnecting..."), (c = n.onConnectionStateChange) == null || c.call(n, E.Connecting, "livekit:signal-reconnecting");
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function Re(e, t) {
|
|
144
|
-
var o;
|
|
145
|
-
i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n, un[e]));
|
|
146
|
-
}
|
|
147
|
-
function be(e) {
|
|
148
|
-
i("Participant connected:", e.identity);
|
|
149
|
-
}
|
|
150
|
-
function Le(e) {
|
|
151
|
-
i("Participant disconnected:", e.identity), Y("livekit:participant-disconnected");
|
|
152
|
-
}
|
|
153
|
-
function Pe() {
|
|
154
|
-
var e;
|
|
155
|
-
O !== b.Start && (i("CALLBACK: onVideoStateChange(Start)"), O = b.Start, (e = n.onVideoStateChange) == null || e.call(n, b.Start));
|
|
156
|
-
}
|
|
157
|
-
function oe(e) {
|
|
158
|
-
var t;
|
|
159
|
-
O !== b.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), O = b.Stop, (t = n.onVideoStateChange) == null || t.call(n, b.Stop, e));
|
|
160
|
-
}
|
|
161
|
-
function Me(e, t, o) {
|
|
162
|
-
var c, d, s;
|
|
163
|
-
i(`Track subscribed: ${e.kind} from ${o.identity}`);
|
|
164
|
-
const r = e.mediaStreamTrack;
|
|
165
|
-
if (!r) {
|
|
166
|
-
i(`No mediaStreamTrack available for ${e.kind}`);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
L ? (L.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (L = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (T = Ye(
|
|
170
|
-
() => e.getRTCStatsReport(),
|
|
171
|
-
({ sttLatency: h, serviceLatency: m }) => {
|
|
172
|
-
var le, fe, he;
|
|
173
|
-
const V = pe.get(!0);
|
|
174
|
-
let F = 0;
|
|
175
|
-
if (h) {
|
|
176
|
-
const ge = ((fe = (le = p == null ? void 0 : p.getReport()) == null ? void 0 : le.webRTCStats) == null ? void 0 : fe.avgRtt) ?? 0;
|
|
177
|
-
F = ge > 0 ? Math.round(ge * 1e3) : 0;
|
|
178
|
-
}
|
|
179
|
-
const D = V > 0 ? V + (h ?? 0) + F : void 0, A = D !== void 0 && m !== void 0 ? D - m : void 0;
|
|
180
|
-
(he = n.onFirstAudioDetected) == null || he.call(n, { latency: D, networkLatency: A });
|
|
181
|
-
}
|
|
182
|
-
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, E.Connected, "livekit:track-subscribed")), p = Ze(
|
|
183
|
-
() => e.getRTCStatsReport(),
|
|
184
|
-
() => w,
|
|
185
|
-
en,
|
|
186
|
-
(h, m) => {
|
|
187
|
-
i(`Video state change: ${h}`), h === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")), Pe()) : h === b.Stop && oe(m);
|
|
188
|
-
}
|
|
189
|
-
), p.start());
|
|
190
|
-
}
|
|
191
|
-
function ke(e, t, o) {
|
|
192
|
-
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (T == null || T.destroy(), T = null), e.kind === "video" && (oe((p == null ? void 0 : p.getReport()) ?? void 0), p == null || p.stop(), p = null);
|
|
193
|
-
}
|
|
194
|
-
function re(e, t) {
|
|
195
|
-
var r;
|
|
196
|
-
const o = an[e];
|
|
197
|
-
o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
|
|
198
|
-
}
|
|
199
|
-
function G(e, t) {
|
|
200
|
-
var o, r, c, d;
|
|
201
|
-
if (e === l.ToolCallStarted) {
|
|
202
|
-
const s = t;
|
|
203
|
-
y.set(s.call_id, {
|
|
204
|
-
call: {
|
|
205
|
-
callId: s.call_id,
|
|
206
|
-
name: s.name,
|
|
207
|
-
executionMode: s.execution_mode === "async" ? "async" : "blocking"
|
|
208
|
-
},
|
|
209
|
-
interruptible: s.interruptible === !0,
|
|
210
|
-
turnId: s.turn_id ?? x
|
|
211
|
-
}), N(), z(), M = C.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, C.ToolActive), (r = n.onToolEvent) == null || r.call(n, l.ToolCallStarted, s);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (e === l.ToolCallDone) {
|
|
215
|
-
const s = t;
|
|
216
|
-
ae(s.call_id), (c = n.onToolEvent) == null || c.call(n, l.ToolCallDone, s);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (e === l.ToolCallError) {
|
|
220
|
-
const s = t;
|
|
221
|
-
ae(s.call_id), (d = n.onToolEvent) == null || d.call(n, l.ToolCallError, s);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function ae(e) {
|
|
225
|
-
y.delete(e) && (N(), z());
|
|
226
|
-
}
|
|
227
|
-
function Ie(e) {
|
|
228
|
-
let t = !1;
|
|
229
|
-
for (const [o, r] of y)
|
|
230
|
-
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (y.delete(o), t = !0));
|
|
231
|
-
t && (N(), z());
|
|
232
|
-
}
|
|
233
|
-
function N() {
|
|
234
|
-
var t;
|
|
235
|
-
const e = ![...y.values()].some(({ call: o }) => o.executionMode === "blocking");
|
|
236
|
-
e !== W && (W = e, (t = n.onInterruptibleChange) == null || t.call(n, e));
|
|
237
|
-
}
|
|
238
|
-
function z() {
|
|
239
|
-
var e;
|
|
240
|
-
(e = n.onRunningToolCallsChange) == null || e.call(
|
|
241
|
-
n,
|
|
242
|
-
y.size === 0 ? cn : [...y.values()].map(({ call: t }) => t)
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
function _e(e, t) {
|
|
246
|
-
var o, r, c;
|
|
247
|
-
if (e === l.StreamVideoCreated) {
|
|
248
|
-
M = C.Talking, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Talking), T == null || T.arm({
|
|
249
|
-
sttLatency: (r = t == null ? void 0 : t.stt) == null ? void 0 : r.latency,
|
|
250
|
-
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
251
|
-
});
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (y.size > 0) {
|
|
255
|
-
M !== C.ToolActive && (M = C.ToolActive, (c = n.onAgentActivityStateChange) == null || c.call(n, C.ToolActive));
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function B(e, t) {
|
|
260
|
-
var d, s, h, m;
|
|
261
|
-
const o = ((s = (d = p == null ? void 0 : p.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : s.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, c = { ...t, downstreamNetworkLatency: r };
|
|
262
|
-
u.debug && ((h = t == null ? void 0 : t.metadata) != null && h.sentiment) && (c.sentiment = {
|
|
263
|
-
id: t.metadata.sentiment.id,
|
|
264
|
-
name: t.metadata.sentiment.sentiment
|
|
265
|
-
}), (m = n.onMessage) == null || m.call(n, e, c), _e(e, t);
|
|
266
|
-
}
|
|
267
|
-
function $e(e, t) {
|
|
268
|
-
var o;
|
|
269
|
-
(o = n.onMessage) == null || o.call(n, J.Transcribe, { event: J.Transcribe, ...t }), queueMicrotask(() => {
|
|
270
|
-
var r;
|
|
271
|
-
(r = n.onAgentActivityStateChange) == null || r.call(n, C.Loading);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
function De(e, t) {
|
|
275
|
-
var o;
|
|
276
|
-
x = (t == null ? void 0 : t.turn_id) ?? null, M = C.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Loading);
|
|
277
|
-
}
|
|
278
|
-
function Ke(e, t) {
|
|
279
|
-
var r;
|
|
280
|
-
const o = (t == null ? void 0 : t.turn_id) ?? null;
|
|
281
|
-
x !== null && o !== null && o < x || (Ie(o), M = C.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, C.Idle));
|
|
282
|
-
}
|
|
283
|
-
function ce(e, t) {
|
|
284
|
-
q = (t == null ? void 0 : t.reason) ?? null;
|
|
285
|
-
}
|
|
286
|
-
const xe = {
|
|
287
|
-
[l.ChatAnswer]: re,
|
|
288
|
-
[l.ChatPartial]: re,
|
|
289
|
-
[l.ToolCallStarted]: G,
|
|
290
|
-
[l.ToolCallDone]: G,
|
|
291
|
-
[l.ToolCallError]: G,
|
|
292
|
-
[l.StreamVideoCreated]: B,
|
|
293
|
-
[l.StreamVideoDone]: B,
|
|
294
|
-
[l.StreamVideoError]: B,
|
|
295
|
-
[l.StreamVideoRejected]: B,
|
|
296
|
-
[l.ChatAudioTranscribed]: $e,
|
|
297
|
-
[l.TurnStarted]: De,
|
|
298
|
-
[l.TurnEnded]: Ke,
|
|
299
|
-
[l.StreamDone]: ce,
|
|
300
|
-
[l.StreamFailed]: ce
|
|
301
|
-
};
|
|
302
|
-
function Ve(e, t, o, r) {
|
|
303
|
-
const c = new TextDecoder().decode(e);
|
|
304
|
-
let d;
|
|
305
|
-
try {
|
|
306
|
-
d = JSON.parse(c);
|
|
307
|
-
} catch (m) {
|
|
308
|
-
i("Failed to parse data channel message:", m);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const s = r || d.subject;
|
|
312
|
-
if (i("Data received:", { subject: s, data: d }), !s) return;
|
|
313
|
-
const h = xe[s];
|
|
314
|
-
if (h)
|
|
315
|
-
try {
|
|
316
|
-
h(s, d);
|
|
317
|
-
} catch (m) {
|
|
318
|
-
console.warn("[LiveKitStreamingManager] Data channel handler failed", { subject: s, error: m });
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function Fe(e) {
|
|
322
|
-
var t;
|
|
323
|
-
i("Media devices error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
|
|
324
|
-
}
|
|
325
|
-
function Ue(e) {
|
|
326
|
-
var t;
|
|
327
|
-
i("Encryption error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
|
|
328
|
-
}
|
|
329
|
-
function je(e, t, o) {
|
|
330
|
-
i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
|
|
331
|
-
}
|
|
332
|
-
function Oe(e, t, o) {
|
|
333
|
-
for (const [r, c] of o)
|
|
334
|
-
if (c.source === t && c.track) {
|
|
335
|
-
const d = c.track.mediaStreamTrack;
|
|
336
|
-
if (d === e || (d == null ? void 0 : d.id) === e.id)
|
|
337
|
-
return c;
|
|
338
|
-
}
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
async function se(e, t, o, r, c, d) {
|
|
342
|
-
var V, F, D;
|
|
343
|
-
if (!w || !a)
|
|
344
|
-
throw i(`Room is not connected, cannot publish ${r} stream`), new Error("Room is not connected");
|
|
345
|
-
if (e.isPublishing) {
|
|
346
|
-
i(`${r} publish already in progress, skipping`);
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
const s = o(t);
|
|
350
|
-
if (s.length === 0)
|
|
351
|
-
throw new Error(`No ${r} track found in the provided MediaStream`);
|
|
352
|
-
const h = s[0], m = Oe(h, r, c());
|
|
353
|
-
if (m) {
|
|
354
|
-
i(`${r} track is already published, skipping`, {
|
|
355
|
-
trackId: h.id,
|
|
356
|
-
publishedTrackId: (F = (V = m.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : F.id
|
|
357
|
-
}), e.publication = m;
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if ((D = e.publication) != null && D.track) {
|
|
361
|
-
const A = e.publication.track.mediaStreamTrack;
|
|
362
|
-
A !== h && (A == null ? void 0 : A.id) !== h.id && (i(`Unpublishing existing ${r} track before publishing new one`), await d());
|
|
363
|
-
}
|
|
364
|
-
i(`Publishing ${r} track from provided MediaStream`, { trackId: h.id }), e.isPublishing = !0;
|
|
365
|
-
try {
|
|
366
|
-
e.publication = await a.localParticipant.publishTrack(h, { source: r }), i(`${r} track published successfully`, { trackSid: e.publication.trackSid });
|
|
367
|
-
} catch (A) {
|
|
368
|
-
throw i(`Failed to publish ${r} track:`, A), A;
|
|
369
|
-
} finally {
|
|
370
|
-
e.isPublishing = !1;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
async function ue(e, t) {
|
|
374
|
-
if (!(!e.publication || !e.publication.track))
|
|
375
|
-
try {
|
|
376
|
-
a && (await a.localParticipant.unpublishTrack(e.publication.track, !1), i(`${t} track unpublished`));
|
|
377
|
-
} catch (o) {
|
|
378
|
-
i(`Error unpublishing ${t} track:`, o);
|
|
379
|
-
} finally {
|
|
380
|
-
e.publication = null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
async function Ne(e) {
|
|
384
|
-
return se(
|
|
385
|
-
P,
|
|
386
|
-
e,
|
|
387
|
-
(t) => t.getAudioTracks(),
|
|
388
|
-
ee.Source.Microphone,
|
|
389
|
-
() => a.localParticipant.audioTrackPublications,
|
|
390
|
-
H
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
async function H() {
|
|
394
|
-
return ue(P, "Microphone");
|
|
395
|
-
}
|
|
396
|
-
async function ze(e) {
|
|
397
|
-
if (!w || !a)
|
|
398
|
-
throw i("Cannot replace microphone track: room is not connected"), new Error("Room is not connected");
|
|
399
|
-
if (e.kind !== "audio")
|
|
400
|
-
throw i("Cannot replace microphone track: not an audio track", { kind: e.kind }), new Error("Microphone track must be an audio track");
|
|
401
|
-
if (P.isPublishing)
|
|
402
|
-
throw i("Cannot replace microphone track: publish in progress"), new Error("Microphone publish in progress");
|
|
403
|
-
const t = P.publication;
|
|
404
|
-
if (!t || !t.track)
|
|
405
|
-
throw i("Cannot replace microphone track: no publication to replace"), new Error("No microphone publication to replace");
|
|
406
|
-
try {
|
|
407
|
-
P.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
|
|
408
|
-
} finally {
|
|
409
|
-
P.isPublishing = !1;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
async function Be(e) {
|
|
413
|
-
return se(
|
|
414
|
-
Q,
|
|
415
|
-
e,
|
|
416
|
-
(t) => t.getVideoTracks(),
|
|
417
|
-
ee.Source.Camera,
|
|
418
|
-
() => a.localParticipant.videoTrackPublications,
|
|
419
|
-
X
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
async function X() {
|
|
423
|
-
return ue(Q, "Camera");
|
|
424
|
-
}
|
|
425
|
-
function Je() {
|
|
426
|
-
L && (L.getTracks().forEach((e) => e.stop()), L = null);
|
|
427
|
-
}
|
|
428
|
-
async function Z(e, t) {
|
|
429
|
-
var o, r;
|
|
430
|
-
if (!w || !a) {
|
|
431
|
-
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, j(), {
|
|
432
|
-
sessionId: v
|
|
433
|
-
});
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
try {
|
|
437
|
-
await a.localParticipant.sendText(t, { topic: e }), i("Message sent successfully:", t);
|
|
438
|
-
} catch (c) {
|
|
439
|
-
i("Failed to send message:", c), (r = n.onError) == null || r.call(n, j(), { sessionId: v });
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
async function Y(e) {
|
|
443
|
-
var t, o;
|
|
444
|
-
R && (clearTimeout(R), R = null), T == null || T.destroy(), T = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, E.Disconnecting, e), await Promise.all([H(), X()]), await a.disconnect()), Je(), w = !1, K = !1, y.size > 0 && (y.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Idle), M = C.Idle;
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
speak(e) {
|
|
448
|
-
const t = typeof e == "string" ? e : JSON.stringify(e);
|
|
449
|
-
return Z(me.Speak, t);
|
|
450
|
-
},
|
|
451
|
-
disconnect: () => Y("user:disconnect"),
|
|
452
|
-
async reconnect() {
|
|
453
|
-
var e, t;
|
|
454
|
-
if ((a == null ? void 0 : a.state) === I.Connected) {
|
|
455
|
-
i("Room is already connected");
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if (!a || !$ || !_)
|
|
459
|
-
throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
460
|
-
i("Reconnecting to LiveKit room, state:", a.state), K = !1, q = null, (e = n.onConnectionStateChange) == null || e.call(n, E.Connecting, "user:reconnect");
|
|
461
|
-
try {
|
|
462
|
-
if (await a.connect($, _), i("Room reconnected"), w = !0, a.remoteParticipants.size === 0) {
|
|
463
|
-
if (i("Waiting for agent to join..."), !await new Promise((r) => {
|
|
464
|
-
const c = setTimeout(() => {
|
|
465
|
-
a == null || a.off(g.ParticipantConnected, d), r(!1);
|
|
466
|
-
}, 5e3), d = () => {
|
|
467
|
-
clearTimeout(c), a == null || a.off(g.ParticipantConnected, d), r(!0);
|
|
468
|
-
};
|
|
469
|
-
a == null || a.on(g.ParticipantConnected, d);
|
|
470
|
-
}))
|
|
471
|
-
throw i("Agent did not join within timeout"), await a.disconnect(), new Error("Agent did not rejoin the room");
|
|
472
|
-
i("Agent joined, reconnection successful");
|
|
473
|
-
}
|
|
474
|
-
} catch (o) {
|
|
475
|
-
throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, E.Fail, "user:reconnect-failed"), o;
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
sendDataChannelMessage: Z,
|
|
479
|
-
publishMicrophoneStream: Ne,
|
|
480
|
-
unpublishMicrophoneStream: H,
|
|
481
|
-
replaceMicrophoneTrack: ze,
|
|
482
|
-
publishCameraStream: Be,
|
|
483
|
-
unpublishCameraStream: X,
|
|
484
|
-
interrupt(e) {
|
|
485
|
-
return e === "text" || !w || !a ? !1 : (Z(me.Interrupt, ""), !0);
|
|
486
|
-
},
|
|
487
|
-
registerRpcMethod(e, t) {
|
|
488
|
-
a == null || a.registerRpcMethod(e, t);
|
|
489
|
-
},
|
|
490
|
-
unregisterRpcMethod(e) {
|
|
491
|
-
a == null || a.unregisterRpcMethod(e);
|
|
492
|
-
},
|
|
493
|
-
sessionId: v,
|
|
494
|
-
streamId: v,
|
|
495
|
-
streamType: te,
|
|
496
|
-
interruptAvailable: ie,
|
|
497
|
-
// A getter, not a snapshot: currentInterruptible changes as blocking tool calls come and go.
|
|
498
|
-
get isInterruptible() {
|
|
499
|
-
return W;
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
export {
|
|
504
|
-
ln as createLiveKitStreamingManager,
|
|
505
|
-
Se as handleInitError
|
|
506
|
-
};
|