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