@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 CHANGED
@@ -1,26 +1,26 @@
1
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
- var I;
5
- const j = typeof process < "u" && ((I = process.env) != null && I.RF_API_BASE_URL) ? process.env.RF_API_BASE_URL : "https://api.roboflow.com", V = [
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 b {
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 = j) {
15
- l(this, "apiKey");
16
- l(this, "serverUrl");
17
- l(this, "apiBaseUrl");
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 b(e, t, n);
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: d = "image",
66
- streamOutputNames: c = [],
67
- dataOutputNames: s = [],
65
+ imageInputName: l = "image",
66
+ streamOutputNames: s = [],
67
+ dataOutputNames: c = [],
68
68
  threadPoolWorkers: y = 4,
69
69
  workflowsParameters: S = {},
70
- iceServers: p,
71
- processingTimeout: u,
72
- requestedPlan: h,
70
+ iceServers: h,
71
+ processingTimeout: d,
72
+ requestedPlan: p,
73
73
  requestedRegion: C,
74
- realtimeProcessing: E = !0,
75
- rtspUrl: R
76
- } = o, v = {
74
+ realtimeProcessing: R = !0,
75
+ rtspUrl: b,
76
+ extraPayload: _
77
+ } = o, w = {
77
78
  type: "WorkflowConfiguration",
78
- image_input_name: d,
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 ? v.workflow_specification = t : (v.workspace_name = n, v.workflow_id = a);
85
+ i ? w.workflow_specification = t : (w.workspace_name = n, w.workflow_id = a);
85
86
  const m = {
86
- workflow_configuration: v,
87
+ workflow_configuration: w,
87
88
  api_key: this.apiKey,
88
- webrtc_realtime_processing: E,
89
+ webrtc_realtime_processing: R,
89
90
  webrtc_offer: {
90
91
  sdp: e.sdp,
91
92
  type: e.type
92
93
  },
93
- webrtc_config: p ? { iceServers: p } : null,
94
- stream_output: c,
95
- data_output: s
94
+ webrtc_config: h ? { iceServers: h } : null,
95
+ stream_output: s,
96
+ data_output: c
96
97
  };
97
- u !== void 0 && (m.processing_timeout = u), h !== void 0 && (m.requested_plan = h), C !== void 0 && (m.requested_region = C), R && (m.rtsp_url = R);
98
- const w = await fetch(`${this.serverUrl}/initialise_webrtc_worker`, {
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 (!w.ok) {
104
- const T = await w.text().catch(() => "");
105
- throw new Error(`initialise_webrtc_worker failed (${w.status}): ${T}`);
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 w.json();
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 ie = {
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 = b.init({ apiKey: r, serverUrl: t, apiBaseUrl: n });
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 O(r) {
335
+ function D(r) {
334
336
  r && (r.getTracks().forEach((e) => e.stop()), console.log("[RFStreams] Stream stopped"));
335
337
  }
336
- const oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
338
+ const se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
337
339
  __proto__: null,
338
- stopStream: O,
340
+ stopStream: D,
339
341
  useCamera: $
340
- }, Symbol.toStringTag, { value: "Module" })), k = 49152, M = 262144, z = 10;
341
- function H(r) {
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 D {
346
+ class A {
345
347
  constructor(e, t) {
346
- l(this, "file");
347
- l(this, "channel");
348
- l(this, "totalChunks");
349
- l(this, "cancelled", !1);
350
- this.file = e, this.channel = t, this.totalChunks = Math.ceil(e.size / k);
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 * k, o = Math.min(a + k, t), i = this.file.slice(a, o), f = new Uint8Array(await i.arrayBuffer()), d = new ArrayBuffer(8 + f.length), c = new DataView(d);
371
- for (c.setUint32(0, n, !0), c.setUint32(4, this.totalChunks, !0), new Uint8Array(d, 8).set(f); this.channel.bufferedAmount > M; ) {
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 H(z);
376
+ await G(z);
375
377
  }
376
- this.channel.send(d), e && e(o, t);
378
+ this.channel.send(l), e && e(o, t);
377
379
  }
378
380
  }
379
381
  }
380
- const J = 12;
382
+ const H = 12;
381
383
  class N {
382
384
  constructor() {
383
- l(this, "pendingFrames", /* @__PURE__ */ new Map());
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((c, s) => c + s.length, 0), f = new Uint8Array(i);
398
- let d = 0;
399
- for (let c = 0; c < n; c++) {
400
- const s = o.chunks.get(c);
401
- f.set(s, d), d += s.length;
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 A(r) {
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, J);
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 G(r, e = 6e3) {
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 Z(r) {
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 Q = [
467
+ const X = [
451
468
  { urls: ["stun:stun.l.google.com:19302"] }
452
469
  ];
453
- async function X(r, e, t, n, a) {
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 c = t ?? Q, s = new RTCPeerConnection({
457
- iceServers: c
473
+ const s = t ?? X, c = new RTCPeerConnection({
474
+ iceServers: s
458
475
  });
459
- a != null && a.onPeerConnectionCreated && await a.onPeerConnectionCreated(s);
476
+ a != null && a.onPeerConnectionCreated && await a.onPeerConnectionCreated(c);
460
477
  try {
461
- s.addTransceiver("video", { direction: "recvonly" });
462
- } catch (h) {
463
- console.warn("[RFWebRTC] Could not add transceiver:", h);
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 h of r.getVideoTracks()) {
467
- const C = s.addTrack(h, r);
468
- a != null && a.onTrackAdded && await a.onTrackAdded(h, C, s);
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 = Z(s), S = s.createDataChannel("inference", {
487
+ const y = Q(c), S = c.createDataChannel("inference", {
471
488
  ordered: !0
472
489
  });
473
- let p;
474
- e && (p = s.createDataChannel("video_upload"));
475
- let u = await s.createOffer();
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 h = await a.onOfferCreated(u);
478
- h && (u = h);
494
+ const p = await a.onOfferCreated(d);
495
+ p && (d = p);
479
496
  }
480
- return await s.setLocalDescription(u), await G(s), {
481
- pc: s,
482
- offer: s.localDescription,
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: p
502
+ uploadChannel: h
486
503
  };
487
504
  }
488
- async function Y(r) {
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 ee(r, e = 3e4) {
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 x {
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
- l(this, "peerConnection");
523
- l(this, "_localStream");
524
- l(this, "remoteStreamPromise");
525
- l(this, "pipelineId");
526
- l(this, "apiKey");
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
- l(this, "dataChannel");
532
- l(this, "reassembler");
533
- l(this, "ackPacingEnabled");
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
- l(this, "uploadChannel");
539
- l(this, "uploader");
540
- l(this, "onComplete");
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", (d) => {
544
- try {
545
- if (d.data instanceof ArrayBuffer) {
546
- const { frameId: c, chunkIndex: s, totalChunks: y, payload: S } = A(d.data), p = this.reassembler.processChunk(c, s, y, S);
547
- if (p) {
548
- const h = new TextDecoder("utf-8").decode(p), C = JSON.parse(h);
549
- Promise.resolve(f(C)).finally(() => {
550
- this.maybeSendAck(c);
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
- } else {
554
- const c = JSON.parse(d.data);
555
- f(c);
575
+ } catch (s) {
576
+ console.error("[RFWebRTC] Failed to parse data channel message:", s);
556
577
  }
557
- } catch (c) {
558
- console.error("[RFWebRTC] Failed to parse data channel message:", c);
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 b.init({ apiKey: this.apiKey }).terminatePipeline({ pipelineId: this.pipelineId });
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 && O(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 ee(this.uploadChannel), this.uploader = new D(e, this.uploadChannel), await this.uploader.upload(t);
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 F({
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: d
736
+ hooks: l
718
737
  }) {
719
- var W;
738
+ var L;
720
739
  if (!t || typeof t.connectWrtc != "function")
721
740
  throw new Error("connector must have a connectWrtc method");
722
- const c = !!e, s = !c && r instanceof File, y = !c && !s && r ? r : void 0, S = s ? r : void 0;
723
- let p = n.iceServers;
724
- if ((!p || p.length === 0) && t.getIceServers)
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 && (p = g, console.log("[RFWebRTC] Using TURN servers from connector"));
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: u, offer: h, remoteStreamPromise: C, dataChannel: E, uploadChannel: R } = await X(
750
+ const { pc: d, offer: p, remoteStreamPromise: C, dataChannel: R, uploadChannel: b } = await Y(
732
751
  y,
733
752
  S,
734
- p,
753
+ h,
735
754
  e,
736
- d
737
- ), v = {
755
+ l
756
+ ), _ = {
738
757
  ...n,
739
- iceServers: p,
740
- realtimeProcessing: n.realtimeProcessing ?? !s,
758
+ iceServers: h,
759
+ realtimeProcessing: n.realtimeProcessing ?? !c,
741
760
  rtspUrl: e
742
- }, m = await t.connectWrtc(
743
- { sdp: h.sdp, type: h.type },
744
- v
745
- ), w = { sdp: m.sdp, type: m.type };
746
- if (!(w != null && w.sdp) || !(w != null && w.type))
747
- throw console.error("[RFWebRTC] Invalid answer from server:", m), new Error("connector.connectWrtc must return answer with sdp and type");
748
- const U = ((W = m == null ? void 0 : m.context) == null ? void 0 : W.pipeline_id) || null;
749
- await u.setRemoteDescription(w), await new Promise((g, L) => {
750
- const _ = () => {
751
- u.connectionState === "connected" ? (u.removeEventListener("connectionstatechange", _), g()) : u.connectionState === "failed" && (u.removeEventListener("connectionstatechange", _), L(new Error("WebRTC connection failed")));
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
- u.addEventListener("connectionstatechange", _), _(), setTimeout(() => {
754
- u.removeEventListener("connectionstatechange", _), L(new Error("WebRTC connection timeout after 30s"));
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 Y(u);
757
- const T = t._apiKey || null, B = v.realtimeProcessing === !1, P = new x(
758
- u,
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
- U,
761
- T,
762
- E,
779
+ v,
780
+ P,
781
+ R,
763
782
  {
764
783
  localStream: y,
765
- uploadChannel: R,
784
+ uploadChannel: b,
766
785
  onData: a,
767
786
  onComplete: o,
768
- ackPacingEnabled: B
787
+ ackPacingEnabled: T
769
788
  }
770
789
  );
771
- return S && R && P.startUpload(S, i).catch((g) => {
790
+ return S && b && W.startUpload(S, i).catch((g) => {
772
791
  console.error("[RFWebRTC] Upload error:", g);
773
- }), P;
792
+ }), W;
774
793
  }
775
- async function te({
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 F({
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 re({
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 F({
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 ne({
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 F({
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 se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
852
+ const ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
834
853
  __proto__: null,
835
854
  ChunkReassembler: N,
836
- FileUploader: D,
837
- RFWebRTCConnection: x,
838
- parseBinaryHeader: A,
839
- useRtspStream: ne,
840
- useStream: te,
841
- useVideoFile: re
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
- b as InferenceHTTPClient,
845
- ie as connectors,
846
- oe as streams,
847
- se as webrtc
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