@decartai/sdk 0.1.2 → 0.1.3
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,7 +1,7 @@
|
|
|
1
1
|
import { createConsoleLogger } from "../utils/logger.js";
|
|
2
2
|
import { REALTIME_CONFIG } from "./config-realtime.js";
|
|
3
3
|
import mitt from "mitt";
|
|
4
|
-
import { Room, RoomEvent, Track
|
|
4
|
+
import { Room, RoomEvent, Track } from "livekit-client";
|
|
5
5
|
//#region src/realtime/media-channel.ts
|
|
6
6
|
function getDefaultVideoPublishOptions(videoCodec) {
|
|
7
7
|
const resolvedCodec = videoCodec ?? REALTIME_CONFIG.livekit.defaultVideoCodec;
|
|
@@ -40,16 +40,13 @@ var MediaChannel = class {
|
|
|
40
40
|
room.on(RoomEvent.TrackSubscribed, (track, _pub, participant) => {
|
|
41
41
|
if (!participant.identity.startsWith(REALTIME_CONFIG.livekit.inferenceServerIdentityPrefix)) return;
|
|
42
42
|
if (track.kind !== Track.Kind.Video && track.kind !== Track.Kind.Audio) return;
|
|
43
|
-
track.attach();
|
|
44
43
|
const mediaStreamTrack = track.mediaStreamTrack;
|
|
45
44
|
if (mediaStreamTrack) {
|
|
46
|
-
this.remoteStream
|
|
47
|
-
if (!
|
|
45
|
+
const tracks = this.remoteStream?.getTracks() ?? [];
|
|
46
|
+
if (!tracks.includes(mediaStreamTrack)) tracks.push(mediaStreamTrack);
|
|
47
|
+
this.remoteStream = new MediaStream(tracks);
|
|
48
48
|
this.events.emit("remoteStream", this.remoteStream);
|
|
49
49
|
}
|
|
50
|
-
track.on(TrackEvent.VideoPlaybackStarted, () => {
|
|
51
|
-
this.events.emit("firstFrame");
|
|
52
|
-
});
|
|
53
50
|
});
|
|
54
51
|
room.on(RoomEvent.Disconnected, (reason) => {
|
|
55
52
|
this.logger.warn("livekit: room disconnected", { reason });
|
|
@@ -262,6 +262,9 @@ var SignalingChannel = class {
|
|
|
262
262
|
queueSize: msg.queue_size
|
|
263
263
|
});
|
|
264
264
|
break;
|
|
265
|
+
case "generation_started":
|
|
266
|
+
this.events.emit("generationStarted");
|
|
267
|
+
break;
|
|
265
268
|
case "generation_tick":
|
|
266
269
|
this.events.emit("generationTick", { seconds: msg.seconds });
|
|
267
270
|
break;
|
|
@@ -165,7 +165,11 @@ var StreamSession = class {
|
|
|
165
165
|
this.queue = qp;
|
|
166
166
|
this.events.emit("queuePosition", qp);
|
|
167
167
|
});
|
|
168
|
-
this.signaling.on("
|
|
168
|
+
this.signaling.on("generationStarted", () => this.markGenerating());
|
|
169
|
+
this.signaling.on("generationTick", (e) => {
|
|
170
|
+
this.markGenerating();
|
|
171
|
+
this.events.emit("generationTick", e);
|
|
172
|
+
});
|
|
169
173
|
this.signaling.on("generationEnded", (e) => this.events.emit("generationEnded", e));
|
|
170
174
|
this.signaling.on("serverError", (err) => this.events.emit("error", err));
|
|
171
175
|
this.signaling.on("closed", (info) => this.handleConnectionLoss({
|
|
@@ -173,11 +177,11 @@ var StreamSession = class {
|
|
|
173
177
|
...info
|
|
174
178
|
}));
|
|
175
179
|
}
|
|
180
|
+
markGenerating() {
|
|
181
|
+
if (this.state === "connected") this.setState("generating");
|
|
182
|
+
}
|
|
176
183
|
wireMediaEvents() {
|
|
177
184
|
this.media.on("remoteStream", (stream) => this.events.emit("remoteStream", stream));
|
|
178
|
-
this.media.on("firstFrame", () => {
|
|
179
|
-
if (this.state === "connected") this.setState("generating");
|
|
180
|
-
});
|
|
181
185
|
this.media.on("disconnected", (info) => this.handleConnectionLoss({
|
|
182
186
|
source: "media",
|
|
183
187
|
reason: info.reason
|
|
@@ -81,11 +81,11 @@ const createRealTimeSubscribeClient = (opts) => {
|
|
|
81
81
|
activeRoom.on(RoomEvent.TrackSubscribed, (track, _pub, participant) => {
|
|
82
82
|
if (!participant.identity.startsWith(REALTIME_CONFIG.livekit.inferenceServerIdentityPrefix)) return;
|
|
83
83
|
if (track.kind !== Track.Kind.Video && track.kind !== Track.Kind.Audio) return;
|
|
84
|
-
track.attach();
|
|
85
84
|
const mediaStreamTrack = track.mediaStreamTrack;
|
|
86
85
|
if (!mediaStreamTrack) return;
|
|
87
|
-
|
|
88
|
-
if (!
|
|
86
|
+
const tracks = remoteStream?.getTracks() ?? [];
|
|
87
|
+
if (!tracks.includes(mediaStreamTrack)) tracks.push(mediaStreamTrack);
|
|
88
|
+
remoteStream = new MediaStream(tracks);
|
|
89
89
|
options.onRemoteStream(remoteStream);
|
|
90
90
|
});
|
|
91
91
|
activeRoom.on(RoomEvent.ConnectionStateChanged, (state) => {
|