@d-id/client-sdk 1.0.19-beta.21 → 1.0.19-beta.22

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.js CHANGED
@@ -1,4 +1,4 @@
1
- const R = "https://api.d-id.com", J = "wss://notifications.d-id.com";
1
+ const S = "https://api.d-id.com", J = "wss://notifications.d-id.com";
2
2
  function F(e) {
3
3
  if (e.type === "bearer")
4
4
  return `Bearer ${e.token}`;
@@ -8,7 +8,7 @@ function F(e) {
8
8
  return `Client-Key ${e.clientKey}.${e.externalId}`;
9
9
  throw new Error(`Unknown auth type: ${e}`);
10
10
  }
11
- function P(e, i = R) {
11
+ function E(e, i = S) {
12
12
  const n = async (t, r) => {
13
13
  const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
14
14
  ...r,
@@ -19,8 +19,8 @@ function P(e, i = R) {
19
19
  }
20
20
  });
21
21
  if (!a.ok) {
22
- let s = await a.text().catch(() => "Failed to fetch");
23
- throw new Error(s);
22
+ let o = await a.text().catch(() => "Failed to fetch");
23
+ throw new Error(o);
24
24
  }
25
25
  return a.json();
26
26
  };
@@ -54,8 +54,8 @@ function P(e, i = R) {
54
54
  }
55
55
  };
56
56
  }
