@d-id/client-sdk 1.0.19-beta.31 → 1.0.19-beta.33
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 +109 -112
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const y = "https://api.d-id.com", Q = "wss://notifications.d-id.com";
|
|
2
|
+
function U(e) {
|
|
3
3
|
if (e.type === "bearer")
|
|
4
4
|
return `Bearer ${e.token}`;
|
|
5
5
|
if (e.type === "basic")
|
|
@@ -8,13 +8,13 @@ function N(e) {
|
|
|
8
8
|
return `Client-Key ${e.clientKey}.${e.externalId}`;
|
|
9
9
|
throw new Error(`Unknown auth type: ${e}`);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function b(e, s = y) {
|
|
12
12
|
const n = async (t, r) => {
|
|
13
13
|
const a = await fetch(s + (t != null && t.startsWith("/") ? t : `/${t}`), {
|
|
14
14
|
...r,
|
|
15
15
|
headers: {
|
|
16
16
|
...r == null ? void 0 : r.headers,
|
|
17
|
-
Authorization:
|
|
17
|
+
Authorization: U(e),
|
|
18
18
|
"Content-Type": "application/json"
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -54,8 +54,8 @@ function L(e, s = R) {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
const n =
|
|
57
|
+
function F(e, s = y) {
|
|
58
|
+
const n = b(e, `${s}/agents`);
|
|
59
59
|
return {
|
|
60
60
|
create(t, r) {
|
|
61
61
|
return n.post("/", t, r);
|
|
@@ -80,8 +80,8 @@ function z(e, s = R) {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
const n =
|
|
83
|
+
function X(e, s = y) {
|
|
84
|
+
const n = b(e, `${s}/knowledge`);
|
|
85
85
|
return {
|
|
86
86
|
createKnowledge(t, r) {
|
|
87
87
|
return n.post("/", t, r);
|
|
@@ -117,8 +117,8 @@ function Q(e, s = R) {
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
const n =
|
|
120
|
+
function Y(e, s = y) {
|
|
121
|
+
const n = b(e, `${s}/chats/ratings`);
|
|
122
122
|
return {
|
|
123
123
|
create(t, r) {
|
|
124
124
|
return n.post("/", t, r);
|
|
@@ -134,8 +134,8 @@ function X(e, s = R) {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
137
|
+
const Z = (e) => new Promise((s) => setTimeout(s, e));
|
|
138
|
+
function O(e) {
|
|
139
139
|
return new Promise((s, n) => {
|
|
140
140
|
const {
|
|
141
141
|
callbacks: t,
|
|
@@ -144,33 +144,33 @@ function Z(e) {
|
|
|
144
144
|
} = e, {
|
|
145
145
|
onMessage: o = null,
|
|
146
146
|
onOpen: l = null,
|
|
147
|
-
onClose:
|
|
147
|
+
onClose: m = null,
|
|
148
148
|
onError: f = null
|
|
149
|
-
} = t || {},
|
|
150
|
-
|
|
149
|
+
} = t || {}, g = new WebSocket(`${r}?authorization=${U(a)}`);
|
|
150
|
+
g.onmessage = o, g.onclose = m, g.onerror = (d) => {
|
|
151
151
|
console.log(d), f == null || f(d), n(d);
|
|
152
|
-
},
|
|
153
|
-
l == null || l(d), s(
|
|
152
|
+
}, g.onopen = (d) => {
|
|
153
|
+
l == null || l(d), s(g);
|
|
154
154
|
};
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
async function
|
|
157
|
+
async function j(e) {
|
|
158
158
|
const {
|
|
159
159
|
retries: s = 1
|
|
160
160
|
} = e;
|
|
161
161
|
let n = null;
|
|
162
162
|
for (let t = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; t++)
|
|
163
163
|
try {
|
|
164
|
-
n = await
|
|
164
|
+
n = await O(e);
|
|
165
165
|
} catch (r) {
|
|
166
166
|
if (t === s)
|
|
167
167
|
throw r;
|
|
168
|
-
await
|
|
168
|
+
await Z(t * 500);
|
|
169
169
|
}
|
|
170
170
|
return n;
|
|
171
171
|
}
|
|
172
|
-
async function
|
|
173
|
-
const t = n ? [n] : [], r = await
|
|
172
|
+
async function ee(e, s, n) {
|
|
173
|
+
const t = n ? [n] : [], r = await j({
|
|
174
174
|
auth: e,
|
|
175
175
|
host: s,
|
|
176
176
|
callbacks: {
|
|
@@ -186,65 +186,65 @@ async function j(e, s, n) {
|
|
|
186
186
|
subscribeToEvents: (a) => t.push(a)
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
var
|
|
190
|
-
function
|
|
191
|
-
return e.presenter.type ===
|
|
192
|
-
videoType:
|
|
189
|
+
var te = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ne || {}), _ = /* @__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))(I || {}), re = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(re || {}), ae = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(ae || {}), K = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(K || {}), se = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(se || {}), ie = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ie || {}), oe = /* @__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))(oe || {}), P = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(P || {});
|
|
190
|
+
function ce(e) {
|
|
191
|
+
return e.presenter.type === P.Clip ? {
|
|
192
|
+
videoType: P.Clip,
|
|
193
193
|
driver_id: e.presenter.driver_id,
|
|
194
194
|
presenter_id: e.presenter.presenter_id
|
|
195
195
|
} : {
|
|
196
|
-
videoType:
|
|
196
|
+
videoType: P.Talk,
|
|
197
197
|
source_url: e.presenter.source_url
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function H(e, s, n, t) {
|
|
201
201
|
return new Promise(async (r, a) => {
|
|
202
|
-
const o = await ge(
|
|
202
|
+
const o = await ge(ce(e), {
|
|
203
203
|
...s,
|
|
204
204
|
callbacks: {
|
|
205
205
|
...s.callbacks,
|
|
206
206
|
onConnectionStateChange: async (l) => {
|
|
207
|
-
var
|
|
207
|
+
var m, f;
|
|
208
208
|
l === "connected" ? (t || (t = await n.newChat(e.id)), r({
|
|
209
209
|
chat: t,
|
|
210
210
|
streamingManager: o
|
|
211
|
-
})) : l === "failed" && a(new Error("Cannot create connection")), (f = (
|
|
211
|
+
})) : l === "failed" && a(new Error("Cannot create connection")), (f = (m = s.callbacks).onConnectionStateChange) == null || f.call(m, l);
|
|
212
212
|
},
|
|
213
213
|
// TODO remove when webscoket will return partial
|
|
214
|
-
onMessage: (l,
|
|
215
|
-
var f,
|
|
216
|
-
l ===
|
|
217
|
-
content:
|
|
218
|
-
event:
|
|
214
|
+
onMessage: (l, m) => {
|
|
215
|
+
var f, g;
|
|
216
|
+
l === I.ChatAnswer && (console.log("ChatAnswer", l, m), (g = (f = s.callbacks).onChatEvents) == null || g.call(f, K.Answer, {
|
|
217
|
+
content: m,
|
|
218
|
+
event: K.Answer
|
|
219
219
|
}));
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
|
-
function
|
|
226
|
-
return
|
|
225
|
+
function pe(e, s, n) {
|
|
226
|
+
return F(s, n || y).getById(e);
|
|
227
227
|
}
|
|
228
|
-
async function
|
|
229
|
-
const n = s.baseURL ||
|
|
228
|
+
async function we(e, s) {
|
|
229
|
+
const n = s.baseURL || y, t = s.wsURL || Q, r = new AbortController(), a = F(s.auth, n), o = Y(s.auth, n), l = X(s.auth, n), m = await a.getById(e), f = await ee(s.auth, t, s.callbacks.onChatEvents);
|
|
230
230
|
let {
|
|
231
|
-
chat:
|
|
231
|
+
chat: g,
|
|
232
232
|
streamingManager: d
|
|
233
|
-
} = await
|
|
233
|
+
} = await H(m, s, a);
|
|
234
234
|
return {
|
|
235
|
-
agent:
|
|
235
|
+
agent: m,
|
|
236
236
|
async reconnectToChat() {
|
|
237
237
|
const {
|
|
238
238
|
streamingManager: c
|
|
239
|
-
} = await
|
|
239
|
+
} = await H(m, s, a, g);
|
|
240
240
|
d = c;
|
|
241
241
|
},
|
|
242
242
|
terminate() {
|
|
243
243
|
return r.abort(), f.terminate(), d.terminate();
|
|
244
244
|
},
|
|
245
|
-
chatId:
|
|
245
|
+
chatId: g.id,
|
|
246
246
|
chat(c) {
|
|
247
|
-
return a.chat(e,
|
|
247
|
+
return a.chat(e, g.id, {
|
|
248
248
|
sessionId: d.sessionId,
|
|
249
249
|
streamId: d.streamId,
|
|
250
250
|
messages: c
|
|
@@ -276,12 +276,12 @@ async function pe(e, s) {
|
|
|
276
276
|
},
|
|
277
277
|
getStarterMessages() {
|
|
278
278
|
var c, w;
|
|
279
|
-
return (c =
|
|
279
|
+
return (c = m.knowledge) != null && c.id ? l.getKnowledge((w = m.knowledge) == null ? void 0 : w.id).then((h) => (h == null ? void 0 : h.starter_message) || []) : Promise.resolve([]);
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
const n =
|
|
283
|
+
function de(e, s) {
|
|
284
|
+
const n = b(e, s);
|
|
285
285
|
return {
|
|
286
286
|
createStream(t) {
|
|
287
287
|
return n.post("/clips/streams", {
|
|
@@ -315,8 +315,8 @@ function ce(e, s) {
|
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
319
|
-
const n =
|
|
318
|
+
function le(e, s) {
|
|
319
|
+
const n = b(e, s);
|
|
320
320
|
return {
|
|
321
321
|
createStream(t, r) {
|
|
322
322
|
return n.post("/talks/streams", {
|
|
@@ -351,7 +351,7 @@ function de(e, s) {
|
|
|
351
351
|
}
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function ue(e, s) {
|
|
355
355
|
return e.map((n, t) => t === 0 ? s ? {
|
|
356
356
|
index: t,
|
|
357
357
|
timestamp: n.timestamp,
|
|
@@ -384,91 +384,88 @@ function le(e, s) {
|
|
|
384
384
|
frameRate: n.frameRate
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
|
-
let
|
|
388
|
-
const
|
|
387
|
+
let T = !1;
|
|
388
|
+
const k = (e, s) => T && console.log(e, s), me = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
389
389
|
async function ge(e, {
|
|
390
390
|
debug: s = !1,
|
|
391
391
|
callbacks: n,
|
|
392
392
|
auth: t,
|
|
393
|
-
baseURL: r =
|
|
393
|
+
baseURL: r = y
|
|
394
394
|
}) {
|
|
395
|
-
|
|
395
|
+
T = s;
|
|
396
396
|
const a = {
|
|
397
397
|
...n
|
|
398
398
|
}, {
|
|
399
399
|
startConnection: o,
|
|
400
400
|
sendStreamRequest: l,
|
|
401
|
-
close:
|
|
401
|
+
close: m,
|
|
402
402
|
createStream: f,
|
|
403
|
-
addIceCandidate:
|
|
404
|
-
} = e.videoType ===
|
|
403
|
+
addIceCandidate: g
|
|
404
|
+
} = e.videoType === P.Clip ? de(t, r) : le(t, r), {
|
|
405
405
|
id: d,
|
|
406
406
|
offer: c,
|
|
407
407
|
ice_servers: w,
|
|
408
408
|
session_id: h
|
|
409
|
-
} = await f(e), u = new
|
|
409
|
+
} = await f(e), u = new me({
|
|
410
410
|
iceServers: w
|
|
411
|
-
}),
|
|
412
|
-
let S = [],
|
|
411
|
+
}), x = u.createDataChannel("JanusDataChannel");
|
|
412
|
+
let S = [], $ = 0, M = 0, R, E, W;
|
|
413
413
|
if (!h)
|
|
414
414
|
throw new Error("Could not create session_id");
|
|
415
415
|
(() => {
|
|
416
|
-
|
|
416
|
+
W = setInterval(() => {
|
|
417
417
|
u.getStats().then((p) => {
|
|
418
418
|
p.forEach((v) => {
|
|
419
|
-
var C
|
|
419
|
+
var C;
|
|
420
420
|
if (v.type === "inbound-rtp" && v.kind === "video") {
|
|
421
|
-
if (
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
isPlaying: k
|
|
430
|
-
}), k)
|
|
431
|
-
_ = S.length;
|
|
421
|
+
if (M = S.length - 1, v && S[M]) {
|
|
422
|
+
const A = v.bytesReceived, N = S[M].bytesReceived;
|
|
423
|
+
let z = R;
|
|
424
|
+
R = A - N > 0;
|
|
425
|
+
let L;
|
|
426
|
+
if (z !== R) {
|
|
427
|
+
if (R)
|
|
428
|
+
$ = S.length;
|
|
432
429
|
else {
|
|
433
|
-
const
|
|
434
|
-
|
|
430
|
+
const J = S.slice($), D = $ === 0 ? void 0 : S[$ - 1];
|
|
431
|
+
L = ue(J, D), L = L.sort((V, G) => G.packetsLost - V.packetsLost).slice(0, 5);
|
|
435
432
|
}
|
|
436
|
-
(
|
|
433
|
+
(C = a.onVideoStateChange) == null || C.call(a, R ? _.Start : _.Stop, L);
|
|
437
434
|
}
|
|
438
435
|
}
|
|
439
|
-
|
|
436
|
+
S.push(v);
|
|
440
437
|
}
|
|
441
438
|
});
|
|
442
439
|
});
|
|
443
440
|
}, 500);
|
|
444
441
|
})();
|
|
445
|
-
const
|
|
446
|
-
clearInterval(
|
|
442
|
+
const q = () => {
|
|
443
|
+
clearInterval(E);
|
|
447
444
|
};
|
|
448
445
|
u.onicecandidate = (i) => {
|
|
449
|
-
|
|
446
|
+
k("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && g(d, {
|
|
450
447
|
candidate: i.candidate.candidate,
|
|
451
448
|
sdpMid: i.candidate.sdpMid,
|
|
452
449
|
sdpMLineIndex: i.candidate.sdpMLineIndex
|
|
453
450
|
}, h);
|
|
454
451
|
}, u.oniceconnectionstatechange = () => {
|
|
455
452
|
var i;
|
|
456
|
-
|
|
453
|
+
k("peerConnection.oniceconnectionstatechange => " + u.iceConnectionState), (i = a.onConnectionStateChange) == null || i.call(a, u.iceConnectionState);
|
|
457
454
|
}, u.ontrack = (i) => {
|
|
458
455
|
var p;
|
|
459
|
-
|
|
460
|
-
},
|
|
456
|
+
k("peerConnection.ontrack", i), (p = a.onSrcObjectReady) == null || p.call(a, i.streams[0]);
|
|
457
|
+
}, x.onmessage = (i) => {
|
|
461
458
|
var p, v;
|
|
462
|
-
if (
|
|
463
|
-
const [C,
|
|
464
|
-
C ===
|
|
459
|
+
if (x.readyState === "open") {
|
|
460
|
+
const [C, A] = i.data.split(":");
|
|
461
|
+
C === I.StreamStarted ? console.log("StreamStarted", C, A) : C === I.StreamDone ? console.log("StreamDone") : C === I.StreamFailed ? ((p = a.onVideoStateChange) == null || p.call(a, _.Stop, {
|
|
465
462
|
event: C,
|
|
466
|
-
data:
|
|
467
|
-
}), S = [],
|
|
463
|
+
data: A
|
|
464
|
+
}), S = [], $ = 0, M = 0, R = !1, console.log("StreamFailed")) : (v = a.onMessage) == null || v.call(a, C, decodeURIComponent(A));
|
|
468
465
|
}
|
|
469
|
-
}, await u.setRemoteDescription(c),
|
|
470
|
-
const
|
|
471
|
-
return
|
|
466
|
+
}, await u.setRemoteDescription(c), k("set remote description OK");
|
|
467
|
+
const B = await u.createAnswer();
|
|
468
|
+
return k("create answer OK"), await u.setLocalDescription(B), k("set local description OK"), await o(d, B, h), k("start connection OK"), {
|
|
472
469
|
/**
|
|
473
470
|
* Method to send request to server to get clip or talk depend on you payload
|
|
474
471
|
* @param payload
|
|
@@ -481,8 +478,8 @@ async function ge(e, {
|
|
|
481
478
|
*/
|
|
482
479
|
async terminate() {
|
|
483
480
|
var i, p;
|
|
484
|
-
d && (u && (u.close(), u.oniceconnectionstatechange = null, u.onnegotiationneeded = null, u.onicecandidate = null, u.ontrack = null, clearInterval(
|
|
485
|
-
}), (i = a.onConnectionStateChange) == null || i.call(a, "closed"), (p = a.onVideoStateChange) == null || p.call(a,
|
|
481
|
+
d && (u && (u.close(), u.oniceconnectionstatechange = null, u.onnegotiationneeded = null, u.onicecandidate = null, u.ontrack = null, clearInterval(E)), await m(d, h).catch((v) => {
|
|
482
|
+
}), (i = a.onConnectionStateChange) == null || i.call(a, "closed"), (p = a.onVideoStateChange) == null || p.call(a, _.Stop), q(), clearInterval(W));
|
|
486
483
|
},
|
|
487
484
|
/**
|
|
488
485
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
@@ -503,22 +500,22 @@ async function ge(e, {
|
|
|
503
500
|
};
|
|
504
501
|
}
|
|
505
502
|
export {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
503
|
+
ae as ChatMode,
|
|
504
|
+
K as ChatProgress,
|
|
505
|
+
oe as DocumentType,
|
|
506
|
+
ie as KnowledgeType,
|
|
507
|
+
te as Providers,
|
|
508
|
+
re as RateState,
|
|
509
|
+
ee as SocketManager,
|
|
510
|
+
I as StreamEvents,
|
|
511
|
+
se as Subject,
|
|
512
|
+
ne as VoiceAccess,
|
|
513
|
+
we as createAgentManager,
|
|
514
|
+
F as createAgentsApi,
|
|
515
|
+
b as createClient,
|
|
516
|
+
X as createKnowledgeApi,
|
|
517
|
+
Y as createRatingsApi,
|
|
521
518
|
ge as createStreamingManager,
|
|
522
|
-
|
|
523
|
-
|
|
519
|
+
pe as getAgent,
|
|
520
|
+
ce as getAgentStreamArgs
|
|
524
521
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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 B(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 A(e,i=p){const n=async(t,a)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...a,headers:{...a==null?void 0:a.headers,Authorization:B(e),"Content-Type":"application/json"}});if(!r.ok){let c=await r.text().catch(()=>"Failed to fetch");throw new Error(c)}return r.json()};return{get(t,a){return n(t,{...a,method:"GET"})},post(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"POST"})},delete(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"DELETE"})},patch(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"PATCH"})}}}function E(e,i=p){const n=A(e,`${i}/agents`);return{create(t,a){return n.post("/",t,a)},getAgents(t,a){return n.get(`/${t?`?tag=${t}`:""}`,a).then(r=>r??[])},getById(t,a){return n.get(`/${t}`,a)},delete(t,a){return n.delete(`/${t}`,void 0,a)},update(t,a,r){return n.patch(`/${t}`,a,r)},newChat(t,a){return n.post(`/${t}/chat`,void 0,a)},chat(t,a,r,c){return n.post(`/${t}/chat/${a}`,r,c)}}}function H(e,i=p){const n=A(e,`${i}/knowledge`);return{createKnowledge(t,a){return n.post("/",t,a)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,a){return n.get(`/${t}`,a)},deleteKnowledge(t,a){return n.delete(`/${t}`,void 0,a)},createDocument(t,a,r){return n.post(`/${t}/documents`,a,r)},deleteDocument(t,a,r){return n.delete(`/${t}/documents/${a}`,void 0,r)},getDocuments(t,a){return n.get(`/${t}/documents`,a)},getDocument(t,a,r){return n.get(`/${t}/documents/${a}`,r)},getRecords(t,a,r){return n.get(`/${t}/documents/${a}/records`,r)},query(t,a,r){return n.post(`/${t}/query`,{query:a},r)}}}function U(e,i=p){const n=A(e,`${i}/chats/ratings`);return{create(t,a){return n.post("/",t,a)},getByKnowledge(t,a){return n.get(`/${t}`,a).then(r=>r??[])},update(t,a,r){return n.patch(`/${t}`,a,r)},delete(t,a){return n.delete(`/${t}`,a)}}}const ie=e=>new Promise(i=>setTimeout(i,e));function se(e){return new Promise((i,n)=>{const{callbacks:t,host:a,auth:r}=e,{onMessage:c=null,onOpen:u=null,onClose:m=null,onError:w=null}=t||{},f=new WebSocket(`${a}?authorization=${B(r)}`);f.onmessage=c,f.onclose=m,f.onerror=l=>{console.log(l),w==null||w(l),n(l)},f.onopen=l=>{u==null||u(l),i(f)}})}async function oe(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 se(e)}catch(a){if(t===i)throw a;await ie(t*500)}return n}async function q(e,i,n){const t=n?[n]:[],a=await oe({auth:e,host:i,callbacks:{onMessage:r=>{const c=JSON.parse(r.data);t.forEach(u=>u(c.event,c))}}});return{socket:a,terminate:()=>a.close(),subscribeToEvents:r=>t.push(r)}}var F=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(F||{}),N=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(N||{}),_=(e=>(e.Start="START",e.Stop="STOP",e))(_||{}),I=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(I||{}),z=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(z||{}),J=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(J||{}),K=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(K||{}),D=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(D||{}),V=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(V||{}),G=(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))(G||{}),M=(e=>(e.Clip="clip",e.Talk="talk",e))(M||{});function Q(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(a,r)=>{const c=await Z(Q(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async u=>{var m,w;u==="connected"?(t||(t=await n.newChat(e.id)),a({chat:t,streamingManager:c})):u==="failed"&&r(new Error("Cannot create connection")),(w=(m=i.callbacks).onConnectionStateChange)==null||w.call(m,u)},onMessage:(u,m)=>{var w,f;u===I.ChatAnswer&&(console.log("ChatAnswer",u,m),(f=(w=i.callbacks).onChatEvents)==null||f.call(w,K.Answer,{content:m,event:K.Answer}))}}})})}function ce(e,i,n){return E(i,n||p).getById(e)}async function de(e,i){const n=i.baseURL||p,t=i.wsURL||re,a=new AbortController,r=E(i.auth,n),c=U(i.auth,n),u=H(i.auth,n),m=await r.getById(e),w=await q(i.auth,t,i.callbacks.onChatEvents);let{chat:f,streamingManager:l}=await X(m,i,r);return{agent:m,async reconnectToChat(){const{streamingManager:d}=await X(m,i,r,f);l=d},terminate(){return a.abort(),w.terminate(),l.terminate()},chatId:f.id,chat(d){return r.chat(e,f.id,{sessionId:l.sessionId,streamId:l.streamId,messages:d},{signal:a.signal})},rate(d,v){return v?c.update(v,d):c.create(d)},deleteRate(d){return c.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=m.knowledge)!=null&&d.id?u.getKnowledge((v=m.knowledge)==null?void 0:v.id).then(C=>(C==null?void 0:C.starter_message)||[]):Promise.resolve([])}}}function le(e,i){const n=A(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,a,r){return n.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:a})},addIceCandidate(t,a,r){return n.post(`/clips/streams/${t}/ice`,{session_id:r,...a})},sendStreamRequest(t,a,r){return n.post(`/clips/streams/${t}`,{session_id:a,...r})},close(t,a){return n.delete(`/clips/streams/${t}`,{session_id:a})}}}function ue(e,i){const n=A(e,i);return{createStream(t,a){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},a)},startConnection(t,a,r,c){return n.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:a},c)},addIceCandidate(t,a,r,c){return n.post(`/talks/streams/${t}/ice`,{session_id:r,...a},c)},sendStreamRequest(t,a,r,c){return n.post(`/talks/streams/${t}`,{session_id:a,...r},c)},close(t,a,r){return n.delete(`/talks/streams/${t}`,{session_id:a},r)}}}function ge(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 Y=!1;const $=(e,i)=>Y&&console.log(e,i),me=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function Z(e,{debug:i=!1,callbacks:n,auth:t,baseURL:a=p}){Y=i;const r={...n},{startConnection:c,sendStreamRequest:u,close:m,createStream:w,addIceCandidate:f}=e.videoType===M.Clip?le(t,a):ue(t,a),{id:l,offer:d,ice_servers:v,session_id:C}=await w(e),g=new me({iceServers:v}),x=g.createDataChannel("JanusDataChannel");let k=[],b=0,L=0,R,O,j;if(!C)throw new Error("Could not create session_id");(()=>{j=setInterval(()=>{g.getStats().then(h=>{h.forEach(S=>{var y,P;if(S.type==="inbound-rtp"&&S.kind==="video"){if(L=k.length-1,console.log("report ",L),S&&k[L]){const te=S.bytesReceived,ne=k[L].bytesReceived;console.log("ontrack interval i <=",te,ne);let we=R;R=te-ne>0;let ae;if(we!==R){if((y=r.onVideoStateChange)==null||y.call(r,R?_.Start:_.Stop,{isPlaying:R}),R)b=k.length;else{const T=k.slice(b),W=b===0?void 0:k[b-1];ae=ge(T,W)}(P=r.onVideoStateChange)==null||P.call(r,_.Stop,ae.sort((T,W)=>W.packetsLost-T.packetsLost).slice(0,5))}}console.log(" ontrack interval isPlaying?",R),k.push(S)}})})},500)})();const fe=()=>{clearInterval(O),console.log("clearInterval palying?")};g.onicecandidate=o=>{$("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&f(l,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},C)},g.oniceconnectionstatechange=()=>{var o;$("peerConnection.oniceconnectionstatechange => "+g.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,g.iceConnectionState)},g.ontrack=o=>{var h;$("peerConnection.ontrack",o),(h=r.onSrcObjectReady)==null||h.call(r,o.streams[0])},x.onmessage=o=>{var h,S;if(x.readyState==="open"){const[y,P]=o.data.split(":");y===I.StreamStarted?console.log("StreamStarted",y,P):y===I.StreamDone?console.log("StreamDone"):y===I.StreamFailed?((h=r.onVideoStateChange)==null||h.call(r,_.Stop,{event:y,data:P}),k=[],b=0,L=0,R=!1):(S=r.onMessage)==null||S.call(r,y,decodeURIComponent(P))}},await g.setRemoteDescription(d),$("set remote description OK");const ee=await g.createAnswer();return $("create answer OK"),await g.setLocalDescription(ee),$("set local description OK"),await c(l,ee,C),$("start connection OK"),{speak(o){return u(l,C,o)},async terminate(){var o,h;l&&(g&&(g.close(),g.oniceconnectionstatechange=null,g.onnegotiationneeded=null,g.onicecandidate=null,g.ontrack=null,clearInterval(O)),await m(l,C).catch(S=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(h=r.onVideoStateChange)==null||h.call(r,_.Stop),fe(),clearInterval(j))},sessionId:C,streamId:l,onCallback(o,h){r[o]=h}}}s.ChatMode=J,s.ChatProgress=K,s.DocumentType=G,s.KnowledgeType=V,s.Providers=F,s.RateState=z,s.SocketManager=q,s.StreamEvents=I,s.Subject=D,s.VoiceAccess=N,s.createAgentManager=de,s.createAgentsApi=E,s.createClient=A,s.createKnowledgeApi=H,s.createRatingsApi=U,s.createStreamingManager=Z,s.getAgent=ce,s.getAgentStreamArgs=Q,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
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",ee="wss://notifications.d-id.com";function W(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,a)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...a,headers:{...a==null?void 0:a.headers,Authorization:W(e),"Content-Type":"application/json"}});if(!r.ok){let c=await r.text().catch(()=>"Failed to fetch");throw new Error(c)}return r.json()};return{get(t,a){return n(t,{...a,method:"GET"})},post(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"POST"})},delete(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"DELETE"})},patch(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"PATCH"})}}}function T(e,i=p){const n=$(e,`${i}/agents`);return{create(t,a){return n.post("/",t,a)},getAgents(t,a){return n.get(`/${t?`?tag=${t}`:""}`,a).then(r=>r??[])},getById(t,a){return n.get(`/${t}`,a)},delete(t,a){return n.delete(`/${t}`,void 0,a)},update(t,a,r){return n.patch(`/${t}`,a,r)},newChat(t,a){return n.post(`/${t}/chat`,void 0,a)},chat(t,a,r,c){return n.post(`/${t}/chat/${a}`,r,c)}}}function B(e,i=p){const n=$(e,`${i}/knowledge`);return{createKnowledge(t,a){return n.post("/",t,a)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,a){return n.get(`/${t}`,a)},deleteKnowledge(t,a){return n.delete(`/${t}`,void 0,a)},createDocument(t,a,r){return n.post(`/${t}/documents`,a,r)},deleteDocument(t,a,r){return n.delete(`/${t}/documents/${a}`,void 0,r)},getDocuments(t,a){return n.get(`/${t}/documents`,a)},getDocument(t,a,r){return n.get(`/${t}/documents/${a}`,r)},getRecords(t,a,r){return n.get(`/${t}/documents/${a}/records`,r)},query(t,a,r){return n.post(`/${t}/query`,{query:a},r)}}}function H(e,i=p){const n=$(e,`${i}/chats/ratings`);return{create(t,a){return n.post("/",t,a)},getByKnowledge(t,a){return n.get(`/${t}`,a).then(r=>r??[])},update(t,a,r){return n.patch(`/${t}`,a,r)},delete(t,a){return n.delete(`/${t}`,a)}}}const te=e=>new Promise(i=>setTimeout(i,e));function ne(e){return new Promise((i,n)=>{const{callbacks:t,host:a,auth:r}=e,{onMessage:c=null,onOpen:u=null,onClose:m=null,onError:w=null}=t||{},f=new WebSocket(`${a}?authorization=${W(r)}`);f.onmessage=c,f.onclose=m,f.onerror=l=>{console.log(l),w==null||w(l),n(l)},f.onopen=l=>{u==null||u(l),i(f)}})}async function ae(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 ne(e)}catch(a){if(t===i)throw a;await te(t*500)}return n}async function U(e,i,n){const t=n?[n]:[],a=await ae({auth:e,host:i,callbacks:{onMessage:r=>{const c=JSON.parse(r.data);t.forEach(u=>u(c.event,c))}}});return{socket:a,terminate:()=>a.close(),subscribeToEvents:r=>t.push(r)}}var F=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(F||{}),q=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(q||{}),I=(e=>(e.Start="START",e.Stop="STOP",e))(I||{}),A=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(A||{}),N=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(N||{}),z=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(z||{}),L=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(L||{}),J=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(J||{}),D=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(D||{}),V=(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))(V||{}),M=(e=>(e.Clip="clip",e.Talk="talk",e))(M||{});function G(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 Q(e,i,n,t){return new Promise(async(a,r)=>{const c=await Y(G(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async u=>{var m,w;u==="connected"?(t||(t=await n.newChat(e.id)),a({chat:t,streamingManager:c})):u==="failed"&&r(new Error("Cannot create connection")),(w=(m=i.callbacks).onConnectionStateChange)==null||w.call(m,u)},onMessage:(u,m)=>{var w,f;u===A.ChatAnswer&&(console.log("ChatAnswer",u,m),(f=(w=i.callbacks).onChatEvents)==null||f.call(w,L.Answer,{content:m,event:L.Answer}))}}})})}function re(e,i,n){return T(i,n||p).getById(e)}async function ie(e,i){const n=i.baseURL||p,t=i.wsURL||ee,a=new AbortController,r=T(i.auth,n),c=H(i.auth,n),u=B(i.auth,n),m=await r.getById(e),w=await U(i.auth,t,i.callbacks.onChatEvents);let{chat:f,streamingManager:l}=await Q(m,i,r);return{agent:m,async reconnectToChat(){const{streamingManager:d}=await Q(m,i,r,f);l=d},terminate(){return a.abort(),w.terminate(),l.terminate()},chatId:f.id,chat(d){return r.chat(e,f.id,{sessionId:l.sessionId,streamId:l.streamId,messages:d},{signal:a.signal})},rate(d,v){return v?c.update(v,d):c.create(d)},deleteRate(d){return c.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=m.knowledge)!=null&&d.id?u.getKnowledge((v=m.knowledge)==null?void 0:v.id).then(C=>(C==null?void 0:C.starter_message)||[]):Promise.resolve([])}}}function se(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,a,r){return n.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:a})},addIceCandidate(t,a,r){return n.post(`/clips/streams/${t}/ice`,{session_id:r,...a})},sendStreamRequest(t,a,r){return n.post(`/clips/streams/${t}`,{session_id:a,...r})},close(t,a){return n.delete(`/clips/streams/${t}`,{session_id:a})}}}function oe(e,i){const n=$(e,i);return{createStream(t,a){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},a)},startConnection(t,a,r,c){return n.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:a},c)},addIceCandidate(t,a,r,c){return n.post(`/talks/streams/${t}/ice`,{session_id:r,...a},c)},sendStreamRequest(t,a,r,c){return n.post(`/talks/streams/${t}`,{session_id:a,...r},c)},close(t,a,r){return n.delete(`/talks/streams/${t}`,{session_id:a},r)}}}function ce(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 X=!1;const R=(e,i)=>X&&console.log(e,i),de=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function Y(e,{debug:i=!1,callbacks:n,auth:t,baseURL:a=p}){X=i;const r={...n},{startConnection:c,sendStreamRequest:u,close:m,createStream:w,addIceCandidate:f}=e.videoType===M.Clip?se(t,a):oe(t,a),{id:l,offer:d,ice_servers:v,session_id:C}=await w(e),g=new de({iceServers:v}),Z=g.createDataChannel("JanusDataChannel");let k=[],P=0,K=0,_,O,j;if(!C)throw new Error("Could not create session_id");(()=>{j=setInterval(()=>{g.getStats().then(h=>{h.forEach(S=>{var y;if(S.type==="inbound-rtp"&&S.kind==="video"){if(K=k.length-1,S&&k[K]){const b=S.bytesReceived,ue=k[K].bytesReceived;let ge=_;_=b-ue>0;let E;if(ge!==_){if(_)P=k.length;else{const me=k.slice(P),fe=P===0?void 0:k[P-1];E=ce(me,fe),E=E.sort((we,he)=>he.packetsLost-we.packetsLost).slice(0,5)}(y=r.onVideoStateChange)==null||y.call(r,_?I.Start:I.Stop,E)}}k.push(S)}})})},500)})();const le=()=>{clearInterval(O)};g.onicecandidate=o=>{R("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&f(l,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},C)},g.oniceconnectionstatechange=()=>{var o;R("peerConnection.oniceconnectionstatechange => "+g.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,g.iceConnectionState)},g.ontrack=o=>{var h;R("peerConnection.ontrack",o),(h=r.onSrcObjectReady)==null||h.call(r,o.streams[0])},Z.onmessage=o=>{var h,S;if(Z.readyState==="open"){const[y,b]=o.data.split(":");y===A.StreamStarted?console.log("StreamStarted",y,b):y===A.StreamDone?console.log("StreamDone"):y===A.StreamFailed?((h=r.onVideoStateChange)==null||h.call(r,I.Stop,{event:y,data:b}),k=[],P=0,K=0,_=!1,console.log("StreamFailed")):(S=r.onMessage)==null||S.call(r,y,decodeURIComponent(b))}},await g.setRemoteDescription(d),R("set remote description OK");const x=await g.createAnswer();return R("create answer OK"),await g.setLocalDescription(x),R("set local description OK"),await c(l,x,C),R("start connection OK"),{speak(o){return u(l,C,o)},async terminate(){var o,h;l&&(g&&(g.close(),g.oniceconnectionstatechange=null,g.onnegotiationneeded=null,g.onicecandidate=null,g.ontrack=null,clearInterval(O)),await m(l,C).catch(S=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(h=r.onVideoStateChange)==null||h.call(r,I.Stop),le(),clearInterval(j))},sessionId:C,streamId:l,onCallback(o,h){r[o]=h}}}s.ChatMode=z,s.ChatProgress=L,s.DocumentType=V,s.KnowledgeType=D,s.Providers=F,s.RateState=N,s.SocketManager=U,s.StreamEvents=A,s.Subject=J,s.VoiceAccess=q,s.createAgentManager=ie,s.createAgentsApi=T,s.createClient=$,s.createKnowledgeApi=B,s.createRatingsApi=H,s.createStreamingManager=Y,s.getAgent=re,s.getAgentStreamArgs=G,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|