@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 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 };
@@ -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;AAGvD,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,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 A = Object.defineProperty;
2
- var q = (r, e, t) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var l = (r, e, t) => q(r, typeof e != "symbol" ? e + "" : 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 K = typeof process < "u" && ((L = process.env) != null && L.RF_API_BASE_URL) ? process.env.RF_API_BASE_URL : "https://api.roboflow.com", B = [
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 E {
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 E(e, t);
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, u = !!(n && o);
58
- if (!i && !u)
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 && u)
60
+ if (i && p)
61
61
  throw new Error("Provide either workflowSpec OR (workspaceName + workflowId), not both");
62
62
  const {
63
- imageInputName: c = "image",
64
- streamOutputNames: s = [],
65
- dataOutputNames: h = ["string"],
63
+ imageInputName: d = "image",
64
+ streamOutputNames: c = [],
65
+ dataOutputNames: s = [],
66
66
  threadPoolWorkers: y = 4,
67
- workflowsParameters: f = {},
68
- iceServers: d,
69
- processingTimeout: m,
70
- requestedPlan: S,
71
- requestedRegion: v,
72
- realtimeProcessing: _ = !0,
73
- rtspUrl: k
74
- } = a, w = {
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: c,
77
- workflows_parameters: f,
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 ? w.workflow_specification = t : (w.workspace_name = n, w.workflow_id = o);
83
- const p = {
84
- workflow_configuration: w,
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: d ? { iceServers: d } : null,
92
- stream_output: s,
93
- data_output: h
91
+ webrtc_config: h ? { iceServers: h } : null,
92
+ stream_output: c,
93
+ data_output: s
94
94
  };
95
- m !== void 0 && (p.processing_timeout = m), S !== void 0 && (p.requested_plan = S), v !== void 0 && (p.requested_region = v), k && (p.rtsp_url = k);
96
- const R = await fetch(`${this.serverUrl}/initialise_webrtc_worker`, {
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(p)
99
+ body: JSON.stringify(m)
100
100
  });
101
- if (!R.ok) {
102
- const b = await R.text().catch(() => "");
103
- throw new Error(`initialise_webrtc_worker failed (${R.status}): ${b}`);
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 R.json();
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 (!B.includes(this.serverUrl))
135
+ if (!j.includes(this.serverUrl))
136
136
  return null;
137
137
  try {
138
138
  const e = await fetch(
139
- `${K}/webrtc_turn_config?api_key=${this.apiKey}`,
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 ne = {
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 = E.init({ apiKey: r, serverUrl: t });
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 j(r = { video: !0 }) {
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 P(r) {
331
+ function O(r) {
332
332
  r && (r.getTracks().forEach((e) => e.stop()), console.log("[RFStreams] Stream stopped"));
333
333
  }
334
- const ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
334
+ const oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
335
335
  __proto__: null,
336
- stopStream: P,
337
- useCamera: j
338
- }, Symbol.toStringTag, { value: "Module" })), T = 49152, V = 262144, $ = 10;
339
- function M(r) {
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 O {
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 / T);
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 * T, a = Math.min(o + T, t), i = this.file.slice(o, a), u = new Uint8Array(await i.arrayBuffer()), c = new ArrayBuffer(8 + u.length), s = new DataView(c);
369
- for (s.setUint32(0, n, !0), s.setUint32(4, this.totalChunks, !0), new Uint8Array(c, 8).set(u); this.channel.bufferedAmount > V; ) {
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(c), e && e(a, t);
374
+ this.channel.send(d), e && e(a, t);
375
375
  }
376
376
  }
377
377
  }
378
- const z = 12;
379
- class D {
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((s, h) => s + h.length, 0), u = new Uint8Array(i);
396
- let c = 0;
397
- for (let s = 0; s < n; s++) {
398
- const h = a.chunks.get(s);
399
- u.set(h, c), c += h.length;
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), u;
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 N(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, z);
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 H(r, e = 6e3) {
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 G(r) {
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 J = [
448
+ const Z = [
449
449
  { urls: ["stun:stun.l.google.com:19302"] }
450
450
  ];
451
- async function Z(r, e, t, n) {
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 ?? J, s = new RTCPeerConnection({
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 (m) {
460
- console.warn("[RFWebRTC] Could not add transceiver:", m);
460
+ } catch (f) {
461
+ console.warn("[RFWebRTC] Could not add transceiver:", f);
461
462
  }
462
- r && r.getVideoTracks().forEach((m) => {
463
- try {
464
- m.contentHint = "detail";
465
- } catch {
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
- s.addTrack(m, r);
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 f;
473
- e && (f = s.createDataChannel("video_upload"));
474
- const d = await s.createOffer();
475
- return await s.setLocalDescription(d), await H(s), {
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: h,
479
- dataChannel: y,
480
- uploadChannel: f
481
+ remoteStreamPromise: y,
482
+ dataChannel: S,
483
+ uploadChannel: h
481
484
  };
482
485
  }
483
- async function Q(r) {
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 X(r, e = 3e4) {
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
- l(this, "pc");
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.pc = e, this._localStream = i == null ? void 0 : i.localStream, this.remoteStreamPromise = t, this.pipelineId = n, this.apiKey = o, this.dataChannel = a, this.reassembler = new D(), this.uploadChannel = i == null ? void 0 : i.uploadChannel, this.onComplete = i == null ? void 0 : i.onComplete, this.dataChannel.binaryType = "arraybuffer";
524
- const u = i == null ? void 0 : i.onData;
525
- u && (this.dataChannel.addEventListener("message", (c) => {
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 (c.data instanceof ArrayBuffer) {
528
- const { frameId: s, chunkIndex: h, totalChunks: y, payload: f } = N(c.data), d = this.reassembler.processChunk(s, h, y, f);
529
- if (d) {
530
- const S = new TextDecoder("utf-8").decode(d), v = JSON.parse(S);
531
- u(v);
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 s = JSON.parse(c.data);
535
- u(s);
549
+ const c = JSON.parse(d.data);
550
+ p(c);
536
551
  }
537
- } catch (s) {
538
- console.error("[RFWebRTC] Failed to parse data channel message:", s);
552
+ } catch (c) {
553
+ console.error("[RFWebRTC] Failed to parse data channel message:", c);
539
554
  }
540
- }), this.dataChannel.addEventListener("error", (c) => {
541
- console.error("[RFWebRTC] Data channel error:", c);
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 E.init({ apiKey: this.apiKey }).terminatePipeline({ pipelineId: this.pipelineId });
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.pc && this.pc.connectionState !== "closed" && this.pc.close(), this._localStream && P(this._localStream);
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 X(this.uploadChannel), this.uploader = new O(e, this.uploadChannel), await this.uploader.upload(t);
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: u = {}
704
+ options: p = {},
705
+ hooks: d
690
706
  }) {
691
- var W;
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, h = !c && !s && r ? r : void 0, y = s ? r : void 0;
695
- let f = n.iceServers;
696
- if ((!f || f.length === 0) && t.getIceServers)
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 && (f = g, console.log("[RFWebRTC] Using TURN servers from connector"));
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: d, offer: m, remoteStreamPromise: S, dataChannel: v, uploadChannel: _ } = await Z(
704
- h,
719
+ const { pc: u, offer: f, remoteStreamPromise: C, dataChannel: b, uploadChannel: R } = await Q(
705
720
  y,
706
- f,
707
- e
708
- ), k = {
721
+ S,
722
+ h,
723
+ e,
724
+ d
725
+ ), v = {
709
726
  ...n,
710
- iceServers: f,
727
+ iceServers: h,
711
728
  realtimeProcessing: n.realtimeProcessing ?? !s,
712
729
  rtspUrl: e
713
- }, w = await t.connectWrtc(
714
- { sdp: m.sdp, type: m.type },
715
- k
716
- ), p = { sdp: w.sdp, type: w.type };
717
- if (!(p != null && p.sdp) || !(p != null && p.type))
718
- throw console.error("[RFWebRTC] Invalid answer from server:", w), new Error("connector.connectWrtc must return answer with sdp and type");
719
- const R = ((W = w == null ? void 0 : w.context) == null ? void 0 : W.pipeline_id) || null;
720
- await d.setRemoteDescription(p), await new Promise((g, I) => {
721
- const C = () => {
722
- d.connectionState === "connected" ? (d.removeEventListener("connectionstatechange", C), g()) : d.connectionState === "failed" && (d.removeEventListener("connectionstatechange", C), I(new Error("WebRTC connection failed")));
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
- d.addEventListener("connectionstatechange", C), C(), setTimeout(() => {
725
- d.removeEventListener("connectionstatechange", C), I(new Error("WebRTC connection timeout after 30s"));
741
+ u.addEventListener("connectionstatechange", _), _(), setTimeout(() => {
742
+ u.removeEventListener("connectionstatechange", _), I(new Error("WebRTC connection timeout after 30s"));
726
743
  }, 3e4);
727
- }), h && u.disableInputStreamDownscaling !== !1 && await Q(d);
728
- const U = t._apiKey || null, b = new x(
729
- d,
730
- S,
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
- v,
749
+ E,
750
+ b,
734
751
  {
735
- localStream: h,
736
- uploadChannel: _,
752
+ localStream: y,
753
+ uploadChannel: R,
737
754
  onData: o,
738
755
  onComplete: a
739
756
  }
740
757
  );
741
- return y && _ && b.startUpload(y, i).catch((g) => {
758
+ return S && R && W.startUpload(S, i).catch((g) => {
742
759
  console.error("[RFWebRTC] Upload error:", g);
743
- }), b;
760
+ }), W;
744
761
  }
745
- async function Y({
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 ee({
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 te({
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 oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
820
+ const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
798
821
  __proto__: null,
799
- ChunkReassembler: D,
800
- FileUploader: O,
822
+ ChunkReassembler: N,
823
+ FileUploader: D,
801
824
  RFWebRTCConnection: x,
802
- parseBinaryHeader: N,
803
- useRtspStream: te,
804
- useStream: Y,
805
- useVideoFile: ee
825
+ parseBinaryHeader: A,
826
+ useRtspStream: re,
827
+ useStream: ee,
828
+ useVideoFile: te
806
829
  }, Symbol.toStringTag, { value: "Module" }));
807
830
  export {
808
- E as InferenceHTTPClient,
809
- ne as connectors,
810
- ae as streams,
811
- oe as webrtc
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