57
- function N(e, i = R) {
58
- const n = P(e, `${i}/agents`);
57
+ function N(e, i = S) {
58
+ const n = E(e, `${i}/agents`);
59
59
  return {
60
60
  create(t, r) {
61
61
  return n.post("/", t, r);
@@ -75,13 +75,13 @@ function N(e, i = R) {
75
75
  newChat(t, r) {
76
76
  return n.post(`/${t}/chat`, void 0, r);
77
77
  },
78
- chat(t, r, a, s) {
79
- return n.post(`/${t}/chat/${r}`, a, s);
78
+ chat(t, r, a, o) {
79
+ return n.post(`/${t}/chat/${r}`, a, o);
80
80
  }
81
81
  };
82
82
  }
83
- function D(e, i = R) {
84
- const n = P(e, `${i}/knowledge`);
83
+ function D(e, i = S) {
84
+ const n = E(e, `${i}/knowledge`);
85
85
  return {
86
86
  createKnowledge(t, r) {
87
87
  return n.post("/", t, r);
@@ -117,8 +117,8 @@ function D(e, i = R) {
117
117
  }
118
118
  };
119
119
  }
120
- function V(e, i = R) {
121
- const n = P(e, `${i}/chats/ratings`);
120
+ function V(e, i = S) {
121
+ const n = E(e, `${i}/chats/ratings`);
122
122
  return {
123
123
  create(t, r) {
124
124
  return n.post("/", t, r);
@@ -142,15 +142,15 @@ function Q(e) {
142
142
  host: r,
143
143
  auth: a
144
144
  } = e, {
145
- onMessage: s = null,
145
+ onMessage: o = null,
146
146
  onOpen: u = null,
147
147
  onClose: m = null,
148
- onError: p = null
148
+ onError: h = null
149
149
  } = t || {}, f = new WebSocket(`${r}?authorization=${F(a)}`);
150
- f.onmessage = s, f.onclose = m, f.onerror = (d) => {
151
- console.log(d), p == null || p(d), n(d);
152
- }, f.onopen = (d) => {
153
- u == null || u(d), i(f);
150
+ f.onmessage = o, f.onclose = m, f.onerror = (l) => {
151
+ console.log(l), h == null || h(l), n(l);
152
+ }, f.onopen = (l) => {
153
+ u == null || u(l), i(f);
154
154
  };
155
155
  });
156
156
  }
@@ -175,8 +175,8 @@ async function Y(e, i, n) {
175
175
  host: i,
176
176
  callbacks: {
177
177
  onMessage: (a) => {
178
- const s = JSON.parse(a.data);
179
- t.forEach((u) => u(s.event, s));
178
+ const o = JSON.parse(a.data);
179
+ t.forEach((u) => u(o.event, o));
180
180
  }
181
181
  }
182
182
  });
@@ -186,36 +186,36 @@ async function Y(e, i, n) {
186
186
  subscribeToEvents: (a) => t.push(a)
187
187
  };
188
188
  }
189
- var Z = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Z || {}), O = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(O || {}), I = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(I || {}), _ = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e))(_ || {}), j = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(j || {}), ee = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(ee || {}), B = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(B || {}), te = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ne || {}), re = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(re || {}), M = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(M || {});
189
+ var Z = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Z || {}), O = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(O || {}), M = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(M || {}), K = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e))(K || {}), j = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(j || {}), ee = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(ee || {}), b = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(b || {}), te = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ne || {}), re = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(re || {}), x = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(x || {});
190
190
  function ae(e) {
191
- return e.presenter.type === M.Clip ? {
192
- videoType: M.Clip,
191
+ return e.presenter.type === x.Clip ? {
192
+ videoType: x.Clip,
193
193
  driver_id: e.presenter.driver_id,
194
194
  presenter_id: e.presenter.presenter_id
195
195
  } : {
196
- videoType: M.Talk,
196
+ videoType: x.Talk,
197
197
  source_url: e.presenter.source_url
198
198
  };
199
199
  }
200
200
  function q(e, i, n, t) {
201
201
  return new Promise(async (r, a) => {
202
- const s = await de(ae(e), {
202
+ const o = await de(ae(e), {
203
203
  ...i,
204
204
  callbacks: {
205
205
  ...i.callbacks,
206
206
  onConnectionStateChange: async (u) => {
207
- var m, p;
207
+ var m, h;
208
208
  u === "connected" ? (t || (t = await n.newChat(e.id)), r({
209
209
  chat: t,
210
- streamingManager: s
211
- })) : u === "failed" && a(new Error("Cannot create connection")), (p = (m = i.callbacks).onConnectionStateChange) == null || p.call(m, u);
210
+ streamingManager: o
211
+ })) : u === "failed" && a(new Error("Cannot create connection")), (h = (m = i.callbacks).onConnectionStateChange) == null || h.call(m, u);
212
212
  },
213
213
  // TODO remove when webscoket will return partial
214
214
  onMessage: (u, m) => {
215
- var p, f;
216
- u === _.ChatAnswer && (console.log("ChatAnswer", u, m), (f = (p = i.callbacks).onChatEvents) == null || f.call(p, B.Answer, {
215
+ var h, f;
216
+ u === K.ChatAnswer && (console.log("ChatAnswer", u, m), (f = (h = i.callbacks).onChatEvents) == null || f.call(h, b.Answer, {
217
217
  content: m,
218
- event: B.Answer
218
+ event: b.Answer
219
219
  }));
220
220
  }
221
221
  }
@@ -223,65 +223,65 @@ function q(e, i, n, t) {
223
223
  });
224
224
  }
225
225
  function le(e, i, n) {
226
- return N(i, n || R).getById(e);
226
+ return N(i, n || S).getById(e);
227
227
  }
228
228
  async function ue(e, i) {
229
- const n = i.baseURL || R, t = i.wsURL || J, r = new AbortController(), a = N(i.auth, n), s = V(i.auth, n), u = D(i.auth, n), m = await a.getById(e), p = await Y(i.auth, t, i.callbacks.onChatEvents);
229
+ const n = i.baseURL || S, t = i.wsURL || J, r = new AbortController(), a = N(i.auth, n), o = V(i.auth, n), u = D(i.auth, n), m = await a.getById(e), h = await Y(i.auth, t, i.callbacks.onChatEvents);
230
230
  let {
231
231
  chat: f,
232
- streamingManager: d
232
+ streamingManager: l
233
233
  } = await q(m, i, a);
234
234
  return {
235
235
  agent: m,
236
236
  async reconnectToChat() {
237
237
  const {
238
- streamingManager: c
238
+ streamingManager: d
239
239
  } = await q(m, i, a, f);
240
- d = c;
240
+ l = d;
241
241
  },
242
242
  terminate() {
243
- return r.abort(), p.terminate(), d.terminate();
243
+ return r.abort(), h.terminate(), l.terminate();
244
244
  },
245
245
  chatId: f.id,
246
- chat(c) {
246
+ chat(d) {
247
247
  return a.chat(e, f.id, {
248
- sessionId: d.sessionId,
249
- streamId: d.streamId,
250
- messages: c
248
+ sessionId: l.sessionId,
249
+ streamId: l.streamId,
250
+ messages: d
251
251
  }, {
252
252
  signal: r.signal
253
253
  });
254
254
  },
255
- rate(c, h) {
256
- return h ? s.update(h, c) : s.create(c);
255
+ rate(d, p) {
256
+ return p ? o.update(p, d) : o.create(d);
257
257
  },
258
- deleteRate(c) {
259
- return s.delete(c);
258
+ deleteRate(d) {
259
+ return o.delete(d);
260
260
  },
261
- speak(c) {
262
- let h;
263
- return c.type === "text" ? h = {
261
+ speak(d) {
262
+ let p;
263
+ return d.type === "text" ? p = {
264
264
  script: {
265
265
  type: "text",
266
- provider: c.provider,
267
- input: c.input,
268
- ssml: c.ssml || !1
266
+ provider: d.provider,
267
+ input: d.input,
268
+ ssml: d.ssml || !1
269
269
  }
270
- } : c.type === "audio" && (h = {
270
+ } : d.type === "audio" && (p = {
271
271
  script: {
272
272
  type: "audio",
273
- audio_url: c.audio_url
273
+ audio_url: d.audio_url
274
274
  }
275
- }), d.speak(h);
275
+ }), l.speak(p);
276
276
  },
277
277
  getStarterMessages() {
278
- var c, h;
279
- return (c = m.knowledge) != null && c.id ? u.getKnowledge((h = m.knowledge) == null ? void 0 : h.id).then((w) => (w == null ? void 0 : w.starter_message) || []) : Promise.resolve([]);
278
+ var d, p;
279
+ return (d = m.knowledge) != null && d.id ? u.getKnowledge((p = m.knowledge) == null ? void 0 : p.id).then((C) => (C == null ? void 0 : C.starter_message) || []) : Promise.resolve([]);
280
280
  }
281
281
  };
282
282
  }
283
283
  function ie(e, i) {
284
- const n = P(e, i);
284
+ const n = E(e, i);
285
285
  return {
286
286
  createStream(t) {
287
287
  return n.post("/clips/streams", {
@@ -316,7 +316,7 @@ function ie(e, i) {
316
316
  };
317
317
  }
318
318
  function se(e, i) {
319
- const n = P(e, i);
319
+ const n = E(e, i);
320
320
  return {
321
321
  createStream(t, r) {
322
322
  return n.post("/talks/streams", {
@@ -326,23 +326,23 @@ function se(e, i) {
326
326
  config: t.config
327
327
  }, r);
328
328
  },
329
- startConnection(t, r, a, s) {
329
+ startConnection(t, r, a, o) {
330
330
  return n.post(`/talks/streams/${t}/sdp`, {
331
331
  session_id: a,
332
332
  answer: r
333
- }, s);
333
+ }, o);
334
334
  },
335
- addIceCandidate(t, r, a, s) {
335
+ addIceCandidate(t, r, a, o) {
336
336
  return n.post(`/talks/streams/${t}/ice`, {
337
337
  session_id: a,
338
338
  ...r
339
- }, s);
339
+ }, o);
340
340
  },
341
- sendStreamRequest(t, r, a, s) {
341
+ sendStreamRequest(t, r, a, o) {
342
342
  return n.post(`/talks/streams/${t}`, {
343
343
  session_id: r,
344
344
  ...a
345
- }, s);
345
+ }, o);
346
346
  },
347
347
  close(t, r, a) {
348
348
  return n.delete(`/talks/streams/${t}`, {
@@ -390,126 +390,132 @@ async function de(e, {
390
390
  debug: i = !1,
391
391
  callbacks: n,
392
392
  auth: t,
393
- baseURL: r = R
393
+ baseURL: r = S
394
394
  }) {
395
395
  z = i;
396
396
  const a = {
397
397
  ...n
398
398
  }, {
399
- startConnection: s,
399
+ startConnection: o,
400
400
  sendStreamRequest: u,
401
401
  close: m,
402
- createStream: p,
402
+ createStream: h,
403
403
  addIceCandidate: f
404
- } = e.videoType === M.Clip ? ie(t, r) : se(t, r), {
405
- id: d,
406
- offer: c,
407
- ice_servers: h,
408
- session_id: w
409
- } = await p(e), g = new ce({
410
- iceServers: h
411
- }), H = g.createDataChannel("JanusDataChannel"), l = [];
412
- let S = 0, L = 0, K = 0, b, T;
413
- if (!w)
404
+ } = e.videoType === x.Clip ? ie(t, r) : se(t, r), {
405
+ id: l,
406
+ offer: d,
407
+ ice_servers: p,
408
+ session_id: C
409
+ } = await h(e), g = new ce({
410
+ iceServers: p
411
+ }), H = g.createDataChannel("JanusDataChannel"), s = [];
412
+ let P = 0, k = 0, I = 0, W, T;
413
+ if (!C)
414
414
  throw new Error("Could not create session_id");
415
- g.onicecandidate = (o) => {
416
- $("peerConnection.onicecandidate", o), o.candidate && o.candidate.sdpMid && o.candidate.sdpMLineIndex !== null && f(d, {
417
- candidate: o.candidate.candidate,
418
- sdpMid: o.candidate.sdpMid,
419
- sdpMLineIndex: o.candidate.sdpMLineIndex
420
- }, w);
415
+ g.onicecandidate = (c) => {
416
+ $("peerConnection.onicecandidate", c), c.candidate && c.candidate.sdpMid && c.candidate.sdpMLineIndex !== null && f(l, {
417
+ candidate: c.candidate.candidate,
418
+ sdpMid: c.candidate.sdpMid,
419
+ sdpMLineIndex: c.candidate.sdpMLineIndex
420
+ }, C);
421
421
  }, g.oniceconnectionstatechange = () => {
422
- var o;
423
- $("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState), (o = a.onConnectionStateChange) == null || o.call(a, g.iceConnectionState);
424
- }, g.ontrack = (o) => {
425
- var v;
426
- $("peerConnection.ontrack", o), (v = a.onSrcObjectReady) == null || v.call(a, o.streams[0]), b = setInterval(() => {
427
- var y, A;
428
- if (console.log(" ontrack interval ", l == null ? void 0 : l.length, L), l != null && l.length && L <= (l == null ? void 0 : l.length)) {
429
- const C = (y = l[L]) == null ? void 0 : y.bytesReceived, k = (C ?? 1 / 0) - K > 0 || K == 0 && C == 0;
430
- K = C ?? 0, k || (A = a.onVideoStateChange) == null || A.call(a, I.Stop, {
431
- isPlaying: k
432
- }), L = l == null ? void 0 : l.length, console.log(" ontrack interval end", k);
422
+ var c;
423
+ $("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState), (c = a.onConnectionStateChange) == null || c.call(a, g.iceConnectionState);
424
+ }, g.ontrack = (c) => {
425
+ var y;
426
+ $("peerConnection.ontrack", c), (y = a.onSrcObjectReady) == null || y.call(a, c.streams[0]), W = setInterval(() => {
427
+ var A, L, R, _;
428
+ if (console.log(" ontrack interval ", s == null ? void 0 : s.length, k), s != null && s.length && k <= (s == null ? void 0 : s.length)) {
429
+ const w = (A = s[k]) == null ? void 0 : A.bytesReceived, v = (w ?? 1 / 0) - I > 0 || I == 0 && w == 0;
430
+ I = w ?? 0, v || (L = a.onVideoStateChange) == null || L.call(a, M.Stop, {
431
+ isPlaying: v
432
+ }), k = s == null ? void 0 : s.length, console.log(" ontrack interval end", v);
433
+ }
434
+ if (k == (s == null ? void 0 : s.length)) {
435
+ const w = (R = s[k]) == null ? void 0 : R.bytesReceived, v = !((w ?? 1 / 0) - I == 0 && I > 0 && w > 0);
436
+ I = w ?? 0, v || (_ = a.onVideoStateChange) == null || _.call(a, M.Stop, {
437
+ isPlaying: v
438
+ }), k = s == null ? void 0 : s.length, console.log(" ontrack interval end", v);
433
439
  }
434
440
  }, 1e3);
435
- }, H.onmessage = (o) => {
436
- var v, y, A;
441
+ }, H.onmessage = (c) => {
442
+ var y, A, L;
437
443
  if (H.readyState === "open") {
438
- const [C, k] = o.data.split(":");
439
- if (C === _.StreamStarted)
440
- console.log("StreamStarted", C, k), S = l.length, T = setInterval(() => {
441
- g.getStats().then((E) => {
442
- E.forEach((W) => {
443
- W.type === "inbound-rtp" && W.kind === "video" && l.push(W);
444
+ const [R, _] = c.data.split(":");
445
+ if (R === K.StreamStarted)
446
+ console.log("StreamStarted", R, _), P = s.length, T = setInterval(() => {
447
+ g.getStats().then((v) => {
448
+ v.forEach((B) => {
449
+ B.type === "inbound-rtp" && B.kind === "video" && s.push(B);
444
450
  });
445
451
  });
446
- }, 1e3), (v = a.onVideoStateChange) == null || v.call(a, I.Start);
447
- else if (C === _.StreamDone) {
452
+ }, 1e3), (y = a.onVideoStateChange) == null || y.call(a, M.Start);
453
+ else if (R === K.StreamDone) {
448
454
  console.log("StreamDone");
449
- const x = l.slice(S);
450
- if (x) {
451
- const E = S === 0 ? void 0 : l[S - 1];
452
- oe(x, E), S = l.length;
455
+ const w = s.slice(P);
456
+ if (w) {
457
+ const v = P === 0 ? void 0 : s[P - 1];
458
+ oe(w, v), P = s.length;
453
459
  }
454
460
  setTimeout(() => {
455
- clearInterval(b), console.log("clearInterval palying?");
461
+ clearInterval(W), console.log("clearInterval palying?");
456
462
  }, 2500), console.log("clearInterval statd?"), clearInterval(T);
457
463
  } else
458
- C === _.StreamFailed ? (y = a.onVideoStateChange) == null || y.call(a, I.Stop, {
459
- event: C,
460
- data: k
461
- }) : (A = a.onMessage) == null || A.call(a, C, decodeURIComponent(k));
464
+ R === K.StreamFailed ? (A = a.onVideoStateChange) == null || A.call(a, M.Stop, {
465
+ event: R,
466
+ data: _
467
+ }) : (L = a.onMessage) == null || L.call(a, R, decodeURIComponent(_));
462
468
  }
463
- }, await g.setRemoteDescription(c), $("set remote description OK");
469
+ }, await g.setRemoteDescription(d), $("set remote description OK");
464
470
  const U = await g.createAnswer();
465
- return $("create answer OK"), await g.setLocalDescription(U), $("set local description OK"), await s(d, U, w), $("start connection OK"), {
471
+ return $("create answer OK"), await g.setLocalDescription(U), $("set local description OK"), await o(l, U, C), $("start connection OK"), {
466
472
  /**
467
473
  * Method to send request to server to get clip or talk depend on you payload
468
474
  * @param payload
469
475
  */
470
- speak(o) {
471
- return u(d, w, o);
476
+ speak(c) {
477
+ return u(l, C, c);
472
478
  },
473
479
  /**
474
480
  * Method to close RTC connection
475
481
  */
476
482
  async terminate() {
477
- var o, v;
478
- d && (g && (g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null, clearInterval(b)), await m(d, w).catch((y) => {
479
- }), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (v = a.onVideoStateChange) == null || v.call(a, I.Stop));
483
+ var c, y;
484
+ l && (g && (g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null, clearInterval(W)), await m(l, C).catch((A) => {
485
+ }), (c = a.onConnectionStateChange) == null || c.call(a, "closed"), (y = a.onVideoStateChange) == null || y.call(a, M.Stop));
480
486
  },
481
487
  /**
482
488
  * Session identifier information, should be returned in the body of all streaming requests
483
489
  */
484
- sessionId: w,
490
+ sessionId: C,
485
491
  /**
486
492
  * Id of current RTC stream
487
493
  */
488
- streamId: d,
494
+ streamId: l,
489
495
  /**
490
496
  * Method to add callback that will be trigered on supported events
491
497
  * @param eventName
492
498
  * @param callback
493
499
  */
494
- onCallback(o, v) {
495
- a[o] = v;
500
+ onCallback(c, y) {
501
+ a[c] = y;
496
502
  }
497
503
  };
498
504
  }
499
505
  export {
500
506
  ee as ChatMode,
501
- B as ChatProgress,
507
+ b as ChatProgress,
502
508
  re as DocumentType,
503
509
  ne as KnowledgeType,
504
510
  Z as Providers,
505
511
  j as RateState,
506
512
  Y as SocketManager,
507
- _ as StreamEvents,
513
+ K as StreamEvents,
508
514
  te as Subject,
509
515
  O as VoiceAccess,
510
516
  ue as createAgentManager,
511
517
  N as createAgentsApi,
512
- P as createClient,
518
+ E as createClient,
513
519
  D as createKnowledgeApi,
514
520
  V as createRatingsApi,
515
521
  de as createStreamingManager,
@@ -1 +1 @@
1
- (function(s,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(s=typeof globalThis<"u"?globalThis:s||self,p(s.index={}))})(this,function(s){"use strict";const p="https://api.d-id.com",re="wss://notifications.d-id.com";function q(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${e.externalId}`;throw new Error(`Unknown auth type: ${e}`)}function $(e,i=p){const n=async(t,r)=>{const a=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:q(e),"Content-Type":"application/json"}});if(!a.ok){let o=await a.text().catch(()=>"Failed to fetch");throw new Error(o)}return a.json()};return{get(t,r){return n(t,{...r,method:"GET"})},post(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"POST"})},delete(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"DELETE"})},patch(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"PATCH"})}}}function T(e,i=p){const n=$(e,`${i}/agents`);return{create(t,r){return n.post("/",t,r)},getAgents(t,r){return n.get(`/${t?`?tag=${t}`:""}`,r).then(a=>a??[])},getById(t,r){return n.get(`/${t}`,r)},delete(t,r){return n.delete(`/${t}`,void 0,r)},update(t,r,a){return n.patch(`/${t}`,r,a)},newChat(t,r){return n.post(`/${t}/chat`,void 0,r)},chat(t,r,a,o){return n.post(`/${t}/chat/${r}`,a,o)}}}function F(e,i=p){const n=$(e,`${i}/knowledge`);return{createKnowledge(t,r){return n.post("/",t,r)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,r){return n.get(`/${t}`,r)},deleteKnowledge(t,r){return n.delete(`/${t}`,void 0,r)},createDocument(t,r,a){return n.post(`/${t}/documents`,r,a)},deleteDocument(t,r,a){return n.delete(`/${t}/documents/${r}`,void 0,a)},getDocuments(t,r){return n.get(`/${t}/documents`,r)},getDocument(t,r,a){return n.get(`/${t}/documents/${r}`,a)},getRecords(t,r,a){return n.get(`/${t}/documents/${r}/records`,a)},query(t,r,a){return n.post(`/${t}/query`,{query:r},a)}}}function N(e,i=p){const n=$(e,`${i}/chats/ratings`);return{create(t,r){return n.post("/",t,r)},getByKnowledge(t,r){return n.get(`/${t}`,r).then(a=>a??[])},update(t,r,a){return n.patch(`/${t}`,r,a)},delete(t,r){return n.delete(`/${t}`,r)}}}const ae=e=>new Promise(i=>setTimeout(i,e));function ie(e){return new Promise((i,n)=>{const{callbacks:t,host:r,auth:a}=e,{onMessage:o=null,onOpen:g=null,onClose:f=null,onError:w=null}=t||{},h=new WebSocket(`${r}?authorization=${q(a)}`);h.onmessage=o,h.onclose=f,h.onerror=l=>{console.log(l),w==null||w(l),n(l)},h.onopen=l=>{g==null||g(l),i(h)}})}async function se(e){const{retries:i=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await ie(e)}catch(r){if(t===i)throw r;await ae(t*500)}return n}async function z(e,i,n){const t=n?[n]:[],r=await se({auth:e,host:i,callbacks:{onMessage:a=>{const o=JSON.parse(a.data);t.forEach(g=>g(o.event,o))}}});return{socket:r,terminate:()=>r.close(),subscribeToEvents:a=>t.push(a)}}var J=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(J||{}),D=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(D||{}),_=(e=>(e.Start="START",e.Stop="STOP",e))(_||{}),A=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(A||{}),V=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(V||{}),G=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(G||{}),L=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(L||{}),Q=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(Q||{}),X=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(X||{}),Y=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(Y||{}),M=(e=>(e.Clip="clip",e.Talk="talk",e))(M||{});function Z(e){return e.presenter.type===M.Clip?{videoType:M.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:M.Talk,source_url:e.presenter.source_url}}function x(e,i,n,t){return new Promise(async(r,a)=>{const o=await j(Z(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async g=>{var f,w;g==="connected"?(t||(t=await n.newChat(e.id)),r({chat:t,streamingManager:o})):g==="failed"&&a(new Error("Cannot create connection")),(w=(f=i.callbacks).onConnectionStateChange)==null||w.call(f,g)},onMessage:(g,f)=>{var w,h;g===A.ChatAnswer&&(console.log("ChatAnswer",g,f),(h=(w=i.callbacks).onChatEvents)==null||h.call(w,L.Answer,{content:f,event:L.Answer}))}}})})}function oe(e,i,n){return T(i,n||p).getById(e)}async function ce(e,i){const n=i.baseURL||p,t=i.wsURL||re,r=new AbortController,a=T(i.auth,n),o=N(i.auth,n),g=F(i.auth,n),f=await a.getById(e),w=await z(i.auth,t,i.callbacks.onChatEvents);let{chat:h,streamingManager:l}=await x(f,i,a);return{agent:f,async reconnectToChat(){const{streamingManager:d}=await x(f,i,a,h);l=d},terminate(){return r.abort(),w.terminate(),l.terminate()},chatId:h.id,chat(d){return a.chat(e,h.id,{sessionId:l.sessionId,streamId:l.streamId,messages:d},{signal:r.signal})},rate(d,v){return v?o.update(v,d):o.create(d)},deleteRate(d){return o.delete(d)},speak(d){let v;return d.type==="text"?v={script:{type:"text",provider:d.provider,input:d.input,ssml:d.ssml||!1}}:d.type==="audio"&&(v={script:{type:"audio",audio_url:d.audio_url}}),l.speak(v)},getStarterMessages(){var d,v;return(d=f.knowledge)!=null&&d.id?g.getKnowledge((v=f.knowledge)==null?void 0:v.id).then(C=>(C==null?void 0:C.starter_message)||[]):Promise.resolve([])}}}function de(e,i){const n=$(e,i);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,r,a){return n.post(`/clips/streams/${t}/sdp`,{session_id:a,answer:r})},addIceCandidate(t,r,a){return n.post(`/clips/streams/${t}/ice`,{session_id:a,...r})},sendStreamRequest(t,r,a){return n.post(`/clips/streams/${t}`,{session_id:r,...a})},close(t,r){return n.delete(`/clips/streams/${t}`,{session_id:r})}}}function le(e,i){const n=$(e,i);return{createStream(t,r){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},r)},startConnection(t,r,a,o){return n.post(`/talks/streams/${t}/sdp`,{session_id:a,answer:r},o)},addIceCandidate(t,r,a,o){return n.post(`/talks/streams/${t}/ice`,{session_id:a,...r},o)},sendStreamRequest(t,r,a,o){return n.post(`/talks/streams/${t}`,{session_id:r,...a},o)},close(t,r,a){return n.delete(`/talks/streams/${t}`,{session_id:r},a)}}}function ue(e,i){return e.map((n,t)=>t===0?i?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-i.bytesReceived,packetsReceived:n.packetsReceived-i.packetsReceived,packetsLost:n.packetsLost-i.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate})}let O=!1;const k=(e,i)=>O&&console.log(e,i),ge=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function j(e,{debug:i=!1,callbacks:n,auth:t,baseURL:r=p}){O=i;const a={...n},{startConnection:o,sendStreamRequest:g,close:f,createStream:w,addIceCandidate:h}=e.videoType===M.Clip?de(t,r):le(t,r),{id:l,offer:d,ice_servers:v,session_id:C}=await w(e),m=new ge({iceServers:v}),ee=m.createDataChannel("JanusDataChannel"),u=[];let P=0,b=0,E=0,W,te;if(!C)throw new Error("Could not create session_id");m.onicecandidate=c=>{k("peerConnection.onicecandidate",c),c.candidate&&c.candidate.sdpMid&&c.candidate.sdpMLineIndex!==null&&h(l,{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex},C)},m.oniceconnectionstatechange=()=>{var c;k("peerConnection.oniceconnectionstatechange => "+m.iceConnectionState),(c=a.onConnectionStateChange)==null||c.call(a,m.iceConnectionState)},m.ontrack=c=>{var y;k("peerConnection.ontrack",c),(y=a.onSrcObjectReady)==null||y.call(a,c.streams[0]),W=setInterval(()=>{var I,K;if(console.log(" ontrack interval ",u==null?void 0:u.length,b),u!=null&&u.length&&b<=(u==null?void 0:u.length)){const S=(I=u[b])==null?void 0:I.bytesReceived,R=(S??1/0)-E>0||E==0&&S==0;E=S??0,R||(K=a.onVideoStateChange)==null||K.call(a,_.Stop,{isPlaying:R}),b=u==null?void 0:u.length,console.log(" ontrack interval end",R)}},1e3)},ee.onmessage=c=>{var y,I,K;if(ee.readyState==="open"){const[S,R]=c.data.split(":");if(S===A.StreamStarted)console.log("StreamStarted",S,R),P=u.length,te=setInterval(()=>{m.getStats().then(H=>{H.forEach(U=>{U.type==="inbound-rtp"&&U.kind==="video"&&u.push(U)})})},1e3),(y=a.onVideoStateChange)==null||y.call(a,_.Start);else if(S===A.StreamDone){console.log("StreamDone");const B=u.slice(P);if(B){const H=P===0?void 0:u[P-1];ue(B,H),P=u.length}setTimeout(()=>{clearInterval(W),console.log("clearInterval palying?")},2500),console.log("clearInterval statd?"),clearInterval(te)}else S===A.StreamFailed?(I=a.onVideoStateChange)==null||I.call(a,_.Stop,{event:S,data:R}):(K=a.onMessage)==null||K.call(a,S,decodeURIComponent(R))}},await m.setRemoteDescription(d),k("set remote description OK");const ne=await m.createAnswer();return k("create answer OK"),await m.setLocalDescription(ne),k("set local description OK"),await o(l,ne,C),k("start connection OK"),{speak(c){return g(l,C,c)},async terminate(){var c,y;l&&(m&&(m.close(),m.oniceconnectionstatechange=null,m.onnegotiationneeded=null,m.onicecandidate=null,m.ontrack=null,clearInterval(W)),await f(l,C).catch(I=>{}),(c=a.onConnectionStateChange)==null||c.call(a,"closed"),(y=a.onVideoStateChange)==null||y.call(a,_.Stop))},sessionId:C,streamId:l,onCallback(c,y){a[c]=y}}}s.ChatMode=G,s.ChatProgress=L,s.DocumentType=Y,s.KnowledgeType=X,s.Providers=J,s.RateState=V,s.SocketManager=z,s.StreamEvents=A,s.Subject=Q,s.VoiceAccess=D,s.createAgentManager=ce,s.createAgentsApi=T,s.createClient=$,s.createKnowledgeApi=F,s.createRatingsApi=N,s.createStreamingManager=j,s.getAgent=oe,s.getAgentStreamArgs=Z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(o=typeof globalThis<"u"?globalThis:o||self,p(o.index={}))})(this,function(o){"use strict";const p="https://api.d-id.com",re="wss://notifications.d-id.com";function q(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${e.externalId}`;throw new Error(`Unknown auth type: ${e}`)}function I(e,i=p){const n=async(t,r)=>{const a=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:q(e),"Content-Type":"application/json"}});if(!a.ok){let c=await a.text().catch(()=>"Failed to fetch");throw new Error(c)}return a.json()};return{get(t,r){return n(t,{...r,method:"GET"})},post(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"POST"})},delete(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"DELETE"})},patch(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"PATCH"})}}}function B(e,i=p){const n=I(e,`${i}/agents`);return{create(t,r){return n.post("/",t,r)},getAgents(t,r){return n.get(`/${t?`?tag=${t}`:""}`,r).then(a=>a??[])},getById(t,r){return n.get(`/${t}`,r)},delete(t,r){return n.delete(`/${t}`,void 0,r)},update(t,r,a){return n.patch(`/${t}`,r,a)},newChat(t,r){return n.post(`/${t}/chat`,void 0,r)},chat(t,r,a,c){return n.post(`/${t}/chat/${r}`,a,c)}}}function F(e,i=p){const n=I(e,`${i}/knowledge`);return{createKnowledge(t,r){return n.post("/",t,r)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,r){return n.get(`/${t}`,r)},deleteKnowledge(t,r){return n.delete(`/${t}`,void 0,r)},createDocument(t,r,a){return n.post(`/${t}/documents`,r,a)},deleteDocument(t,r,a){return n.delete(`/${t}/documents/${r}`,void 0,a)},getDocuments(t,r){return n.get(`/${t}/documents`,r)},getDocument(t,r,a){return n.get(`/${t}/documents/${r}`,a)},getRecords(t,r,a){return n.get(`/${t}/documents/${r}/records`,a)},query(t,r,a){return n.post(`/${t}/query`,{query:r},a)}}}function N(e,i=p){const n=I(e,`${i}/chats/ratings`);return{create(t,r){return n.post("/",t,r)},getByKnowledge(t,r){return n.get(`/${t}`,r).then(a=>a??[])},update(t,r,a){return n.patch(`/${t}`,r,a)},delete(t,r){return n.delete(`/${t}`,r)}}}const ae=e=>new Promise(i=>setTimeout(i,e));function ie(e){return new Promise((i,n)=>{const{callbacks:t,host:r,auth:a}=e,{onMessage:c=null,onOpen:g=null,onClose:f=null,onError:w=null}=t||{},h=new WebSocket(`${r}?authorization=${q(a)}`);h.onmessage=c,h.onclose=f,h.onerror=u=>{console.log(u),w==null||w(u),n(u)},h.onopen=u=>{g==null||g(u),i(h)}})}async function se(e){const{retries:i=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await ie(e)}catch(r){if(t===i)throw r;await ae(t*500)}return n}async function z(e,i,n){const t=n?[n]:[],r=await se({auth:e,host:i,callbacks:{onMessage:a=>{const c=JSON.parse(a.data);t.forEach(g=>g(c.event,c))}}});return{socket:r,terminate:()=>r.close(),subscribeToEvents:a=>t.push(a)}}var J=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(J||{}),D=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(D||{}),_=(e=>(e.Start="START",e.Stop="STOP",e))(_||{}),M=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(M||{}),V=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(V||{}),G=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(G||{}),W=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(W||{}),Q=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(Q||{}),X=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(X||{}),Y=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(Y||{}),T=(e=>(e.Clip="clip",e.Talk="talk",e))(T||{});function Z(e){return e.presenter.type===T.Clip?{videoType:T.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:T.Talk,source_url:e.presenter.source_url}}function x(e,i,n,t){return new Promise(async(r,a)=>{const c=await j(Z(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async g=>{var f,w;g==="connected"?(t||(t=await n.newChat(e.id)),r({chat:t,streamingManager:c})):g==="failed"&&a(new Error("Cannot create connection")),(w=(f=i.callbacks).onConnectionStateChange)==null||w.call(f,g)},onMessage:(g,f)=>{var w,h;g===M.ChatAnswer&&(console.log("ChatAnswer",g,f),(h=(w=i.callbacks).onChatEvents)==null||h.call(w,W.Answer,{content:f,event:W.Answer}))}}})})}function oe(e,i,n){return B(i,n||p).getById(e)}async function ce(e,i){const n=i.baseURL||p,t=i.wsURL||re,r=new AbortController,a=B(i.auth,n),c=N(i.auth,n),g=F(i.auth,n),f=await a.getById(e),w=await z(i.auth,t,i.callbacks.onChatEvents);let{chat:h,streamingManager:u}=await x(f,i,a);return{agent:f,async reconnectToChat(){const{streamingManager:l}=await x(f,i,a,h);u=l},terminate(){return r.abort(),w.terminate(),u.terminate()},chatId:h.id,chat(l){return a.chat(e,h.id,{sessionId:u.sessionId,streamId:u.streamId,messages:l},{signal:r.signal})},rate(l,v){return v?c.update(v,l):c.create(l)},deleteRate(l){return c.delete(l)},speak(l){let v;return l.type==="text"?v={script:{type:"text",provider:l.provider,input:l.input,ssml:l.ssml||!1}}:l.type==="audio"&&(v={script:{type:"audio",audio_url:l.audio_url}}),u.speak(v)},getStarterMessages(){var l,v;return(l=f.knowledge)!=null&&l.id?g.getKnowledge((v=f.knowledge)==null?void 0:v.id).then(R=>(R==null?void 0:R.starter_message)||[]):Promise.resolve([])}}}function de(e,i){const n=I(e,i);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,r,a){return n.post(`/clips/streams/${t}/sdp`,{session_id:a,answer:r})},addIceCandidate(t,r,a){return n.post(`/clips/streams/${t}/ice`,{session_id:a,...r})},sendStreamRequest(t,r,a){return n.post(`/clips/streams/${t}`,{session_id:r,...a})},close(t,r){return n.delete(`/clips/streams/${t}`,{session_id:r})}}}function le(e,i){const n=I(e,i);return{createStream(t,r){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},r)},startConnection(t,r,a,c){return n.post(`/talks/streams/${t}/sdp`,{session_id:a,answer:r},c)},addIceCandidate(t,r,a,c){return n.post(`/talks/streams/${t}/ice`,{session_id:a,...r},c)},sendStreamRequest(t,r,a,c){return n.post(`/talks/streams/${t}`,{session_id:r,...a},c)},close(t,r,a){return n.delete(`/talks/streams/${t}`,{session_id:r},a)}}}function ue(e,i){return e.map((n,t)=>t===0?i?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-i.bytesReceived,packetsReceived:n.packetsReceived-i.packetsReceived,packetsLost:n.packetsLost-i.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate})}let O=!1;const $=(e,i)=>O&&console.log(e,i),ge=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function j(e,{debug:i=!1,callbacks:n,auth:t,baseURL:r=p}){O=i;const a={...n},{startConnection:c,sendStreamRequest:g,close:f,createStream:w,addIceCandidate:h}=e.videoType===T.Clip?de(t,r):le(t,r),{id:u,offer:l,ice_servers:v,session_id:R}=await w(e),m=new ge({iceServers:v}),ee=m.createDataChannel("JanusDataChannel"),s=[];let b=0,A=0,P=0,H,te;if(!R)throw new Error("Could not create session_id");m.onicecandidate=d=>{$("peerConnection.onicecandidate",d),d.candidate&&d.candidate.sdpMid&&d.candidate.sdpMLineIndex!==null&&h(u,{candidate:d.candidate.candidate,sdpMid:d.candidate.sdpMid,sdpMLineIndex:d.candidate.sdpMLineIndex},R)},m.oniceconnectionstatechange=()=>{var d;$("peerConnection.oniceconnectionstatechange => "+m.iceConnectionState),(d=a.onConnectionStateChange)==null||d.call(a,m.iceConnectionState)},m.ontrack=d=>{var S;$("peerConnection.ontrack",d),(S=a.onSrcObjectReady)==null||S.call(a,d.streams[0]),H=setInterval(()=>{var K,E,k,L;if(console.log(" ontrack interval ",s==null?void 0:s.length,A),s!=null&&s.length&&A<=(s==null?void 0:s.length)){const C=(K=s[A])==null?void 0:K.bytesReceived,y=(C??1/0)-P>0||P==0&&C==0;P=C??0,y||(E=a.onVideoStateChange)==null||E.call(a,_.Stop,{isPlaying:y}),A=s==null?void 0:s.length,console.log(" ontrack interval end",y)}if(A==(s==null?void 0:s.length)){const C=(k=s[A])==null?void 0:k.bytesReceived,y=!((C??1/0)-P==0&&P>0&&C>0);P=C??0,y||(L=a.onVideoStateChange)==null||L.call(a,_.Stop,{isPlaying:y}),A=s==null?void 0:s.length,console.log(" ontrack interval end",y)}},1e3)},ee.onmessage=d=>{var S,K,E;if(ee.readyState==="open"){const[k,L]=d.data.split(":");if(k===M.StreamStarted)console.log("StreamStarted",k,L),b=s.length,te=setInterval(()=>{m.getStats().then(y=>{y.forEach(U=>{U.type==="inbound-rtp"&&U.kind==="video"&&s.push(U)})})},1e3),(S=a.onVideoStateChange)==null||S.call(a,_.Start);else if(k===M.StreamDone){console.log("StreamDone");const C=s.slice(b);if(C){const y=b===0?void 0:s[b-1];ue(C,y),b=s.length}setTimeout(()=>{clearInterval(H),console.log("clearInterval palying?")},2500),console.log("clearInterval statd?"),clearInterval(te)}else k===M.StreamFailed?(K=a.onVideoStateChange)==null||K.call(a,_.Stop,{event:k,data:L}):(E=a.onMessage)==null||E.call(a,k,decodeURIComponent(L))}},await m.setRemoteDescription(l),$("set remote description OK");const ne=await m.createAnswer();return $("create answer OK"),await m.setLocalDescription(ne),$("set local description OK"),await c(u,ne,R),$("start connection OK"),{speak(d){return g(u,R,d)},async terminate(){var d,S;u&&(m&&(m.close(),m.oniceconnectionstatechange=null,m.onnegotiationneeded=null,m.onicecandidate=null,m.ontrack=null,clearInterval(H)),await f(u,R).catch(K=>{}),(d=a.onConnectionStateChange)==null||d.call(a,"closed"),(S=a.onVideoStateChange)==null||S.call(a,_.Stop))},sessionId:R,streamId:u,onCallback(d,S){a[d]=S}}}o.ChatMode=G,o.ChatProgress=W,o.DocumentType=Y,o.KnowledgeType=X,o.Providers=J,o.RateState=V,o.SocketManager=z,o.StreamEvents=M,o.Subject=Q,o.VoiceAccess=D,o.createAgentManager=ce,o.createAgentsApi=B,o.createClient=I,o.createKnowledgeApi=F,o.createRatingsApi=N,o.createStreamingManager=j,o.getAgent=oe,o.getAgentStreamArgs=Z,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "1.0.19-beta.21",
4
+ "version": "1.0.19-beta.22",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {