@d-id/client-sdk 1.1.18 → 1.1.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.
@@ -1,124 +0,0 @@
1
- import { c as x, a as N, S as O, C as g, b as U, d as P, e as $, A as T, f as q, T as J } from "./index-CQEmC7n0.js";
2
- function Q(u, p, h, i) {
3
- const w = x(u, `${p}/v2/agents/${h}`, i);
4
- return {
5
- async createStream(d) {
6
- return w.post("/streams", d);
7
- }
8
- };
9
- }
10
- async function W() {
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
- async function H(u, p, h) {
20
- var E, K, I;
21
- const i = N(h.debug || !1, "LiveKitStreamingManager"), {
22
- Room: w,
23
- RoomEvent: d,
24
- ConnectionState: C,
25
- RemoteParticipant: z,
26
- RemoteTrack: B
27
- } = await W(), { callbacks: e, auth: V, baseURL: j, analytics: F } = h;
28
- let a = null, v = !1, y = null, c = null;
29
- const L = O.Fluent;
30
- a = new w({
31
- adaptiveStream: !0,
32
- dynacast: !0
33
- }), a.on(d.ConnectionStateChanged, (n) => {
34
- var t, o, r, s, S;
35
- switch (i("Connection state changed:", n), n) {
36
- case C.Connecting:
37
- (t = e.onConnectionStateChange) == null || t.call(e, g.Connecting);
38
- break;
39
- case C.Connected:
40
- i("LiveKit room connected successfully"), v = !0, (o = e.onConnectionStateChange) == null || o.call(e, g.Connected);
41
- break;
42
- case C.Disconnected:
43
- i("LiveKit room disconnected"), v = !1, (r = e.onConnectionStateChange) == null || r.call(e, g.Disconnected);
44
- break;
45
- case C.Reconnecting:
46
- i("LiveKit room reconnecting..."), (s = e.onConnectionStateChange) == null || s.call(e, g.Connecting);
47
- break;
48
- case C.SignalReconnecting:
49
- i("LiveKit room signal reconnecting..."), (S = e.onConnectionStateChange) == null || S.call(e, g.Connecting);
50
- break;
51
- }
52
- }), a.on(d.ConnectionQualityChanged, (n, t) => {
53
- var o;
54
- t != null && t.isLocal && n === "poor" && (i("Connection quality is poor"), (o = e.onConnectivityStateChange) == null || o.call(e, U.Weak));
55
- }), a.on(d.ParticipantConnected, (n) => {
56
- i("Participant connected:", n.identity);
57
- }), a.on(d.TrackSubscribed, (n, t, o) => {
58
- var r, s;
59
- i(`Track subscribed: ${n.kind} from ${o.identity}`), c ? c.addTrack(n.mediaStreamTrack) : c = new MediaStream([n.mediaStreamTrack]), (r = e.onSrcObjectReady) == null || r.call(e, c), n.kind === "video" && ((s = e.onVideoStateChange) == null || s.call(e, P.Start));
60
- }), a.on(d.TrackUnsubscribed, (n, t, o) => {
61
- var r;
62
- i(`Track unsubscribed: ${n.kind} from ${o.identity}`), n.kind === "video" && ((r = e.onVideoStateChange) == null || r.call(e, P.Stop));
63
- }), a.on(d.DataReceived, (n, t) => {
64
- var r, s, S, D, _;
65
- const o = new TextDecoder().decode(n);
66
- i("Data received:", o);
67
- try {
68
- const m = JSON.parse(o);
69
- m.subject === $.StreamStarted && ((r = m.metadata) != null && r.videoId) ? (y = m.metadata.videoId, (s = e.onVideoIdChange) == null || s.call(e, y), (S = e.onAgentActivityStateChange) == null || S.call(e, T.Talking)) : m.subject === $.StreamDone && (y = null, (D = e.onVideoIdChange) == null || D.call(e, y), (_ = e.onAgentActivityStateChange) == null || _.call(e, T.Idle));
70
- } catch (m) {
71
- i("Failed to parse data channel message:", m);
72
- }
73
- }), (E = e.onConnectionStateChange) == null || E.call(e, g.New);
74
- const M = Q(V, j || q, u, e.onError);
75
- let f, A;
76
- try {
77
- const n = await M.createStream({
78
- transport_provider: J.Livekit,
79
- chat_id: p.chat_id
80
- }), { agent_id: t, session_id: o, session_token: r, session_url: s } = n;
81
- f = t, A = o, await a.connect(s, r), i("LiveKit room joined successfully");
82
- } catch (n) {
83
- throw i("Failed to connect to LiveKit room:", n), (K = e.onConnectionStateChange) == null || K.call(e, g.Fail), (I = e.onError) == null || I.call(e, n, { streamId: "" }), n;
84
- }
85
- F.enrich({
86
- "stream-type": L
87
- });
88
- async function R(n) {
89
- var t, o;
90
- if (!v || !a) {
91
- i("Room is not connected for sending messages"), (t = e.onError) == null || t.call(e, new Error("Room is not connected for sending messages"), {
92
- streamId: f
93
- });
94
- return;
95
- }
96
- try {
97
- await a.localParticipant.publishData(new TextEncoder().encode(n), { reliable: !0 });
98
- } catch (r) {
99
- i("Error sending data channel message", r), (o = e.onError) == null || o.call(e, r, { streamId: f });
100
- }
101
- }
102
- return {
103
- speak(n) {
104
- const t = JSON.stringify({
105
- type: "speak",
106
- payload: n
107
- });
108
- return R(t);
109
- },
110
- async disconnect() {
111
- var n, t;
112
- a && (await a.disconnect(), a = null), c && (c.getTracks().forEach((o) => o.stop()), c = null), v = !1, (n = e.onConnectionStateChange) == null || n.call(e, g.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, T.Idle);
113
- },
114
- sendDataChannelMessage: R,
115
- sessionId: A,
116
- streamId: f,
117
- streamType: L,
118
- interruptAvailable: !0,
119
- triggersAvailable: !1
120
- };
121
- }
122
- export {
123
- H as createLiveKitStreamingManager
124
- };