@d-id/client-sdk 2.0.3 → 2.0.4-staging.388

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 l, 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-DROeMYRR.js";
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-Ct3dvC58.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 p = navigator.userAgent ?? "", C = (navigator.platform ?? "").toLowerCase();
12
+ const l = navigator.userAgent ?? "", C = (navigator.platform ?? "").toLowerCase();
13
13
  let u = "Unknown";
14
- /android/i.test(p) ? u = "Android" : /iphone|ipad|ipod/i.test(p) ? 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(p);
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 p = {}, C = Ze();
20
- C && (p.timezone = C);
19
+ const l = {}, C = Ze();
20
+ C && (l.timezone = C);
21
21
  const u = Ge();
22
- return u && (p.device = u), p;
22
+ return u && (l.device = u), l;
23
23
  }
24
- function en(p, C, u, i) {
25
- const M = Ne(p, `${C}/v2/agents/${u}`, i);
24
+ function en(l, C, u, i) {
25
+ const M = Ne(l, `${C}/v2/agents/${u}`, i);
26
26
  return {
27
- async createStream(g) {
28
- return M.post("/sessions", g);
27
+ async createStream(f) {
28
+ return M.post("/sessions", f);
29
29
  }
30
30
  };
31
31
  }
32
32
  const nn = {
33
- [l.ChatAnswer]: B.Answer,
34
- [l.ChatPartial]: B.Partial
35
- }, fe = 2e4;
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("./livekit-client.esm-DypJ_fOm.js");
38
+ return await import("./index-Ct3dvC58.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 = (p = "Stream Error") => new Qe(p);
52
- function ge(p, C, u) {
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:", p), (i = u.onConnectionStateChange) == null || i.call(u, w.Fail, "internal:init-error"), (M = u.onError) == null || M.call(u, p, { sessionId: "" }), p;
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(p, C, u) {
56
+ async function an(l, C, u) {
57
57
  var ce;
58
- const i = ze(u.debug || !1, "LiveKitStreamingManager"), { Room: M, RoomEvent: g, ConnectionState: k, Track: Z } = await tn(), { callbacks: n, auth: he, baseURL: me, analytics: G } = u;
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 h = null, S = null, j = null, D = !1;
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(he, me || Je, p, n.onError);
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: p }), T = t, I = o, $ = r, ee = s ?? !0, await a.prepareConnection($, I);
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
- ge(e, i, n);
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(g.ConnectionStateChanged, ye).on(g.ConnectionQualityChanged, ve).on(g.ParticipantConnected, we).on(g.ParticipantDisconnected, Ae).on(g.TrackSubscribed, Pe).on(g.TrackUnsubscribed, Re).on(g.DataReceived, $e).on(g.MediaDevicesError, _e).on(g.TranscriptionReceived, Se).on(g.EncryptionError, Ke).on(g.TrackSubscriptionFailed, De);
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 ${fe / 1e3} seconds after connect`
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
- }, fe);
110
+ }, he);
111
111
  } catch (e) {
112
- ge(e, i, n);
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, f;
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 = h == null ? void 0 : h.getReport()) == null ? void 0 : se.webRTCStats) == null ? void 0 : de.avgRtt) ?? 0;
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)"), (f = n.onConnectionStateChange) == null || f.call(n, w.Connected, "livekit:track-subscribed")), h = qe(
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
- ), h.start());
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(h == null ? void 0 : h.getReport()), h == null || h.stop(), h = null);
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, f;
195
- if (e === l.ToolCallStarted) {
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, l.ToolCallStarted, c);
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 === l.ToolCallDone) {
200
+ if (e === p.ToolCallDone) {
201
201
  const c = t;
202
- ie(c.call_id), (d = n.onToolEvent) == null || d.call(n, l.ToolCallDone, c);
202
+ ie(c.call_id), (d = n.onToolEvent) == null || d.call(n, p.ToolCallDone, c);
203
203
  return;
204
204
  }
205
- if (e === l.ToolCallError) {
205
+ if (e === p.ToolCallError) {
206
206
  const c = t;
207
- ie(c.call_id), (f = n.onToolEvent) == null || f.call(n, l.ToolCallError, c);
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, f;
215
- if (V = ((o = t.metadata) == null ? void 0 : o.interruptible) !== !1, (r = n.onInterruptibleChange) == null || r.call(n, V), e === l.StreamVideoCreated) {
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, (f = n.onAgentActivityStateChange) == null || f.call(n, 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, f, c, y;
229
- const o = ((f = (d = h == null ? void 0 : h.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : f.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, s = { ...t, downstreamNetworkLatency: r };
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
- [l.ChatAnswer]: te,
253
- [l.ChatPartial]: te,
254
- [l.ToolCallStarted]: Q,
255
- [l.ToolCallDone]: Q,
256
- [l.ToolCallError]: Q,
257
- [l.StreamVideoCreated]: z,
258
- [l.StreamVideoDone]: z,
259
- [l.StreamVideoError]: z,
260
- [l.StreamVideoRejected]: z,
261
- [l.ChatAudioTranscribed]: be,
262
- [l.TurnStarted]: Me,
263
- [l.TurnEnded]: ke
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), f = r || d.subject;
269
- if (i("Data received:", { subject: f, data: d }), !f) return;
270
- const c = Ie[f];
271
- c == null || c(f, d);
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 f = o(t);
305
- if (f.length === 0)
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 = f[0], y = Ve(c, r, s());
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(g.ParticipantConnected, d), r(!1);
440
+ a == null || a.off(f.ParticipantConnected, d), r(!1);
441
441
  }, 5e3), d = () => {
442
- clearTimeout(s), a == null || a.off(g.ParticipantConnected, d), r(!0);
442
+ clearTimeout(s), a == null || a.off(f.ParticipantConnected, d), r(!0);
443
443
  };
444
- a == null || a.on(g.ParticipantConnected, d);
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
- ge as handleInitError
481
+ fe as handleInitError
482
482
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "2.0.3",
4
+ "version": "2.0.4-staging.388",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {