@d-id/client-sdk 1.0.19-beta.13 → 1.0.19-beta.15
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 +89 -87
- 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 k = "https://api.d-id.com", J = "wss://notifications.d-id.com";
|
|
2
|
+
function F(e) {
|
|
3
3
|
if (e.type === "bearer")
|
|
4
4
|
return `Bearer ${e.token}`;
|
|
5
5
|
if (e.type === "basic")
|
|
@@ -8,13 +8,13 @@ function q(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 P(e, i = k) {
|
|
12
12
|
const n = async (t, r) => {
|
|
13
13
|
const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
|
|
14
14
|
...r,
|
|
15
15
|
headers: {
|
|
16
16
|
...r == null ? void 0 : r.headers,
|
|
17
|
-
Authorization:
|
|
17
|
+
Authorization: F(e),
|
|
18
18
|
"Content-Type": "application/json"
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -54,8 +54,8 @@ function L(e, i = R) {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
const n =
|
|
57
|
+
function N(e, i = k) {
|
|
58
|
+
const n = P(e, `${i}/agents`);
|
|
59
59
|
return {
|
|
60
60
|
create(t, r) {
|
|
61
61
|
return n.post("/", t, r);
|
|
@@ -80,8 +80,8 @@ function F(e, i = R) {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function D(e, i =
|
|
84
|
-
const n =
|
|
83
|
+
function D(e, i = k) {
|
|
84
|
+
const n = P(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
|
|
121
|
-
const n =
|
|
120
|
+
function V(e, i = k) {
|
|
121
|
+
const n = P(e, `${i}/chats/ratings`);
|
|
122
122
|
return {
|
|
123
123
|
create(t, r) {
|
|
124
124
|
return n.post("/", t, r);
|
|
@@ -134,8 +134,8 @@ function Y(e, i = R) {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
137
|
+
const G = (e) => new Promise((i) => setTimeout(i, e));
|
|
138
|
+
function Q(e) {
|
|
139
139
|
return new Promise((i, n) => {
|
|
140
140
|
const {
|
|
141
141
|
callbacks: t,
|
|
@@ -143,40 +143,40 @@ function G(e) {
|
|
|
143
143
|
auth: a
|
|
144
144
|
} = e, {
|
|
145
145
|
onMessage: s = null,
|
|
146
|
-
onOpen:
|
|
146
|
+
onOpen: l = null,
|
|
147
147
|
onClose: m = null,
|
|
148
148
|
onError: p = null
|
|
149
|
-
} = t || {}, f = new WebSocket(`${r}?authorization=${
|
|
149
|
+
} = t || {}, f = new WebSocket(`${r}?authorization=${F(a)}`);
|
|
150
150
|
f.onmessage = s, f.onclose = m, f.onerror = (d) => {
|
|
151
151
|
console.log(d), p == null || p(d), n(d);
|
|
152
152
|
}, f.onopen = (d) => {
|
|
153
|
-
|
|
153
|
+
l == null || l(d), i(f);
|
|
154
154
|
};
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
async function
|
|
157
|
+
async function X(e) {
|
|
158
158
|
const {
|
|
159
159
|
retries: i = 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 Q(e);
|
|
165
165
|
} catch (r) {
|
|
166
166
|
if (t === i)
|
|
167
167
|
throw r;
|
|
168
|
-
await
|
|
168
|
+
await G(t * 500);
|
|
169
169
|
}
|
|
170
170
|
return n;
|
|
171
171
|
}
|
|
172
|
-
async function
|
|
173
|
-
const t = n ? [n] : [], r = await
|
|
172
|
+
async function Y(e, i, n) {
|
|
173
|
+
const t = n ? [n] : [], r = await X({
|
|
174
174
|
auth: e,
|
|
175
175
|
host: i,
|
|
176
176
|
callbacks: {
|
|
177
177
|
onMessage: (a) => {
|
|
178
178
|
const s = JSON.parse(a.data);
|
|
179
|
-
t.forEach((
|
|
179
|
+
t.forEach((l) => l(s.event, s));
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
});
|
|
@@ -186,36 +186,36 @@ async function X(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 || {}),
|
|
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 || {}), y = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(y || {}), _ = /* @__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 || {});
|
|
190
190
|
function ae(e) {
|
|
191
|
-
return e.presenter.type ===
|
|
192
|
-
videoType:
|
|
191
|
+
return e.presenter.type === M.Clip ? {
|
|
192
|
+
videoType: M.Clip,
|
|
193
193
|
driver_id: e.presenter.driver_id,
|
|
194
194
|
presenter_id: e.presenter.presenter_id
|
|
195
195
|
} : {
|
|
196
|
-
videoType:
|
|
196
|
+
videoType: M.Talk,
|
|
197
197
|
source_url: e.presenter.source_url
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function q(e, i, n, t) {
|
|
201
201
|
return new Promise(async (r, a) => {
|
|
202
202
|
const s = await de(ae(e), {
|
|
203
203
|
...i,
|
|
204
204
|
callbacks: {
|
|
205
205
|
...i.callbacks,
|
|
206
|
-
onConnectionStateChange: async (
|
|
206
|
+
onConnectionStateChange: async (l) => {
|
|
207
207
|
var m, p;
|
|
208
|
-
|
|
208
|
+
l === "connected" ? (t || (t = await n.newChat(e.id)), r({
|
|
209
209
|
chat: t,
|
|
210
210
|
streamingManager: s
|
|
211
|
-
})) :
|
|
211
|
+
})) : l === "failed" && a(new Error("Cannot create connection")), (p = (m = i.callbacks).onConnectionStateChange) == null || p.call(m, l);
|
|
212
212
|
},
|
|
213
213
|
// TODO remove when webscoket will return partial
|
|
214
|
-
onMessage: (
|
|
214
|
+
onMessage: (l, m) => {
|
|
215
215
|
var p, f;
|
|
216
|
-
|
|
216
|
+
l === _.ChatAnswer && (console.log("ChatAnswer", l, m), (f = (p = i.callbacks).onChatEvents) == null || f.call(p, B.Answer, {
|
|
217
217
|
content: m,
|
|
218
|
-
event:
|
|
218
|
+
event: B.Answer
|
|
219
219
|
}));
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -223,20 +223,20 @@ function T(e, i, n, t) {
|
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
function le(e, i, n) {
|
|
226
|
-
return
|
|
226
|
+
return N(i, n || k).getById(e);
|
|
227
227
|
}
|
|
228
228
|
async function ue(e, i) {
|
|
229
|
-
const n = i.baseURL ||
|
|
229
|
+
const n = i.baseURL || k, t = i.wsURL || J, r = new AbortController(), a = N(i.auth, n), s = V(i.auth, n), l = D(i.auth, n), m = await a.getById(e), p = await Y(i.auth, t, i.callbacks.onChatEvents);
|
|
230
230
|
let {
|
|
231
231
|
chat: f,
|
|
232
232
|
streamingManager: d
|
|
233
|
-
} = await
|
|
233
|
+
} = await q(m, i, a);
|
|
234
234
|
return {
|
|
235
235
|
agent: m,
|
|
236
236
|
async reconnectToChat() {
|
|
237
237
|
const {
|
|
238
238
|
streamingManager: c
|
|
239
|
-
} = await
|
|
239
|
+
} = await q(m, i, a, f);
|
|
240
240
|
d = c;
|
|
241
241
|
},
|
|
242
242
|
terminate() {
|
|
@@ -276,12 +276,12 @@ async function ue(e, i) {
|
|
|
276
276
|
},
|
|
277
277
|
getStarterMessages() {
|
|
278
278
|
var c, w;
|
|
279
|
-
return (c = m.knowledge) != null && c.id ?
|
|
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
283
|
function ie(e, i) {
|
|
284
|
-
const n =
|
|
284
|
+
const n = P(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 =
|
|
319
|
+
const n = P(e, i);
|
|
320
320
|
return {
|
|
321
321
|
createStream(t, r) {
|
|
322
322
|
return n.post("/talks/streams", {
|
|
@@ -385,93 +385,95 @@ function oe(e, i) {
|
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
387
|
let z = !1;
|
|
388
|
-
const
|
|
388
|
+
const $ = (e, i) => z && console.log(e, i), ce = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
389
389
|
async function de(e, {
|
|
390
390
|
debug: i = !1,
|
|
391
391
|
callbacks: n,
|
|
392
392
|
auth: t,
|
|
393
|
-
baseURL: r =
|
|
393
|
+
baseURL: r = k
|
|
394
394
|
}) {
|
|
395
395
|
z = i;
|
|
396
396
|
const a = {
|
|
397
397
|
...n
|
|
398
398
|
}, {
|
|
399
399
|
startConnection: s,
|
|
400
|
-
sendStreamRequest:
|
|
400
|
+
sendStreamRequest: l,
|
|
401
401
|
close: m,
|
|
402
402
|
createStream: p,
|
|
403
403
|
addIceCandidate: f
|
|
404
|
-
} = e.videoType ===
|
|
404
|
+
} = e.videoType === M.Clip ? ie(t, r) : se(t, r), {
|
|
405
405
|
id: d,
|
|
406
406
|
offer: c,
|
|
407
407
|
ice_servers: w,
|
|
408
408
|
session_id: h
|
|
409
|
-
} = await p(e),
|
|
409
|
+
} = await p(e), u = new ce({
|
|
410
410
|
iceServers: w
|
|
411
|
-
}),
|
|
412
|
-
let A = 0,
|
|
411
|
+
}), H = u.createDataChannel("JanusDataChannel"), g = [];
|
|
412
|
+
let A = 0, L = 0, K = 0, b, U;
|
|
413
413
|
if (!h)
|
|
414
414
|
throw new Error("Could not create session_id");
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
u.onicecandidate = (o) => {
|
|
416
|
+
$("peerConnection.onicecandidate", o), o.candidate && o.candidate.sdpMid && o.candidate.sdpMLineIndex !== null && f(d, {
|
|
417
417
|
candidate: o.candidate.candidate,
|
|
418
418
|
sdpMid: o.candidate.sdpMid,
|
|
419
419
|
sdpMLineIndex: o.candidate.sdpMLineIndex
|
|
420
420
|
}, h);
|
|
421
|
-
},
|
|
421
|
+
}, u.oniceconnectionstatechange = () => {
|
|
422
422
|
var o;
|
|
423
|
-
|
|
424
|
-
},
|
|
423
|
+
$("peerConnection.oniceconnectionstatechange => " + u.iceConnectionState), (o = a.onConnectionStateChange) == null || o.call(a, u.iceConnectionState);
|
|
424
|
+
}, u.ontrack = (o) => {
|
|
425
425
|
var v;
|
|
426
|
-
|
|
427
|
-
var
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
430
|
-
|
|
426
|
+
$("peerConnection.ontrack", o), (v = a.onSrcObjectReady) == null || v.call(a, o.streams[0]), b = setInterval(() => {
|
|
427
|
+
var R, I;
|
|
428
|
+
if (g != null && g.length && L < (g == null ? void 0 : g.length)) {
|
|
429
|
+
const C = (R = g[L]) == null ? void 0 : R.bytesReceived, S = (C ?? 1 / 0) - K > 0 || K == 0 && C == 0;
|
|
430
|
+
K = C ?? 0, (I = a.onVideoStateChange) == null || I.call(a, S ? y.Start : y.Stop, {
|
|
431
|
+
isPlaying: S
|
|
432
|
+
}), L = g == null ? void 0 : g.length;
|
|
431
433
|
}
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
var v,
|
|
435
|
-
if (
|
|
436
|
-
const [C,
|
|
437
|
-
if (C ===
|
|
438
|
-
console.log("StreamStarted", C,
|
|
439
|
-
|
|
434
|
+
}, 1e3);
|
|
435
|
+
}, H.onmessage = (o) => {
|
|
436
|
+
var v, R, I;
|
|
437
|
+
if (H.readyState === "open") {
|
|
438
|
+
const [C, S] = o.data.split(":");
|
|
439
|
+
if (C === _.StreamStarted)
|
|
440
|
+
console.log("StreamStarted", C, S), A = g.length, U = setInterval(() => {
|
|
441
|
+
u.getStats().then((E) => {
|
|
440
442
|
E.forEach((W) => {
|
|
441
|
-
W.type === "inbound-rtp" && W.kind === "video" &&
|
|
443
|
+
W.type === "inbound-rtp" && W.kind === "video" && g.push(W);
|
|
442
444
|
});
|
|
443
445
|
});
|
|
444
|
-
}, 1e3), (v = a.onVideoStateChange) == null || v.call(a,
|
|
445
|
-
else if (C ===
|
|
446
|
-
console.log("StreamDone"), clearInterval(
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
const E = A === 0 ? void 0 :
|
|
450
|
-
oe(
|
|
446
|
+
}, 1e3), (v = a.onVideoStateChange) == null || v.call(a, y.Start);
|
|
447
|
+
else if (C === _.StreamDone) {
|
|
448
|
+
console.log("StreamDone"), clearInterval(U), clearInterval(b);
|
|
449
|
+
const x = g.slice(A);
|
|
450
|
+
if (x) {
|
|
451
|
+
const E = A === 0 ? void 0 : g[A - 1];
|
|
452
|
+
oe(x, E), A = g.length;
|
|
451
453
|
}
|
|
452
454
|
} else
|
|
453
|
-
C ===
|
|
455
|
+
C === _.StreamFailed ? (R = a.onVideoStateChange) == null || R.call(a, y.Stop, {
|
|
454
456
|
event: C,
|
|
455
|
-
data:
|
|
456
|
-
}) : (I = a.onMessage) == null || I.call(a, C, decodeURIComponent(
|
|
457
|
+
data: S
|
|
458
|
+
}) : (I = a.onMessage) == null || I.call(a, C, decodeURIComponent(S));
|
|
457
459
|
}
|
|
458
|
-
}, await
|
|
459
|
-
const
|
|
460
|
-
return
|
|
460
|
+
}, await u.setRemoteDescription(c), $("set remote description OK");
|
|
461
|
+
const T = await u.createAnswer();
|
|
462
|
+
return $("create answer OK"), await u.setLocalDescription(T), $("set local description OK"), await s(d, T, h), $("start connection OK"), {
|
|
461
463
|
/**
|
|
462
464
|
* Method to send request to server to get clip or talk depend on you payload
|
|
463
465
|
* @param payload
|
|
464
466
|
*/
|
|
465
467
|
speak(o) {
|
|
466
|
-
return
|
|
468
|
+
return l(d, h, o);
|
|
467
469
|
},
|
|
468
470
|
/**
|
|
469
471
|
* Method to close RTC connection
|
|
470
472
|
*/
|
|
471
473
|
async terminate() {
|
|
472
474
|
var o, v;
|
|
473
|
-
d && (
|
|
474
|
-
}), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (v = a.onVideoStateChange) == null || v.call(a,
|
|
475
|
+
d && (u && (u.close(), u.oniceconnectionstatechange = null, u.onnegotiationneeded = null, u.onicecandidate = null, u.ontrack = null, clearInterval(b)), await m(d, h).catch((R) => {
|
|
476
|
+
}), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (v = a.onVideoStateChange) == null || v.call(a, y.Stop));
|
|
475
477
|
},
|
|
476
478
|
/**
|
|
477
479
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
@@ -493,20 +495,20 @@ async function de(e, {
|
|
|
493
495
|
}
|
|
494
496
|
export {
|
|
495
497
|
ee as ChatMode,
|
|
496
|
-
|
|
498
|
+
B as ChatProgress,
|
|
497
499
|
re as DocumentType,
|
|
498
500
|
ne as KnowledgeType,
|
|
499
501
|
Z as Providers,
|
|
500
502
|
j as RateState,
|
|
501
|
-
|
|
502
|
-
|
|
503
|
+
Y as SocketManager,
|
|
504
|
+
_ as StreamEvents,
|
|
503
505
|
te as Subject,
|
|
504
506
|
O as VoiceAccess,
|
|
505
507
|
ue as createAgentManager,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
+
N as createAgentsApi,
|
|
509
|
+
P as createClient,
|
|
508
510
|
D as createKnowledgeApi,
|
|
509
|
-
|
|
511
|
+
V as createRatingsApi,
|
|
510
512
|
de as createStreamingManager,
|
|
511
513
|
le as getAgent,
|
|
512
514
|
ae as getAgentStreamArgs
|
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 N(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 k(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:N(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=k(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 q(e,i=p){const n=k(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 F(e,i=p){const n=k(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=${N(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||{}),M=(e=>(e.Start="START",e.Stop="STOP",e))(M||{}),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||{}),Y=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(Y||{}),L=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(L||{}),G=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(G||{}),Q=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(Q||{}),X=(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))(X||{}),P=(e=>(e.Clip="clip",e.Talk="talk",e))(P||{});function Z(e){return e.presenter.type===P.Clip?{videoType:P.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:P.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=F(i.auth,n),g=q(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=k(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=k(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 R=(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===P.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 b=0,E=0,W=0,H,te;if(!C)throw new Error("Could not create session_id");m.onicecandidate=c=>{R("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;R("peerConnection.oniceconnectionstatechange => "+m.iceConnectionState),(c=a.onConnectionStateChange)==null||c.call(a,m.iceConnectionState)},m.ontrack=c=>{var S;R("peerConnection.ontrack",c),(S=a.onSrcObjectReady)==null||S.call(a,c.streams[0]),H=setInterval(()=>{var $,K,y,I;if(u!=null&&u.length&&E<(u==null?void 0:u.length)){const _=((($=u[E])==null?void 0:$.bytesReceived)??1/0)>W;W=((K=u[E])==null?void 0:K.bytesReceived)??0,console.log("videoStatsStartIndex ",_,(y=u.slice(-1))==null?void 0:y[0].bytesReceived,W,u),_?console.log("PLAYYYY....."):((I=a.onVideoStateChange)==null||I.call(a,M.Stop),console.log("isPlaying NO by stats")),E=u==null?void 0:u.length}},500)},ee.onmessage=c=>{var S,$,K;if(ee.readyState==="open"){const[y,I]=c.data.split(":");if(y===A.StreamStarted)console.log("StreamStarted",y,I),b=u.length,te=setInterval(()=>{m.getStats().then(U=>{U.forEach(B=>{B.type==="inbound-rtp"&&B.kind==="video"&&u.push(B)})})},1e3),(S=a.onVideoStateChange)==null||S.call(a,M.Start);else if(y===A.StreamDone){console.log("StreamDone"),clearInterval(te),clearInterval(H);const _=u.slice(b);if(_){const U=b===0?void 0:u[b-1];ue(_,U),b=u.length}}else y===A.StreamFailed?($=a.onVideoStateChange)==null||$.call(a,M.Stop,{event:y,data:I}):(K=a.onMessage)==null||K.call(a,y,decodeURIComponent(I))}},await m.setRemoteDescription(d),R("set remote description OK");const ne=await m.createAnswer();return R("create answer OK"),await m.setLocalDescription(ne),R("set local description OK"),await o(l,ne,C),R("start connection OK"),{speak(c){return g(l,C,c)},async terminate(){var c,S;l&&(m&&(m.close(),m.oniceconnectionstatechange=null,m.onnegotiationneeded=null,m.onicecandidate=null,m.ontrack=null,clearInterval(H)),await f(l,C).catch($=>{}),(c=a.onConnectionStateChange)==null||c.call(a,"closed"),(S=a.onVideoStateChange)==null||S.call(a,M.Stop))},sessionId:C,streamId:l,onCallback(c,S){a[c]=S}}}s.ChatMode=Y,s.ChatProgress=L,s.DocumentType=X,s.KnowledgeType=Q,s.Providers=J,s.RateState=V,s.SocketManager=z,s.StreamEvents=A,s.Subject=G,s.VoiceAccess=D,s.createAgentManager=ce,s.createAgentsApi=T,s.createClient=k,s.createKnowledgeApi=q,s.createRatingsApi=F,s.createStreamingManager=j,s.getAgent=oe,s.getAgentStreamArgs=Z,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",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 k(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=k(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=k(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=k(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:u=null,onClose:m=null,onError:w=null}=t||{},h=new WebSocket(`${r}?authorization=${q(a)}`);h.onmessage=c,h.onclose=m,h.onerror=l=>{console.log(l),w==null||w(l),n(l)},h.onopen=l=>{u==null||u(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 c=JSON.parse(a.data);t.forEach(u=>u(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))($||{}),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 c=await j(Z(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async u=>{var m,w;u==="connected"?(t||(t=await n.newChat(e.id)),r({chat:t,streamingManager:c})):u==="failed"&&a(new Error("Cannot create connection")),(w=(m=i.callbacks).onConnectionStateChange)==null||w.call(m,u)},onMessage:(u,m)=>{var w,h;u===A.ChatAnswer&&(console.log("ChatAnswer",u,m),(h=(w=i.callbacks).onChatEvents)==null||h.call(w,L.Answer,{content:m,event:L.Answer}))}}})})}function ce(e,i,n){return b(i,n||p).getById(e)}async function oe(e,i){const n=i.baseURL||p,t=i.wsURL||re,r=new AbortController,a=b(i.auth,n),c=N(i.auth,n),u=F(i.auth,n),m=await a.getById(e),w=await z(i.auth,t,i.callbacks.onChatEvents);let{chat:h,streamingManager:l}=await x(m,i,a);return{agent:m,async reconnectToChat(){const{streamingManager:d}=await x(m,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?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 de(e,i){const n=k(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=k(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 R=(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:u,close:m,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),g=new ge({iceServers:v}),ee=g.createDataChannel("JanusDataChannel"),f=[];let P=0,E=0,T=0,W,te;if(!C)throw new Error("Could not create session_id");g.onicecandidate=o=>{R("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&h(l,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},C)},g.oniceconnectionstatechange=()=>{var o;R("peerConnection.oniceconnectionstatechange => "+g.iceConnectionState),(o=a.onConnectionStateChange)==null||o.call(a,g.iceConnectionState)},g.ontrack=o=>{var S;R("peerConnection.ontrack",o),(S=a.onSrcObjectReady)==null||S.call(a,o.streams[0]),W=setInterval(()=>{var I,K;if(f!=null&&f.length&&E<(f==null?void 0:f.length)){const y=(I=f[E])==null?void 0:I.bytesReceived,_=(y??1/0)-T>0||T==0&&y==0;T=y??0,(K=a.onVideoStateChange)==null||K.call(a,_?$.Start:$.Stop,{isPlaying:_}),E=f==null?void 0:f.length}},1e3)},ee.onmessage=o=>{var S,I,K;if(ee.readyState==="open"){const[y,_]=o.data.split(":");if(y===A.StreamStarted)console.log("StreamStarted",y,_),P=f.length,te=setInterval(()=>{g.getStats().then(H=>{H.forEach(U=>{U.type==="inbound-rtp"&&U.kind==="video"&&f.push(U)})})},1e3),(S=a.onVideoStateChange)==null||S.call(a,$.Start);else if(y===A.StreamDone){console.log("StreamDone"),clearInterval(te),clearInterval(W);const B=f.slice(P);if(B){const H=P===0?void 0:f[P-1];ue(B,H),P=f.length}}else y===A.StreamFailed?(I=a.onVideoStateChange)==null||I.call(a,$.Stop,{event:y,data:_}):(K=a.onMessage)==null||K.call(a,y,decodeURIComponent(_))}},await g.setRemoteDescription(d),R("set remote description OK");const ne=await g.createAnswer();return R("create answer OK"),await g.setLocalDescription(ne),R("set local description OK"),await c(l,ne,C),R("start connection OK"),{speak(o){return u(l,C,o)},async terminate(){var o,S;l&&(g&&(g.close(),g.oniceconnectionstatechange=null,g.onnegotiationneeded=null,g.onicecandidate=null,g.ontrack=null,clearInterval(W)),await m(l,C).catch(I=>{}),(o=a.onConnectionStateChange)==null||o.call(a,"closed"),(S=a.onVideoStateChange)==null||S.call(a,$.Stop))},sessionId:C,streamId:l,onCallback(o,S){a[o]=S}}}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=oe,s.createAgentsApi=b,s.createClient=k,s.createKnowledgeApi=F,s.createRatingsApi=N,s.createStreamingManager=j,s.getAgent=ce,s.getAgentStreamArgs=Z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|