@reactor-team/js-sdk 2.7.0 → 2.8.0
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.d.mts +16 -211
- package/dist/index.d.ts +16 -211
- package/dist/index.js +25 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -71,7 +71,7 @@ import { z } from "zod";
|
|
|
71
71
|
// package.json
|
|
72
72
|
var package_default = {
|
|
73
73
|
name: "@reactor-team/js-sdk",
|
|
74
|
-
version: "2.
|
|
74
|
+
version: "2.8.0",
|
|
75
75
|
description: "Reactor JavaScript frontend SDK",
|
|
76
76
|
main: "dist/index.js",
|
|
77
77
|
module: "dist/index.mjs",
|
|
@@ -172,13 +172,6 @@ var CreateSessionRequestSchema = z.object({
|
|
|
172
172
|
supported_transports: z.array(TransportDeclarationSchema),
|
|
173
173
|
extra_args: z.record(z.string(), z.any()).optional()
|
|
174
174
|
});
|
|
175
|
-
var InitialSessionResponseSchema = z.object({
|
|
176
|
-
session_id: z.string(),
|
|
177
|
-
model: z.object({ name: z.string() }),
|
|
178
|
-
server_info: z.object({ server_version: z.string() }).optional(),
|
|
179
|
-
state: z.string(),
|
|
180
|
-
cluster: z.string().optional()
|
|
181
|
-
});
|
|
182
175
|
var CommandCapabilitySchema = z.object({
|
|
183
176
|
name: z.string(),
|
|
184
177
|
description: z.string(),
|
|
@@ -190,23 +183,18 @@ var CapabilitiesSchema = z.object({
|
|
|
190
183
|
commands: z.array(CommandCapabilitySchema).optional(),
|
|
191
184
|
emission_fps: z.number().nullable().optional()
|
|
192
185
|
});
|
|
193
|
-
var
|
|
186
|
+
var SessionInfoResponseSchema = z.object({
|
|
194
187
|
session_id: z.string(),
|
|
195
|
-
server_info: z.object({ server_version: z.string() }).optional(),
|
|
196
|
-
selected_transport: TransportDeclarationSchema.optional(),
|
|
197
|
-
model: z.object({ name: z.string(), version: z.string().optional() }),
|
|
198
|
-
capabilities: CapabilitiesSchema.optional(),
|
|
199
188
|
state: z.string(),
|
|
200
|
-
cluster: z.string()
|
|
189
|
+
cluster: z.string()
|
|
201
190
|
});
|
|
202
|
-
var CreateSessionResponseSchema =
|
|
203
|
-
|
|
204
|
-
|
|
191
|
+
var CreateSessionResponseSchema = SessionInfoResponseSchema.extend({
|
|
192
|
+
model: z.object({ name: z.string(), version: z.string().optional() }),
|
|
193
|
+
server_info: z.object({ server_version: z.string() })
|
|
205
194
|
});
|
|
206
|
-
var
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
state: z.string()
|
|
195
|
+
var SessionResponseSchema = CreateSessionResponseSchema.extend({
|
|
196
|
+
selected_transport: TransportDeclarationSchema.optional(),
|
|
197
|
+
capabilities: CapabilitiesSchema.optional()
|
|
210
198
|
});
|
|
211
199
|
var TerminateSessionRequestSchema = z.object({
|
|
212
200
|
reason: z.string().optional()
|
|
@@ -341,7 +329,7 @@ var CoordinatorClient = class {
|
|
|
341
329
|
);
|
|
342
330
|
}
|
|
343
331
|
const data = yield response.json();
|
|
344
|
-
const parsed =
|
|
332
|
+
const parsed = CreateSessionResponseSchema.parse(data);
|
|
345
333
|
this.currentSessionId = parsed.session_id;
|
|
346
334
|
console.debug(
|
|
347
335
|
"[CoordinatorClient] Session created:",
|
|
@@ -405,11 +393,10 @@ var CoordinatorClient = class {
|
|
|
405
393
|
);
|
|
406
394
|
}
|
|
407
395
|
if (partial.capabilities && partial.selected_transport) {
|
|
408
|
-
const full = CreateSessionResponseSchema.parse(data);
|
|
409
396
|
console.debug(
|
|
410
|
-
`[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${
|
|
397
|
+
`[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${partial.selected_transport.protocol}, tracks: ${partial.capabilities.tracks.length}`
|
|
411
398
|
);
|
|
412
|
-
return
|
|
399
|
+
return partial;
|
|
413
400
|
}
|
|
414
401
|
console.debug(
|
|
415
402
|
`[CoordinatorClient] Session poll ${attempt}/${maxAttempts} \u2014 state: ${partial.state}, waiting ${backoffMs}ms...`
|
|
@@ -423,8 +410,9 @@ var CoordinatorClient = class {
|
|
|
423
410
|
});
|
|
424
411
|
}
|
|
425
412
|
/**
|
|
426
|
-
* Gets
|
|
427
|
-
*
|
|
413
|
+
* Gets session details from the coordinator.
|
|
414
|
+
* Fields like selected_transport and capabilities are only present
|
|
415
|
+
* after the Runtime accepts the session.
|
|
428
416
|
*/
|
|
429
417
|
getSession() {
|
|
430
418
|
return __async(this, null, function* () {
|
|
@@ -445,7 +433,7 @@ var CoordinatorClient = class {
|
|
|
445
433
|
throw new Error(`Failed to get session: ${response.status} ${errorText}`);
|
|
446
434
|
}
|
|
447
435
|
const data = yield response.json();
|
|
448
|
-
return
|
|
436
|
+
return SessionResponseSchema.parse(data);
|
|
449
437
|
});
|
|
450
438
|
}
|
|
451
439
|
/**
|
|
@@ -575,6 +563,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
575
563
|
*/
|
|
576
564
|
createSession(extraArgs) {
|
|
577
565
|
return __async(this, null, function* () {
|
|
566
|
+
var _a, _b;
|
|
578
567
|
console.debug("[LocalCoordinatorClient] Starting session...");
|
|
579
568
|
const response = yield fetch(`${this.baseUrl}/start_session`, {
|
|
580
569
|
method: "POST",
|
|
@@ -591,17 +580,18 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
591
580
|
);
|
|
592
581
|
}
|
|
593
582
|
const data = yield response.json();
|
|
594
|
-
|
|
595
|
-
this.
|
|
583
|
+
const session = SessionResponseSchema.parse(data);
|
|
584
|
+
this.cachedSessionResponse = session;
|
|
585
|
+
this.currentSessionId = session.session_id;
|
|
596
586
|
console.debug(
|
|
597
587
|
"[LocalCoordinatorClient] Session started:",
|
|
598
588
|
this.currentSessionId,
|
|
599
589
|
"transport:",
|
|
600
|
-
|
|
590
|
+
(_a = session.selected_transport) == null ? void 0 : _a.protocol,
|
|
601
591
|
"tracks:",
|
|
602
|
-
|
|
592
|
+
(_b = session.capabilities) == null ? void 0 : _b.tracks.length
|
|
603
593
|
);
|
|
604
|
-
return
|
|
594
|
+
return CreateSessionResponseSchema.parse(data);
|
|
605
595
|
});
|
|
606
596
|
}
|
|
607
597
|
/**
|
|
@@ -1526,7 +1516,7 @@ var Reactor = class {
|
|
|
1526
1516
|
*/
|
|
1527
1517
|
connect(jwtToken, options) {
|
|
1528
1518
|
return __async(this, null, function* () {
|
|
1529
|
-
var _a;
|
|
1519
|
+
var _a, _b;
|
|
1530
1520
|
console.debug("[Reactor] Connecting, status:", this.status);
|
|
1531
1521
|
if (jwtToken == void 0 && !this.local) {
|
|
1532
1522
|
throw new Error("No authentication provided and not in local mode");
|
|
@@ -1574,7 +1564,7 @@ var Reactor = class {
|
|
|
1574
1564
|
baseUrl: this.coordinatorUrl,
|
|
1575
1565
|
sessionId: sessionResponse.session_id,
|
|
1576
1566
|
jwtToken: this.local ? "local" : jwtToken,
|
|
1577
|
-
webrtcVersion: (_a = sessionResponse.selected_transport.version) != null ?
|
|
1567
|
+
webrtcVersion: (_b = (_a = sessionResponse.selected_transport) == null ? void 0 : _a.version) != null ? _b : REACTOR_WEBRTC_VERSION,
|
|
1578
1568
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|
|
1579
1569
|
});
|
|
1580
1570
|
this.setupTransportHandlers();
|
|
@@ -2880,27 +2870,6 @@ function WebcamStream({
|
|
|
2880
2870
|
}
|
|
2881
2871
|
);
|
|
2882
2872
|
}
|
|
2883
|
-
|
|
2884
|
-
// src/utils/tokens.ts
|
|
2885
|
-
function fetchInsecureToken(_0) {
|
|
2886
|
-
return __async(this, arguments, function* (apiKey, apiUrl = DEFAULT_BASE_URL) {
|
|
2887
|
-
console.warn(
|
|
2888
|
-
"[Reactor] \u26A0\uFE0F SECURITY WARNING: fetchInsecureToken() exposes your API key in client-side code. This should ONLY be used for local development or testing. In production, fetch tokens from your server instead."
|
|
2889
|
-
);
|
|
2890
|
-
const response = yield fetch(`${apiUrl}/tokens`, {
|
|
2891
|
-
method: "GET",
|
|
2892
|
-
headers: {
|
|
2893
|
-
"Reactor-API-Key": apiKey
|
|
2894
|
-
}
|
|
2895
|
-
});
|
|
2896
|
-
if (!response.ok) {
|
|
2897
|
-
const error = yield response.text();
|
|
2898
|
-
throw new Error(`Failed to create token: ${response.status} ${error}`);
|
|
2899
|
-
}
|
|
2900
|
-
const { jwt } = yield response.json();
|
|
2901
|
-
return jwt;
|
|
2902
|
-
});
|
|
2903
|
-
}
|
|
2904
2873
|
export {
|
|
2905
2874
|
AbortError,
|
|
2906
2875
|
ConflictError,
|
|
@@ -2909,9 +2878,7 @@ export {
|
|
|
2909
2878
|
ReactorController,
|
|
2910
2879
|
ReactorProvider,
|
|
2911
2880
|
ReactorView,
|
|
2912
|
-
WebRTCTransportClient,
|
|
2913
2881
|
WebcamStream,
|
|
2914
|
-
fetchInsecureToken,
|
|
2915
2882
|
isAbortError,
|
|
2916
2883
|
useReactor,
|
|
2917
2884
|
useReactorInternalMessage,
|