@roboflow/inference-sdk 0.1.9 → 0.1.10
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.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +181 -158
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/webrtc-types.d.ts +63 -0
- package/dist/webrtc-types.d.ts.map +1 -1
- package/dist/webrtc.d.ts +26 -8
- package/dist/webrtc.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides WebRTC streaming, HTTP client, and camera utilities.
|
|
6
6
|
*/
|
|
7
7
|
export * from './inference-api';
|
|
8
|
-
export type { WebRTCOutputData } from './webrtc-types';
|
|
8
|
+
export type { WebRTCOutputData, WebRTCHooks } from './webrtc-types';
|
|
9
9
|
import * as webrtc from './webrtc';
|
|
10
10
|
import * as streams from './streams';
|
|
11
11
|
export { webrtc, streams };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var l = (r, e, t) =>
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var K = (r, e, t) => e in r ? q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var l = (r, e, t) => K(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
var L;
|
|
5
|
-
const
|
|
5
|
+
const B = typeof process < "u" && ((L = process.env) != null && L.RF_API_BASE_URL) ? process.env.RF_API_BASE_URL : "https://api.roboflow.com", j = [
|
|
6
6
|
"https://serverless.roboflow.com"
|
|
7
7
|
];
|
|
8
|
-
class
|
|
8
|
+
class T {
|
|
9
9
|
/**
|
|
10
10
|
* @private
|
|
11
11
|
* Use InferenceHTTPClient.init() instead
|
|
@@ -18,7 +18,7 @@ class E {
|
|
|
18
18
|
static init({ apiKey: e, serverUrl: t }) {
|
|
19
19
|
if (!e)
|
|
20
20
|
throw new Error("apiKey is required");
|
|
21
|
-
return new
|
|
21
|
+
return new T(e, t);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Initialize a WebRTC worker pipeline
|
|
@@ -54,55 +54,55 @@ class E {
|
|
|
54
54
|
}) {
|
|
55
55
|
if (!e || !e.sdp || !e.type)
|
|
56
56
|
throw new Error("offer with sdp and type is required");
|
|
57
|
-
const i = !!t,
|
|
58
|
-
if (!i && !
|
|
57
|
+
const i = !!t, p = !!(n && o);
|
|
58
|
+
if (!i && !p)
|
|
59
59
|
throw new Error("Either workflowSpec OR (workspaceName + workflowId) is required");
|
|
60
|
-
if (i &&
|
|
60
|
+
if (i && p)
|
|
61
61
|
throw new Error("Provide either workflowSpec OR (workspaceName + workflowId), not both");
|
|
62
62
|
const {
|
|
63
|
-
imageInputName:
|
|
64
|
-
streamOutputNames:
|
|
65
|
-
dataOutputNames:
|
|
63
|
+
imageInputName: d = "image",
|
|
64
|
+
streamOutputNames: c = [],
|
|
65
|
+
dataOutputNames: s = [],
|
|
66
66
|
threadPoolWorkers: y = 4,
|
|
67
|
-
workflowsParameters:
|
|
68
|
-
iceServers:
|
|
69
|
-
processingTimeout:
|
|
70
|
-
requestedPlan:
|
|
71
|
-
requestedRegion:
|
|
72
|
-
realtimeProcessing:
|
|
73
|
-
rtspUrl:
|
|
74
|
-
} = a,
|
|
67
|
+
workflowsParameters: S = {},
|
|
68
|
+
iceServers: h,
|
|
69
|
+
processingTimeout: u,
|
|
70
|
+
requestedPlan: f,
|
|
71
|
+
requestedRegion: C,
|
|
72
|
+
realtimeProcessing: b = !0,
|
|
73
|
+
rtspUrl: R
|
|
74
|
+
} = a, v = {
|
|
75
75
|
type: "WorkflowConfiguration",
|
|
76
|
-
image_input_name:
|
|
77
|
-
workflows_parameters:
|
|
76
|
+
image_input_name: d,
|
|
77
|
+
workflows_parameters: S,
|
|
78
78
|
workflows_thread_pool_workers: y,
|
|
79
79
|
cancel_thread_pool_tasks_on_exit: !0,
|
|
80
80
|
video_metadata_input_name: "video_metadata"
|
|
81
81
|
};
|
|
82
|
-
i ?
|
|
83
|
-
const
|
|
84
|
-
workflow_configuration:
|
|
82
|
+
i ? v.workflow_specification = t : (v.workspace_name = n, v.workflow_id = o);
|
|
83
|
+
const m = {
|
|
84
|
+
workflow_configuration: v,
|
|
85
85
|
api_key: this.apiKey,
|
|
86
|
-
webrtc_realtime_processing:
|
|
86
|
+
webrtc_realtime_processing: b,
|
|
87
87
|
webrtc_offer: {
|
|
88
88
|
sdp: e.sdp,
|
|
89
89
|
type: e.type
|
|
90
90
|
},
|
|
91
|
-
webrtc_config:
|
|
92
|
-
stream_output:
|
|
93
|
-
data_output:
|
|
91
|
+
webrtc_config: h ? { iceServers: h } : null,
|
|
92
|
+
stream_output: c,
|
|
93
|
+
data_output: s
|
|
94
94
|
};
|
|
95
|
-
|
|
96
|
-
const
|
|
95
|
+
u !== void 0 && (m.processing_timeout = u), f !== void 0 && (m.requested_plan = f), C !== void 0 && (m.requested_region = C), R && (m.rtsp_url = R);
|
|
96
|
+
const w = await fetch(`${this.serverUrl}/initialise_webrtc_worker`, {
|
|
97
97
|
method: "POST",
|
|
98
98
|
headers: { "Content-Type": "application/json" },
|
|
99
|
-
body: JSON.stringify(
|
|
99
|
+
body: JSON.stringify(m)
|
|
100
100
|
});
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
103
|
-
throw new Error(`initialise_webrtc_worker failed (${
|
|
101
|
+
if (!w.ok) {
|
|
102
|
+
const E = await w.text().catch(() => "");
|
|
103
|
+
throw new Error(`initialise_webrtc_worker failed (${w.status}): ${E}`);
|
|
104
104
|
}
|
|
105
|
-
return await
|
|
105
|
+
return await w.json();
|
|
106
106
|
}
|
|
107
107
|
async terminatePipeline({ pipelineId: e }) {
|
|
108
108
|
if (!e)
|
|
@@ -132,11 +132,11 @@ class E {
|
|
|
132
132
|
* ```
|
|
133
133
|
*/
|
|
134
134
|
async fetchTurnConfig() {
|
|
135
|
-
if (!
|
|
135
|
+
if (!j.includes(this.serverUrl))
|
|
136
136
|
return null;
|
|
137
137
|
try {
|
|
138
138
|
const e = await fetch(
|
|
139
|
-
`${
|
|
139
|
+
`${B}/webrtc_turn_config?api_key=${this.apiKey}`,
|
|
140
140
|
{
|
|
141
141
|
method: "GET",
|
|
142
142
|
headers: { "Content-Type": "application/json" }
|
|
@@ -164,7 +164,7 @@ class E {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
const
|
|
167
|
+
const ae = {
|
|
168
168
|
/**
|
|
169
169
|
* Create a connector that uses API key directly
|
|
170
170
|
*
|
|
@@ -188,7 +188,7 @@ const ne = {
|
|
|
188
188
|
typeof window < "u" && console.warn(
|
|
189
189
|
"[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"
|
|
190
190
|
);
|
|
191
|
-
const n =
|
|
191
|
+
const n = T.init({ apiKey: r, serverUrl: t });
|
|
192
192
|
return {
|
|
193
193
|
connectWrtc: async (o, a) => (console.debug("wrtcParams", a), await n.initializeWebrtcWorker({
|
|
194
194
|
offer: o,
|
|
@@ -317,7 +317,7 @@ const ne = {
|
|
|
317
317
|
};
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
|
-
async function
|
|
320
|
+
async function V(r = { video: !0 }) {
|
|
321
321
|
try {
|
|
322
322
|
console.log("[RFStreams] requesting with", r);
|
|
323
323
|
const e = await navigator.mediaDevices.getUserMedia(r);
|
|
@@ -328,24 +328,24 @@ async function j(r = { video: !0 }) {
|
|
|
328
328
|
return console.log("[RFStreams] fallback stream", t.getVideoTracks().map((n) => ({ id: n.id, label: n.label }))), t;
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
function
|
|
331
|
+
function O(r) {
|
|
332
332
|
r && (r.getTracks().forEach((e) => e.stop()), console.log("[RFStreams] Stream stopped"));
|
|
333
333
|
}
|
|
334
|
-
const
|
|
334
|
+
const oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
335
335
|
__proto__: null,
|
|
336
|
-
stopStream:
|
|
337
|
-
useCamera:
|
|
338
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
339
|
-
function
|
|
336
|
+
stopStream: O,
|
|
337
|
+
useCamera: V
|
|
338
|
+
}, Symbol.toStringTag, { value: "Module" })), k = 49152, $ = 262144, M = 10;
|
|
339
|
+
function z(r) {
|
|
340
340
|
return new Promise((e) => setTimeout(e, r));
|
|
341
341
|
}
|
|
342
|
-
class
|
|
342
|
+
class D {
|
|
343
343
|
constructor(e, t) {
|
|
344
344
|
l(this, "file");
|
|
345
345
|
l(this, "channel");
|
|
346
346
|
l(this, "totalChunks");
|
|
347
347
|
l(this, "cancelled", !1);
|
|
348
|
-
this.file = e, this.channel = t, this.totalChunks = Math.ceil(e.size /
|
|
348
|
+
this.file = e, this.channel = t, this.totalChunks = Math.ceil(e.size / k);
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
351
|
* Cancel the upload
|
|
@@ -365,18 +365,18 @@ class O {
|
|
|
365
365
|
throw new Error("Upload cancelled");
|
|
366
366
|
if (this.channel.readyState !== "open")
|
|
367
367
|
throw new Error("Video upload interrupted");
|
|
368
|
-
const o = n *
|
|
369
|
-
for (
|
|
368
|
+
const o = n * k, a = Math.min(o + k, t), i = this.file.slice(o, a), p = new Uint8Array(await i.arrayBuffer()), d = new ArrayBuffer(8 + p.length), c = new DataView(d);
|
|
369
|
+
for (c.setUint32(0, n, !0), c.setUint32(4, this.totalChunks, !0), new Uint8Array(d, 8).set(p); this.channel.bufferedAmount > $; ) {
|
|
370
370
|
if (this.channel.readyState !== "open")
|
|
371
371
|
throw new Error("Video upload interrupted");
|
|
372
|
-
await M
|
|
372
|
+
await z(M);
|
|
373
373
|
}
|
|
374
|
-
this.channel.send(
|
|
374
|
+
this.channel.send(d), e && e(a, t);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
|
-
const
|
|
379
|
-
class
|
|
378
|
+
const H = 12;
|
|
379
|
+
class N {
|
|
380
380
|
constructor() {
|
|
381
381
|
l(this, "pendingFrames", /* @__PURE__ */ new Map());
|
|
382
382
|
}
|
|
@@ -392,13 +392,13 @@ class D {
|
|
|
392
392
|
});
|
|
393
393
|
const a = this.pendingFrames.get(e);
|
|
394
394
|
if (a.chunks.set(t, o), a.chunks.size === n) {
|
|
395
|
-
const i = Array.from(a.chunks.values()).reduce((
|
|
396
|
-
let
|
|
397
|
-
for (let
|
|
398
|
-
const
|
|
399
|
-
|
|
395
|
+
const i = Array.from(a.chunks.values()).reduce((c, s) => c + s.length, 0), p = new Uint8Array(i);
|
|
396
|
+
let d = 0;
|
|
397
|
+
for (let c = 0; c < n; c++) {
|
|
398
|
+
const s = a.chunks.get(c);
|
|
399
|
+
p.set(s, d), d += s.length;
|
|
400
400
|
}
|
|
401
|
-
return this.pendingFrames.delete(e),
|
|
401
|
+
return this.pendingFrames.delete(e), p;
|
|
402
402
|
}
|
|
403
403
|
return null;
|
|
404
404
|
}
|
|
@@ -409,11 +409,11 @@ class D {
|
|
|
409
409
|
this.pendingFrames.clear();
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
function
|
|
413
|
-
const e = new DataView(r), t = e.getUint32(0, !0), n = e.getUint32(4, !0), o = e.getUint32(8, !0), a = new Uint8Array(r,
|
|
412
|
+
function A(r) {
|
|
413
|
+
const e = new DataView(r), t = e.getUint32(0, !0), n = e.getUint32(4, !0), o = e.getUint32(8, !0), a = new Uint8Array(r, H);
|
|
414
414
|
return { frameId: t, chunkIndex: n, totalChunks: o, payload: a };
|
|
415
415
|
}
|
|
416
|
-
async function
|
|
416
|
+
async function G(r, e = 6e3) {
|
|
417
417
|
if (r.iceGatheringState === "complete") return;
|
|
418
418
|
let t = !1;
|
|
419
419
|
const n = (o) => {
|
|
@@ -438,49 +438,52 @@ async function H(r, e = 6e3) {
|
|
|
438
438
|
r.removeEventListener("icecandidate", n);
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
|
-
function
|
|
441
|
+
function J(r) {
|
|
442
442
|
return new Promise((e) => {
|
|
443
443
|
r.addEventListener("track", (t) => {
|
|
444
444
|
t.streams && t.streams[0] && e(t.streams[0]);
|
|
445
445
|
});
|
|
446
446
|
});
|
|
447
447
|
}
|
|
448
|
-
const
|
|
448
|
+
const Z = [
|
|
449
449
|
{ urls: ["stun:stun.l.google.com:19302"] }
|
|
450
450
|
];
|
|
451
|
-
async function
|
|
451
|
+
async function Q(r, e, t, n, o) {
|
|
452
452
|
if ([!!r, !!e, !!n].filter(Boolean).length !== 1)
|
|
453
453
|
throw new Error("Exactly one of localStream, file, or rtspUrl must be provided");
|
|
454
|
-
const c = t ??
|
|
454
|
+
const c = t ?? Z, s = new RTCPeerConnection({
|
|
455
455
|
iceServers: c
|
|
456
456
|
});
|
|
457
|
+
o != null && o.onPeerConnectionCreated && await o.onPeerConnectionCreated(s);
|
|
457
458
|
try {
|
|
458
459
|
s.addTransceiver("video", { direction: "recvonly" });
|
|
459
|
-
} catch (
|
|
460
|
-
console.warn("[RFWebRTC] Could not add transceiver:",
|
|
460
|
+
} catch (f) {
|
|
461
|
+
console.warn("[RFWebRTC] Could not add transceiver:", f);
|
|
461
462
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
if (r)
|
|
464
|
+
for (const f of r.getVideoTracks()) {
|
|
465
|
+
const C = s.addTrack(f, r);
|
|
466
|
+
o != null && o.onTrackAdded && await o.onTrackAdded(f, C, s);
|
|
466
467
|
}
|
|
467
|
-
|
|
468
|
-
});
|
|
469
|
-
const h = G(s), y = s.createDataChannel("inference", {
|
|
468
|
+
const y = J(s), S = s.createDataChannel("inference", {
|
|
470
469
|
ordered: !0
|
|
471
470
|
});
|
|
472
|
-
let
|
|
473
|
-
e && (
|
|
474
|
-
|
|
475
|
-
|
|
471
|
+
let h;
|
|
472
|
+
e && (h = s.createDataChannel("video_upload"));
|
|
473
|
+
let u = await s.createOffer();
|
|
474
|
+
if (o != null && o.onOfferCreated) {
|
|
475
|
+
const f = await o.onOfferCreated(u);
|
|
476
|
+
f && (u = f);
|
|
477
|
+
}
|
|
478
|
+
return await s.setLocalDescription(u), await G(s), {
|
|
476
479
|
pc: s,
|
|
477
480
|
offer: s.localDescription,
|
|
478
|
-
remoteStreamPromise:
|
|
479
|
-
dataChannel:
|
|
480
|
-
uploadChannel:
|
|
481
|
+
remoteStreamPromise: y,
|
|
482
|
+
dataChannel: S,
|
|
483
|
+
uploadChannel: h
|
|
481
484
|
};
|
|
482
485
|
}
|
|
483
|
-
async function
|
|
486
|
+
async function X(r) {
|
|
484
487
|
const e = r.getSenders().find((n) => n.track && n.track.kind === "video");
|
|
485
488
|
if (!e) return;
|
|
486
489
|
const t = e.getParameters();
|
|
@@ -491,7 +494,7 @@ async function Q(r) {
|
|
|
491
494
|
console.warn("[RFWebRTC] Failed to set encoding parameters:", n);
|
|
492
495
|
}
|
|
493
496
|
}
|
|
494
|
-
function
|
|
497
|
+
function Y(r, e = 3e4) {
|
|
495
498
|
return new Promise((t, n) => {
|
|
496
499
|
if (r.readyState === "open") {
|
|
497
500
|
t();
|
|
@@ -510,35 +513,47 @@ function X(r, e = 3e4) {
|
|
|
510
513
|
class x {
|
|
511
514
|
/** @private */
|
|
512
515
|
constructor(e, t, n, o, a, i) {
|
|
513
|
-
|
|
516
|
+
/**
|
|
517
|
+
* The underlying RTCPeerConnection.
|
|
518
|
+
* Exposed for advanced use cases like getting stats or accessing senders.
|
|
519
|
+
*/
|
|
520
|
+
l(this, "peerConnection");
|
|
514
521
|
l(this, "_localStream");
|
|
515
522
|
l(this, "remoteStreamPromise");
|
|
516
523
|
l(this, "pipelineId");
|
|
517
524
|
l(this, "apiKey");
|
|
525
|
+
/**
|
|
526
|
+
* The data channel used for receiving inference results.
|
|
527
|
+
* Exposed for advanced use cases.
|
|
528
|
+
*/
|
|
518
529
|
l(this, "dataChannel");
|
|
519
530
|
l(this, "reassembler");
|
|
531
|
+
/**
|
|
532
|
+
* The data channel used for uploading video files (only available in file upload mode).
|
|
533
|
+
* Exposed for advanced use cases.
|
|
534
|
+
*/
|
|
520
535
|
l(this, "uploadChannel");
|
|
521
536
|
l(this, "uploader");
|
|
522
537
|
l(this, "onComplete");
|
|
523
|
-
this.
|
|
524
|
-
const
|
|
525
|
-
|
|
538
|
+
this.peerConnection = e, this._localStream = i == null ? void 0 : i.localStream, this.remoteStreamPromise = t, this.pipelineId = n, this.apiKey = o, this.dataChannel = a, this.reassembler = new N(), this.uploadChannel = i == null ? void 0 : i.uploadChannel, this.onComplete = i == null ? void 0 : i.onComplete, this.dataChannel.binaryType = "arraybuffer";
|
|
539
|
+
const p = i == null ? void 0 : i.onData;
|
|
540
|
+
p && (this.dataChannel.addEventListener("message", (d) => {
|
|
526
541
|
try {
|
|
527
|
-
if (
|
|
528
|
-
const { frameId:
|
|
529
|
-
if (
|
|
530
|
-
const
|
|
531
|
-
|
|
542
|
+
if (d.data instanceof ArrayBuffer) {
|
|
543
|
+
const { frameId: c, chunkIndex: s, totalChunks: y, payload: S } = A(d.data), h = this.reassembler.processChunk(c, s, y, S);
|
|
544
|
+
if (h) {
|
|
545
|
+
const f = new TextDecoder("utf-8").decode(h), C = JSON.parse(f);
|
|
546
|
+
p(C);
|
|
532
547
|
}
|
|
533
548
|
} else {
|
|
534
|
-
const
|
|
535
|
-
|
|
549
|
+
const c = JSON.parse(d.data);
|
|
550
|
+
p(c);
|
|
536
551
|
}
|
|
537
|
-
} catch (
|
|
538
|
-
console.error("[RFWebRTC] Failed to parse data channel message:",
|
|
552
|
+
} catch (c) {
|
|
553
|
+
console.error("[RFWebRTC] Failed to parse data channel message:", c);
|
|
539
554
|
}
|
|
540
|
-
}), this.dataChannel.addEventListener("error", (
|
|
541
|
-
console.error("[RFWebRTC] Data channel error:",
|
|
555
|
+
}), this.dataChannel.addEventListener("error", (d) => {
|
|
556
|
+
console.error("[RFWebRTC] Data channel error:", d);
|
|
542
557
|
})), this.dataChannel.addEventListener("close", () => {
|
|
543
558
|
this.reassembler.clear(), this.onComplete && this.onComplete();
|
|
544
559
|
});
|
|
@@ -593,11 +608,11 @@ class x {
|
|
|
593
608
|
async cleanup() {
|
|
594
609
|
if (this.uploader && this.uploader.cancel(), this.reassembler.clear(), this.pipelineId && this.apiKey)
|
|
595
610
|
try {
|
|
596
|
-
await
|
|
611
|
+
await T.init({ apiKey: this.apiKey }).terminatePipeline({ pipelineId: this.pipelineId });
|
|
597
612
|
} catch (e) {
|
|
598
613
|
console.warn("[RFWebRTC] Failed to terminate pipeline:", e);
|
|
599
614
|
}
|
|
600
|
-
this.
|
|
615
|
+
this.peerConnection && this.peerConnection.connectionState !== "closed" && this.peerConnection.close(), this._localStream && O(this._localStream);
|
|
601
616
|
}
|
|
602
617
|
/**
|
|
603
618
|
* Start uploading a file through the connection
|
|
@@ -617,7 +632,7 @@ class x {
|
|
|
617
632
|
async startUpload(e, t) {
|
|
618
633
|
if (!this.uploadChannel)
|
|
619
634
|
throw new Error("No upload channel available. This connection was not created for file uploads.");
|
|
620
|
-
await
|
|
635
|
+
await Y(this.uploadChannel), this.uploader = new D(e, this.uploadChannel), await this.uploader.upload(t);
|
|
621
636
|
}
|
|
622
637
|
/**
|
|
623
638
|
* Cancel any ongoing file upload
|
|
@@ -686,68 +701,71 @@ async function F({
|
|
|
686
701
|
onData: o,
|
|
687
702
|
onComplete: a,
|
|
688
703
|
onFileUploadProgress: i,
|
|
689
|
-
options:
|
|
704
|
+
options: p = {},
|
|
705
|
+
hooks: d
|
|
690
706
|
}) {
|
|
691
|
-
var
|
|
707
|
+
var P;
|
|
692
708
|
if (!t || typeof t.connectWrtc != "function")
|
|
693
709
|
throw new Error("connector must have a connectWrtc method");
|
|
694
|
-
const c = !!e, s = !c && r instanceof File,
|
|
695
|
-
let
|
|
696
|
-
if ((!
|
|
710
|
+
const c = !!e, s = !c && r instanceof File, y = !c && !s && r ? r : void 0, S = s ? r : void 0;
|
|
711
|
+
let h = n.iceServers;
|
|
712
|
+
if ((!h || h.length === 0) && t.getIceServers)
|
|
697
713
|
try {
|
|
698
714
|
const g = await t.getIceServers();
|
|
699
|
-
g && g.length > 0 && (
|
|
715
|
+
g && g.length > 0 && (h = g, console.log("[RFWebRTC] Using TURN servers from connector"));
|
|
700
716
|
} catch (g) {
|
|
701
717
|
console.warn("[RFWebRTC] Failed to fetch TURN config, using defaults:", g);
|
|
702
718
|
}
|
|
703
|
-
const { pc:
|
|
704
|
-
h,
|
|
719
|
+
const { pc: u, offer: f, remoteStreamPromise: C, dataChannel: b, uploadChannel: R } = await Q(
|
|
705
720
|
y,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
721
|
+
S,
|
|
722
|
+
h,
|
|
723
|
+
e,
|
|
724
|
+
d
|
|
725
|
+
), v = {
|
|
709
726
|
...n,
|
|
710
|
-
iceServers:
|
|
727
|
+
iceServers: h,
|
|
711
728
|
realtimeProcessing: n.realtimeProcessing ?? !s,
|
|
712
729
|
rtspUrl: e
|
|
713
|
-
},
|
|
714
|
-
{ sdp:
|
|
715
|
-
|
|
716
|
-
),
|
|
717
|
-
if (!(
|
|
718
|
-
throw console.error("[RFWebRTC] Invalid answer from server:",
|
|
719
|
-
const
|
|
720
|
-
await
|
|
721
|
-
const
|
|
722
|
-
|
|
730
|
+
}, m = await t.connectWrtc(
|
|
731
|
+
{ sdp: f.sdp, type: f.type },
|
|
732
|
+
v
|
|
733
|
+
), w = { sdp: m.sdp, type: m.type };
|
|
734
|
+
if (!(w != null && w.sdp) || !(w != null && w.type))
|
|
735
|
+
throw console.error("[RFWebRTC] Invalid answer from server:", m), new Error("connector.connectWrtc must return answer with sdp and type");
|
|
736
|
+
const U = ((P = m == null ? void 0 : m.context) == null ? void 0 : P.pipeline_id) || null;
|
|
737
|
+
await u.setRemoteDescription(w), await new Promise((g, I) => {
|
|
738
|
+
const _ = () => {
|
|
739
|
+
u.connectionState === "connected" ? (u.removeEventListener("connectionstatechange", _), g()) : u.connectionState === "failed" && (u.removeEventListener("connectionstatechange", _), I(new Error("WebRTC connection failed")));
|
|
723
740
|
};
|
|
724
|
-
|
|
725
|
-
|
|
741
|
+
u.addEventListener("connectionstatechange", _), _(), setTimeout(() => {
|
|
742
|
+
u.removeEventListener("connectionstatechange", _), I(new Error("WebRTC connection timeout after 30s"));
|
|
726
743
|
}, 3e4);
|
|
727
|
-
}),
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
R,
|
|
744
|
+
}), y && p.disableInputStreamDownscaling !== !1 && await X(u);
|
|
745
|
+
const E = t._apiKey || null, W = new x(
|
|
746
|
+
u,
|
|
747
|
+
C,
|
|
732
748
|
U,
|
|
733
|
-
|
|
749
|
+
E,
|
|
750
|
+
b,
|
|
734
751
|
{
|
|
735
|
-
localStream:
|
|
736
|
-
uploadChannel:
|
|
752
|
+
localStream: y,
|
|
753
|
+
uploadChannel: R,
|
|
737
754
|
onData: o,
|
|
738
755
|
onComplete: a
|
|
739
756
|
}
|
|
740
757
|
);
|
|
741
|
-
return
|
|
758
|
+
return S && R && W.startUpload(S, i).catch((g) => {
|
|
742
759
|
console.error("[RFWebRTC] Upload error:", g);
|
|
743
|
-
}),
|
|
760
|
+
}), W;
|
|
744
761
|
}
|
|
745
|
-
async function
|
|
762
|
+
async function ee({
|
|
746
763
|
source: r,
|
|
747
764
|
connector: e,
|
|
748
765
|
wrtcParams: t,
|
|
749
766
|
onData: n,
|
|
750
|
-
options: o = {}
|
|
767
|
+
options: o = {},
|
|
768
|
+
hooks: a
|
|
751
769
|
}) {
|
|
752
770
|
if (r instanceof File)
|
|
753
771
|
throw new Error("useStream requires a MediaStream. Use useVideoFile for File uploads.");
|
|
@@ -756,16 +774,18 @@ async function Y({
|
|
|
756
774
|
connector: e,
|
|
757
775
|
wrtcParams: t,
|
|
758
776
|
onData: n,
|
|
759
|
-
options: o
|
|
777
|
+
options: o,
|
|
778
|
+
hooks: a
|
|
760
779
|
});
|
|
761
780
|
}
|
|
762
|
-
async function
|
|
781
|
+
async function te({
|
|
763
782
|
file: r,
|
|
764
783
|
connector: e,
|
|
765
784
|
wrtcParams: t,
|
|
766
785
|
onData: n,
|
|
767
786
|
onUploadProgress: o,
|
|
768
|
-
onComplete: a
|
|
787
|
+
onComplete: a,
|
|
788
|
+
hooks: i
|
|
769
789
|
}) {
|
|
770
790
|
return F({
|
|
771
791
|
source: r,
|
|
@@ -776,14 +796,16 @@ async function ee({
|
|
|
776
796
|
},
|
|
777
797
|
onData: n,
|
|
778
798
|
onComplete: a,
|
|
779
|
-
onFileUploadProgress: o
|
|
799
|
+
onFileUploadProgress: o,
|
|
800
|
+
hooks: i
|
|
780
801
|
});
|
|
781
802
|
}
|
|
782
|
-
async function
|
|
803
|
+
async function re({
|
|
783
804
|
rtspUrl: r,
|
|
784
805
|
connector: e,
|
|
785
806
|
wrtcParams: t,
|
|
786
|
-
onData: n
|
|
807
|
+
onData: n,
|
|
808
|
+
hooks: o
|
|
787
809
|
}) {
|
|
788
810
|
if (!r.startsWith("rtsp://") && !r.startsWith("rtsps://"))
|
|
789
811
|
throw new Error("Invalid RTSP URL: must start with rtsp:// or rtsps://");
|
|
@@ -791,23 +813,24 @@ async function te({
|
|
|
791
813
|
rtspUrl: r,
|
|
792
814
|
connector: e,
|
|
793
815
|
wrtcParams: t,
|
|
794
|
-
onData: n
|
|
816
|
+
onData: n,
|
|
817
|
+
hooks: o
|
|
795
818
|
});
|
|
796
819
|
}
|
|
797
|
-
const
|
|
820
|
+
const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
798
821
|
__proto__: null,
|
|
799
|
-
ChunkReassembler:
|
|
800
|
-
FileUploader:
|
|
822
|
+
ChunkReassembler: N,
|
|
823
|
+
FileUploader: D,
|
|
801
824
|
RFWebRTCConnection: x,
|
|
802
|
-
parseBinaryHeader:
|
|
803
|
-
useRtspStream:
|
|
804
|
-
useStream:
|
|
805
|
-
useVideoFile:
|
|
825
|
+
parseBinaryHeader: A,
|
|
826
|
+
useRtspStream: re,
|
|
827
|
+
useStream: ee,
|
|
828
|
+
useVideoFile: te
|
|
806
829
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
807
830
|
export {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
831
|
+
T as InferenceHTTPClient,
|
|
832
|
+
ae as connectors,
|
|
833
|
+
oe as streams,
|
|
834
|
+
ie as webrtc
|
|
812
835
|
};
|
|
813
836
|
//# sourceMappingURL=index.es.js.map
|