@d-id/client-sdk 2.0.2-staging.383 → 2.0.3-staging.385
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,4 +1,4 @@
|
|
|
1
|
-
import { c as Ne, C as B, S as
|
|
1
|
+
import { c as Ne, C as B, S as p, a as ze, b as Be, A as m, d as Je, l as pe, e as Qe, t as We, f as w, g as U, h as qe, i as He, j as P, n as Xe } from "./index-CcN1tzMS.js";
|
|
2
2
|
function Ze() {
|
|
3
3
|
try {
|
|
4
4
|
return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
@@ -9,33 +9,33 @@ function Ze() {
|
|
|
9
9
|
function Ge() {
|
|
10
10
|
if (typeof navigator > "u")
|
|
11
11
|
return "";
|
|
12
|
-
const
|
|
12
|
+
const l = navigator.userAgent ?? "", C = (navigator.platform ?? "").toLowerCase();
|
|
13
13
|
let u = "Unknown";
|
|
14
|
-
/android/i.test(
|
|
15
|
-
const i = u === "Android" || u === "iOS" || /Mobi/i.test(
|
|
14
|
+
/android/i.test(l) ? u = "Android" : /iphone|ipad|ipod/i.test(l) ? u = "iOS" : C.includes("win") ? u = "Windows" : C.includes("mac") ? u = "Mac OS X" : C.includes("linux") && (u = "Linux");
|
|
15
|
+
const i = u === "Android" || u === "iOS" || /Mobi/i.test(l);
|
|
16
16
|
return `${u}, ${i ? "Mobile" : "Desktop"}`;
|
|
17
17
|
}
|
|
18
18
|
function Ye() {
|
|
19
|
-
const
|
|
20
|
-
C && (
|
|
19
|
+
const l = {}, C = Ze();
|
|
20
|
+
C && (l.timezone = C);
|
|
21
21
|
const u = Ge();
|
|
22
|
-
return u && (
|
|
22
|
+
return u && (l.device = u), l;
|
|
23
23
|
}
|
|
24
|
-
function en(
|
|
25
|
-
const M = Ne(
|
|
24
|
+
function en(l, C, u, i) {
|
|
25
|
+
const M = Ne(l, `${C}/v2/agents/${u}`, i);
|
|
26
26
|
return {
|
|
27
|
-
async createStream(
|
|
28
|
-
return M.post("/sessions",
|
|
27
|
+
async createStream(f) {
|
|
28
|
+
return M.post("/sessions", f);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
const nn = {
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
},
|
|
33
|
+
[p.ChatAnswer]: B.Answer,
|
|
34
|
+
[p.ChatPartial]: B.Partial
|
|
35
|
+
}, he = 2e4;
|
|
36
36
|
async function tn() {
|
|
37
37
|
try {
|
|
38
|
-
return await import("./
|
|
38
|
+
return await import("./index-CcN1tzMS.js").then((l) => l.y);
|
|
39
39
|
} catch {
|
|
40
40
|
throw new Error(
|
|
41
41
|
"LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
|
|
@@ -48,19 +48,19 @@ const on = {
|
|
|
48
48
|
poor: U.Weak,
|
|
49
49
|
lost: U.Unknown,
|
|
50
50
|
unknown: U.Unknown
|
|
51
|
-
}, K = (
|
|
52
|
-
function
|
|
51
|
+
}, K = (l = "Stream Error") => new Qe(l);
|
|
52
|
+
function fe(l, C, u) {
|
|
53
53
|
var i, M;
|
|
54
|
-
throw C("Failed to connect to LiveKit room:",
|
|
54
|
+
throw C("Failed to connect to LiveKit room:", l), (i = u.onConnectionStateChange) == null || i.call(u, w.Fail, "internal:init-error"), (M = u.onError) == null || M.call(u, l, { sessionId: "" }), l;
|
|
55
55
|
}
|
|
56
|
-
async function an(
|
|
56
|
+
async function an(l, C, u) {
|
|
57
57
|
var ce;
|
|
58
|
-
const i = ze(u.debug || !1, "LiveKitStreamingManager"), { Room: M, RoomEvent:
|
|
58
|
+
const i = ze(u.debug || !1, "LiveKitStreamingManager"), { Room: M, RoomEvent: f, ConnectionState: k, Track: Z } = await tn(), { callbacks: n, auth: ge, baseURL: me, analytics: G } = u;
|
|
59
59
|
let a = null, A = !1;
|
|
60
60
|
const Y = Be.Fluent;
|
|
61
61
|
let R = null;
|
|
62
62
|
const L = { isPublishing: !1, publication: null }, J = { isPublishing: !1, publication: null };
|
|
63
|
-
let
|
|
63
|
+
let g = null, S = null, j = null, D = !1;
|
|
64
64
|
a = new M({
|
|
65
65
|
adaptiveStream: !1,
|
|
66
66
|
// Must be false to use mediaStreamTrack directly
|
|
@@ -69,7 +69,7 @@ async function an(p, C, u) {
|
|
|
69
69
|
let E = null, b = m.Idle, V = !0;
|
|
70
70
|
const O = /* @__PURE__ */ new Set();
|
|
71
71
|
let N = null;
|
|
72
|
-
const Ce = en(
|
|
72
|
+
const Ce = en(ge, me || Je, l, n.onError);
|
|
73
73
|
let T, I, $, ee = !0;
|
|
74
74
|
try {
|
|
75
75
|
const e = await Ce.createStream({
|
|
@@ -77,13 +77,13 @@ async function an(p, C, u) {
|
|
|
77
77
|
chat_persist: C.chat_persist ?? !0,
|
|
78
78
|
verbose: u.verbose ?? !1
|
|
79
79
|
}), { id: t, session_token: o, session_url: r, interrupt_enabled: s } = e;
|
|
80
|
-
(ce = n.onStreamCreated) == null || ce.call(n, { session_id: t, stream_id: t, agent_id:
|
|
80
|
+
(ce = n.onStreamCreated) == null || ce.call(n, { session_id: t, stream_id: t, agent_id: l }), T = t, I = o, $ = r, ee = s ?? !0, await a.prepareConnection($, I);
|
|
81
81
|
} catch (e) {
|
|
82
|
-
|
|
82
|
+
fe(e, i, n);
|
|
83
83
|
}
|
|
84
84
|
if (!$ || !I || !T)
|
|
85
85
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
86
|
-
a.on(
|
|
86
|
+
a.on(f.ConnectionStateChanged, ye).on(f.ConnectionQualityChanged, ve).on(f.ParticipantConnected, we).on(f.ParticipantDisconnected, Ae).on(f.TrackSubscribed, Pe).on(f.TrackUnsubscribed, Re).on(f.DataReceived, $e).on(f.MediaDevicesError, _e).on(f.TranscriptionReceived, Se).on(f.EncryptionError, Ke).on(f.TrackSubscriptionFailed, De);
|
|
87
87
|
function Se(e, t) {
|
|
88
88
|
t != null && t.isLocal && pe.update();
|
|
89
89
|
}
|
|
@@ -100,16 +100,16 @@ async function an(p, C, u) {
|
|
|
100
100
|
await a.connect($, I), i("LiveKit room joined successfully"), Te(), E = setTimeout(() => {
|
|
101
101
|
var t;
|
|
102
102
|
i(
|
|
103
|
-
`Track subscription timeout - no track subscribed within ${
|
|
103
|
+
`Track subscription timeout - no track subscribed within ${he / 1e3} seconds after connect`
|
|
104
104
|
), E = null;
|
|
105
105
|
const e = K("Track subscription timeout");
|
|
106
106
|
G.track("connectivity-error", {
|
|
107
107
|
error: We(e),
|
|
108
108
|
sessionId: T
|
|
109
109
|
}), (t = n.onError) == null || t.call(n, e, { sessionId: T }), X("internal:track-subscription-timeout");
|
|
110
|
-
},
|
|
110
|
+
}, he);
|
|
111
111
|
} catch (e) {
|
|
112
|
-
|
|
112
|
+
fe(e, i, n);
|
|
113
113
|
}
|
|
114
114
|
G.enrich({
|
|
115
115
|
"stream-type": Y
|
|
@@ -153,7 +153,7 @@ async function an(p, C, u) {
|
|
|
153
153
|
j !== P.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), j = P.Stop, (t = n.onVideoStateChange) == null || t.call(n, P.Stop, e));
|
|
154
154
|
}
|
|
155
155
|
function Pe(e, t, o) {
|
|
156
|
-
var s, d,
|
|
156
|
+
var s, d, h;
|
|
157
157
|
i(`Track subscribed: ${e.kind} from ${o.identity}`);
|
|
158
158
|
const r = e.mediaStreamTrack;
|
|
159
159
|
if (!r) {
|
|
@@ -167,23 +167,23 @@ async function an(p, C, u) {
|
|
|
167
167
|
const F = pe.get(!0);
|
|
168
168
|
let x = 0;
|
|
169
169
|
if (c) {
|
|
170
|
-
const le = ((de = (se =
|
|
170
|
+
const le = ((de = (se = g == null ? void 0 : g.getReport()) == null ? void 0 : se.webRTCStats) == null ? void 0 : de.avgRtt) ?? 0;
|
|
171
171
|
x = le > 0 ? Math.round(le * 1e3) : 0;
|
|
172
172
|
}
|
|
173
173
|
const _ = F > 0 ? F + (c ?? 0) + x : void 0, v = _ !== void 0 && y !== void 0 ? _ - y : void 0;
|
|
174
174
|
(ue = n.onFirstAudioDetected) == null || ue.call(n, { latency: _, networkLatency: v });
|
|
175
175
|
}
|
|
176
|
-
)), e.kind === "video" && ((s = n.onStreamReady) == null || s.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, R), D || (D = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
176
|
+
)), e.kind === "video" && ((s = n.onStreamReady) == null || s.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, R), D || (D = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (h = n.onConnectionStateChange) == null || h.call(n, w.Connected, "livekit:track-subscribed")), g = qe(
|
|
177
177
|
() => e.getRTCStatsReport(),
|
|
178
178
|
() => A,
|
|
179
179
|
Xe,
|
|
180
180
|
(c, y) => {
|
|
181
181
|
i(`Video state change: ${c}`), c === P.Start ? (E && (clearTimeout(E), E = null, i("Track subscription timeout cleared")), Ee()) : c === P.Stop && ne(y);
|
|
182
182
|
}
|
|
183
|
-
),
|
|
183
|
+
), g.start());
|
|
184
184
|
}
|
|
185
185
|
function Re(e, t, o) {
|
|
186
|
-
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (ne(
|
|
186
|
+
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (ne(g == null ? void 0 : g.getReport()), g == null || g.stop(), g = null);
|
|
187
187
|
}
|
|
188
188
|
function te(e, t) {
|
|
189
189
|
var r;
|
|
@@ -191,28 +191,28 @@ async function an(p, C, u) {
|
|
|
191
191
|
o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
|
|
192
192
|
}
|
|
193
193
|
function Q(e, t) {
|
|
194
|
-
var o, r, s, d,
|
|
195
|
-
if (e ===
|
|
194
|
+
var o, r, s, d, h;
|
|
195
|
+
if (e === p.ToolCallStarted) {
|
|
196
196
|
const c = t;
|
|
197
|
-
V = c.interruptible !== !1, (o = n.onInterruptibleChange) == null || o.call(n, V), O.add(c.call_id), b = m.ToolActive, (r = n.onAgentActivityStateChange) == null || r.call(n, m.ToolActive), (s = n.onToolEvent) == null || s.call(n,
|
|
197
|
+
V = c.interruptible !== !1, (o = n.onInterruptibleChange) == null || o.call(n, V), O.add(c.call_id), b = m.ToolActive, (r = n.onAgentActivityStateChange) == null || r.call(n, m.ToolActive), (s = n.onToolEvent) == null || s.call(n, p.ToolCallStarted, c);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
|
-
if (e ===
|
|
200
|
+
if (e === p.ToolCallDone) {
|
|
201
201
|
const c = t;
|
|
202
|
-
ie(c.call_id), (d = n.onToolEvent) == null || d.call(n,
|
|
202
|
+
ie(c.call_id), (d = n.onToolEvent) == null || d.call(n, p.ToolCallDone, c);
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
|
-
if (e ===
|
|
205
|
+
if (e === p.ToolCallError) {
|
|
206
206
|
const c = t;
|
|
207
|
-
ie(c.call_id), (
|
|
207
|
+
ie(c.call_id), (h = n.onToolEvent) == null || h.call(n, p.ToolCallError, c);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
function ie(e) {
|
|
211
211
|
O.delete(e);
|
|
212
212
|
}
|
|
213
213
|
function Le(e, t) {
|
|
214
|
-
var o, r, s, d,
|
|
215
|
-
if (V = ((o = t.metadata) == null ? void 0 : o.interruptible) !== !1, (r = n.onInterruptibleChange) == null || r.call(n, V), e ===
|
|
214
|
+
var o, r, s, d, h;
|
|
215
|
+
if (V = ((o = t.metadata) == null ? void 0 : o.interruptible) !== !1, (r = n.onInterruptibleChange) == null || r.call(n, V), e === p.StreamVideoCreated) {
|
|
216
216
|
b = m.Talking, (s = n.onAgentActivityStateChange) == null || s.call(n, m.Talking), S == null || S.arm({
|
|
217
217
|
sttLatency: (d = t == null ? void 0 : t.stt) == null ? void 0 : d.latency,
|
|
218
218
|
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
@@ -220,13 +220,13 @@ async function an(p, C, u) {
|
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
if (O.size > 0) {
|
|
223
|
-
b !== m.ToolActive && (b = m.ToolActive, (
|
|
223
|
+
b !== m.ToolActive && (b = m.ToolActive, (h = n.onAgentActivityStateChange) == null || h.call(n, m.ToolActive));
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
function z(e, t) {
|
|
228
|
-
var d,
|
|
229
|
-
const o = ((
|
|
228
|
+
var d, h, c, y;
|
|
229
|
+
const o = ((h = (d = g == null ? void 0 : g.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : h.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, s = { ...t, downstreamNetworkLatency: r };
|
|
230
230
|
u.debug && ((c = t == null ? void 0 : t.metadata) != null && c.sentiment) && (s.sentiment = {
|
|
231
231
|
id: t.metadata.sentiment.id,
|
|
232
232
|
name: t.metadata.sentiment.sentiment
|
|
@@ -249,26 +249,26 @@ async function an(p, C, u) {
|
|
|
249
249
|
N !== null && o !== null && o < N || (b = m.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle));
|
|
250
250
|
}
|
|
251
251
|
const Ie = {
|
|
252
|
-
[
|
|
253
|
-
[
|
|
254
|
-
[
|
|
255
|
-
[
|
|
256
|
-
[
|
|
257
|
-
[
|
|
258
|
-
[
|
|
259
|
-
[
|
|
260
|
-
[
|
|
261
|
-
[
|
|
262
|
-
[
|
|
263
|
-
[
|
|
252
|
+
[p.ChatAnswer]: te,
|
|
253
|
+
[p.ChatPartial]: te,
|
|
254
|
+
[p.ToolCallStarted]: Q,
|
|
255
|
+
[p.ToolCallDone]: Q,
|
|
256
|
+
[p.ToolCallError]: Q,
|
|
257
|
+
[p.StreamVideoCreated]: z,
|
|
258
|
+
[p.StreamVideoDone]: z,
|
|
259
|
+
[p.StreamVideoError]: z,
|
|
260
|
+
[p.StreamVideoRejected]: z,
|
|
261
|
+
[p.ChatAudioTranscribed]: be,
|
|
262
|
+
[p.TurnStarted]: Me,
|
|
263
|
+
[p.TurnEnded]: ke
|
|
264
264
|
};
|
|
265
265
|
function $e(e, t, o, r) {
|
|
266
266
|
const s = new TextDecoder().decode(e);
|
|
267
267
|
try {
|
|
268
|
-
const d = JSON.parse(s),
|
|
269
|
-
if (i("Data received:", { subject:
|
|
270
|
-
const c = Ie[
|
|
271
|
-
c == null || c(
|
|
268
|
+
const d = JSON.parse(s), h = r || d.subject;
|
|
269
|
+
if (i("Data received:", { subject: h, data: d }), !h) return;
|
|
270
|
+
const c = Ie[h];
|
|
271
|
+
c == null || c(h, d);
|
|
272
272
|
} catch (d) {
|
|
273
273
|
i("Failed to parse data channel message:", d);
|
|
274
274
|
}
|
|
@@ -301,10 +301,10 @@ async function an(p, C, u) {
|
|
|
301
301
|
i(`${r} publish already in progress, skipping`);
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
304
|
+
const h = o(t);
|
|
305
|
+
if (h.length === 0)
|
|
306
306
|
throw new Error(`No ${r} track found in the provided MediaStream`);
|
|
307
|
-
const c =
|
|
307
|
+
const c = h[0], y = Ve(c, r, s());
|
|
308
308
|
if (y) {
|
|
309
309
|
i(`${r} track is already published, skipping`, {
|
|
310
310
|
trackId: c.id,
|
|
@@ -437,11 +437,11 @@ async function an(p, C, u) {
|
|
|
437
437
|
if (await a.connect($, I), i("Room reconnected"), A = !0, a.remoteParticipants.size === 0) {
|
|
438
438
|
if (i("Waiting for agent to join..."), !await new Promise((r) => {
|
|
439
439
|
const s = setTimeout(() => {
|
|
440
|
-
a == null || a.off(
|
|
440
|
+
a == null || a.off(f.ParticipantConnected, d), r(!1);
|
|
441
441
|
}, 5e3), d = () => {
|
|
442
|
-
clearTimeout(s), a == null || a.off(
|
|
442
|
+
clearTimeout(s), a == null || a.off(f.ParticipantConnected, d), r(!0);
|
|
443
443
|
};
|
|
444
|
-
a == null || a.on(
|
|
444
|
+
a == null || a.on(f.ParticipantConnected, d);
|
|
445
445
|
}))
|
|
446
446
|
throw i("Agent did not join within timeout"), await a.disconnect(), new Error("Agent did not rejoin the room");
|
|
447
447
|
i("Agent joined, reconnection successful");
|
|
@@ -478,5 +478,5 @@ async function an(p, C, u) {
|
|
|
478
478
|
}
|
|
479
479
|
export {
|
|
480
480
|
an as createLiveKitStreamingManager,
|
|
481
|
-
|
|
481
|
+
fe as handleInitError
|
|
482
482
|
};
|