@d-id/client-sdk 1.0.13 → 1.0.14
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 +42 -47
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function k(r) {
|
|
2
2
|
return r.type === "bearer" ? "Bearer " + r.token : r.type === "basic" ? "Basic " + btoa(`${r.username}:${r.password}`) : "Client-Key " + r.clientKey;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function p(r, o = "https://api.d-id.com") {
|
|
5
5
|
const n = async (e, t) => {
|
|
6
6
|
const s = await fetch(o + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
7
|
...t,
|
|
@@ -12,13 +12,8 @@ function g(r, o = "https://api.d-id.com") {
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
if (!s.ok) {
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
const c = JSON.parse(u);
|
|
18
|
-
c.description ? u = c.description : c.message && (u = c.message);
|
|
19
|
-
} catch {
|
|
20
|
-
}
|
|
21
|
-
throw new Error(u);
|
|
15
|
+
let m = await s.text().catch(() => "Failed to fetch");
|
|
16
|
+
throw new Error(m);
|
|
22
17
|
}
|
|
23
18
|
return s.json();
|
|
24
19
|
};
|
|
@@ -53,7 +48,7 @@ function g(r, o = "https://api.d-id.com") {
|
|
|
53
48
|
};
|
|
54
49
|
}
|
|
55
50
|
function K(r, o = "https://api.d-id.com") {
|
|
56
|
-
const n =
|
|
51
|
+
const n = p(r, `${o}/knowledge`);
|
|
57
52
|
return {
|
|
58
53
|
createKnowledge(e) {
|
|
59
54
|
return n.post("/", e);
|
|
@@ -90,7 +85,7 @@ function K(r, o = "https://api.d-id.com") {
|
|
|
90
85
|
};
|
|
91
86
|
}
|
|
92
87
|
function O(r, o = "https://api.d-id.com") {
|
|
93
|
-
const n =
|
|
88
|
+
const n = p(r, `${o}/agents`);
|
|
94
89
|
return {
|
|
95
90
|
create(e) {
|
|
96
91
|
return n.post("/", e);
|
|
@@ -116,7 +111,7 @@ function O(r, o = "https://api.d-id.com") {
|
|
|
116
111
|
};
|
|
117
112
|
}
|
|
118
113
|
function A(r, o) {
|
|
119
|
-
const n =
|
|
114
|
+
const n = p(r, o);
|
|
120
115
|
return {
|
|
121
116
|
createStream(e) {
|
|
122
117
|
return n.post("/clips/streams", {
|
|
@@ -151,7 +146,7 @@ function A(r, o) {
|
|
|
151
146
|
};
|
|
152
147
|
}
|
|
153
148
|
function T(r, o) {
|
|
154
|
-
const n =
|
|
149
|
+
const n = p(r, o);
|
|
155
150
|
return {
|
|
156
151
|
createStream(e) {
|
|
157
152
|
return n.post("/talks/streams", {
|
|
@@ -186,61 +181,61 @@ function T(r, o) {
|
|
|
186
181
|
}
|
|
187
182
|
};
|
|
188
183
|
}
|
|
189
|
-
var
|
|
190
|
-
let
|
|
191
|
-
const
|
|
192
|
-
async function
|
|
184
|
+
var l = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(l || {}), w = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(w || {});
|
|
185
|
+
let $ = !1;
|
|
186
|
+
const c = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
187
|
+
async function R(r, {
|
|
193
188
|
debug: o = !1,
|
|
194
189
|
callbacks: n,
|
|
195
190
|
auth: e,
|
|
196
191
|
baseURL: t = "https://api.d-id.com"
|
|
197
192
|
}) {
|
|
198
|
-
|
|
193
|
+
$ = o;
|
|
199
194
|
let s = null;
|
|
200
195
|
const {
|
|
201
|
-
startConnection:
|
|
202
|
-
sendStreamRequest:
|
|
196
|
+
startConnection: m,
|
|
197
|
+
sendStreamRequest: f,
|
|
203
198
|
close: h,
|
|
204
199
|
createStream: S,
|
|
205
200
|
addIceCandidate: _
|
|
206
|
-
} = r.videoType ===
|
|
207
|
-
id:
|
|
201
|
+
} = r.videoType === w.Clip ? A(e, t) : T(e, t), {
|
|
202
|
+
id: d,
|
|
208
203
|
offer: y,
|
|
209
204
|
ice_servers: I,
|
|
210
|
-
session_id:
|
|
211
|
-
} = await S(r),
|
|
205
|
+
session_id: u
|
|
206
|
+
} = await S(r), i = new D({
|
|
212
207
|
iceServers: I
|
|
213
|
-
}),
|
|
214
|
-
if (!
|
|
208
|
+
}), g = i.createDataChannel("JanusDataChannel");
|
|
209
|
+
if (!u)
|
|
215
210
|
throw new Error("Could not create session_id");
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
candidate:
|
|
219
|
-
sdpMid:
|
|
220
|
-
sdpMLineIndex:
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
}, await
|
|
229
|
-
const
|
|
230
|
-
return
|
|
231
|
-
speak(
|
|
232
|
-
return
|
|
211
|
+
i.onicecandidate = (a) => {
|
|
212
|
+
c("peerConnection.onicecandidate", a), a.candidate && a.candidate.sdpMid && a.candidate.sdpMLineIndex !== null && _(d, {
|
|
213
|
+
candidate: a.candidate.candidate,
|
|
214
|
+
sdpMid: a.candidate.sdpMid,
|
|
215
|
+
sdpMLineIndex: a.candidate.sdpMLineIndex
|
|
216
|
+
}, u);
|
|
217
|
+
}, i.oniceconnectionstatechange = () => {
|
|
218
|
+
c("peerConnection.oniceconnectionstatechange => " + i.iceConnectionState), n.onConnectionStateChange(i.iceConnectionState);
|
|
219
|
+
}, i.ontrack = (a) => {
|
|
220
|
+
c("peerConnection.ontrack", a), s = a.streams[0], n.onSrcObjectReady(s);
|
|
221
|
+
}, g.onmessage = (a) => {
|
|
222
|
+
g.readyState === "open" && n.onStreamingStateChange(a.data === "stream/done" ? l.Idle : l.Streaming);
|
|
223
|
+
}, await i.setRemoteDescription(y), c("set remote description OK");
|
|
224
|
+
const C = await i.createAnswer();
|
|
225
|
+
return c("create answer OK"), await i.setLocalDescription(C), c("set local description OK"), await m(d, C, u), c("start connection OK"), {
|
|
226
|
+
speak(a) {
|
|
227
|
+
return f(d, u, a);
|
|
233
228
|
},
|
|
234
229
|
async terminate() {
|
|
235
|
-
|
|
230
|
+
d && (s && (s.getTracks().forEach((a) => a.stop()), s = null), i && (i.close(), i.oniceconnectionstatechange = null, i.onnegotiationneeded = null, i.onicecandidate = null, i.ontrack = null), await h(d, u), n.onConnectionStateChange("closed"), n.onStreamingStateChange(l.Idle));
|
|
236
231
|
},
|
|
237
|
-
sessionId:
|
|
238
|
-
streamId:
|
|
232
|
+
sessionId: u,
|
|
233
|
+
streamId: d
|
|
239
234
|
};
|
|
240
235
|
}
|
|
241
236
|
export {
|
|
242
237
|
O as createAgentsApi,
|
|
243
|
-
|
|
238
|
+
p as createClient,
|
|
244
239
|
K as createKnowledgeApi,
|
|
245
|
-
|
|
240
|
+
R as createStreamingManager
|
|
246
241
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(c=typeof globalThis<"u"?globalThis:c||self,p(c.index={}))})(this,function(c){"use strict";function p(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function m(r,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:p(r),"Content-Type":"application/json"}});if(!i.ok){let f=await i.text().catch(()=>"Failed to fetch");throw new Error(f)}return i.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"POST"})},delete(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"PATCH"})}}}function S(r,o="https://api.d-id.com"){const n=m(r,`${o}/knowledge`);return{createKnowledge(e){return n.post("/",e)},getKnowledgeBase(){return n.get("/")},getKnowledge(e){return n.get(`/${e}`)},deleteKnowledge(e){return n.delete(`/${e}`)},createDocument(e,t){return n.post(`/${e}/documents`,t)},deleteDocument(e,t){return n.delete(`/${e}/documents/${t}`)},getDocuments(e){return n.get(`/${e}/documents`)},getDocument(e,t){return n.get(`/${e}/documents/${t}`)},getRecords(e,t){return n.get(`/${e}/documents/${t}/records`)},query(e,t){return n.post(`/${e}/query`,{query:t})}}}function y(r,o="https://api.d-id.com"){const n=m(r,`${o}/agents`);return{create(e){return n.post("/",e)},getAgents(e){return n.get(`/${e?`?tag=${e}`:""}`)},getById(e){return n.get(`/${e}`)},delete(e){return n.delete(`/${e}`)},update(e,t){return n.patch(`/${e}`,t)},newChat(e){return n.post(`/${e}/chat`)},chat(e,t,i){return n.post(`/${e}/chat/${t}`,i)}}}function _(r,o){const n=m(r,o);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,i){return n.post(`/clips/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/clips/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/clips/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function A(r,o){const n=m(r,o);return{createStream(e){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config})},startConnection(e,t,i){return n.post(`/talks/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/talks/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/talks/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/talks/streams/${e}`,{session_id:t})}}}var g=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(g||{}),C=(r=>(r.Clip="clip",r.Talk="talk",r))(C||{});let w=!1;const d=(r,o)=>w&&console.log(r,o),I=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function T(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){w=o;let i=null;const{startConnection:f,sendStreamRequest:k,close:K,createStream:b,addIceCandidate:D}=r.videoType===C.Clip?_(e,t):A(e,t),{id:u,offer:O,ice_servers:M,session_id:l}=await b(r),a=new I({iceServers:M}),$=a.createDataChannel("JanusDataChannel");if(!l)throw new Error("Could not create session_id");a.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&D(u,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},l)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?g.Idle:g.Streaming)},await a.setRemoteDescription(O),d("set remote description OK");const h=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(h),d("set local description OK"),await f(u,h,l),d("start connection OK"),{speak(s){return k(u,l,s)},async terminate(){u&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.ontrack=null),await K(u,l),n.onConnectionStateChange("closed"),n.onStreamingStateChange(g.Idle))},sessionId:l,streamId:u}}c.createAgentsApi=y,c.createClient=m,c.createKnowledgeApi=S,c.createStreamingManager=T,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|