@d-id/client-sdk 1.1.23-staging.109 → 1.1.24
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-VqW3e8UX.js +1425 -0
- package/dist/index.js +26 -1699
- package/dist/index.umd.cjs +5 -5
- package/dist/livekit-manager-CQZ_EbD9.js +256 -0
- package/dist/src/services/interrupt/index.d.ts +1 -2
- package/dist/src/services/streaming-manager/livekit-manager.d.ts +0 -5
- package/package.json +1 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { c as oe, a as ae, S as se, d as ce, T as de, C as S, b as E, A as _, e as U, f as R, g as j } from "./index-VqW3e8UX.js";
|
|
2
|
+
function ue(m, T, h, i) {
|
|
3
|
+
const y = oe(m, `${T}/v2/agents/${h}`, i);
|
|
4
|
+
return {
|
|
5
|
+
async createStream(s) {
|
|
6
|
+
return y.post("/sessions", s);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
async function F() {
|
|
11
|
+
try {
|
|
12
|
+
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const he = {
|
|
20
|
+
excellent: E.Strong,
|
|
21
|
+
good: E.Strong,
|
|
22
|
+
poor: E.Weak,
|
|
23
|
+
lost: E.Unknown,
|
|
24
|
+
unknown: E.Unknown
|
|
25
|
+
}, K = JSON.stringify({
|
|
26
|
+
kind: "InternalServerError",
|
|
27
|
+
description: "Stream Error"
|
|
28
|
+
});
|
|
29
|
+
function V(m, T, h, i) {
|
|
30
|
+
var y, s;
|
|
31
|
+
throw T("Failed to connect to LiveKit room:", m), i(), (y = h.onConnectionStateChange) == null || y.call(h, S.Fail), (s = h.onError) == null || s.call(h, m, { sessionId: "" }), m;
|
|
32
|
+
}
|
|
33
|
+
async function fe(m, T, h) {
|
|
34
|
+
var N, x;
|
|
35
|
+
const i = ae(h.debug || !1, "LiveKitStreamingManager"), { Room: y, RoomEvent: s, ConnectionState: l } = await F(), { callbacks: e, auth: O, baseURL: J, analytics: Q, microphoneStream: ge } = h;
|
|
36
|
+
let c = null, w = !1;
|
|
37
|
+
const $ = se.Fluent;
|
|
38
|
+
let A = !0, C = null, g = null;
|
|
39
|
+
c = new y({
|
|
40
|
+
adaptiveStream: !1,
|
|
41
|
+
// Must be false to use mediaStreamTrack directly
|
|
42
|
+
dynacast: !0
|
|
43
|
+
});
|
|
44
|
+
const q = ue(O, J || ce, m, e.onError);
|
|
45
|
+
let p, k, P;
|
|
46
|
+
try {
|
|
47
|
+
const n = await q.createStream({
|
|
48
|
+
transport_provider: de.Livekit,
|
|
49
|
+
chat_persist: T.chat_persist ?? !0
|
|
50
|
+
}), { id: t, session_token: r, session_url: o } = n;
|
|
51
|
+
(N = e.onStreamCreated) == null || N.call(e, { session_id: t, stream_id: t, agent_id: m }), p = t, k = r, P = o, await c.prepareConnection(P, k);
|
|
52
|
+
} catch (n) {
|
|
53
|
+
V(n, i, e, () => {
|
|
54
|
+
A = !1;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!P || !k || !p)
|
|
58
|
+
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
59
|
+
c.on(s.ConnectionStateChanged, b).on(s.ConnectionQualityChanged, z).on(s.ActiveSpeakersChanged, W).on(s.ParticipantConnected, B).on(s.TrackSubscribed, G).on(s.TrackUnsubscribed, H).on(s.DataReceived, X).on(s.MediaDevicesError, Y).on(s.EncryptionError, Z).on(s.TrackSubscriptionFailed, ee), (x = e.onConnectionStateChange) == null || x.call(e, S.New);
|
|
60
|
+
try {
|
|
61
|
+
await c.connect(P, k), i("LiveKit room joined successfully"), A = !1;
|
|
62
|
+
} catch (n) {
|
|
63
|
+
V(n, i, e, () => {
|
|
64
|
+
A = !1;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
Q.enrich({
|
|
68
|
+
"stream-type": $
|
|
69
|
+
});
|
|
70
|
+
function b(n) {
|
|
71
|
+
var t, r, o, a, u;
|
|
72
|
+
switch (i("Connection state changed:", n), n) {
|
|
73
|
+
case l.Connecting:
|
|
74
|
+
(t = e.onConnectionStateChange) == null || t.call(e, S.Connecting);
|
|
75
|
+
break;
|
|
76
|
+
case l.Connected:
|
|
77
|
+
i("LiveKit room connected successfully"), w = !0, A ? queueMicrotask(() => {
|
|
78
|
+
var d;
|
|
79
|
+
(d = e.onConnectionStateChange) == null || d.call(e, S.Connected);
|
|
80
|
+
}) : (r = e.onConnectionStateChange) == null || r.call(e, S.Connected);
|
|
81
|
+
break;
|
|
82
|
+
case l.Disconnected:
|
|
83
|
+
i("LiveKit room disconnected"), w = !1, (o = e.onConnectionStateChange) == null || o.call(e, S.Disconnected);
|
|
84
|
+
break;
|
|
85
|
+
case l.Reconnecting:
|
|
86
|
+
i("LiveKit room reconnecting..."), (a = e.onConnectionStateChange) == null || a.call(e, S.Connecting);
|
|
87
|
+
break;
|
|
88
|
+
case l.SignalReconnecting:
|
|
89
|
+
i("LiveKit room signal reconnecting..."), (u = e.onConnectionStateChange) == null || u.call(e, S.Connecting);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function z(n, t) {
|
|
94
|
+
var r;
|
|
95
|
+
i("Connection quality:", n), t != null && t.isLocal && ((r = e.onConnectivityStateChange) == null || r.call(e, he[n]));
|
|
96
|
+
}
|
|
97
|
+
function W(n) {
|
|
98
|
+
var r, o;
|
|
99
|
+
i("Active speakers changed:", n), n[0] ? (r = e.onAgentActivityStateChange) == null || r.call(e, _.Talking) : (o = e.onAgentActivityStateChange) == null || o.call(e, _.Idle);
|
|
100
|
+
}
|
|
101
|
+
function B(n) {
|
|
102
|
+
i("Participant connected:", n.identity);
|
|
103
|
+
}
|
|
104
|
+
function G(n, t, r) {
|
|
105
|
+
var a, u, d;
|
|
106
|
+
i(`Track subscribed: ${n.kind} from ${r.identity}`);
|
|
107
|
+
const o = n.mediaStreamTrack;
|
|
108
|
+
if (!o) {
|
|
109
|
+
i(`No mediaStreamTrack available for ${n.kind}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
C ? (C.addTrack(o), i(`Added ${n.kind} track to shared MediaStream`)) : (C = new MediaStream([o]), i(`Created shared MediaStream with ${n.kind} track`)), n.kind === "video" && ((a = e.onStreamReady) == null || a.call(e), (u = e.onSrcObjectReady) == null || u.call(e, C), (d = e.onVideoStateChange) == null || d.call(e, U.Start));
|
|
113
|
+
}
|
|
114
|
+
function H(n, t, r) {
|
|
115
|
+
var o;
|
|
116
|
+
i(`Track unsubscribed: ${n.kind} from ${r.identity}`), n.kind === "video" && ((o = e.onVideoStateChange) == null || o.call(e, U.Stop));
|
|
117
|
+
}
|
|
118
|
+
function X(n, t, r, o) {
|
|
119
|
+
var u, d, M;
|
|
120
|
+
const a = new TextDecoder().decode(n);
|
|
121
|
+
i("Data received:", a);
|
|
122
|
+
try {
|
|
123
|
+
const f = JSON.parse(a), L = o || f.subject;
|
|
124
|
+
if (L === R.ChatAnswer) {
|
|
125
|
+
const v = j.Answer;
|
|
126
|
+
(u = e.onMessage) == null || u.call(e, v, {
|
|
127
|
+
event: v,
|
|
128
|
+
...f
|
|
129
|
+
});
|
|
130
|
+
} else if ([R.StreamVideoCreated, R.StreamVideoDone].includes(L)) {
|
|
131
|
+
const v = (f == null ? void 0 : f.role) || (t == null ? void 0 : t.identity) || "datachannel";
|
|
132
|
+
(d = e.onMessage) == null || d.call(e, L, {
|
|
133
|
+
[v]: f
|
|
134
|
+
});
|
|
135
|
+
} else if (L === R.ChatAudioTranscribed) {
|
|
136
|
+
const v = j.Transcribe;
|
|
137
|
+
(M = e.onMessage) == null || M.call(e, v, {
|
|
138
|
+
event: v,
|
|
139
|
+
...f
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
} catch (f) {
|
|
143
|
+
i("Failed to parse data channel message:", f);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function Y(n) {
|
|
147
|
+
var t;
|
|
148
|
+
i("Media devices error:", n), (t = e.onError) == null || t.call(e, new Error(K), { sessionId: p });
|
|
149
|
+
}
|
|
150
|
+
function Z(n) {
|
|
151
|
+
var t;
|
|
152
|
+
i("Encryption error:", n), (t = e.onError) == null || t.call(e, new Error(K), { sessionId: p });
|
|
153
|
+
}
|
|
154
|
+
function ee(n, t, r) {
|
|
155
|
+
i("Track subscription failed:", { trackSid: n, participant: t, reason: r });
|
|
156
|
+
}
|
|
157
|
+
async function ne(n) {
|
|
158
|
+
if (!c) return null;
|
|
159
|
+
const { Track: t } = await F(), r = c.localParticipant.audioTrackPublications;
|
|
160
|
+
if (r) {
|
|
161
|
+
for (const [o, a] of r)
|
|
162
|
+
if (a.source === t.Source.Microphone && a.track) {
|
|
163
|
+
const d = a.track.mediaStreamTrack;
|
|
164
|
+
if (d === n || d && d.id === n.id)
|
|
165
|
+
return a;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function te(n) {
|
|
171
|
+
if (!g || !g.track)
|
|
172
|
+
return !1;
|
|
173
|
+
const t = g.track.mediaStreamTrack;
|
|
174
|
+
return t !== n && (t == null ? void 0 : t.id) !== n.id;
|
|
175
|
+
}
|
|
176
|
+
async function ie(n) {
|
|
177
|
+
var u, d;
|
|
178
|
+
if (!w || !c)
|
|
179
|
+
throw i("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
180
|
+
const t = n.getAudioTracks();
|
|
181
|
+
if (t.length === 0) {
|
|
182
|
+
i("No audio track found in the provided MediaStream");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const r = t[0], { Track: o } = await F(), a = await ne(r);
|
|
186
|
+
if (a) {
|
|
187
|
+
i("Microphone track is already published, skipping", {
|
|
188
|
+
trackId: r.id,
|
|
189
|
+
publishedTrackId: (d = (u = a.track) == null ? void 0 : u.mediaStreamTrack) == null ? void 0 : d.id
|
|
190
|
+
}), g = a;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
te(r) && (i("Unpublishing existing microphone track before publishing new one"), await D()), i("Publishing microphone track from provided MediaStream", { trackId: r.id });
|
|
194
|
+
try {
|
|
195
|
+
g = await c.localParticipant.publishTrack(r, {
|
|
196
|
+
source: o.Source.Microphone
|
|
197
|
+
}), i("Microphone track published successfully", { trackSid: g.trackSid });
|
|
198
|
+
} catch (M) {
|
|
199
|
+
throw i("Failed to publish microphone track:", M), M;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function D() {
|
|
203
|
+
if (!(!g || !g.track))
|
|
204
|
+
try {
|
|
205
|
+
c && (await c.localParticipant.unpublishTrack(g.track), i("Microphone track unpublished"));
|
|
206
|
+
} catch (n) {
|
|
207
|
+
i("Error unpublishing microphone track:", n);
|
|
208
|
+
} finally {
|
|
209
|
+
g = null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function re() {
|
|
213
|
+
C && (C.getTracks().forEach((n) => n.stop()), C = null);
|
|
214
|
+
}
|
|
215
|
+
async function I(n, t = "lk.chat") {
|
|
216
|
+
var r, o;
|
|
217
|
+
if (!w || !c) {
|
|
218
|
+
i("Room is not connected for sending messages"), (r = e.onError) == null || r.call(e, new Error(K), {
|
|
219
|
+
sessionId: p
|
|
220
|
+
});
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
await c.localParticipant.sendText(n, { topic: t }), i("Message sent successfully:", n);
|
|
225
|
+
} catch (a) {
|
|
226
|
+
i("Failed to send message:", a), (o = e.onError) == null || o.call(e, new Error(K), { sessionId: p });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
speak(n) {
|
|
231
|
+
const t = typeof n == "string" ? n : JSON.stringify(n);
|
|
232
|
+
return I(
|
|
233
|
+
t,
|
|
234
|
+
"did.speak"
|
|
235
|
+
/* Speak */
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
async disconnect() {
|
|
239
|
+
var n, t;
|
|
240
|
+
c && (await D(), await c.disconnect(), c = null), re(), w = !1, (n = e.onConnectionStateChange) == null || n.call(e, S.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, _.Idle);
|
|
241
|
+
},
|
|
242
|
+
sendDataChannelMessage: I,
|
|
243
|
+
sendTextMessage: I,
|
|
244
|
+
publishMicrophoneStream: ie,
|
|
245
|
+
unpublishMicrophoneStream: D,
|
|
246
|
+
sessionId: p,
|
|
247
|
+
streamId: p,
|
|
248
|
+
streamType: $,
|
|
249
|
+
interruptAvailable: !0,
|
|
250
|
+
triggersAvailable: !1
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export {
|
|
254
|
+
fe as createLiveKitStreamingManager,
|
|
255
|
+
V as handleInitError
|
|
256
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateStreamOptions, StreamType } from '../../types';
|
|
2
2
|
import { StreamingManager } from '../streaming-manager';
|
|
3
3
|
|
|
4
4
|
export declare function validateInterrupt(streamingManager: StreamingManager<CreateStreamOptions> | undefined, streamType: StreamType | undefined, videoId: string | null): void;
|
|
5
5
|
export declare function sendInterrupt(streamingManager: StreamingManager<CreateStreamOptions>, videoId: string): Promise<void>;
|
|
6
|
-
export declare function sendInterruptV2(streamingManager: StreamingManager<CreateSessionV2Options>): Promise<void>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { CreateSessionV2Options, CreateStreamOptions, StreamingManagerOptions } from '../../types';
|
|
2
2
|
import { StreamingManager } from './common';
|
|
3
3
|
|
|
4
|
-
export declare enum DataChannelTopic {
|
|
5
|
-
Chat = "lk.chat",
|
|
6
|
-
Speak = "did.speak",
|
|
7
|
-
Interrupt = "did.interrupt"
|
|
8
|
-
}
|
|
9
4
|
export declare function handleInitError(error: unknown, log: (message?: any, ...optionalParams: any[]) => void, callbacks: StreamingManagerOptions['callbacks'], markInitialConnectionDone: () => void): void;
|
|
10
5
|
export declare function createLiveKitStreamingManager<T extends CreateSessionV2Options>(agentId: string, sessionOptions: CreateSessionV2Options, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
|
|
11
6
|
export type LiveKitStreamingManager<T extends CreateStreamOptions> = StreamingManager<T>;
|