@eyepop.ai/eyepop 0.11.0 → 0.12.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.mjs CHANGED
@@ -8915,7 +8915,7 @@ var AbstractJob = class {
8915
8915
  return Promise.reject("abstract class");
8916
8916
  }
8917
8917
  start(done, status) {
8918
- this._responseStream = new Promise(async (resolve2, reject) => {
8918
+ this._responseStream = new Promise(async (resolve, reject) => {
8919
8919
  try {
8920
8920
  let retries = 1;
8921
8921
  while (true) {
@@ -8944,7 +8944,7 @@ var AbstractJob = class {
8944
8944
  reject(`response body is empty`);
8945
8945
  break;
8946
8946
  } else {
8947
- resolve2(response.body);
8947
+ resolve(response.body);
8948
8948
  break;
8949
8949
  }
8950
8950
  } catch (error) {
@@ -9480,7 +9480,7 @@ var Whip = class _Whip extends WebRtcBase {
9480
9480
  });
9481
9481
  this._pc = pc;
9482
9482
  pc.onicecandidate = (evt) => this.onLocalCandidate(evt);
9483
- return new Promise(async (resolve2, reject) => {
9483
+ return new Promise(async (resolve, reject) => {
9484
9484
  pc.oniceconnectionstatechange = () => {
9485
9485
  switch (pc.iceConnectionState) {
9486
9486
  case "failed":
@@ -9488,7 +9488,7 @@ var Whip = class _Whip extends WebRtcBase {
9488
9488
  reject(`peer connection: ${pc.iceConnectionState}`);
9489
9489
  break;
9490
9490
  case "connected":
9491
- resolve2(this);
9491
+ resolve(this);
9492
9492
  break;
9493
9493
  }
9494
9494
  };
@@ -9605,44 +9605,22 @@ var Whip = class _Whip extends WebRtcBase {
9605
9605
  };
9606
9606
 
9607
9607
  // src/shims/local_file.ts
9608
- var resolve;
9608
+ var resolvePath;
9609
9609
  if ("document" in globalThis && "implementation" in globalThis.document) {
9610
- const isFileLike = (value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number";
9611
- resolve = async (params) => {
9612
- if (params.file) {
9613
- if (isFileLike(params.file)) {
9614
- params = {
9615
- mimeType: params.file.type,
9616
- file: params.file
9617
- };
9618
- return params;
9619
- }
9620
- }
9610
+ resolvePath = async (source) => {
9621
9611
  throw new DOMException("resolving a path to a file is not supported in browser");
9622
9612
  };
9623
9613
  } else {
9624
- resolve = async (params) => {
9625
- if (params.file) {
9626
- return params;
9627
- }
9614
+ resolvePath = async (source) => {
9628
9615
  const mime = require_mime_types();
9629
- const fs = __require("fs");
9630
- let mimeType;
9631
- let stream;
9632
- if (params.filePath) {
9633
- if (params.mimeType) {
9634
- mimeType = params.mimeType;
9635
- } else {
9636
- mimeType = mime.lookup(params.filePath) || void 0;
9637
- }
9638
- stream = fs.createReadStream(params.filePath);
9639
- }
9640
- params = {
9641
- filePath: params.filePath,
9642
- mimeType,
9643
- file: stream
9616
+ const filehandle = __require("fs/promises");
9617
+ const fd = await filehandle.open(source.path, "r");
9618
+ const stream = fd.createReadStream();
9619
+ const mimeType = mime.lookup(source.path) || "application/octet-stream";
9620
+ return {
9621
+ stream,
9622
+ mimeType
9644
9623
  };
9645
- return params;
9646
9624
  };
9647
9625
  }
9648
9626
 
@@ -9756,59 +9734,126 @@ var Endpoint = class {
9756
9734
  if (!this._baseUrl || !this._client) {
9757
9735
  return Promise.reject("endpoint not connected, use connect() before ingress()");
9758
9736
  }
9759
- const job = new Whip(stream, async () => {
9737
+ const whip = new Whip(stream, async () => {
9760
9738
  return this.session();
9761
9739
  }, this._client, this._requestLogger);
9762
- return job.start();
9740
+ return whip.start();
9741
+ }
9742
+ async process(source) {
9743
+ if (source.file !== void 0) {
9744
+ return this.uploadFile(source);
9745
+ } else if (source.stream !== void 0) {
9746
+ return this.uploadStream(source);
9747
+ } else if (source.path !== void 0) {
9748
+ return this.uploadPath(source);
9749
+ } else if (source.url !== void 0) {
9750
+ return this.loadFrom(source);
9751
+ } else if (source.ingressId !== void 0) {
9752
+ return this.loadLiveIngress(source);
9753
+ } else {
9754
+ return Promise.reject("unknown source type");
9755
+ }
9763
9756
  }
9764
- async upload(params) {
9757
+ async uploadFile(source) {
9765
9758
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9766
9759
  return Promise.reject("endpoint not connected, use connect() before upload()");
9767
9760
  }
9768
- params = await resolve(params);
9769
- if (!params.mimeType) {
9770
- return Promise.reject("upload for streams requires a mimeType");
9761
+ await this._limit.acquire();
9762
+ try {
9763
+ this.updateState();
9764
+ const job = new UploadJob(source.file, source.file.type, async () => {
9765
+ return this.session();
9766
+ }, this._client, this._requestLogger);
9767
+ return job.start(() => {
9768
+ this.jobDone(job);
9769
+ }, (statusCode) => {
9770
+ this.jobStatus(job, statusCode);
9771
+ });
9772
+ } catch (e) {
9773
+ this._limit.release();
9774
+ throw e;
9775
+ }
9776
+ }
9777
+ async uploadStream(source) {
9778
+ if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9779
+ return Promise.reject("endpoint not connected, use connect() before upload()");
9771
9780
  }
9772
9781
  await this._limit.acquire();
9773
- this.updateState();
9774
- const job = new UploadJob(params.file, params.mimeType, async () => {
9775
- return this.session();
9776
- }, this._client, this._requestLogger);
9777
- return job.start(() => {
9778
- this.jobDone(job);
9779
- }, (statusCode) => {
9780
- this.jobStatus(job, statusCode);
9781
- });
9782
+ try {
9783
+ this.updateState();
9784
+ const job = new UploadJob(source.stream, source.mimeType, async () => {
9785
+ return this.session();
9786
+ }, this._client, this._requestLogger);
9787
+ return job.start(() => {
9788
+ this.jobDone(job);
9789
+ }, (statusCode) => {
9790
+ this.jobStatus(job, statusCode);
9791
+ });
9792
+ } catch (e) {
9793
+ this._limit.release();
9794
+ throw e;
9795
+ }
9782
9796
  }
9783
- async loadFrom(location) {
9797
+ async uploadPath(source) {
9798
+ if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9799
+ throw new Error("endpoint not connected, use connect() before process()");
9800
+ }
9801
+ await this._limit.acquire();
9802
+ try {
9803
+ this.updateState();
9804
+ const streamSource = await resolvePath(source);
9805
+ const job = new UploadJob(streamSource.stream, streamSource.mimeType, async () => {
9806
+ return this.session();
9807
+ }, this._client, this._requestLogger);
9808
+ return job.start(() => {
9809
+ this.jobDone(job);
9810
+ }, (statusCode) => {
9811
+ this.jobStatus(job, statusCode);
9812
+ });
9813
+ } catch (e) {
9814
+ this._limit.release();
9815
+ throw e;
9816
+ }
9817
+ }
9818
+ async loadFrom(source) {
9784
9819
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9785
9820
  throw new Error("endpoint not connected, use connect() before loadFrom()");
9786
9821
  }
9787
9822
  await this._limit.acquire();
9788
- this.updateState();
9789
- const job = new LoadFromJob(location, async () => {
9790
- return this.session();
9791
- }, this._client, this._requestLogger);
9792
- return job.start(() => {
9793
- this.jobDone(job);
9794
- }, (statusCode) => {
9795
- this.jobStatus(job, statusCode);
9796
- });
9823
+ try {
9824
+ this.updateState();
9825
+ const job = new LoadFromJob(source.url, async () => {
9826
+ return this.session();
9827
+ }, this._client, this._requestLogger);
9828
+ return job.start(() => {
9829
+ this.jobDone(job);
9830
+ }, (statusCode) => {
9831
+ this.jobStatus(job, statusCode);
9832
+ });
9833
+ } catch (e) {
9834
+ this._limit.release();
9835
+ throw e;
9836
+ }
9797
9837
  }
9798
- async loadLiveIngress(ingressId) {
9838
+ async loadLiveIngress(source) {
9799
9839
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9800
9840
  throw new Error("endpoint not connected, use connect() before loadLiveIngress()");
9801
9841
  }
9802
9842
  await this._limit.acquire();
9803
- this.updateState();
9804
- const job = new LoadLiveIngressJob(ingressId, async () => {
9805
- return this.session();
9806
- }, this._client, this._requestLogger);
9807
- return job.start(() => {
9808
- this.jobDone(job);
9809
- }, (statusCode) => {
9810
- this.jobStatus(job, statusCode);
9811
- });
9843
+ try {
9844
+ this.updateState();
9845
+ const job = new LoadLiveIngressJob(source.ingressId, async () => {
9846
+ return this.session();
9847
+ }, this._client, this._requestLogger);
9848
+ return job.start(() => {
9849
+ this.jobDone(job);
9850
+ }, (statusCode) => {
9851
+ this.jobStatus(job, statusCode);
9852
+ });
9853
+ } catch (e) {
9854
+ this._limit.release();
9855
+ throw e;
9856
+ }
9812
9857
  }
9813
9858
  // noinspection TypeScriptValidateTypes
9814
9859
  async connect() {