@d-id/client-sdk 1.1.23 → 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.
@@ -1,188 +0,0 @@
1
- import { c as H, a as X, S as Y, d as Z, T as l, C as u, b as p, A as M, e as F, f as k, g as b } from "./index-CVpJq_KA.js";
2
- function ee(c, f, d, i) {
3
- const m = H(c, `${f}/v2/agents/${d}`, i);
4
- return {
5
- async createStream(a) {
6
- return m.post("/sessions", a);
7
- }
8
- };
9
- }
10
- async function ne() {
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 te = {
20
- excellent: p.Strong,
21
- good: p.Strong,
22
- poor: p.Weak,
23
- lost: p.Unknown,
24
- unknown: p.Unknown
25
- }, A = JSON.stringify({
26
- kind: "InternalServerError",
27
- description: "Stream Error"
28
- });
29
- function P(c, f, d, i) {
30
- var m, a;
31
- throw f("Failed to connect to LiveKit room:", c), i(), (m = d.onConnectionStateChange) == null || m.call(d, u.Fail), (a = d.onError) == null || a.call(d, c, { sessionId: "" }), c;
32
- }
33
- async function oe(c, f, d) {
34
- var R, D;
35
- const i = X(d.debug || !1, "LiveKitStreamingManager"), { Room: m, RoomEvent: a, ConnectionState: v } = await ne(), { callbacks: e, auth: _, baseURL: I, analytics: N } = d;
36
- let g = null, y = !1;
37
- const K = Y.Fluent;
38
- let w = !0, h = null;
39
- g = new m({
40
- adaptiveStream: !1,
41
- // Must be false to use mediaStreamTrack directly
42
- dynacast: !0
43
- });
44
- const U = ee(_, I || Z, c, e.onError);
45
- let S, E, T;
46
- try {
47
- const n = await U.createStream({
48
- transport_provider: l.Livekit,
49
- chat_persist: f.chat_persist ?? !0
50
- }), { id: t, session_token: o, session_url: r } = n;
51
- (R = e.onStreamCreated) == null || R.call(e, { session_id: t, stream_id: t, agent_id: c }), S = t, E = o, T = r, await g.prepareConnection(T, E);
52
- } catch (n) {
53
- P(n, i, e, () => {
54
- w = !1;
55
- });
56
- }
57
- if (!T || !E || !S)
58
- return Promise.reject(new Error("Failed to initialize LiveKit stream"));
59
- g.on(a.ConnectionStateChanged, x).on(a.ConnectionQualityChanged, j).on(a.ActiveSpeakersChanged, O).on(a.ParticipantConnected, J).on(a.TrackSubscribed, Q).on(a.TrackUnsubscribed, V).on(a.DataReceived, q).on(a.MediaDevicesError, z).on(a.EncryptionError, W).on(a.TrackSubscriptionFailed, B), (D = e.onConnectionStateChange) == null || D.call(e, u.New);
60
- try {
61
- await g.connect(T, E), i("LiveKit room joined successfully"), w = !1;
62
- } catch (n) {
63
- P(n, i, e, () => {
64
- w = !1;
65
- });
66
- }
67
- N.enrich({
68
- "stream-type": K
69
- });
70
- function x(n) {
71
- var t, o, r, s, C;
72
- switch (i("Connection state changed:", n), n) {
73
- case v.Connecting:
74
- (t = e.onConnectionStateChange) == null || t.call(e, u.Connecting);
75
- break;
76
- case v.Connected:
77
- i("LiveKit room connected successfully"), y = !0, w ? queueMicrotask(() => {
78
- var $;
79
- ($ = e.onConnectionStateChange) == null || $.call(e, u.Connected);
80
- }) : (o = e.onConnectionStateChange) == null || o.call(e, u.Connected);
81
- break;
82
- case v.Disconnected:
83
- i("LiveKit room disconnected"), y = !1, (r = e.onConnectionStateChange) == null || r.call(e, u.Disconnected);
84
- break;
85
- case v.Reconnecting:
86
- i("LiveKit room reconnecting..."), (s = e.onConnectionStateChange) == null || s.call(e, u.Connecting);
87
- break;
88
- case v.SignalReconnecting:
89
- i("LiveKit room signal reconnecting..."), (C = e.onConnectionStateChange) == null || C.call(e, u.Connecting);
90
- break;
91
- }
92
- }
93
- function j(n, t) {
94
- var o;
95
- i("Connection quality:", n), t != null && t.isLocal && ((o = e.onConnectivityStateChange) == null || o.call(e, te[n]));
96
- }
97
- function O(n) {
98
- var o, r;
99
- i("Active speakers changed:", n), n[0] ? (o = e.onAgentActivityStateChange) == null || o.call(e, M.Talking) : (r = e.onAgentActivityStateChange) == null || r.call(e, M.Idle);
100
- }
101
- function J(n) {
102
- i("Participant connected:", n.identity);
103
- }
104
- function Q(n, t, o) {
105
- var s, C;
106
- i(`Track subscribed: ${n.kind} from ${o.identity}`);
107
- const r = n.mediaStreamTrack;
108
- if (!r) {
109
- i(`No mediaStreamTrack available for ${n.kind}`);
110
- return;
111
- }
112
- h ? (h.addTrack(r), i(`Added ${n.kind} track to shared MediaStream`)) : (h = new MediaStream([r]), i(`Created shared MediaStream with ${n.kind} track`)), n.kind === "video" && ((s = e.onSrcObjectReady) == null || s.call(e, h), (C = e.onVideoStateChange) == null || C.call(e, F.Start));
113
- }
114
- function V(n, t, o) {
115
- var r;
116
- i(`Track unsubscribed: ${n.kind} from ${o.identity}`), n.kind === "video" && ((r = e.onVideoStateChange) == null || r.call(e, F.Stop));
117
- }
118
- function q(n, t) {
119
- var r;
120
- const o = new TextDecoder().decode(n);
121
- i("Data received:", o);
122
- try {
123
- const s = JSON.parse(o);
124
- if (s.subject === k.ChatAnswer) {
125
- const C = b.Answer;
126
- (r = e.onMessage) == null || r.call(e, C, {
127
- event: C,
128
- ...s
129
- });
130
- }
131
- } catch (s) {
132
- i("Failed to parse data channel message:", s);
133
- }
134
- }
135
- function z(n) {
136
- var t;
137
- i("Media devices error:", n), (t = e.onError) == null || t.call(e, new Error(A), { sessionId: S });
138
- }
139
- function W(n) {
140
- var t;
141
- i("Encryption error:", n), (t = e.onError) == null || t.call(e, new Error(A), { sessionId: S });
142
- }
143
- function B(n, t, o) {
144
- i("Track subscription failed:", { trackSid: n, participant: t, reason: o });
145
- }
146
- function G() {
147
- h && (h.getTracks().forEach((n) => n.stop()), h = null);
148
- }
149
- async function L(n, t = "lk.chat") {
150
- var o, r;
151
- if (!y || !g) {
152
- i("Room is not connected for sending messages"), (o = e.onError) == null || o.call(e, new Error(A), {
153
- sessionId: S
154
- });
155
- return;
156
- }
157
- try {
158
- await g.localParticipant.sendText(n, { topic: t }), i("Message sent successfully:", n);
159
- } catch (s) {
160
- i("Failed to send message:", s), (r = e.onError) == null || r.call(e, new Error(A), { sessionId: S });
161
- }
162
- }
163
- return {
164
- speak(n) {
165
- const t = typeof n == "string" ? n : JSON.stringify(n);
166
- return L(
167
- t,
168
- "did.speak"
169
- /* Speak */
170
- );
171
- },
172
- async disconnect() {
173
- var n, t;
174
- g && (await g.disconnect(), g = null), G(), y = !1, (n = e.onConnectionStateChange) == null || n.call(e, u.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, M.Idle);
175
- },
176
- sendDataChannelMessage: L,
177
- sendTextMessage: L,
178
- sessionId: S,
179
- streamId: S,
180
- streamType: K,
181
- interruptAvailable: !0,
182
- triggersAvailable: !1
183
- };
184
- }
185
- export {
186
- oe as createLiveKitStreamingManager,
187
- P as handleInitError
188
- };