@reactor-team/js-sdk 2.10.1 → 2.11.1
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/README.md +10 -8
- package/dist/index.d.mts +80 -5
- package/dist/index.d.ts +80 -5
- package/dist/index.js +239 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +239 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -91,7 +91,7 @@ import { z } from "zod";
|
|
|
91
91
|
// package.json
|
|
92
92
|
var package_default = {
|
|
93
93
|
name: "@reactor-team/js-sdk",
|
|
94
|
-
version: "2.
|
|
94
|
+
version: "2.11.1",
|
|
95
95
|
description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
|
|
96
96
|
license: "Apache-2.0",
|
|
97
97
|
repository: {
|
|
@@ -263,6 +263,16 @@ var WebRTCSdpOfferRequestSchema = z.object({
|
|
|
263
263
|
var WebRTCSdpAnswerResponseSchema = z.object({
|
|
264
264
|
sdp_answer: z.string()
|
|
265
265
|
});
|
|
266
|
+
var IceCandidateSchema = z.object({
|
|
267
|
+
candidate: z.string(),
|
|
268
|
+
sdp_mid: z.string().optional(),
|
|
269
|
+
sdp_mline_index: z.number().optional()
|
|
270
|
+
});
|
|
271
|
+
var IceCandidatesRequestSchema = z.object({
|
|
272
|
+
candidates: z.array(IceCandidateSchema),
|
|
273
|
+
is_final: z.boolean(),
|
|
274
|
+
client_info: ClientInfoSchema.optional()
|
|
275
|
+
});
|
|
266
276
|
|
|
267
277
|
// src/core/CoordinatorClient.ts
|
|
268
278
|
var SESSION_POLL_INITIAL_BACKOFF_MS = 200;
|
|
@@ -1117,7 +1127,6 @@ function createOffer(pc) {
|
|
|
1117
1127
|
yield pc.setLocalDescription(
|
|
1118
1128
|
new RTCSessionDescription({ type: initial.type, sdp })
|
|
1119
1129
|
);
|
|
1120
|
-
yield waitForIceGathering(pc);
|
|
1121
1130
|
const localDescription = pc.localDescription;
|
|
1122
1131
|
if (!localDescription) {
|
|
1123
1132
|
throw new Error("Failed to create local description");
|
|
@@ -1146,28 +1155,6 @@ function transformIceServers(response) {
|
|
|
1146
1155
|
return rtcServer;
|
|
1147
1156
|
});
|
|
1148
1157
|
}
|
|
1149
|
-
function waitForIceGathering(pc, timeoutMs = 5e3) {
|
|
1150
|
-
return new Promise((resolve) => {
|
|
1151
|
-
if (pc.iceGatheringState === "complete") {
|
|
1152
|
-
resolve();
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
const onGatheringStateChange = () => {
|
|
1156
|
-
if (pc.iceGatheringState === "complete") {
|
|
1157
|
-
pc.removeEventListener(
|
|
1158
|
-
"icegatheringstatechange",
|
|
1159
|
-
onGatheringStateChange
|
|
1160
|
-
);
|
|
1161
|
-
resolve();
|
|
1162
|
-
}
|
|
1163
|
-
};
|
|
1164
|
-
pc.addEventListener("icegatheringstatechange", onGatheringStateChange);
|
|
1165
|
-
setTimeout(() => {
|
|
1166
|
-
pc.removeEventListener("icegatheringstatechange", onGatheringStateChange);
|
|
1167
|
-
resolve();
|
|
1168
|
-
}, timeoutMs);
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
1158
|
function sendMessage(channel, command, data, scope = "application", maxBytes = DEFAULT_MAX_MESSAGE_BYTES, uploads) {
|
|
1172
1159
|
if (channel.readyState !== "open") {
|
|
1173
1160
|
throw new Error(`Data channel not open: ${channel.readyState}`);
|
|
@@ -1282,6 +1269,7 @@ var INITIAL_BACKOFF_MS = 200;
|
|
|
1282
1269
|
var MAX_BACKOFF_MS = 15e3;
|
|
1283
1270
|
var BACKOFF_MULTIPLIER = 2;
|
|
1284
1271
|
var DEFAULT_MAX_POLL_ATTEMPTS = 6;
|
|
1272
|
+
var ICE_CANDIDATE_BATCH_WINDOW_MS = 25;
|
|
1285
1273
|
var WebRTCTransportClient = class {
|
|
1286
1274
|
constructor(config) {
|
|
1287
1275
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
@@ -1290,6 +1278,8 @@ var WebRTCTransportClient = class {
|
|
|
1290
1278
|
this.publishedTracks = /* @__PURE__ */ new Map();
|
|
1291
1279
|
this.peerConnected = false;
|
|
1292
1280
|
this.dataChannelOpen = false;
|
|
1281
|
+
// Trickle ICE batching
|
|
1282
|
+
this.pendingIceCandidates = [];
|
|
1293
1283
|
var _a, _b;
|
|
1294
1284
|
this.baseUrl = config.baseUrl;
|
|
1295
1285
|
this.sessionId = config.sessionId;
|
|
@@ -1424,6 +1414,70 @@ var WebRTCTransportClient = class {
|
|
|
1424
1414
|
console.debug("[WebRTCTransport] SDP offer accepted (202)");
|
|
1425
1415
|
});
|
|
1426
1416
|
}
|
|
1417
|
+
sendIceCandidates(candidates, is_final) {
|
|
1418
|
+
return __async(this, null, function* () {
|
|
1419
|
+
console.debug(
|
|
1420
|
+
`[WebRTCTransport] Sending ICE candidates (count=${candidates.length}, is_final=${is_final})`
|
|
1421
|
+
);
|
|
1422
|
+
const requestBody = {
|
|
1423
|
+
candidates,
|
|
1424
|
+
is_final,
|
|
1425
|
+
client_info: {
|
|
1426
|
+
sdk_version: REACTOR_SDK_VERSION,
|
|
1427
|
+
sdk_type: REACTOR_SDK_TYPE
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
const response = yield fetch(`${this.transportBaseUrl}/ice_candidates`, {
|
|
1431
|
+
method: "POST",
|
|
1432
|
+
headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
|
|
1433
|
+
"Content-Type": "application/json"
|
|
1434
|
+
}),
|
|
1435
|
+
body: JSON.stringify(requestBody),
|
|
1436
|
+
signal: this.signal
|
|
1437
|
+
});
|
|
1438
|
+
yield this.checkVersionMismatch(response);
|
|
1439
|
+
if (response.status !== 202) {
|
|
1440
|
+
const errorText = yield response.text();
|
|
1441
|
+
throw new Error(
|
|
1442
|
+
`Failed to send ICE candidates: ${response.status} ${errorText}`
|
|
1443
|
+
);
|
|
1444
|
+
}
|
|
1445
|
+
console.debug("[WebRTCTransport] ICE candidates accepted (202)");
|
|
1446
|
+
return;
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Drain the pending ICE candidates buffer and POST them as a single
|
|
1451
|
+
* batch. Called either by the debounce timer (collected candidates so
|
|
1452
|
+
* far) or directly by the gathering-complete handler (with
|
|
1453
|
+
* ``isFinal=true``).
|
|
1454
|
+
*
|
|
1455
|
+
* Errors are logged at debug level — trickle ICE is fire-and-forget,
|
|
1456
|
+
* and the connection can still succeed even if some candidate batches
|
|
1457
|
+
* are lost (host/srflx candidates from the other side are usually
|
|
1458
|
+
* sufficient).
|
|
1459
|
+
*/
|
|
1460
|
+
flushPendingIceCandidates(isFinal) {
|
|
1461
|
+
if (this.iceCandidateFlushTimer !== void 0) {
|
|
1462
|
+
clearTimeout(this.iceCandidateFlushTimer);
|
|
1463
|
+
this.iceCandidateFlushTimer = void 0;
|
|
1464
|
+
}
|
|
1465
|
+
const batch = this.pendingIceCandidates;
|
|
1466
|
+
this.pendingIceCandidates = [];
|
|
1467
|
+
if (batch.length === 0 && !isFinal) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
this.sendIceCandidates(batch, isFinal).catch((err) => {
|
|
1471
|
+
console.debug("[WebRTCTransport] ICE candidate flush failed:", err);
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
cancelPendingIceCandidates() {
|
|
1475
|
+
if (this.iceCandidateFlushTimer !== void 0) {
|
|
1476
|
+
clearTimeout(this.iceCandidateFlushTimer);
|
|
1477
|
+
this.iceCandidateFlushTimer = void 0;
|
|
1478
|
+
}
|
|
1479
|
+
this.pendingIceCandidates = [];
|
|
1480
|
+
}
|
|
1427
1481
|
pollSdpAnswer() {
|
|
1428
1482
|
return __async(this, null, function* () {
|
|
1429
1483
|
console.debug("[WebRTCTransport] Polling for SDP answer...");
|
|
@@ -1493,6 +1547,7 @@ var WebRTCTransportClient = class {
|
|
|
1493
1547
|
this.resetTransportTimings();
|
|
1494
1548
|
this.stopPing();
|
|
1495
1549
|
this.stopStatsPolling();
|
|
1550
|
+
this.cancelPendingIceCandidates();
|
|
1496
1551
|
if (this.dataChannel) {
|
|
1497
1552
|
this.dataChannel.close();
|
|
1498
1553
|
this.dataChannel = void 0;
|
|
@@ -1555,6 +1610,7 @@ var WebRTCTransportClient = class {
|
|
|
1555
1610
|
return __async(this, null, function* () {
|
|
1556
1611
|
this.stopPing();
|
|
1557
1612
|
this.stopStatsPolling();
|
|
1613
|
+
this.cancelPendingIceCandidates();
|
|
1558
1614
|
for (const name of Array.from(this.publishedTracks.keys())) {
|
|
1559
1615
|
yield this.unpublishTrack(name);
|
|
1560
1616
|
}
|
|
@@ -1808,8 +1864,21 @@ var WebRTCTransportClient = class {
|
|
|
1808
1864
|
this.emit("trackReceived", trackName, event.track, stream);
|
|
1809
1865
|
};
|
|
1810
1866
|
this.peerConnection.onicecandidate = (event) => {
|
|
1867
|
+
var _a, _b;
|
|
1811
1868
|
if (event.candidate) {
|
|
1812
|
-
|
|
1869
|
+
this.pendingIceCandidates.push({
|
|
1870
|
+
candidate: event.candidate.candidate,
|
|
1871
|
+
sdp_mid: (_a = event.candidate.sdpMid) != null ? _a : void 0,
|
|
1872
|
+
sdp_mline_index: (_b = event.candidate.sdpMLineIndex) != null ? _b : void 0
|
|
1873
|
+
});
|
|
1874
|
+
if (this.iceCandidateFlushTimer === void 0) {
|
|
1875
|
+
this.iceCandidateFlushTimer = setTimeout(
|
|
1876
|
+
() => this.flushPendingIceCandidates(false),
|
|
1877
|
+
ICE_CANDIDATE_BATCH_WINDOW_MS
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
} else {
|
|
1881
|
+
this.flushPendingIceCandidates(true);
|
|
1813
1882
|
}
|
|
1814
1883
|
};
|
|
1815
1884
|
this.peerConnection.onicecandidateerror = (event) => {
|
|
@@ -2604,9 +2673,13 @@ var Reactor = class {
|
|
|
2604
2673
|
sendCommand(command, data, scope = "application") {
|
|
2605
2674
|
return __async(this, null, function* () {
|
|
2606
2675
|
var _a;
|
|
2607
|
-
if (
|
|
2608
|
-
|
|
2609
|
-
|
|
2676
|
+
if (this.status !== "ready") {
|
|
2677
|
+
this.createError(
|
|
2678
|
+
"NOT_READY",
|
|
2679
|
+
`Cannot send command "${command}" while status is "${this.status}". Must be "ready".`,
|
|
2680
|
+
"api",
|
|
2681
|
+
true
|
|
2682
|
+
);
|
|
2610
2683
|
return;
|
|
2611
2684
|
}
|
|
2612
2685
|
try {
|
|
@@ -3299,7 +3372,10 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3299
3372
|
console.error("[ReactorStore] Failed to upload file:", error);
|
|
3300
3373
|
throw error;
|
|
3301
3374
|
}
|
|
3302
|
-
})
|
|
3375
|
+
}),
|
|
3376
|
+
requestClip: (durationSeconds) => get().internal.reactor.requestClip(durationSeconds),
|
|
3377
|
+
requestRecording: () => get().internal.reactor.requestRecording(),
|
|
3378
|
+
downloadClipAsFile: (clip, filename, options) => get().internal.reactor.downloadClipAsFile(clip, filename, options)
|
|
3303
3379
|
});
|
|
3304
3380
|
});
|
|
3305
3381
|
};
|
|
@@ -3427,7 +3503,7 @@ function ReactorProvider(_a) {
|
|
|
3427
3503
|
console.error("[ReactorProvider] Failed to disconnect:", error);
|
|
3428
3504
|
});
|
|
3429
3505
|
};
|
|
3430
|
-
}, [apiUrl, modelName,
|
|
3506
|
+
}, [apiUrl, modelName, local, jwtSource]);
|
|
3431
3507
|
return /* @__PURE__ */ jsx(ReactorContext.Provider, { value: storeRef.current, children });
|
|
3432
3508
|
}
|
|
3433
3509
|
function useReactorStore(selector) {
|
|
@@ -3503,7 +3579,7 @@ function ReactorView({
|
|
|
3503
3579
|
className,
|
|
3504
3580
|
style,
|
|
3505
3581
|
videoObjectFit = "contain",
|
|
3506
|
-
muted =
|
|
3582
|
+
muted = audioTrack === void 0
|
|
3507
3583
|
}) {
|
|
3508
3584
|
const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
|
|
3509
3585
|
var _a, _b;
|
|
@@ -4146,6 +4222,8 @@ import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } fro
|
|
|
4146
4222
|
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4147
4223
|
function WebcamStream({
|
|
4148
4224
|
track,
|
|
4225
|
+
audio = false,
|
|
4226
|
+
audioTrack,
|
|
4149
4227
|
className,
|
|
4150
4228
|
style,
|
|
4151
4229
|
videoConstraints = {
|
|
@@ -4153,7 +4231,10 @@ function WebcamStream({
|
|
|
4153
4231
|
height: { ideal: 720 }
|
|
4154
4232
|
},
|
|
4155
4233
|
showWebcam = true,
|
|
4156
|
-
videoObjectFit = "contain"
|
|
4234
|
+
videoObjectFit = "contain",
|
|
4235
|
+
onPermissionDenied,
|
|
4236
|
+
onPublished,
|
|
4237
|
+
onError
|
|
4157
4238
|
}) {
|
|
4158
4239
|
const [stream, setStream] = useState4(null);
|
|
4159
4240
|
const [isPublishing, setIsPublishing] = useState4(false);
|
|
@@ -4165,12 +4246,28 @@ function WebcamStream({
|
|
|
4165
4246
|
reactor: state.internal.reactor
|
|
4166
4247
|
}));
|
|
4167
4248
|
const videoRef = useRef5(null);
|
|
4249
|
+
const onPermissionDeniedRef = useRef5(onPermissionDenied);
|
|
4250
|
+
const onPublishedRef = useRef5(onPublished);
|
|
4251
|
+
const onErrorRef = useRef5(onError);
|
|
4252
|
+
useEffect4(() => {
|
|
4253
|
+
onPermissionDeniedRef.current = onPermissionDenied;
|
|
4254
|
+
onPublishedRef.current = onPublished;
|
|
4255
|
+
onErrorRef.current = onError;
|
|
4256
|
+
});
|
|
4257
|
+
const audioRequested = audio !== false && audio !== void 0;
|
|
4258
|
+
const audioEnabled = audioRequested && !!audioTrack;
|
|
4259
|
+
if (audioRequested && !audioTrack) {
|
|
4260
|
+
console.warn(
|
|
4261
|
+
"[WebcamStream] `audio` was set but `audioTrack` is missing; capturing video-only."
|
|
4262
|
+
);
|
|
4263
|
+
}
|
|
4168
4264
|
const startWebcam = () => __async(null, null, function* () {
|
|
4265
|
+
var _a, _b;
|
|
4169
4266
|
console.debug("[WebcamPublisher] Starting webcam");
|
|
4170
4267
|
try {
|
|
4171
4268
|
const mediaStream = yield navigator.mediaDevices.getUserMedia({
|
|
4172
4269
|
video: videoConstraints,
|
|
4173
|
-
audio: false
|
|
4270
|
+
audio: audioEnabled ? audio === true ? true : audio : false
|
|
4174
4271
|
});
|
|
4175
4272
|
console.debug("[WebcamPublisher] Webcam started successfully");
|
|
4176
4273
|
setStream(mediaStream);
|
|
@@ -4180,16 +4277,34 @@ function WebcamStream({
|
|
|
4180
4277
|
if (err instanceof DOMException && (err.name === "NotAllowedError" || err.name === "PermissionDeniedError")) {
|
|
4181
4278
|
console.debug("[WebcamPublisher] Camera permission denied");
|
|
4182
4279
|
setPermissionDenied(true);
|
|
4280
|
+
(_a = onPermissionDeniedRef.current) == null ? void 0 : _a.call(onPermissionDeniedRef);
|
|
4281
|
+
} else {
|
|
4282
|
+
(_b = onErrorRef.current) == null ? void 0 : _b.call(
|
|
4283
|
+
onErrorRef,
|
|
4284
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4285
|
+
);
|
|
4183
4286
|
}
|
|
4184
4287
|
}
|
|
4185
4288
|
});
|
|
4186
4289
|
const stopWebcam = () => __async(null, null, function* () {
|
|
4290
|
+
var _a;
|
|
4187
4291
|
console.debug("[WebcamPublisher] Stopping webcam");
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
}
|
|
4192
|
-
|
|
4292
|
+
const unpublishTasks = [unpublish(track)];
|
|
4293
|
+
if (audioEnabled && audioTrack) {
|
|
4294
|
+
unpublishTasks.push(unpublish(audioTrack));
|
|
4295
|
+
}
|
|
4296
|
+
const results = yield Promise.allSettled(unpublishTasks);
|
|
4297
|
+
for (const r of results) {
|
|
4298
|
+
if (r.status === "rejected") {
|
|
4299
|
+
console.error(
|
|
4300
|
+
"[WebcamPublisher] Error unpublishing before stop:",
|
|
4301
|
+
r.reason
|
|
4302
|
+
);
|
|
4303
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4304
|
+
onErrorRef,
|
|
4305
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4193
4308
|
}
|
|
4194
4309
|
setIsPublishing(false);
|
|
4195
4310
|
stream == null ? void 0 : stream.getTracks().forEach((t) => {
|
|
@@ -4224,25 +4339,54 @@ function WebcamStream({
|
|
|
4224
4339
|
console.debug(
|
|
4225
4340
|
"[WebcamPublisher] Reactor ready, auto-publishing webcam stream"
|
|
4226
4341
|
);
|
|
4227
|
-
const
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4342
|
+
const videoMediaTrack = stream.getVideoTracks()[0];
|
|
4343
|
+
const audioMediaTrack = audioEnabled && audioTrack ? stream.getAudioTracks()[0] : null;
|
|
4344
|
+
const tasks = [];
|
|
4345
|
+
if (videoMediaTrack) tasks.push(publish(track, videoMediaTrack));
|
|
4346
|
+
if (audioMediaTrack && audioTrack)
|
|
4347
|
+
tasks.push(publish(audioTrack, audioMediaTrack));
|
|
4348
|
+
if (tasks.length === 0) return;
|
|
4349
|
+
Promise.all(tasks).then(() => {
|
|
4350
|
+
var _a;
|
|
4351
|
+
console.debug("[WebcamPublisher] Auto-publish successful");
|
|
4352
|
+
setIsPublishing(true);
|
|
4353
|
+
(_a = onPublishedRef.current) == null ? void 0 : _a.call(onPublishedRef);
|
|
4354
|
+
}).catch((err) => {
|
|
4355
|
+
var _a;
|
|
4356
|
+
console.error("[WebcamPublisher] Auto-publish failed:", err);
|
|
4357
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4358
|
+
onErrorRef,
|
|
4359
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4360
|
+
);
|
|
4361
|
+
});
|
|
4236
4362
|
} else if (status !== "ready" && isPublishing) {
|
|
4237
4363
|
console.debug("[WebcamPublisher] Reactor not ready, auto-unpublishing");
|
|
4238
|
-
unpublish(track)
|
|
4239
|
-
|
|
4364
|
+
const tasks = [unpublish(track)];
|
|
4365
|
+
if (audioEnabled && audioTrack) tasks.push(unpublish(audioTrack));
|
|
4366
|
+
Promise.allSettled(tasks).then((results) => {
|
|
4367
|
+
var _a;
|
|
4368
|
+
for (const r of results) {
|
|
4369
|
+
if (r.status === "rejected") {
|
|
4370
|
+
console.error("[WebcamPublisher] Auto-unpublish failed:", r.reason);
|
|
4371
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4372
|
+
onErrorRef,
|
|
4373
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4240
4377
|
setIsPublishing(false);
|
|
4241
|
-
}).catch((err) => {
|
|
4242
|
-
console.error("[WebcamPublisher] Auto-unpublish failed:", err);
|
|
4243
4378
|
});
|
|
4244
4379
|
}
|
|
4245
|
-
}, [
|
|
4380
|
+
}, [
|
|
4381
|
+
status,
|
|
4382
|
+
stream,
|
|
4383
|
+
isPublishing,
|
|
4384
|
+
publish,
|
|
4385
|
+
unpublish,
|
|
4386
|
+
track,
|
|
4387
|
+
audioEnabled,
|
|
4388
|
+
audioTrack
|
|
4389
|
+
]);
|
|
4246
4390
|
useEffect4(() => {
|
|
4247
4391
|
const handleError = (error) => {
|
|
4248
4392
|
console.debug("[WebcamPublisher] Received error event:", error);
|
|
@@ -4345,7 +4489,8 @@ function ClipPlayer({
|
|
|
4345
4489
|
autoPlay = true,
|
|
4346
4490
|
muted = true,
|
|
4347
4491
|
className,
|
|
4348
|
-
style
|
|
4492
|
+
style,
|
|
4493
|
+
onError
|
|
4349
4494
|
}) {
|
|
4350
4495
|
const videoRef = useRef6(null);
|
|
4351
4496
|
const [phase, setPhase] = useState5({ kind: "waiting" });
|
|
@@ -4353,13 +4498,21 @@ function ClipPlayer({
|
|
|
4353
4498
|
const getJwtRef = useRef6(getJwt);
|
|
4354
4499
|
const autoPlayRef = useRef6(autoPlay);
|
|
4355
4500
|
const slackMsRef = useRef6(slackMs);
|
|
4501
|
+
const onErrorRef = useRef6(onError);
|
|
4356
4502
|
const storeRef = useRef6(store);
|
|
4357
4503
|
useEffect5(() => {
|
|
4358
4504
|
getJwtRef.current = getJwt;
|
|
4359
4505
|
autoPlayRef.current = autoPlay;
|
|
4360
4506
|
slackMsRef.current = slackMs;
|
|
4507
|
+
onErrorRef.current = onError;
|
|
4361
4508
|
storeRef.current = store;
|
|
4362
4509
|
});
|
|
4510
|
+
useEffect5(() => {
|
|
4511
|
+
var _a;
|
|
4512
|
+
if (phase.kind === "error") {
|
|
4513
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, phase.error);
|
|
4514
|
+
}
|
|
4515
|
+
}, [phase]);
|
|
4363
4516
|
useEffect5(() => {
|
|
4364
4517
|
const video = videoRef.current;
|
|
4365
4518
|
if (!video) return;
|
|
@@ -4367,9 +4520,10 @@ function ClipPlayer({
|
|
|
4367
4520
|
let cancelled = false;
|
|
4368
4521
|
let hlsInstance = null;
|
|
4369
4522
|
let manifestBlobUrl = null;
|
|
4370
|
-
const fail = (
|
|
4523
|
+
const fail = (error) => {
|
|
4371
4524
|
if (cancelled) return;
|
|
4372
|
-
|
|
4525
|
+
const message = error instanceof RecordingError ? `${error.code}: ${error.reason}` : error.message;
|
|
4526
|
+
setPhase({ kind: "error", message, error });
|
|
4373
4527
|
};
|
|
4374
4528
|
const attachPlayer = (manifestUrl) => __async(null, null, function* () {
|
|
4375
4529
|
const canPlayNative = video.canPlayType("application/vnd.apple.mpegurl") !== "";
|
|
@@ -4388,13 +4542,17 @@ function ClipPlayer({
|
|
|
4388
4542
|
HlsCtor = mod.default;
|
|
4389
4543
|
} catch (e) {
|
|
4390
4544
|
fail(
|
|
4391
|
-
|
|
4545
|
+
new Error(
|
|
4546
|
+
"HLS playback unavailable in this browser. Install `hls.js` as a peer dependency, or use Download."
|
|
4547
|
+
)
|
|
4392
4548
|
);
|
|
4393
4549
|
return;
|
|
4394
4550
|
}
|
|
4395
4551
|
if (cancelled) return;
|
|
4396
4552
|
if (!HlsCtor.isSupported()) {
|
|
4397
|
-
fail(
|
|
4553
|
+
fail(
|
|
4554
|
+
new Error("This browser cannot play HLS clips. Use Download instead.")
|
|
4555
|
+
);
|
|
4398
4556
|
return;
|
|
4399
4557
|
}
|
|
4400
4558
|
const hls = new HlsCtor();
|
|
@@ -4412,7 +4570,7 @@ function ClipPlayer({
|
|
|
4412
4570
|
var _a;
|
|
4413
4571
|
if (cancelled) return;
|
|
4414
4572
|
if (data.fatal) {
|
|
4415
|
-
fail(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`);
|
|
4573
|
+
fail(new Error(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`));
|
|
4416
4574
|
return;
|
|
4417
4575
|
}
|
|
4418
4576
|
console.warn("[Reactor.ClipPlayer] hls.js non-fatal error", data);
|
|
@@ -4443,8 +4601,7 @@ function ClipPlayer({
|
|
|
4443
4601
|
if (err instanceof DOMException && err.name === "AbortError") {
|
|
4444
4602
|
return;
|
|
4445
4603
|
}
|
|
4446
|
-
|
|
4447
|
-
fail(message);
|
|
4604
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
4448
4605
|
}
|
|
4449
4606
|
});
|
|
4450
4607
|
setup();
|
|
@@ -4528,6 +4685,9 @@ function ClipPlayer({
|
|
|
4528
4685
|
);
|
|
4529
4686
|
}
|
|
4530
4687
|
|
|
4688
|
+
// src/react/ClipDownloadButton.tsx
|
|
4689
|
+
import { useEffect as useEffect7, useRef as useRef8 } from "react";
|
|
4690
|
+
|
|
4531
4691
|
// src/react/useClipDownload.ts
|
|
4532
4692
|
import { useCallback as useCallback2, useContext as useContext3, useEffect as useEffect6, useRef as useRef7, useState as useState6 } from "react";
|
|
4533
4693
|
function useClipDownload(clip, options = {}) {
|
|
@@ -4585,18 +4745,35 @@ function ClipDownloadButton({
|
|
|
4585
4745
|
children,
|
|
4586
4746
|
className,
|
|
4587
4747
|
style,
|
|
4588
|
-
disabled
|
|
4748
|
+
disabled,
|
|
4749
|
+
onSuccess,
|
|
4750
|
+
onError
|
|
4589
4751
|
}) {
|
|
4590
4752
|
const { state, download } = useClipDownload(clip, { filename, getJwt });
|
|
4591
4753
|
const downloading = state.kind === "downloading";
|
|
4592
4754
|
const isDisabled = downloading || !!disabled;
|
|
4755
|
+
const onSuccessRef = useRef8(onSuccess);
|
|
4756
|
+
const onErrorRef = useRef8(onError);
|
|
4757
|
+
useEffect7(() => {
|
|
4758
|
+
onSuccessRef.current = onSuccess;
|
|
4759
|
+
onErrorRef.current = onError;
|
|
4760
|
+
});
|
|
4761
|
+
useEffect7(() => {
|
|
4762
|
+
var _a;
|
|
4763
|
+
if (state.kind === "error") {
|
|
4764
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, new Error(state.message));
|
|
4765
|
+
}
|
|
4766
|
+
}, [state]);
|
|
4593
4767
|
const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
|
|
4594
4768
|
return /* @__PURE__ */ jsx6(
|
|
4595
4769
|
"button",
|
|
4596
4770
|
{
|
|
4597
4771
|
type: "button",
|
|
4598
4772
|
onClick: () => {
|
|
4599
|
-
void download()
|
|
4773
|
+
void download().then((blob) => {
|
|
4774
|
+
var _a;
|
|
4775
|
+
if (blob) (_a = onSuccessRef.current) == null ? void 0 : _a.call(onSuccessRef, blob);
|
|
4776
|
+
});
|
|
4600
4777
|
},
|
|
4601
4778
|
disabled: isDisabled,
|
|
4602
4779
|
title: state.kind === "error" ? state.message : void 0,
|