@roboflow/inference-sdk 0.1.13 → 0.3.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.es.js +187 -168
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inference-api.d.ts +2 -0
- package/dist/inference-api.d.ts.map +1 -1
- package/dist/webrtc.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
var q = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
const
|
|
2
|
+
var j = (r, e, t) => e in r ? q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var u = (r, e, t) => j(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
var O;
|
|
5
|
+
const K = typeof process < "u" && ((O = process.env) != null && O.RF_API_BASE_URL) ? process.env.RF_API_BASE_URL : "https://api.roboflow.com", V = [
|
|
6
6
|
"https://serverless.roboflow.com",
|
|
7
7
|
"https://serverless.roboflow.one"
|
|
8
8
|
];
|
|
9
|
-
class
|
|
9
|
+
class k {
|
|
10
10
|
/**
|
|
11
11
|
* @private
|
|
12
12
|
* Use InferenceHTTPClient.init() instead
|
|
13
13
|
*/
|
|
14
|
-
constructor(e, t = "https://serverless.roboflow.com", n =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
constructor(e, t = "https://serverless.roboflow.com", n = K) {
|
|
15
|
+
u(this, "apiKey");
|
|
16
|
+
u(this, "serverUrl");
|
|
17
|
+
u(this, "apiBaseUrl");
|
|
18
18
|
this.apiKey = e, this.serverUrl = t, this.apiBaseUrl = n;
|
|
19
19
|
}
|
|
20
20
|
static init({ apiKey: e, serverUrl: t, apiBaseUrl: n }) {
|
|
21
21
|
if (!e)
|
|
22
22
|
throw new Error("apiKey is required");
|
|
23
|
-
return new
|
|
23
|
+
return new k(e, t, n);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Initialize a WebRTC worker pipeline
|
|
@@ -62,49 +62,50 @@ class b {
|
|
|
62
62
|
if (i && f)
|
|
63
63
|
throw new Error("Provide either workflowSpec OR (workspaceName + workflowId), not both");
|
|
64
64
|
const {
|
|
65
|
-
imageInputName:
|
|
66
|
-
streamOutputNames:
|
|
67
|
-
dataOutputNames:
|
|
65
|
+
imageInputName: l = "image",
|
|
66
|
+
streamOutputNames: s = [],
|
|
67
|
+
dataOutputNames: c = [],
|
|
68
68
|
threadPoolWorkers: y = 4,
|
|
69
69
|
workflowsParameters: S = {},
|
|
70
|
-
iceServers:
|
|
71
|
-
processingTimeout:
|
|
72
|
-
requestedPlan:
|
|
70
|
+
iceServers: h,
|
|
71
|
+
processingTimeout: d,
|
|
72
|
+
requestedPlan: p,
|
|
73
73
|
requestedRegion: C,
|
|
74
|
-
realtimeProcessing:
|
|
75
|
-
rtspUrl:
|
|
76
|
-
|
|
74
|
+
realtimeProcessing: R = !0,
|
|
75
|
+
rtspUrl: b,
|
|
76
|
+
extraPayload: _
|
|
77
|
+
} = o, w = {
|
|
77
78
|
type: "WorkflowConfiguration",
|
|
78
|
-
image_input_name:
|
|
79
|
+
image_input_name: l,
|
|
79
80
|
workflows_parameters: S,
|
|
80
81
|
workflows_thread_pool_workers: y,
|
|
81
82
|
cancel_thread_pool_tasks_on_exit: !0,
|
|
82
83
|
video_metadata_input_name: "video_metadata"
|
|
83
84
|
};
|
|
84
|
-
i ?
|
|
85
|
+
i ? w.workflow_specification = t : (w.workspace_name = n, w.workflow_id = a);
|
|
85
86
|
const m = {
|
|
86
|
-
workflow_configuration:
|
|
87
|
+
workflow_configuration: w,
|
|
87
88
|
api_key: this.apiKey,
|
|
88
|
-
webrtc_realtime_processing:
|
|
89
|
+
webrtc_realtime_processing: R,
|
|
89
90
|
webrtc_offer: {
|
|
90
91
|
sdp: e.sdp,
|
|
91
92
|
type: e.type
|
|
92
93
|
},
|
|
93
|
-
webrtc_config:
|
|
94
|
-
stream_output:
|
|
95
|
-
data_output:
|
|
94
|
+
webrtc_config: h ? { iceServers: h } : null,
|
|
95
|
+
stream_output: s,
|
|
96
|
+
data_output: c
|
|
96
97
|
};
|
|
97
|
-
|
|
98
|
-
const
|
|
98
|
+
d !== void 0 && (m.processing_timeout = d), p !== void 0 && (m.requested_plan = p), C !== void 0 && (m.requested_region = C), b && (m.rtsp_url = b), _ && Object.assign(m, _);
|
|
99
|
+
const v = await fetch(`${this.serverUrl}/initialise_webrtc_worker`, {
|
|
99
100
|
method: "POST",
|
|
100
101
|
headers: { "Content-Type": "application/json" },
|
|
101
102
|
body: JSON.stringify(m)
|
|
102
103
|
});
|
|
103
|
-
if (!
|
|
104
|
-
const T = await
|
|
105
|
-
throw new Error(`initialise_webrtc_worker failed (${
|
|
104
|
+
if (!v.ok) {
|
|
105
|
+
const T = await v.text().catch(() => "");
|
|
106
|
+
throw new Error(`initialise_webrtc_worker failed (${v.status}): ${T}`);
|
|
106
107
|
}
|
|
107
|
-
return await
|
|
108
|
+
return await v.json();
|
|
108
109
|
}
|
|
109
110
|
async terminatePipeline({ pipelineId: e }) {
|
|
110
111
|
if (!e)
|
|
@@ -166,7 +167,7 @@ class b {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
|
-
const
|
|
170
|
+
const oe = {
|
|
170
171
|
/**
|
|
171
172
|
* Create a connector that uses API key directly
|
|
172
173
|
*
|
|
@@ -190,7 +191,7 @@ const ie = {
|
|
|
190
191
|
typeof window < "u" && console.warn(
|
|
191
192
|
"[Security Warning] Using API key directly in browser will expose it. Use connectors.withProxyUrl() for production. See: https://docs.roboflow.com/api-reference/authentication#securing-your-api-key"
|
|
192
193
|
);
|
|
193
|
-
const a =
|
|
194
|
+
const a = k.init({ apiKey: r, serverUrl: t, apiBaseUrl: n });
|
|
194
195
|
return {
|
|
195
196
|
connectWrtc: async (o, i) => (console.debug("wrtcParams", i), await a.initializeWebrtcWorker({
|
|
196
197
|
offer: o,
|
|
@@ -208,7 +209,8 @@ const ie = {
|
|
|
208
209
|
requestedPlan: i.requestedPlan,
|
|
209
210
|
requestedRegion: i.requestedRegion,
|
|
210
211
|
realtimeProcessing: i.realtimeProcessing,
|
|
211
|
-
rtspUrl: i.rtspUrl
|
|
212
|
+
rtspUrl: i.rtspUrl,
|
|
213
|
+
extraPayload: i.extraPayload
|
|
212
214
|
}
|
|
213
215
|
})),
|
|
214
216
|
/**
|
|
@@ -330,24 +332,24 @@ async function $(r = { video: !0 }) {
|
|
|
330
332
|
return console.log("[RFStreams] fallback stream", t.getVideoTracks().map((n) => ({ id: n.id, label: n.label }))), t;
|
|
331
333
|
}
|
|
332
334
|
}
|
|
333
|
-
function
|
|
335
|
+
function D(r) {
|
|
334
336
|
r && (r.getTracks().forEach((e) => e.stop()), console.log("[RFStreams] Stream stopped"));
|
|
335
337
|
}
|
|
336
|
-
const
|
|
338
|
+
const se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
337
339
|
__proto__: null,
|
|
338
|
-
stopStream:
|
|
340
|
+
stopStream: D,
|
|
339
341
|
useCamera: $
|
|
340
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
341
|
-
function
|
|
342
|
+
}, Symbol.toStringTag, { value: "Module" })), F = 49152, M = 262144, z = 10;
|
|
343
|
+
function G(r) {
|
|
342
344
|
return new Promise((e) => setTimeout(e, r));
|
|
343
345
|
}
|
|
344
|
-
class
|
|
346
|
+
class A {
|
|
345
347
|
constructor(e, t) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
this.file = e, this.channel = t, this.totalChunks = Math.ceil(e.size /
|
|
348
|
+
u(this, "file");
|
|
349
|
+
u(this, "channel");
|
|
350
|
+
u(this, "totalChunks");
|
|
351
|
+
u(this, "cancelled", !1);
|
|
352
|
+
this.file = e, this.channel = t, this.totalChunks = Math.ceil(e.size / F);
|
|
351
353
|
}
|
|
352
354
|
/**
|
|
353
355
|
* Cancel the upload
|
|
@@ -367,20 +369,20 @@ class D {
|
|
|
367
369
|
throw new Error("Upload cancelled");
|
|
368
370
|
if (this.channel.readyState !== "open")
|
|
369
371
|
throw new Error("Video upload interrupted");
|
|
370
|
-
const a = n *
|
|
371
|
-
for (
|
|
372
|
+
const a = n * F, o = Math.min(a + F, t), i = this.file.slice(a, o), f = new Uint8Array(await i.arrayBuffer()), l = new ArrayBuffer(8 + f.length), s = new DataView(l);
|
|
373
|
+
for (s.setUint32(0, n, !0), s.setUint32(4, this.totalChunks, !0), new Uint8Array(l, 8).set(f); this.channel.bufferedAmount > M; ) {
|
|
372
374
|
if (this.channel.readyState !== "open")
|
|
373
375
|
throw new Error("Video upload interrupted");
|
|
374
|
-
await
|
|
376
|
+
await G(z);
|
|
375
377
|
}
|
|
376
|
-
this.channel.send(
|
|
378
|
+
this.channel.send(l), e && e(o, t);
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
381
|
}
|
|
380
|
-
const
|
|
382
|
+
const H = 12;
|
|
381
383
|
class N {
|
|
382
384
|
constructor() {
|
|
383
|
-
|
|
385
|
+
u(this, "pendingFrames", /* @__PURE__ */ new Map());
|
|
384
386
|
}
|
|
385
387
|
/**
|
|
386
388
|
* Process an incoming chunk and return the complete message if all chunks received
|
|
@@ -394,11 +396,11 @@ class N {
|
|
|
394
396
|
});
|
|
395
397
|
const o = this.pendingFrames.get(e);
|
|
396
398
|
if (o.chunks.set(t, a), o.chunks.size === n) {
|
|
397
|
-
const i = Array.from(o.chunks.values()).reduce((
|
|
398
|
-
let
|
|
399
|
-
for (let
|
|
400
|
-
const
|
|
401
|
-
f.set(
|
|
399
|
+
const i = Array.from(o.chunks.values()).reduce((s, c) => s + c.length, 0), f = new Uint8Array(i);
|
|
400
|
+
let l = 0;
|
|
401
|
+
for (let s = 0; s < n; s++) {
|
|
402
|
+
const c = o.chunks.get(s);
|
|
403
|
+
f.set(c, l), l += c.length;
|
|
402
404
|
}
|
|
403
405
|
return this.pendingFrames.delete(e), f;
|
|
404
406
|
}
|
|
@@ -411,11 +413,26 @@ class N {
|
|
|
411
413
|
this.pendingFrames.clear();
|
|
412
414
|
}
|
|
413
415
|
}
|
|
414
|
-
function
|
|
415
|
-
const e = new DataView(r), t = e.getUint32(0, !0), n = e.getUint32(4, !0), a = e.getUint32(8, !0), o = new Uint8Array(r,
|
|
416
|
+
function x(r) {
|
|
417
|
+
const e = new DataView(r), t = e.getUint32(0, !0), n = e.getUint32(4, !0), a = e.getUint32(8, !0), o = new Uint8Array(r, H);
|
|
416
418
|
return { frameId: t, chunkIndex: n, totalChunks: a, payload: o };
|
|
417
419
|
}
|
|
418
|
-
async function
|
|
420
|
+
async function J(r) {
|
|
421
|
+
const e = new DecompressionStream("gzip"), t = e.writable.getWriter();
|
|
422
|
+
t.write(r), t.close();
|
|
423
|
+
const n = e.readable.getReader(), a = [];
|
|
424
|
+
for (; ; ) {
|
|
425
|
+
const { done: l, value: s } = await n.read();
|
|
426
|
+
if (l) break;
|
|
427
|
+
a.push(s);
|
|
428
|
+
}
|
|
429
|
+
const o = a.reduce((l, s) => l + s.length, 0), i = new Uint8Array(o);
|
|
430
|
+
let f = 0;
|
|
431
|
+
for (const l of a)
|
|
432
|
+
i.set(l, f), f += l.length;
|
|
433
|
+
return i;
|
|
434
|
+
}
|
|
435
|
+
async function Z(r, e = 6e3) {
|
|
419
436
|
if (r.iceGatheringState === "complete") return;
|
|
420
437
|
let t = !1;
|
|
421
438
|
const n = (a) => {
|
|
@@ -440,52 +457,52 @@ async function G(r, e = 6e3) {
|
|
|
440
457
|
r.removeEventListener("icecandidate", n);
|
|
441
458
|
}
|
|
442
459
|
}
|
|
443
|
-
function
|
|
460
|
+
function Q(r) {
|
|
444
461
|
return new Promise((e) => {
|
|
445
462
|
r.addEventListener("track", (t) => {
|
|
446
463
|
t.streams && t.streams[0] && e(t.streams[0]);
|
|
447
464
|
});
|
|
448
465
|
});
|
|
449
466
|
}
|
|
450
|
-
const
|
|
467
|
+
const X = [
|
|
451
468
|
{ urls: ["stun:stun.l.google.com:19302"] }
|
|
452
469
|
];
|
|
453
|
-
async function
|
|
470
|
+
async function Y(r, e, t, n, a) {
|
|
454
471
|
if ([!!r, !!e, !!n].filter(Boolean).length !== 1)
|
|
455
472
|
throw new Error("Exactly one of localStream, file, or rtspUrl must be provided");
|
|
456
|
-
const
|
|
457
|
-
iceServers:
|
|
473
|
+
const s = t ?? X, c = new RTCPeerConnection({
|
|
474
|
+
iceServers: s
|
|
458
475
|
});
|
|
459
|
-
a != null && a.onPeerConnectionCreated && await a.onPeerConnectionCreated(
|
|
476
|
+
a != null && a.onPeerConnectionCreated && await a.onPeerConnectionCreated(c);
|
|
460
477
|
try {
|
|
461
|
-
|
|
462
|
-
} catch (
|
|
463
|
-
console.warn("[RFWebRTC] Could not add transceiver:",
|
|
478
|
+
c.addTransceiver("video", { direction: "recvonly" });
|
|
479
|
+
} catch (p) {
|
|
480
|
+
console.warn("[RFWebRTC] Could not add transceiver:", p);
|
|
464
481
|
}
|
|
465
482
|
if (r)
|
|
466
|
-
for (const
|
|
467
|
-
const C =
|
|
468
|
-
a != null && a.onTrackAdded && await a.onTrackAdded(
|
|
483
|
+
for (const p of r.getVideoTracks()) {
|
|
484
|
+
const C = c.addTrack(p, r);
|
|
485
|
+
a != null && a.onTrackAdded && await a.onTrackAdded(p, C, c);
|
|
469
486
|
}
|
|
470
|
-
const y =
|
|
487
|
+
const y = Q(c), S = c.createDataChannel("inference", {
|
|
471
488
|
ordered: !0
|
|
472
489
|
});
|
|
473
|
-
let
|
|
474
|
-
e && (
|
|
475
|
-
let
|
|
490
|
+
let h;
|
|
491
|
+
e && (h = c.createDataChannel("video_upload"));
|
|
492
|
+
let d = await c.createOffer();
|
|
476
493
|
if (a != null && a.onOfferCreated) {
|
|
477
|
-
const
|
|
478
|
-
|
|
494
|
+
const p = await a.onOfferCreated(d);
|
|
495
|
+
p && (d = p);
|
|
479
496
|
}
|
|
480
|
-
return await
|
|
481
|
-
pc:
|
|
482
|
-
offer:
|
|
497
|
+
return await c.setLocalDescription(d), await Z(c), {
|
|
498
|
+
pc: c,
|
|
499
|
+
offer: c.localDescription,
|
|
483
500
|
remoteStreamPromise: y,
|
|
484
501
|
dataChannel: S,
|
|
485
|
-
uploadChannel:
|
|
502
|
+
uploadChannel: h
|
|
486
503
|
};
|
|
487
504
|
}
|
|
488
|
-
async function
|
|
505
|
+
async function ee(r) {
|
|
489
506
|
const e = r.getSenders().find((n) => n.track && n.track.kind === "video");
|
|
490
507
|
if (!e) return;
|
|
491
508
|
const t = e.getParameters();
|
|
@@ -496,7 +513,7 @@ async function Y(r) {
|
|
|
496
513
|
console.warn("[RFWebRTC] Failed to set encoding parameters:", n);
|
|
497
514
|
}
|
|
498
515
|
}
|
|
499
|
-
function
|
|
516
|
+
function te(r, e = 3e4) {
|
|
500
517
|
return new Promise((t, n) => {
|
|
501
518
|
if (r.readyState === "open") {
|
|
502
519
|
t();
|
|
@@ -512,53 +529,55 @@ function ee(r, e = 3e4) {
|
|
|
512
529
|
r.addEventListener("open", a), r.addEventListener("error", o);
|
|
513
530
|
});
|
|
514
531
|
}
|
|
515
|
-
class
|
|
532
|
+
class B {
|
|
516
533
|
/** @private */
|
|
517
534
|
constructor(e, t, n, a, o, i) {
|
|
518
535
|
/**
|
|
519
536
|
* The underlying RTCPeerConnection.
|
|
520
537
|
* Exposed for advanced use cases like getting stats or accessing senders.
|
|
521
538
|
*/
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
539
|
+
u(this, "peerConnection");
|
|
540
|
+
u(this, "_localStream");
|
|
541
|
+
u(this, "remoteStreamPromise");
|
|
542
|
+
u(this, "pipelineId");
|
|
543
|
+
u(this, "apiKey");
|
|
527
544
|
/**
|
|
528
545
|
* The data channel used for receiving inference results.
|
|
529
546
|
* Exposed for advanced use cases.
|
|
530
547
|
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
548
|
+
u(this, "dataChannel");
|
|
549
|
+
u(this, "reassembler");
|
|
550
|
+
u(this, "ackPacingEnabled");
|
|
534
551
|
/**
|
|
535
552
|
* The data channel used for uploading video files (only available in file upload mode).
|
|
536
553
|
* Exposed for advanced use cases.
|
|
537
554
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
555
|
+
u(this, "uploadChannel");
|
|
556
|
+
u(this, "uploader");
|
|
557
|
+
u(this, "onComplete");
|
|
541
558
|
this.peerConnection = e, this._localStream = i == null ? void 0 : i.localStream, this.remoteStreamPromise = t, this.pipelineId = n, this.apiKey = a, this.dataChannel = o, this.reassembler = new N(), this.ackPacingEnabled = (i == null ? void 0 : i.ackPacingEnabled) === !0, this.uploadChannel = i == null ? void 0 : i.uploadChannel, this.onComplete = i == null ? void 0 : i.onComplete, this.dataChannel.binaryType = "arraybuffer";
|
|
542
559
|
const f = i == null ? void 0 : i.onData;
|
|
543
|
-
f && (this.dataChannel.addEventListener("message", (
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
560
|
+
f && (this.dataChannel.addEventListener("message", (l) => {
|
|
561
|
+
(async () => {
|
|
562
|
+
try {
|
|
563
|
+
if (l.data instanceof ArrayBuffer) {
|
|
564
|
+
const { frameId: s, chunkIndex: c, totalChunks: y, payload: S } = x(l.data), h = this.reassembler.processChunk(s, c, y, S);
|
|
565
|
+
if (h) {
|
|
566
|
+
let d;
|
|
567
|
+
h[0] === 31 && h[1] === 139 ? d = await J(h) : d = h;
|
|
568
|
+
const C = new TextDecoder("utf-8").decode(d), R = JSON.parse(C);
|
|
569
|
+
await Promise.resolve(f(R)), this.maybeSendAck(s);
|
|
570
|
+
}
|
|
571
|
+
} else {
|
|
572
|
+
const s = JSON.parse(l.data);
|
|
573
|
+
f(s);
|
|
552
574
|
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
f(c);
|
|
575
|
+
} catch (s) {
|
|
576
|
+
console.error("[RFWebRTC] Failed to parse data channel message:", s);
|
|
556
577
|
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}), this.dataChannel.addEventListener("error", (d) => {
|
|
561
|
-
console.error("[RFWebRTC] Data channel error:", d);
|
|
578
|
+
})();
|
|
579
|
+
}), this.dataChannel.addEventListener("error", (l) => {
|
|
580
|
+
console.error("[RFWebRTC] Data channel error:", l);
|
|
562
581
|
})), this.dataChannel.addEventListener("close", () => {
|
|
563
582
|
this.reassembler.clear(), this.onComplete && this.onComplete();
|
|
564
583
|
});
|
|
@@ -620,11 +639,11 @@ class x {
|
|
|
620
639
|
async cleanup() {
|
|
621
640
|
if (this.uploader && this.uploader.cancel(), this.reassembler.clear(), this.pipelineId && this.apiKey)
|
|
622
641
|
try {
|
|
623
|
-
await
|
|
642
|
+
await k.init({ apiKey: this.apiKey }).terminatePipeline({ pipelineId: this.pipelineId });
|
|
624
643
|
} catch (e) {
|
|
625
644
|
console.warn("[RFWebRTC] Failed to terminate pipeline:", e);
|
|
626
645
|
}
|
|
627
|
-
this.peerConnection && this.peerConnection.connectionState !== "closed" && this.peerConnection.close(), this._localStream &&
|
|
646
|
+
this.peerConnection && this.peerConnection.connectionState !== "closed" && this.peerConnection.close(), this._localStream && D(this._localStream);
|
|
628
647
|
}
|
|
629
648
|
/**
|
|
630
649
|
* Start uploading a file through the connection
|
|
@@ -644,7 +663,7 @@ class x {
|
|
|
644
663
|
async startUpload(e, t) {
|
|
645
664
|
if (!this.uploadChannel)
|
|
646
665
|
throw new Error("No upload channel available. This connection was not created for file uploads.");
|
|
647
|
-
await
|
|
666
|
+
await te(this.uploadChannel), this.uploader = new A(e, this.uploadChannel), await this.uploader.upload(t);
|
|
648
667
|
}
|
|
649
668
|
/**
|
|
650
669
|
* Cancel any ongoing file upload
|
|
@@ -705,7 +724,7 @@ class x {
|
|
|
705
724
|
}
|
|
706
725
|
}
|
|
707
726
|
}
|
|
708
|
-
async function
|
|
727
|
+
async function U({
|
|
709
728
|
source: r,
|
|
710
729
|
rtspUrl: e,
|
|
711
730
|
connector: t,
|
|
@@ -714,65 +733,65 @@ async function F({
|
|
|
714
733
|
onComplete: o,
|
|
715
734
|
onFileUploadProgress: i,
|
|
716
735
|
options: f = {},
|
|
717
|
-
hooks:
|
|
736
|
+
hooks: l
|
|
718
737
|
}) {
|
|
719
|
-
var
|
|
738
|
+
var L;
|
|
720
739
|
if (!t || typeof t.connectWrtc != "function")
|
|
721
740
|
throw new Error("connector must have a connectWrtc method");
|
|
722
|
-
const
|
|
723
|
-
let
|
|
724
|
-
if ((!
|
|
741
|
+
const s = !!e, c = !s && r instanceof File, y = !s && !c && r ? r : void 0, S = c ? r : void 0;
|
|
742
|
+
let h = n.iceServers;
|
|
743
|
+
if ((!h || h.length === 0) && t.getIceServers)
|
|
725
744
|
try {
|
|
726
745
|
const g = await t.getIceServers();
|
|
727
|
-
g && g.length > 0 && (
|
|
746
|
+
g && g.length > 0 && (h = g);
|
|
728
747
|
} catch (g) {
|
|
729
748
|
console.warn("[RFWebRTC] Failed to fetch TURN config, using defaults:", g);
|
|
730
749
|
}
|
|
731
|
-
const { pc:
|
|
750
|
+
const { pc: d, offer: p, remoteStreamPromise: C, dataChannel: R, uploadChannel: b } = await Y(
|
|
732
751
|
y,
|
|
733
752
|
S,
|
|
734
|
-
|
|
753
|
+
h,
|
|
735
754
|
e,
|
|
736
|
-
|
|
737
|
-
),
|
|
755
|
+
l
|
|
756
|
+
), _ = {
|
|
738
757
|
...n,
|
|
739
|
-
iceServers:
|
|
740
|
-
realtimeProcessing: n.realtimeProcessing ?? !
|
|
758
|
+
iceServers: h,
|
|
759
|
+
realtimeProcessing: n.realtimeProcessing ?? !c,
|
|
741
760
|
rtspUrl: e
|
|
742
|
-
},
|
|
743
|
-
{ sdp:
|
|
744
|
-
|
|
745
|
-
),
|
|
746
|
-
if (!(
|
|
747
|
-
throw console.error("[RFWebRTC] Invalid answer from server:",
|
|
748
|
-
const
|
|
749
|
-
await
|
|
750
|
-
const
|
|
751
|
-
|
|
761
|
+
}, w = await t.connectWrtc(
|
|
762
|
+
{ sdp: p.sdp, type: p.type },
|
|
763
|
+
_
|
|
764
|
+
), m = { sdp: w.sdp, type: w.type };
|
|
765
|
+
if (!(m != null && m.sdp) || !(m != null && m.type))
|
|
766
|
+
throw console.error("[RFWebRTC] Invalid answer from server:", w), new Error("connector.connectWrtc must return answer with sdp and type");
|
|
767
|
+
const v = ((L = w == null ? void 0 : w.context) == null ? void 0 : L.pipeline_id) || null;
|
|
768
|
+
await d.setRemoteDescription(m), await new Promise((g, I) => {
|
|
769
|
+
const E = () => {
|
|
770
|
+
d.connectionState === "connected" ? (d.removeEventListener("connectionstatechange", E), g()) : d.connectionState === "failed" && (d.removeEventListener("connectionstatechange", E), I(new Error("WebRTC connection failed")));
|
|
752
771
|
};
|
|
753
|
-
|
|
754
|
-
|
|
772
|
+
d.addEventListener("connectionstatechange", E), E(), setTimeout(() => {
|
|
773
|
+
d.removeEventListener("connectionstatechange", E), I(new Error("WebRTC connection timeout after 30s"));
|
|
755
774
|
}, 3e4);
|
|
756
|
-
}), y && f.disableInputStreamDownscaling !== !1 && await
|
|
757
|
-
const
|
|
758
|
-
|
|
775
|
+
}), y && f.disableInputStreamDownscaling !== !1 && await ee(d);
|
|
776
|
+
const P = t._apiKey || null, T = _.realtimeProcessing === !1, W = new B(
|
|
777
|
+
d,
|
|
759
778
|
C,
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
779
|
+
v,
|
|
780
|
+
P,
|
|
781
|
+
R,
|
|
763
782
|
{
|
|
764
783
|
localStream: y,
|
|
765
|
-
uploadChannel:
|
|
784
|
+
uploadChannel: b,
|
|
766
785
|
onData: a,
|
|
767
786
|
onComplete: o,
|
|
768
|
-
ackPacingEnabled:
|
|
787
|
+
ackPacingEnabled: T
|
|
769
788
|
}
|
|
770
789
|
);
|
|
771
|
-
return S &&
|
|
790
|
+
return S && b && W.startUpload(S, i).catch((g) => {
|
|
772
791
|
console.error("[RFWebRTC] Upload error:", g);
|
|
773
|
-
}),
|
|
792
|
+
}), W;
|
|
774
793
|
}
|
|
775
|
-
async function
|
|
794
|
+
async function re({
|
|
776
795
|
source: r,
|
|
777
796
|
connector: e,
|
|
778
797
|
wrtcParams: t,
|
|
@@ -782,7 +801,7 @@ async function te({
|
|
|
782
801
|
}) {
|
|
783
802
|
if (r instanceof File)
|
|
784
803
|
throw new Error("useStream requires a MediaStream. Use useVideoFile for File uploads.");
|
|
785
|
-
return
|
|
804
|
+
return U({
|
|
786
805
|
source: r,
|
|
787
806
|
connector: e,
|
|
788
807
|
wrtcParams: t,
|
|
@@ -791,7 +810,7 @@ async function te({
|
|
|
791
810
|
hooks: o
|
|
792
811
|
});
|
|
793
812
|
}
|
|
794
|
-
async function
|
|
813
|
+
async function ne({
|
|
795
814
|
file: r,
|
|
796
815
|
connector: e,
|
|
797
816
|
wrtcParams: t,
|
|
@@ -800,7 +819,7 @@ async function re({
|
|
|
800
819
|
onComplete: o,
|
|
801
820
|
hooks: i
|
|
802
821
|
}) {
|
|
803
|
-
return
|
|
822
|
+
return U({
|
|
804
823
|
source: r,
|
|
805
824
|
connector: e,
|
|
806
825
|
wrtcParams: {
|
|
@@ -813,7 +832,7 @@ async function re({
|
|
|
813
832
|
hooks: i
|
|
814
833
|
});
|
|
815
834
|
}
|
|
816
|
-
async function
|
|
835
|
+
async function ae({
|
|
817
836
|
rtspUrl: r,
|
|
818
837
|
connector: e,
|
|
819
838
|
wrtcParams: t,
|
|
@@ -822,7 +841,7 @@ async function ne({
|
|
|
822
841
|
}) {
|
|
823
842
|
if (!r.startsWith("rtsp://") && !r.startsWith("rtsps://"))
|
|
824
843
|
throw new Error("Invalid RTSP URL: must start with rtsp:// or rtsps://");
|
|
825
|
-
return
|
|
844
|
+
return U({
|
|
826
845
|
rtspUrl: r,
|
|
827
846
|
connector: e,
|
|
828
847
|
wrtcParams: t,
|
|
@@ -830,20 +849,20 @@ async function ne({
|
|
|
830
849
|
hooks: a
|
|
831
850
|
});
|
|
832
851
|
}
|
|
833
|
-
const
|
|
852
|
+
const ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
834
853
|
__proto__: null,
|
|
835
854
|
ChunkReassembler: N,
|
|
836
|
-
FileUploader:
|
|
837
|
-
RFWebRTCConnection:
|
|
838
|
-
parseBinaryHeader:
|
|
839
|
-
useRtspStream:
|
|
840
|
-
useStream:
|
|
841
|
-
useVideoFile:
|
|
855
|
+
FileUploader: A,
|
|
856
|
+
RFWebRTCConnection: B,
|
|
857
|
+
parseBinaryHeader: x,
|
|
858
|
+
useRtspStream: ae,
|
|
859
|
+
useStream: re,
|
|
860
|
+
useVideoFile: ne
|
|
842
861
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
843
862
|
export {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
863
|
+
k as InferenceHTTPClient,
|
|
864
|
+
oe as connectors,
|
|
865
|
+
se as streams,
|
|
866
|
+
ce as webrtc
|
|
848
867
|
};
|
|
849
868
|
//# sourceMappingURL=index.es.js.map
|