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