@decartai/sdk 0.1.6 → 0.1.7
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,6 +1,5 @@
|
|
|
1
1
|
import { createConsoleLogger } from "../utils/logger.js";
|
|
2
2
|
import { REALTIME_CONFIG } from "./config-realtime.js";
|
|
3
|
-
import { InitialStateGate } from "./initial-state-gate.js";
|
|
4
3
|
import { MediaChannel } from "./media-channel.js";
|
|
5
4
|
import { SignalingChannel } from "./signaling-channel.js";
|
|
6
5
|
import mitt from "mitt";
|
|
@@ -25,7 +24,7 @@ var StreamSession = class {
|
|
|
25
24
|
queue = null;
|
|
26
25
|
disposed = false;
|
|
27
26
|
currentAttempt = 0;
|
|
28
|
-
|
|
27
|
+
teardownGeneration = 0;
|
|
29
28
|
logger;
|
|
30
29
|
constructor(config) {
|
|
31
30
|
this.config = config;
|
|
@@ -102,11 +101,11 @@ var StreamSession = class {
|
|
|
102
101
|
const initialState = this.getInitialState();
|
|
103
102
|
this.config.observability?.beginConnectionBreakdown(attempt, getInitialImageSizeKb(initialState?.image));
|
|
104
103
|
this.config.observability?.markGlassToGlassStart();
|
|
105
|
-
const gateAttempt = this.initialStateGate.startAttempt(initialState);
|
|
106
104
|
const { roomInfo, initialStateAck } = await this.signaling.openAndJoin({
|
|
107
105
|
connectTimeout: REALTIME_CONFIG.session.connectionTimeoutMs,
|
|
108
106
|
initialState
|
|
109
107
|
});
|
|
108
|
+
this.watchInitialStateAck(initialStateAck, attempt);
|
|
110
109
|
if (this.disposed || this.currentAttempt !== attempt) {
|
|
111
110
|
this.tearDown();
|
|
112
111
|
throw new AbortError("Stale connect attempt");
|
|
@@ -117,7 +116,6 @@ var StreamSession = class {
|
|
|
117
116
|
url: roomInfo.livekitUrl,
|
|
118
117
|
token: roomInfo.token
|
|
119
118
|
});
|
|
120
|
-
if (!await gateAttempt.waitForReadiness(initialStateAck)) throw new AbortError("Stale connect attempt");
|
|
121
119
|
await this.media.publishLocalTracks();
|
|
122
120
|
} catch (error) {
|
|
123
121
|
this.tearDown();
|
|
@@ -141,6 +139,13 @@ var StreamSession = class {
|
|
|
141
139
|
throw error;
|
|
142
140
|
}
|
|
143
141
|
}
|
|
142
|
+
watchInitialStateAck(initialStateAck, attempt) {
|
|
143
|
+
const generation = this.teardownGeneration;
|
|
144
|
+
initialStateAck.catch((error) => {
|
|
145
|
+
if (this.disposed || this.currentAttempt !== attempt || this.teardownGeneration !== generation) return;
|
|
146
|
+
this.events.emit("error", error instanceof Error ? error : new Error(String(error)));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
144
149
|
getInitialState() {
|
|
145
150
|
if (this.config.initialImageRef !== void 0) return {
|
|
146
151
|
imageRef: this.config.initialImageRef,
|
|
@@ -240,9 +245,9 @@ var StreamSession = class {
|
|
|
240
245
|
this.wireMediaEvents();
|
|
241
246
|
}
|
|
242
247
|
tearDown() {
|
|
248
|
+
this.teardownGeneration++;
|
|
243
249
|
this.signaling.close();
|
|
244
250
|
this.media.disconnect();
|
|
245
|
-
this.initialStateGate.reset();
|
|
246
251
|
this.resetHandshakeState();
|
|
247
252
|
}
|
|
248
253
|
resetHandshakeState() {
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region src/realtime/initial-state-gate.ts
|
|
2
|
-
var InitialStateGate = class {
|
|
3
|
-
attemptId = 0;
|
|
4
|
-
startAttempt(initialState) {
|
|
5
|
-
const attemptId = ++this.attemptId;
|
|
6
|
-
const shouldWait = hasCallerProvidedInitialState(initialState);
|
|
7
|
-
return { waitForReadiness: async (initialStateAck) => {
|
|
8
|
-
if (shouldWait) await initialStateAck;
|
|
9
|
-
return this.attemptId === attemptId;
|
|
10
|
-
} };
|
|
11
|
-
}
|
|
12
|
-
reset() {
|
|
13
|
-
this.attemptId++;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
function hasCallerProvidedInitialState(state) {
|
|
17
|
-
if (!state) return false;
|
|
18
|
-
return state.image !== void 0 && state.image !== null || state.prompt !== void 0 && state.prompt !== null;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { InitialStateGate };
|