@d-id/client-sdk 1.0.18 → 1.0.19
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/README.md +2 -0
- package/dist/index.js +409 -221
- package/dist/index.umd.cjs +1 -1
- package/dist/src/index.d.ts +8 -0
- package/dist/{apps/sdk → src}/lib/api/agents.d.ts +1 -1
- package/dist/{apps/sdk → src}/lib/api/clipStream.d.ts +1 -1
- package/dist/{apps/sdk → src}/lib/api/getClient.d.ts +1 -1
- package/dist/{apps/sdk → src}/lib/api/knowledge.d.ts +1 -1
- package/dist/{apps/sdk → src}/lib/api/ratings.d.ts +2 -4
- package/dist/{apps/sdk → src}/lib/api/talkStream.d.ts +1 -1
- package/dist/{apps/sdk → src}/lib/auth/getAuthHeader.d.ts +1 -1
- package/dist/src/lib/connectToSocket.d.ts +9 -0
- package/dist/src/lib/createAgentManager.d.ts +15 -0
- package/dist/src/lib/createStreamingManager.d.ts +27 -0
- package/dist/src/lib/environment.d.ts +7 -0
- package/dist/src/lib/utils/webrtc.d.ts +2 -0
- package/dist/{common/types/src → src/types}/StreamScript.d.ts +1 -0
- package/dist/{common/types/src → src/types}/auth.d.ts +2 -0
- package/dist/src/types/entities/agents/agent.d.ts +28 -0
- package/dist/{common/types/src → src/types}/entities/agents/chat.d.ts +1 -0
- package/dist/src/types/entities/agents/manager.d.ts +112 -0
- package/dist/{common/types/src → src/types}/index.d.ts +1 -0
- package/dist/{common/types/src → src/types}/stream/api/clip.d.ts +1 -1
- package/dist/{common/types/src → src/types}/stream/api/talk.d.ts +1 -1
- package/dist/{common/types/src → src/types}/stream/stream.d.ts +13 -1
- package/package.json +8 -12
- package/dist/apps/sdk/lib/createAgentManager.d.ts +0 -9
- package/dist/apps/sdk/lib/createStreamingManager.d.ts +0 -8
- package/dist/apps/sdk/lib/index.d.ts +0 -6
- package/dist/common/types/src/entities/agents/agent.d.ts +0 -18
- package/dist/common/types/src/entities/agents/manager.d.ts +0 -21
- /package/dist/{common/types/src → src/types}/entities/agents/index.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/agents/knowledge.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/agents/llm.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/agents/presenter.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/index.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/knowledge/document.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/knowledge/index.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/knowledge/knowledge.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/knowledge/record.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/knowledge/retrival.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/entities/video.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/stream/api/index.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/stream/index.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/stream/rtc.d.ts +0 -0
- /package/dist/{common/types/src → src/types}/tts.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,311 +1,499 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const v = "https://api.d-id.com", J = "wss://notifications.d-id.com";
|
|
2
|
+
function q(e) {
|
|
3
|
+
if (e.type === "bearer")
|
|
4
|
+
return `Bearer ${e.token}`;
|
|
5
|
+
if (e.type === "basic")
|
|
6
|
+
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
7
|
+
if (e.type === "key")
|
|
8
|
+
return `Client-Key ${e.clientKey}`;
|
|
9
|
+
throw new Error(`Unknown auth type: ${e}`);
|
|
3
10
|
}
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
...
|
|
11
|
+
function y(e, i = v) {
|
|
12
|
+
const r = async (t, n) => {
|
|
13
|
+
const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
|
|
14
|
+
...n,
|
|
8
15
|
headers: {
|
|
9
|
-
...
|
|
10
|
-
Authorization:
|
|
16
|
+
...n == null ? void 0 : n.headers,
|
|
17
|
+
Authorization: q(e),
|
|
11
18
|
"Content-Type": "application/json"
|
|
12
19
|
}
|
|
13
20
|
});
|
|
14
|
-
if (!
|
|
15
|
-
let
|
|
16
|
-
throw new Error(
|
|
21
|
+
if (!a.ok) {
|
|
22
|
+
let c = await a.text().catch(() => "Failed to fetch");
|
|
23
|
+
throw new Error(c);
|
|
17
24
|
}
|
|
18
|
-
return
|
|
25
|
+
return a.json();
|
|
19
26
|
};
|
|
20
27
|
return {
|
|
21
|
-
get(
|
|
22
|
-
return
|
|
23
|
-
...
|
|
28
|
+
get(t, n) {
|
|
29
|
+
return r(t, {
|
|
30
|
+
...n,
|
|
24
31
|
method: "GET"
|
|
25
32
|
});
|
|
26
33
|
},
|
|
27
|
-
post(
|
|
28
|
-
return
|
|
29
|
-
...
|
|
30
|
-
body: JSON.stringify(
|
|
34
|
+
post(t, n, a) {
|
|
35
|
+
return r(t, {
|
|
36
|
+
...a,
|
|
37
|
+
body: JSON.stringify(n),
|
|
31
38
|
method: "POST"
|
|
32
39
|
});
|
|
33
40
|
},
|
|
34
|
-
delete(
|
|
35
|
-
return
|
|
36
|
-
...
|
|
37
|
-
body: JSON.stringify(
|
|
41
|
+
delete(t, n, a) {
|
|
42
|
+
return r(t, {
|
|
43
|
+
...a,
|
|
44
|
+
body: JSON.stringify(n),
|
|
38
45
|
method: "DELETE"
|
|
39
46
|
});
|
|
40
47
|
},
|
|
41
|
-
patch(
|
|
42
|
-
return
|
|
43
|
-
...
|
|
44
|
-
body: JSON.stringify(
|
|
48
|
+
patch(t, n, a) {
|
|
49
|
+
return r(t, {
|
|
50
|
+
...a,
|
|
51
|
+
body: JSON.stringify(n),
|
|
45
52
|
method: "PATCH"
|
|
46
53
|
});
|
|
47
54
|
}
|
|
48
55
|
};
|
|
49
56
|
}
|
|
50
|
-
function
|
|
51
|
-
const
|
|
57
|
+
function T(e, i = v) {
|
|
58
|
+
const r = y(e, `${i}/agents`);
|
|
52
59
|
return {
|
|
53
|
-
create(
|
|
54
|
-
return
|
|
60
|
+
create(t, n) {
|
|
61
|
+
return r.post("/", t, n);
|
|
55
62
|
},
|
|
56
|
-
getAgents(
|
|
57
|
-
return
|
|
63
|
+
getAgents(t, n) {
|
|
64
|
+
return r.get(`/${t ? `?tag=${t}` : ""}`, n).then((a) => a ?? []);
|
|
58
65
|
},
|
|
59
|
-
getById(
|
|
60
|
-
return
|
|
66
|
+
getById(t, n) {
|
|
67
|
+
return r.get(`/${t}`, n);
|
|
61
68
|
},
|
|
62
|
-
delete(
|
|
63
|
-
return
|
|
69
|
+
delete(t, n) {
|
|
70
|
+
return r.delete(`/${t}`, void 0, n);
|
|
64
71
|
},
|
|
65
|
-
update(
|
|
66
|
-
return
|
|
72
|
+
update(t, n, a) {
|
|
73
|
+
return r.patch(`/${t}`, n, a);
|
|
67
74
|
},
|
|
68
|
-
newChat(
|
|
69
|
-
return
|
|
75
|
+
newChat(t, n) {
|
|
76
|
+
return r.post(`/${t}/chat`, void 0, n);
|
|
70
77
|
},
|
|
71
|
-
chat(
|
|
72
|
-
return
|
|
78
|
+
chat(t, n, a, c) {
|
|
79
|
+
return r.post(`/${t}/chat/${n}`, a, c);
|
|
73
80
|
}
|
|
74
81
|
};
|
|
75
82
|
}
|
|
76
|
-
function
|
|
77
|
-
const
|
|
83
|
+
function D(e, i = v) {
|
|
84
|
+
const r = y(e, `${i}/knowledge`);
|
|
78
85
|
return {
|
|
79
|
-
createKnowledge(
|
|
80
|
-
return
|
|
86
|
+
createKnowledge(t, n) {
|
|
87
|
+
return r.post("/", t, n);
|
|
81
88
|
},
|
|
82
|
-
getKnowledgeBase(
|
|
83
|
-
return
|
|
89
|
+
getKnowledgeBase(t) {
|
|
90
|
+
return r.get("/", t);
|
|
84
91
|
},
|
|
85
|
-
getKnowledge(
|
|
86
|
-
return
|
|
92
|
+
getKnowledge(t, n) {
|
|
93
|
+
return r.get(`/${t}`, n);
|
|
87
94
|
},
|
|
88
|
-
deleteKnowledge(
|
|
89
|
-
return
|
|
95
|
+
deleteKnowledge(t, n) {
|
|
96
|
+
return r.delete(`/${t}`, void 0, n);
|
|
90
97
|
},
|
|
91
|
-
createDocument(
|
|
92
|
-
return
|
|
98
|
+
createDocument(t, n, a) {
|
|
99
|
+
return r.post(`/${t}/documents`, n, a);
|
|
93
100
|
},
|
|
94
|
-
deleteDocument(
|
|
95
|
-
return
|
|
101
|
+
deleteDocument(t, n, a) {
|
|
102
|
+
return r.delete(`/${t}/documents/${n}`, void 0, a);
|
|
96
103
|
},
|
|
97
|
-
getDocuments(
|
|
98
|
-
return
|
|
104
|
+
getDocuments(t, n) {
|
|
105
|
+
return r.get(`/${t}/documents`, n);
|
|
99
106
|
},
|
|
100
|
-
getDocument(
|
|
101
|
-
return
|
|
107
|
+
getDocument(t, n, a) {
|
|
108
|
+
return r.get(`/${t}/documents/${n}`, a);
|
|
102
109
|
},
|
|
103
|
-
getRecords(
|
|
104
|
-
return
|
|
110
|
+
getRecords(t, n, a) {
|
|
111
|
+
return r.get(`/${t}/documents/${n}/records`, a);
|
|
105
112
|
},
|
|
106
|
-
query(
|
|
107
|
-
return
|
|
108
|
-
query:
|
|
109
|
-
},
|
|
113
|
+
query(t, n, a) {
|
|
114
|
+
return r.post(`/${t}/query`, {
|
|
115
|
+
query: n
|
|
116
|
+
}, a);
|
|
110
117
|
}
|
|
111
118
|
};
|
|
112
119
|
}
|
|
113
|
-
function
|
|
114
|
-
const
|
|
120
|
+
function F(e, i = v) {
|
|
121
|
+
const r = y(e, `${i}/chats/ratings`);
|
|
115
122
|
return {
|
|
116
|
-
create(
|
|
117
|
-
return
|
|
123
|
+
create(t, n) {
|
|
124
|
+
return r.post("/", t, n);
|
|
118
125
|
},
|
|
119
|
-
getByKnowledge(
|
|
120
|
-
return
|
|
126
|
+
getByKnowledge(t, n) {
|
|
127
|
+
return r.get(`/${t}`, n).then((a) => a ?? []);
|
|
121
128
|
},
|
|
122
|
-
update(
|
|
123
|
-
return
|
|
129
|
+
update(t, n, a) {
|
|
130
|
+
return r.patch(`/${t}`, n, a);
|
|
124
131
|
},
|
|
125
|
-
delete(
|
|
126
|
-
return
|
|
132
|
+
delete(t, n) {
|
|
133
|
+
return r.delete(`/${t}`, n);
|
|
127
134
|
}
|
|
128
135
|
};
|
|
129
136
|
}
|
|
130
|
-
|
|
131
|
-
function
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
const V = (e) => new Promise((i) => setTimeout(i, e));
|
|
138
|
+
function G(e) {
|
|
139
|
+
return new Promise((i, r) => {
|
|
140
|
+
const {
|
|
141
|
+
callbacks: t,
|
|
142
|
+
host: n,
|
|
143
|
+
auth: a
|
|
144
|
+
} = e, {
|
|
145
|
+
onMessage: c = null,
|
|
146
|
+
onOpen: d = null,
|
|
147
|
+
onClose: f = null,
|
|
148
|
+
onError: m = null
|
|
149
|
+
} = t || {}, l = new WebSocket(`${n}?authorization=${q(a)}`);
|
|
150
|
+
l.onmessage = c, l.onclose = f, l.onerror = (s) => {
|
|
151
|
+
console.log(s), m == null || m(s), r(s);
|
|
152
|
+
}, l.onopen = (s) => {
|
|
153
|
+
d == null || d(s), i(l);
|
|
154
|
+
};
|
|
155
|
+
});
|
|
140
156
|
}
|
|
141
|
-
async function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
async function Q(e) {
|
|
158
|
+
const {
|
|
159
|
+
retries: i = 1
|
|
160
|
+
} = e;
|
|
161
|
+
let r = null;
|
|
162
|
+
for (let t = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; t++)
|
|
163
|
+
try {
|
|
164
|
+
r = await G(e);
|
|
165
|
+
} catch (n) {
|
|
166
|
+
if (t === i)
|
|
167
|
+
throw n;
|
|
168
|
+
await V(t * 500);
|
|
169
|
+
}
|
|
170
|
+
return r;
|
|
171
|
+
}
|
|
172
|
+
async function X(e, i, r = J) {
|
|
173
|
+
const t = i ? [i] : [], n = await Q({
|
|
174
|
+
auth: e,
|
|
175
|
+
host: r,
|
|
151
176
|
callbacks: {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
177
|
+
onMessage: (a) => {
|
|
178
|
+
const c = JSON.parse(a.data);
|
|
179
|
+
t.forEach((d) => d(c.event, c));
|
|
180
|
+
}
|
|
155
181
|
}
|
|
156
182
|
});
|
|
157
183
|
return {
|
|
158
|
-
|
|
184
|
+
socket: n,
|
|
185
|
+
terminate: () => n.close(),
|
|
186
|
+
subscribeToEvents: (a) => t.push(a)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
var Y = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Y || {}), Z = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Z || {}), _ = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(_ || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e))(A || {}), O = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(O || {}), L = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(L || {}), j = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(j || {}), ee = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ee || {}), te = /* @__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))(te || {}), R = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(R || {});
|
|
190
|
+
function ne(e) {
|
|
191
|
+
return e.presenter.type === R.Clip ? {
|
|
192
|
+
videoType: R.Clip,
|
|
193
|
+
driver_id: e.presenter.driver_id,
|
|
194
|
+
presenter_id: e.presenter.presenter_id
|
|
195
|
+
} : {
|
|
196
|
+
videoType: R.Talk,
|
|
197
|
+
source_url: e.presenter.source_url
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function x(e, i, r, t) {
|
|
201
|
+
return new Promise(async (n, a) => {
|
|
202
|
+
const c = await oe(ne(e), {
|
|
203
|
+
...i,
|
|
204
|
+
callbacks: {
|
|
205
|
+
...i.callbacks,
|
|
206
|
+
onConnectionStateChange: async (d) => {
|
|
207
|
+
var f, m;
|
|
208
|
+
d === "connected" ? (t || (t = await r.newChat(e.id)), n({
|
|
209
|
+
chat: t,
|
|
210
|
+
streamingManager: c
|
|
211
|
+
})) : d === "failed" && a(new Error("Cannot create connection")), (m = (f = i.callbacks).onConnectionStateChange) == null || m.call(f, d);
|
|
212
|
+
},
|
|
213
|
+
// TODO remove when webscoket will return partial
|
|
214
|
+
onMessage: (d, f) => {
|
|
215
|
+
var m, l;
|
|
216
|
+
d === A.ChatPartial && ((l = (m = i.callbacks).onChatEvents) == null || l.call(m, L.Partial, {
|
|
217
|
+
content: f,
|
|
218
|
+
event: L.Partial
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async function ce(e, i) {
|
|
226
|
+
const r = i.baseURL || v, t = new AbortController(), n = T(i.auth, r), a = F(i.auth, r), c = D(i.auth, r), d = await n.getById(e), f = await X(i.auth, i.callbacks.onChatEvents);
|
|
227
|
+
let {
|
|
228
|
+
chat: m,
|
|
229
|
+
streamingManager: l
|
|
230
|
+
} = await x(d, i, n);
|
|
231
|
+
return {
|
|
232
|
+
agent: d,
|
|
233
|
+
async reconnectToChat() {
|
|
234
|
+
const {
|
|
235
|
+
streamingManager: s
|
|
236
|
+
} = await x(d, i, n, m);
|
|
237
|
+
l = s;
|
|
238
|
+
},
|
|
159
239
|
terminate() {
|
|
160
|
-
return
|
|
161
|
-
},
|
|
162
|
-
chatId:
|
|
163
|
-
chat(
|
|
164
|
-
return
|
|
165
|
-
sessionId:
|
|
166
|
-
streamId:
|
|
167
|
-
messages:
|
|
240
|
+
return t.abort(), f.terminate(), l.terminate();
|
|
241
|
+
},
|
|
242
|
+
chatId: m.id,
|
|
243
|
+
chat(s) {
|
|
244
|
+
return n.chat(e, m.id, {
|
|
245
|
+
sessionId: l.sessionId,
|
|
246
|
+
streamId: l.streamId,
|
|
247
|
+
messages: s
|
|
168
248
|
}, {
|
|
169
|
-
signal:
|
|
249
|
+
signal: t.signal
|
|
170
250
|
});
|
|
251
|
+
},
|
|
252
|
+
rate(s, g) {
|
|
253
|
+
return g ? a.update(g, s) : a.create(s);
|
|
254
|
+
},
|
|
255
|
+
deleteRate(s) {
|
|
256
|
+
return a.delete(s);
|
|
257
|
+
},
|
|
258
|
+
speak(s) {
|
|
259
|
+
let g;
|
|
260
|
+
return s.type === "text" ? g = {
|
|
261
|
+
script: {
|
|
262
|
+
type: "text",
|
|
263
|
+
provider: s.provider,
|
|
264
|
+
input: s.input,
|
|
265
|
+
ssml: s.ssml || !1
|
|
266
|
+
}
|
|
267
|
+
} : s.type === "audio" && (g = {
|
|
268
|
+
script: {
|
|
269
|
+
type: "audio",
|
|
270
|
+
audio_url: s.audio_url
|
|
271
|
+
}
|
|
272
|
+
}), l.speak(g);
|
|
273
|
+
},
|
|
274
|
+
getStarterMessages() {
|
|
275
|
+
var s, g;
|
|
276
|
+
return (s = d.knowledge) != null && s.id ? c.getKnowledge((g = d.knowledge) == null ? void 0 : g.id).then((C) => (C == null ? void 0 : C.starter_message) || []) : Promise.resolve([]);
|
|
171
277
|
}
|
|
172
278
|
};
|
|
173
279
|
}
|
|
174
|
-
function
|
|
175
|
-
const
|
|
280
|
+
function re(e, i) {
|
|
281
|
+
const r = y(e, i);
|
|
176
282
|
return {
|
|
177
|
-
createStream(
|
|
178
|
-
return
|
|
179
|
-
driver_id:
|
|
180
|
-
presenter_id:
|
|
181
|
-
compatibility_mode:
|
|
283
|
+
createStream(t) {
|
|
284
|
+
return r.post("/clips/streams", {
|
|
285
|
+
driver_id: t.driver_id,
|
|
286
|
+
presenter_id: t.presenter_id,
|
|
287
|
+
compatibility_mode: t.compatibility_mode
|
|
182
288
|
});
|
|
183
289
|
},
|
|
184
|
-
startConnection(
|
|
185
|
-
return
|
|
186
|
-
session_id:
|
|
187
|
-
answer:
|
|
290
|
+
startConnection(t, n, a) {
|
|
291
|
+
return r.post(`/clips/streams/${t}/sdp`, {
|
|
292
|
+
session_id: a,
|
|
293
|
+
answer: n
|
|
188
294
|
});
|
|
189
295
|
},
|
|
190
|
-
addIceCandidate(
|
|
191
|
-
return
|
|
192
|
-
session_id:
|
|
193
|
-
...
|
|
296
|
+
addIceCandidate(t, n, a) {
|
|
297
|
+
return r.post(`/clips/streams/${t}/ice`, {
|
|
298
|
+
session_id: a,
|
|
299
|
+
...n
|
|
194
300
|
});
|
|
195
301
|
},
|
|
196
|
-
sendStreamRequest(
|
|
197
|
-
return
|
|
198
|
-
session_id:
|
|
199
|
-
...
|
|
302
|
+
sendStreamRequest(t, n, a) {
|
|
303
|
+
return r.post(`/clips/streams/${t}`, {
|
|
304
|
+
session_id: n,
|
|
305
|
+
...a
|
|
200
306
|
});
|
|
201
307
|
},
|
|
202
|
-
close(
|
|
203
|
-
return
|
|
204
|
-
session_id:
|
|
308
|
+
close(t, n) {
|
|
309
|
+
return r.delete(`/clips/streams/${t}`, {
|
|
310
|
+
session_id: n
|
|
205
311
|
});
|
|
206
312
|
}
|
|
207
313
|
};
|
|
208
314
|
}
|
|
209
|
-
function
|
|
210
|
-
const
|
|
315
|
+
function ae(e, i) {
|
|
316
|
+
const r = y(e, i);
|
|
211
317
|
return {
|
|
212
|
-
createStream(
|
|
213
|
-
return
|
|
214
|
-
source_url:
|
|
215
|
-
driver_url:
|
|
216
|
-
face:
|
|
217
|
-
config:
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
startConnection(
|
|
221
|
-
return
|
|
222
|
-
session_id:
|
|
223
|
-
answer:
|
|
318
|
+
createStream(t, n) {
|
|
319
|
+
return r.post("/talks/streams", {
|
|
320
|
+
source_url: t.source_url,
|
|
321
|
+
driver_url: t.driver_url,
|
|
322
|
+
face: t.face,
|
|
323
|
+
config: t.config
|
|
324
|
+
}, n);
|
|
325
|
+
},
|
|
326
|
+
startConnection(t, n, a, c) {
|
|
327
|
+
return r.post(`/talks/streams/${t}/sdp`, {
|
|
328
|
+
session_id: a,
|
|
329
|
+
answer: n
|
|
330
|
+
}, c);
|
|
331
|
+
},
|
|
332
|
+
addIceCandidate(t, n, a, c) {
|
|
333
|
+
return r.post(`/talks/streams/${t}/ice`, {
|
|
334
|
+
session_id: a,
|
|
335
|
+
...n
|
|
336
|
+
}, c);
|
|
337
|
+
},
|
|
338
|
+
sendStreamRequest(t, n, a, c) {
|
|
339
|
+
return r.post(`/talks/streams/${t}`, {
|
|
340
|
+
session_id: n,
|
|
341
|
+
...a
|
|
342
|
+
}, c);
|
|
343
|
+
},
|
|
344
|
+
close(t, n, a) {
|
|
345
|
+
return r.delete(`/talks/streams/${t}`, {
|
|
346
|
+
session_id: n
|
|
224
347
|
}, a);
|
|
225
|
-
},
|
|
226
|
-
addIceCandidate(e, t, r, a) {
|
|
227
|
-
return n.post(`/talks/streams/${e}/ice`, {
|
|
228
|
-
session_id: r,
|
|
229
|
-
...t
|
|
230
|
-
}, a);
|
|
231
|
-
},
|
|
232
|
-
sendStreamRequest(e, t, r, a) {
|
|
233
|
-
return n.post(`/talks/streams/${e}`, {
|
|
234
|
-
session_id: t,
|
|
235
|
-
...r
|
|
236
|
-
}, a);
|
|
237
|
-
},
|
|
238
|
-
close(e, t, r) {
|
|
239
|
-
return n.delete(`/talks/streams/${e}`, {
|
|
240
|
-
session_id: t
|
|
241
|
-
}, r);
|
|
242
348
|
}
|
|
243
349
|
};
|
|
244
350
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
351
|
+
function ie(e, i) {
|
|
352
|
+
return e.map((r, t) => t === 0 ? i ? {
|
|
353
|
+
index: t,
|
|
354
|
+
timestamp: r.timestamp,
|
|
355
|
+
bytesReceived: r.bytesReceived - i.bytesReceived,
|
|
356
|
+
packetsReceived: r.packetsReceived - i.packetsReceived,
|
|
357
|
+
packetsLost: r.packetsLost - i.packetsLost,
|
|
358
|
+
jitter: r.jitter,
|
|
359
|
+
frameWidth: r.frameWidth,
|
|
360
|
+
frameHeight: r.frameHeight,
|
|
361
|
+
frameRate: r.frameRate
|
|
362
|
+
} : {
|
|
363
|
+
index: t,
|
|
364
|
+
timestamp: r.timestamp,
|
|
365
|
+
bytesReceived: r.bytesReceived,
|
|
366
|
+
packetsReceived: r.packetsReceived,
|
|
367
|
+
packetsLost: r.packetsLost,
|
|
368
|
+
jitter: r.jitter,
|
|
369
|
+
frameWidth: r.frameWidth,
|
|
370
|
+
frameHeight: r.frameHeight,
|
|
371
|
+
frameRate: r.frameRate
|
|
372
|
+
} : {
|
|
373
|
+
index: t,
|
|
374
|
+
timestamp: r.timestamp,
|
|
375
|
+
bytesReceived: r.bytesReceived - e[t - 1].bytesReceived,
|
|
376
|
+
packetsReceived: r.packetsReceived - e[t - 1].packetsReceived,
|
|
377
|
+
packetsLost: r.packetsLost - e[t - 1].packetsLost,
|
|
378
|
+
jitter: r.jitter,
|
|
379
|
+
frameWidth: r.frameWidth,
|
|
380
|
+
frameHeight: r.frameHeight,
|
|
381
|
+
frameRate: r.frameRate
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
let N = !1;
|
|
385
|
+
const h = (e, i) => N && console.log(e, i), se = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
386
|
+
async function oe(e, {
|
|
248
387
|
debug: i = !1,
|
|
249
|
-
callbacks:
|
|
250
|
-
auth:
|
|
251
|
-
baseURL:
|
|
388
|
+
callbacks: r,
|
|
389
|
+
auth: t,
|
|
390
|
+
baseURL: n = v
|
|
252
391
|
}) {
|
|
253
|
-
|
|
254
|
-
const {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}),
|
|
268
|
-
|
|
392
|
+
N = i;
|
|
393
|
+
const a = {
|
|
394
|
+
...r
|
|
395
|
+
}, {
|
|
396
|
+
startConnection: c,
|
|
397
|
+
sendStreamRequest: d,
|
|
398
|
+
close: f,
|
|
399
|
+
createStream: m,
|
|
400
|
+
addIceCandidate: l
|
|
401
|
+
} = e.videoType === R.Clip ? re(t, n) : ae(t, n), {
|
|
402
|
+
id: s,
|
|
403
|
+
offer: g,
|
|
404
|
+
ice_servers: C,
|
|
405
|
+
session_id: w
|
|
406
|
+
} = await m(e), u = new se({
|
|
407
|
+
iceServers: C
|
|
408
|
+
}), b = u.createDataChannel("JanusDataChannel"), k = [];
|
|
409
|
+
let $ = 0, E;
|
|
410
|
+
if (!w)
|
|
269
411
|
throw new Error("Could not create session_id");
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
candidate:
|
|
273
|
-
sdpMid:
|
|
274
|
-
sdpMLineIndex:
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
},
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
var
|
|
284
|
-
if (
|
|
285
|
-
const [
|
|
286
|
-
|
|
412
|
+
u.onicecandidate = (o) => {
|
|
413
|
+
h("peerConnection.onicecandidate", o), o.candidate && o.candidate.sdpMid && o.candidate.sdpMLineIndex !== null && l(s, {
|
|
414
|
+
candidate: o.candidate.candidate,
|
|
415
|
+
sdpMid: o.candidate.sdpMid,
|
|
416
|
+
sdpMLineIndex: o.candidate.sdpMLineIndex
|
|
417
|
+
}, w);
|
|
418
|
+
}, u.oniceconnectionstatechange = () => {
|
|
419
|
+
var o;
|
|
420
|
+
h("peerConnection.oniceconnectionstatechange => " + u.iceConnectionState), (o = a.onConnectionStateChange) == null || o.call(a, u.iceConnectionState);
|
|
421
|
+
}, u.ontrack = (o) => {
|
|
422
|
+
var p;
|
|
423
|
+
h("peerConnection.ontrack", o), (p = a.onSrcObjectReady) == null || p.call(a, o.streams[0]);
|
|
424
|
+
}, b.onmessage = (o) => {
|
|
425
|
+
var p, I, H;
|
|
426
|
+
if (b.readyState === "open") {
|
|
427
|
+
const [M, U] = o.data.split(":");
|
|
428
|
+
if (M === A.StreamStarted)
|
|
429
|
+
$ = k.length, E = setInterval(() => {
|
|
430
|
+
u.getStats().then((K) => {
|
|
431
|
+
K.forEach((S) => {
|
|
432
|
+
S.type === "inbound-rtp" && S.kind === "video" && k.push(S);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
}, 1e3), (p = a.onVideoStateChange) == null || p.call(a, _.Start);
|
|
436
|
+
else if (M === A.StreamDone) {
|
|
437
|
+
clearInterval(E);
|
|
438
|
+
const P = k.slice($);
|
|
439
|
+
if (P) {
|
|
440
|
+
const K = $ === 0 ? void 0 : k[$ - 1], S = ie(P, K);
|
|
441
|
+
$ = k.length, (I = a.onVideoStateChange) == null || I.call(a, _.Stop, S.sort((z, B) => B.packetsLost - z.packetsLost).slice(0, 5));
|
|
442
|
+
}
|
|
443
|
+
} else
|
|
444
|
+
(H = a.onMessage) == null || H.call(a, M, decodeURIComponent(U));
|
|
287
445
|
}
|
|
288
|
-
}, await
|
|
289
|
-
const
|
|
290
|
-
return
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
446
|
+
}, await u.setRemoteDescription(g), h("set remote description OK");
|
|
447
|
+
const W = await u.createAnswer();
|
|
448
|
+
return h("create answer OK"), await u.setLocalDescription(W), h("set local description OK"), await c(s, W, w), h("start connection OK"), {
|
|
449
|
+
/**
|
|
450
|
+
* Method to send request to server to get clip or talk depend on you payload
|
|
451
|
+
* @param payload
|
|
452
|
+
*/
|
|
453
|
+
speak(o) {
|
|
454
|
+
return d(s, w, o);
|
|
455
|
+
},
|
|
456
|
+
/**
|
|
457
|
+
* Method to close RTC connection
|
|
458
|
+
*/
|
|
294
459
|
async terminate() {
|
|
295
|
-
var
|
|
296
|
-
|
|
297
|
-
}), (
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
|
|
460
|
+
var o, p;
|
|
461
|
+
s && (u && (u.close(), u.oniceconnectionstatechange = null, u.onnegotiationneeded = null, u.onicecandidate = null, u.ontrack = null), await f(s, w).catch((I) => {
|
|
462
|
+
}), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (p = a.onVideoStateChange) == null || p.call(a, _.Stop));
|
|
463
|
+
},
|
|
464
|
+
/**
|
|
465
|
+
* Session identifier information, should be returned in the body of all streaming requests
|
|
466
|
+
*/
|
|
467
|
+
sessionId: w,
|
|
468
|
+
/**
|
|
469
|
+
* Id of current RTC stream
|
|
470
|
+
*/
|
|
471
|
+
streamId: s,
|
|
472
|
+
/**
|
|
473
|
+
* Method to add callback that will be trigered on supported events
|
|
474
|
+
* @param eventName
|
|
475
|
+
* @param callback
|
|
476
|
+
*/
|
|
477
|
+
onCallback(o, p) {
|
|
478
|
+
a[o] = p;
|
|
479
|
+
}
|
|
301
480
|
};
|
|
302
481
|
}
|
|
303
482
|
export {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
483
|
+
L as ChatProgress,
|
|
484
|
+
te as DocumentType,
|
|
485
|
+
ee as KnowledgeType,
|
|
486
|
+
Y as Providers,
|
|
487
|
+
O as RateState,
|
|
488
|
+
X as SocketManager,
|
|
489
|
+
A as StreamEvents,
|
|
490
|
+
j as Subject,
|
|
491
|
+
Z as VoiceAccess,
|
|
492
|
+
ce as createAgentManager,
|
|
493
|
+
T as createAgentsApi,
|
|
494
|
+
y as createClient,
|
|
495
|
+
D as createKnowledgeApi,
|
|
496
|
+
F as createRatingsApi,
|
|
497
|
+
oe as createStreamingManager,
|
|
498
|
+
ne as getAgentStreamArgs
|
|
311
499
|
};
|