@eyepop.ai/eyepop 1.13.2 → 1.14.1
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/README.md +13 -2
- package/dist/eyepop.index.d.mts +27 -7
- package/dist/eyepop.index.d.ts +27 -7
- package/dist/eyepop.index.js +597 -32
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +596 -32
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +1 -1
package/dist/eyepop.index.mjs
CHANGED
|
@@ -8928,7 +8928,7 @@ var AbstractJob = class {
|
|
|
8928
8928
|
reject(`upload error ${response.status}: ${await response.text()}`);
|
|
8929
8929
|
break;
|
|
8930
8930
|
} else if (!response.body) {
|
|
8931
|
-
reject(
|
|
8931
|
+
reject("response body is empty");
|
|
8932
8932
|
break;
|
|
8933
8933
|
} else {
|
|
8934
8934
|
resolve(response.body);
|
|
@@ -8962,10 +8962,11 @@ var UploadJob = class extends AbstractJob {
|
|
|
8962
8962
|
get [Symbol.toStringTag]() {
|
|
8963
8963
|
return "uploadJob";
|
|
8964
8964
|
}
|
|
8965
|
-
constructor(stream, mimeType, videoMode, params, getSession, client, requestLogger) {
|
|
8965
|
+
constructor(stream, mimeType, size, videoMode, params, getSession, client, requestLogger) {
|
|
8966
8966
|
super(params, getSession, client, requestLogger);
|
|
8967
8967
|
this._uploadStream = stream;
|
|
8968
8968
|
this._mimeType = mimeType;
|
|
8969
|
+
this._size = size;
|
|
8969
8970
|
this._videoMode = videoMode;
|
|
8970
8971
|
this._needsFullDuplex = !client.isFullDuplex() && mimeType.startsWith("video/") && videoMode == "stream" /* STREAM */;
|
|
8971
8972
|
}
|
|
@@ -8982,7 +8983,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
8982
8983
|
const videoModeQuery = this._videoMode ? `&videoMode=${this._videoMode}` : "";
|
|
8983
8984
|
const postUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=queue&processing=async&sourceId=${event.source_id}${videoModeQuery}`;
|
|
8984
8985
|
if (this._params) {
|
|
8985
|
-
this._requestLogger.debug(
|
|
8986
|
+
this._requestLogger.debug(`before POST ${postUrl} with multipart body because of params`);
|
|
8986
8987
|
const params = JSON.stringify(this._params);
|
|
8987
8988
|
const paramBlob = new Blob([params], { type: "application/json" });
|
|
8988
8989
|
const formData = new FormData();
|
|
@@ -9002,12 +9003,15 @@ var UploadJob = class extends AbstractJob {
|
|
|
9002
9003
|
duplex: "half"
|
|
9003
9004
|
});
|
|
9004
9005
|
} else {
|
|
9005
|
-
this._requestLogger.debug(
|
|
9006
|
+
this._requestLogger.debug(`before POST ${postUrl} with stream as body`);
|
|
9006
9007
|
const headers = {
|
|
9007
9008
|
...session.authenticationHeaders(),
|
|
9008
9009
|
Accept: "application/jsonl",
|
|
9009
9010
|
"Content-Type": this._mimeType
|
|
9010
9011
|
};
|
|
9012
|
+
if (this._size) {
|
|
9013
|
+
headers["Content-Length"] = `${this._size}`;
|
|
9014
|
+
}
|
|
9011
9015
|
request = this._client.fetch(postUrl, {
|
|
9012
9016
|
headers,
|
|
9013
9017
|
method: "POST",
|
|
@@ -9019,12 +9023,12 @@ var UploadJob = class extends AbstractJob {
|
|
|
9019
9023
|
}
|
|
9020
9024
|
request.then(async (value) => {
|
|
9021
9025
|
if (value.status != 204) {
|
|
9022
|
-
this._requestLogger.debug(
|
|
9026
|
+
this._requestLogger.debug(`unexpected status ${value.status} (${await value.text()}) for POST ${postUrl}`);
|
|
9023
9027
|
}
|
|
9024
9028
|
}).catch((reason) => {
|
|
9025
|
-
this._requestLogger.debug(
|
|
9029
|
+
this._requestLogger.debug(`error ${reason} for POST ${postUrl}`);
|
|
9026
9030
|
}).finally(() => {
|
|
9027
|
-
this._requestLogger.debug(
|
|
9031
|
+
this._requestLogger.debug(`after POST ${postUrl}`);
|
|
9028
9032
|
});
|
|
9029
9033
|
}
|
|
9030
9034
|
return Promise.resolve();
|
|
@@ -9032,7 +9036,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9032
9036
|
async startJob() {
|
|
9033
9037
|
const session = await this._getSession();
|
|
9034
9038
|
if (!session.baseUrl) {
|
|
9035
|
-
return Promise.reject("session.baseUrl must not
|
|
9039
|
+
return Promise.reject("session.baseUrl must not be null");
|
|
9036
9040
|
}
|
|
9037
9041
|
let response;
|
|
9038
9042
|
if (this._needsFullDuplex) {
|
|
@@ -9041,7 +9045,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9041
9045
|
...session.authenticationHeaders(),
|
|
9042
9046
|
Accept: "application/jsonl"
|
|
9043
9047
|
};
|
|
9044
|
-
this._requestLogger.debug(
|
|
9048
|
+
this._requestLogger.debug(`before POST ${prepareUrl} to prepare full duplex upload`);
|
|
9045
9049
|
response = await this._client.fetch(prepareUrl, {
|
|
9046
9050
|
headers,
|
|
9047
9051
|
method: "POST",
|
|
@@ -9049,12 +9053,12 @@ var UploadJob = class extends AbstractJob {
|
|
|
9049
9053
|
// @ts-ignore
|
|
9050
9054
|
duplex: "half"
|
|
9051
9055
|
});
|
|
9052
|
-
this._requestLogger.debug(
|
|
9056
|
+
this._requestLogger.debug(`after POST ${prepareUrl} to prepare full duplex upload ${response.status} ${response.statusText}`);
|
|
9053
9057
|
} else {
|
|
9054
9058
|
const videoModeQuery = this._videoMode ? `&videoMode=${this._videoMode}` : "";
|
|
9055
9059
|
const postUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=queue&processing=sync${videoModeQuery}`;
|
|
9056
9060
|
if (this._params) {
|
|
9057
|
-
this._requestLogger.debug(
|
|
9061
|
+
this._requestLogger.debug(`before POST ${postUrl} with multipart body because of params`);
|
|
9058
9062
|
const params = JSON.stringify(this._params);
|
|
9059
9063
|
const paramBlob = new Blob([params], { type: "application/json" });
|
|
9060
9064
|
const formData = new FormData();
|
|
@@ -9073,14 +9077,17 @@ var UploadJob = class extends AbstractJob {
|
|
|
9073
9077
|
// @ts-ignore
|
|
9074
9078
|
duplex: "half"
|
|
9075
9079
|
});
|
|
9076
|
-
this._requestLogger.debug(
|
|
9080
|
+
this._requestLogger.debug(`after POST ${postUrl} with multipart body because of params)`);
|
|
9077
9081
|
} else {
|
|
9078
|
-
this._requestLogger.debug(
|
|
9082
|
+
this._requestLogger.debug(`before POST ${postUrl} with stream as body`);
|
|
9079
9083
|
const headers = {
|
|
9080
9084
|
...session.authenticationHeaders(),
|
|
9081
9085
|
Accept: "application/jsonl",
|
|
9082
9086
|
"Content-Type": this._mimeType
|
|
9083
9087
|
};
|
|
9088
|
+
if (this._size) {
|
|
9089
|
+
headers["Content-Length"] = `${this._size}`;
|
|
9090
|
+
}
|
|
9084
9091
|
response = await this._client.fetch(postUrl, {
|
|
9085
9092
|
headers,
|
|
9086
9093
|
method: "POST",
|
|
@@ -9089,7 +9096,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9089
9096
|
// @ts-ignore
|
|
9090
9097
|
duplex: "half"
|
|
9091
9098
|
});
|
|
9092
|
-
this._requestLogger.debug(
|
|
9099
|
+
this._requestLogger.debug(`after POST ${postUrl} with stream as body`);
|
|
9093
9100
|
}
|
|
9094
9101
|
}
|
|
9095
9102
|
return response;
|
|
@@ -9591,17 +9598,85 @@ var WebrtcWhep = class extends WebrtcBase {
|
|
|
9591
9598
|
// shims/local_file.ts
|
|
9592
9599
|
var resolvePath;
|
|
9593
9600
|
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
9594
|
-
resolvePath = async (source) => {
|
|
9601
|
+
resolvePath = async (source, logger) => {
|
|
9595
9602
|
throw new DOMException("resolving a path to a file is not supported in browser");
|
|
9596
9603
|
};
|
|
9597
9604
|
} else if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
+
let RNFSName = "react-native-fs";
|
|
9606
|
+
let RNFS;
|
|
9607
|
+
let RNFSLoadError;
|
|
9608
|
+
try {
|
|
9609
|
+
RNFS = __require(RNFSName);
|
|
9610
|
+
} catch (e) {
|
|
9611
|
+
RNFSLoadError = e;
|
|
9612
|
+
}
|
|
9613
|
+
let EFSName = "expo-file-system";
|
|
9614
|
+
let EFS;
|
|
9615
|
+
let EFSLoadError;
|
|
9616
|
+
try {
|
|
9617
|
+
EFS = __require(EFSName);
|
|
9618
|
+
} catch (e) {
|
|
9619
|
+
EFSLoadError = e;
|
|
9620
|
+
}
|
|
9621
|
+
resolvePath = async (source, logger) => {
|
|
9622
|
+
if (RNFS?.read !== void 0) {
|
|
9623
|
+
logger.debug("Using react-native-fs to read local file");
|
|
9624
|
+
const bufferSize = 1024 * 1024;
|
|
9625
|
+
let pos = 0;
|
|
9626
|
+
let eof = false;
|
|
9627
|
+
const stream = new ReadableStream({
|
|
9628
|
+
async pull(controller) {
|
|
9629
|
+
if (eof) {
|
|
9630
|
+
return;
|
|
9631
|
+
}
|
|
9632
|
+
const chunkAsB64 = await RNFS.read(source.path, bufferSize, pos, "base64");
|
|
9633
|
+
if (chunkAsB64.length > 0) {
|
|
9634
|
+
const chunk = Buffer.from(chunkAsB64, "base64");
|
|
9635
|
+
controller.enqueue(chunk);
|
|
9636
|
+
pos += chunk.length;
|
|
9637
|
+
} else {
|
|
9638
|
+
eof = true;
|
|
9639
|
+
controller.close();
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9642
|
+
});
|
|
9643
|
+
return {
|
|
9644
|
+
stream,
|
|
9645
|
+
size: (await RNFS.stat(source.path)).size,
|
|
9646
|
+
mimeType: source.mimeType || "image/*"
|
|
9647
|
+
};
|
|
9648
|
+
} else if (EFS?.readAsStringAsync !== void 0) {
|
|
9649
|
+
logger.debug("Using expo-file-system to read local file");
|
|
9650
|
+
const bufferSize = 1024 * 1024;
|
|
9651
|
+
let pos = 0;
|
|
9652
|
+
let eof = false;
|
|
9653
|
+
const stream = new ReadableStream({
|
|
9654
|
+
async pull(controller) {
|
|
9655
|
+
if (eof) {
|
|
9656
|
+
return;
|
|
9657
|
+
}
|
|
9658
|
+
const chunkAsB64 = await EFS.readAsStringAsync(`file://${source.path}`, {
|
|
9659
|
+
length: bufferSize,
|
|
9660
|
+
position: pos,
|
|
9661
|
+
encoding: "base64"
|
|
9662
|
+
});
|
|
9663
|
+
if (chunkAsB64) {
|
|
9664
|
+
const chunk = Buffer.from(chunkAsB64, "base64");
|
|
9665
|
+
controller.enqueue(chunk);
|
|
9666
|
+
pos += chunk.length;
|
|
9667
|
+
} else {
|
|
9668
|
+
eof = true;
|
|
9669
|
+
controller.close();
|
|
9670
|
+
}
|
|
9671
|
+
}
|
|
9672
|
+
});
|
|
9673
|
+
return {
|
|
9674
|
+
stream,
|
|
9675
|
+
size: (await EFS.getInfoAsync(`file://${source.path}`)).size,
|
|
9676
|
+
mimeType: source.mimeType || "image/*"
|
|
9677
|
+
};
|
|
9678
|
+
}
|
|
9679
|
+
return Promise.reject(`Could not load '${RNFSName}' (reason" ${RNFSLoadError}) or '${EFSName}' (reason" ${EFSLoadError}), include either of those packages in your application to enable uploads via PathSource - or provide the stream itself via StreamSource.`);
|
|
9605
9680
|
};
|
|
9606
9681
|
} else {
|
|
9607
9682
|
let iteratorToStream = function(iterator) {
|
|
@@ -9622,7 +9697,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9622
9697
|
yield chunk;
|
|
9623
9698
|
}
|
|
9624
9699
|
}
|
|
9625
|
-
resolvePath = async (source) => {
|
|
9700
|
+
resolvePath = async (source, logger) => {
|
|
9626
9701
|
const mime = require_mime_types();
|
|
9627
9702
|
const filehandle = __require("node:fs/promises");
|
|
9628
9703
|
const fd = await filehandle.open(source.path, "r");
|
|
@@ -9638,6 +9713,403 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9638
9713
|
}
|
|
9639
9714
|
var iteratorToStream2;
|
|
9640
9715
|
|
|
9716
|
+
// shims/rn_http_header_parser.ts
|
|
9717
|
+
var startLine = /^[A-Z_]+(\/\d\.\d)? /;
|
|
9718
|
+
var requestLine = /^([A-Z_]+) (.+) [A-Z]+\/(\d)\.(\d)$/;
|
|
9719
|
+
var statusLine = /^[A-Z]+\/(\d)\.(\d) (\d{3}) (.*)$/;
|
|
9720
|
+
function parseHttpHeader(lines, onlyHeaders) {
|
|
9721
|
+
var line = lines[0];
|
|
9722
|
+
var match;
|
|
9723
|
+
if (onlyHeaders && startLine.test(line)) {
|
|
9724
|
+
return parseHeaders(lines);
|
|
9725
|
+
} else if ((match = line.match(requestLine)) !== null) {
|
|
9726
|
+
return {
|
|
9727
|
+
method: match[1],
|
|
9728
|
+
url: match[2],
|
|
9729
|
+
version: { major: parseInt(match[3], 10), minor: parseInt(match[4], 10) },
|
|
9730
|
+
headers: parseHeaders(lines)
|
|
9731
|
+
};
|
|
9732
|
+
} else if ((match = line.match(statusLine)) !== null) {
|
|
9733
|
+
return {
|
|
9734
|
+
version: { major: parseInt(match[1], 10), minor: parseInt(match[2], 10) },
|
|
9735
|
+
statusCode: parseInt(match[3], 10),
|
|
9736
|
+
statusMessage: match[4],
|
|
9737
|
+
headers: parseHeaders(lines)
|
|
9738
|
+
};
|
|
9739
|
+
} else {
|
|
9740
|
+
return parseHeaders(lines);
|
|
9741
|
+
}
|
|
9742
|
+
}
|
|
9743
|
+
function parseHeaders(lines) {
|
|
9744
|
+
var headers = {};
|
|
9745
|
+
var i = 0;
|
|
9746
|
+
var line = lines[i];
|
|
9747
|
+
var index, name, value;
|
|
9748
|
+
if (startLine.test(line)) {
|
|
9749
|
+
line = line[++i];
|
|
9750
|
+
}
|
|
9751
|
+
while (line) {
|
|
9752
|
+
if (line[0] === " " || line[0] === " ") {
|
|
9753
|
+
value += " " + line.trim();
|
|
9754
|
+
i++;
|
|
9755
|
+
if (i < lines.length) {
|
|
9756
|
+
line = lines[i];
|
|
9757
|
+
} else {
|
|
9758
|
+
line = "";
|
|
9759
|
+
}
|
|
9760
|
+
continue;
|
|
9761
|
+
}
|
|
9762
|
+
if (name && value) {
|
|
9763
|
+
addHeaderLine(name, value, headers);
|
|
9764
|
+
}
|
|
9765
|
+
index = line.indexOf(":");
|
|
9766
|
+
name = line.substr(0, index);
|
|
9767
|
+
value = line.substr(index + 1).trim();
|
|
9768
|
+
i++;
|
|
9769
|
+
if (i < lines.length) {
|
|
9770
|
+
line = lines[i];
|
|
9771
|
+
} else {
|
|
9772
|
+
line = "";
|
|
9773
|
+
}
|
|
9774
|
+
}
|
|
9775
|
+
if (name && value) {
|
|
9776
|
+
addHeaderLine(name, value, headers);
|
|
9777
|
+
}
|
|
9778
|
+
return headers;
|
|
9779
|
+
}
|
|
9780
|
+
function addHeaderLine(field, value, dest) {
|
|
9781
|
+
field = field.toLowerCase();
|
|
9782
|
+
switch (field) {
|
|
9783
|
+
// Array headers:
|
|
9784
|
+
case "set-cookie":
|
|
9785
|
+
if (dest[field] !== void 0) {
|
|
9786
|
+
dest[field].push(value);
|
|
9787
|
+
} else {
|
|
9788
|
+
dest[field] = [value];
|
|
9789
|
+
}
|
|
9790
|
+
break;
|
|
9791
|
+
// list is taken from:
|
|
9792
|
+
// https://mxr.mozilla.org/mozilla/source/netwerk/protocol/http/src/nsHttpHeaderArray.cpp
|
|
9793
|
+
case "content-type":
|
|
9794
|
+
case "content-length":
|
|
9795
|
+
case "user-agent":
|
|
9796
|
+
case "referer":
|
|
9797
|
+
case "host":
|
|
9798
|
+
case "authorization":
|
|
9799
|
+
case "proxy-authorization":
|
|
9800
|
+
case "if-modified-since":
|
|
9801
|
+
case "if-unmodified-since":
|
|
9802
|
+
case "from":
|
|
9803
|
+
case "location":
|
|
9804
|
+
case "max-forwards":
|
|
9805
|
+
case "retry-after":
|
|
9806
|
+
case "etag":
|
|
9807
|
+
case "last-modified":
|
|
9808
|
+
case "server":
|
|
9809
|
+
case "age":
|
|
9810
|
+
case "expires":
|
|
9811
|
+
if (dest[field] === void 0) dest[field] = value;
|
|
9812
|
+
break;
|
|
9813
|
+
default:
|
|
9814
|
+
if (typeof dest[field] === "string") {
|
|
9815
|
+
dest[field] += ", " + value;
|
|
9816
|
+
} else {
|
|
9817
|
+
dest[field] = value;
|
|
9818
|
+
}
|
|
9819
|
+
}
|
|
9820
|
+
}
|
|
9821
|
+
|
|
9822
|
+
// shims/rn_http_response_parser.ts
|
|
9823
|
+
var ResponseParser = class {
|
|
9824
|
+
constructor(logger, resolve, reject) {
|
|
9825
|
+
this.responseChunkRemainder = 0;
|
|
9826
|
+
this.logger = logger;
|
|
9827
|
+
this.resolve = resolve;
|
|
9828
|
+
this.reject = reject;
|
|
9829
|
+
this.error = null;
|
|
9830
|
+
this.responseReadBuffer = void 0;
|
|
9831
|
+
this.responseState = 0 /* RECEIVING_HEADER */;
|
|
9832
|
+
this.pullController = void 0;
|
|
9833
|
+
this.pullResolve = void 0;
|
|
9834
|
+
this.pullReject = void 0;
|
|
9835
|
+
}
|
|
9836
|
+
processResponseReadBuffer(data) {
|
|
9837
|
+
if (this.error) {
|
|
9838
|
+
this.logger.info(`RN http streamed response, received ${data.length} bytes in error mode`);
|
|
9839
|
+
return false;
|
|
9840
|
+
}
|
|
9841
|
+
if (this.responseReadBuffer) {
|
|
9842
|
+
this.responseReadBuffer = Buffer.concat([this.responseReadBuffer, data]);
|
|
9843
|
+
} else {
|
|
9844
|
+
this.responseReadBuffer = Buffer.from(data.subarray());
|
|
9845
|
+
}
|
|
9846
|
+
if (this.responseState === 3 /* RECEIVING_COMPLETED */) {
|
|
9847
|
+
if (this.pullController) {
|
|
9848
|
+
this.pullController.close();
|
|
9849
|
+
if (this.pullResolve) {
|
|
9850
|
+
this.pullResolve();
|
|
9851
|
+
}
|
|
9852
|
+
}
|
|
9853
|
+
return false;
|
|
9854
|
+
} else if (this.responseState === 0 /* RECEIVING_HEADER */) {
|
|
9855
|
+
const headerEnd = this.responseReadBuffer.indexOf("\r\n\r\n");
|
|
9856
|
+
if (headerEnd >= 0) {
|
|
9857
|
+
let headerChunk = this.responseReadBuffer.subarray(0, headerEnd + 4);
|
|
9858
|
+
this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(headerEnd + 4));
|
|
9859
|
+
const maxHeaderLines = 128;
|
|
9860
|
+
let responseHeaderLines = [];
|
|
9861
|
+
const lineDecoder = new EyepopLineDecoder();
|
|
9862
|
+
for (const line of lineDecoder.decode(headerChunk)) {
|
|
9863
|
+
if (line.length > 0) {
|
|
9864
|
+
responseHeaderLines.push(line);
|
|
9865
|
+
if (responseHeaderLines.length > maxHeaderLines) {
|
|
9866
|
+
this.error = `Response header exceeds ${maxHeaderLines} lines`;
|
|
9867
|
+
this.reject(this.error);
|
|
9868
|
+
return false;
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
}
|
|
9872
|
+
let responseHeader = parseHttpHeader(responseHeaderLines, false);
|
|
9873
|
+
if (responseHeader.statusCode === void 0) {
|
|
9874
|
+
this.logger.warn(`Could not find status header in HTTP response ${JSON.stringify(responseHeader)}`);
|
|
9875
|
+
this.reject("missing status header in HTTP response");
|
|
9876
|
+
return false;
|
|
9877
|
+
}
|
|
9878
|
+
const headers = new Headers(responseHeader.headers);
|
|
9879
|
+
if (headers.has("transfer-encoding")) {
|
|
9880
|
+
if (headers.get("transfer-encoding")?.toLowerCase() === "chunked") {
|
|
9881
|
+
this.responseState = 2 /* RECEIVING_BODY_CHUNKED */;
|
|
9882
|
+
this.responseChunkRemainder = 0;
|
|
9883
|
+
} else {
|
|
9884
|
+
this.error = `Response with unsupported transfer-encoding '${headers.get("transfer-encoding")}'`;
|
|
9885
|
+
this.reject(this.error);
|
|
9886
|
+
return false;
|
|
9887
|
+
}
|
|
9888
|
+
} else if (headers.has("content-length")) {
|
|
9889
|
+
this.responseState = 1 /* RECEIVING_BODY */;
|
|
9890
|
+
this.responseChunkRemainder = parseInt(headers.get("content-length") || "-1");
|
|
9891
|
+
} else {
|
|
9892
|
+
this.responseState = 2 /* RECEIVING_BODY_CHUNKED */;
|
|
9893
|
+
this.responseChunkRemainder = 0;
|
|
9894
|
+
}
|
|
9895
|
+
const responseBody = new ReadableStream({
|
|
9896
|
+
pull: (controller) => {
|
|
9897
|
+
if (this.error || this.responseState == 3 /* RECEIVING_COMPLETED */) {
|
|
9898
|
+
return;
|
|
9899
|
+
}
|
|
9900
|
+
if (this.pull(controller)) {
|
|
9901
|
+
return;
|
|
9902
|
+
}
|
|
9903
|
+
return new Promise((resolve, reject) => {
|
|
9904
|
+
if (this.pullController) {
|
|
9905
|
+
if (this.pullReject) {
|
|
9906
|
+
this.pullReject("pull, we got a pending controller already");
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
this.pullController = controller;
|
|
9910
|
+
this.pullResolve = resolve;
|
|
9911
|
+
this.pullReject = reject;
|
|
9912
|
+
});
|
|
9913
|
+
},
|
|
9914
|
+
cancel: (reason) => {
|
|
9915
|
+
if (!this.error) {
|
|
9916
|
+
this.error = `cancelled: ${reason}`;
|
|
9917
|
+
this.reject(this.error);
|
|
9918
|
+
}
|
|
9919
|
+
}
|
|
9920
|
+
});
|
|
9921
|
+
this.resolve(new Response(responseBody, {
|
|
9922
|
+
status: responseHeader.statusCode,
|
|
9923
|
+
statusText: responseHeader.statusText,
|
|
9924
|
+
headers
|
|
9925
|
+
}));
|
|
9926
|
+
}
|
|
9927
|
+
} else if (this.pullController) {
|
|
9928
|
+
if (this.pull(this.pullController)) {
|
|
9929
|
+
this.pullController = void 0;
|
|
9930
|
+
if (this.pullResolve) {
|
|
9931
|
+
this.pullResolve();
|
|
9932
|
+
}
|
|
9933
|
+
this.pullResolve = void 0;
|
|
9934
|
+
this.pullReject = void 0;
|
|
9935
|
+
}
|
|
9936
|
+
}
|
|
9937
|
+
return true;
|
|
9938
|
+
}
|
|
9939
|
+
pull(controller) {
|
|
9940
|
+
if (this.responseState == 3 /* RECEIVING_COMPLETED */) {
|
|
9941
|
+
controller.close();
|
|
9942
|
+
return false;
|
|
9943
|
+
}
|
|
9944
|
+
if (this.responseReadBuffer === void 0) {
|
|
9945
|
+
return false;
|
|
9946
|
+
}
|
|
9947
|
+
if (this.responseState == 1 /* RECEIVING_BODY */) {
|
|
9948
|
+
controller.enqueue(this.responseReadBuffer);
|
|
9949
|
+
this.responseChunkRemainder -= this.responseReadBuffer.length;
|
|
9950
|
+
this.responseReadBuffer = void 0;
|
|
9951
|
+
if (this.responseChunkRemainder <= 0) {
|
|
9952
|
+
this.responseState = 3 /* RECEIVING_COMPLETED */;
|
|
9953
|
+
controller.close();
|
|
9954
|
+
}
|
|
9955
|
+
return true;
|
|
9956
|
+
} else if (this.responseState == 2 /* RECEIVING_BODY_CHUNKED */) {
|
|
9957
|
+
while (this.responseReadBuffer.length > 1) {
|
|
9958
|
+
if (this.responseChunkRemainder == 0) {
|
|
9959
|
+
let chunkHeaderEnd = 0;
|
|
9960
|
+
while (this.responseReadBuffer.length >= 2 && chunkHeaderEnd == 0) {
|
|
9961
|
+
chunkHeaderEnd = this.responseReadBuffer.indexOf("\r\n");
|
|
9962
|
+
if (chunkHeaderEnd == 0) {
|
|
9963
|
+
this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(2));
|
|
9964
|
+
}
|
|
9965
|
+
}
|
|
9966
|
+
if (chunkHeaderEnd > 0) {
|
|
9967
|
+
this.responseChunkRemainder = parseInt(Buffer.from(this.responseReadBuffer, 0, chunkHeaderEnd).toString("utf8"), 16);
|
|
9968
|
+
this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(chunkHeaderEnd + 2));
|
|
9969
|
+
if (this.responseChunkRemainder <= 0) {
|
|
9970
|
+
this.responseState = 3 /* RECEIVING_COMPLETED */;
|
|
9971
|
+
controller.close();
|
|
9972
|
+
return true;
|
|
9973
|
+
}
|
|
9974
|
+
} else if (this.responseReadBuffer.length > 64) {
|
|
9975
|
+
this.error = "Cannot find chunked encoding header within 64 bytes, given up";
|
|
9976
|
+
controller.error(this.error);
|
|
9977
|
+
}
|
|
9978
|
+
}
|
|
9979
|
+
if (this.responseChunkRemainder > 0 && this.responseReadBuffer.length > 0) {
|
|
9980
|
+
const chunk = Buffer.from(this.responseReadBuffer.subarray(0, this.responseChunkRemainder));
|
|
9981
|
+
this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(this.responseChunkRemainder));
|
|
9982
|
+
controller.enqueue(chunk);
|
|
9983
|
+
this.responseChunkRemainder -= chunk.length;
|
|
9984
|
+
return true;
|
|
9985
|
+
} else {
|
|
9986
|
+
break;
|
|
9987
|
+
}
|
|
9988
|
+
}
|
|
9989
|
+
} else {
|
|
9990
|
+
this.error = `Received more data in wrong state ${this.responseState}`;
|
|
9991
|
+
controller.error(this.error);
|
|
9992
|
+
}
|
|
9993
|
+
return false;
|
|
9994
|
+
}
|
|
9995
|
+
};
|
|
9996
|
+
|
|
9997
|
+
// shims/rn_streaming_fetch.ts
|
|
9998
|
+
async function reactNativeStreamingFetch(url, method, headers, body, contentLength, sockets, logger) {
|
|
9999
|
+
const isHttps = url.protocol == "https:";
|
|
10000
|
+
const port = url.port ? parseInt(url.port) : isHttps ? 443 : 80;
|
|
10001
|
+
return new Promise((resolve, reject) => {
|
|
10002
|
+
const connectOptions = {
|
|
10003
|
+
port,
|
|
10004
|
+
host: url.hostname,
|
|
10005
|
+
reuseAddress: true
|
|
10006
|
+
};
|
|
10007
|
+
const clientSocket = new sockets.Socket();
|
|
10008
|
+
const client = isHttps ? new sockets.TLSSocket(clientSocket) : clientSocket;
|
|
10009
|
+
let error;
|
|
10010
|
+
const responseParser = new ResponseParser(logger, resolve, (reason) => {
|
|
10011
|
+
error = reason;
|
|
10012
|
+
reject(error);
|
|
10013
|
+
client.destroy();
|
|
10014
|
+
});
|
|
10015
|
+
client.on("data", function(data) {
|
|
10016
|
+
responseParser.processResponseReadBuffer(data);
|
|
10017
|
+
});
|
|
10018
|
+
client.on("error", function(err) {
|
|
10019
|
+
logger.info(`error: ${err}`);
|
|
10020
|
+
if (!error) {
|
|
10021
|
+
error = err;
|
|
10022
|
+
reject(error);
|
|
10023
|
+
}
|
|
10024
|
+
client.destroy();
|
|
10025
|
+
});
|
|
10026
|
+
client.on("close", function() {
|
|
10027
|
+
if (!error) {
|
|
10028
|
+
error = "socket closed";
|
|
10029
|
+
reject(error);
|
|
10030
|
+
}
|
|
10031
|
+
});
|
|
10032
|
+
client.connect(connectOptions, async () => {
|
|
10033
|
+
const headerLines = [
|
|
10034
|
+
`${method} ${url.pathname}${url.search} HTTP/1.1\r
|
|
10035
|
+
`,
|
|
10036
|
+
`Host: ${url.host}\r
|
|
10037
|
+
`
|
|
10038
|
+
];
|
|
10039
|
+
headers.forEach((value, key) => {
|
|
10040
|
+
headerLines.push(`${key}: ${value}\r
|
|
10041
|
+
`);
|
|
10042
|
+
});
|
|
10043
|
+
headerLines.push("\r\n");
|
|
10044
|
+
const textEncoder = new TextEncoder();
|
|
10045
|
+
const headerChunk = headerLines.join("");
|
|
10046
|
+
const bodyReader = body ? body.getReader() : void 0;
|
|
10047
|
+
let headerEnqueued = false;
|
|
10048
|
+
let eof = false;
|
|
10049
|
+
const readableHeaderChunkedBody = new ReadableStream({
|
|
10050
|
+
async pull(controller) {
|
|
10051
|
+
if (!headerEnqueued) {
|
|
10052
|
+
controller.enqueue(headerChunk);
|
|
10053
|
+
headerEnqueued = true;
|
|
10054
|
+
return;
|
|
10055
|
+
}
|
|
10056
|
+
if (eof) {
|
|
10057
|
+
controller.close();
|
|
10058
|
+
return;
|
|
10059
|
+
}
|
|
10060
|
+
if (!bodyReader) {
|
|
10061
|
+
controller.close();
|
|
10062
|
+
return;
|
|
10063
|
+
}
|
|
10064
|
+
const chunk = await bodyReader.read();
|
|
10065
|
+
if (chunk.value) {
|
|
10066
|
+
let outputChunk;
|
|
10067
|
+
if (contentLength) {
|
|
10068
|
+
outputChunk = chunk.value;
|
|
10069
|
+
} else {
|
|
10070
|
+
outputChunk = Buffer.concat([
|
|
10071
|
+
textEncoder.encode(`${chunk.value.length.toString(16)}\r
|
|
10072
|
+
`),
|
|
10073
|
+
chunk.value,
|
|
10074
|
+
textEncoder.encode(`\r
|
|
10075
|
+
`)
|
|
10076
|
+
]);
|
|
10077
|
+
}
|
|
10078
|
+
controller.enqueue(outputChunk);
|
|
10079
|
+
} else if (chunk.done) {
|
|
10080
|
+
if (!contentLength) {
|
|
10081
|
+
controller.enqueue(Buffer.from(`0\r
|
|
10082
|
+
\r
|
|
10083
|
+
`, "utf8"));
|
|
10084
|
+
}
|
|
10085
|
+
eof = true;
|
|
10086
|
+
}
|
|
10087
|
+
}
|
|
10088
|
+
});
|
|
10089
|
+
const readableHeaderChunkedBodyReader = readableHeaderChunkedBody.getReader();
|
|
10090
|
+
const pipeChunk = async () => {
|
|
10091
|
+
while (true) {
|
|
10092
|
+
try {
|
|
10093
|
+
const chunk = await readableHeaderChunkedBodyReader.read();
|
|
10094
|
+
if (chunk.value) {
|
|
10095
|
+
if (!client.write(chunk.value)) {
|
|
10096
|
+
break;
|
|
10097
|
+
}
|
|
10098
|
+
} else if (chunk.done) {
|
|
10099
|
+
break;
|
|
10100
|
+
}
|
|
10101
|
+
} catch (e) {
|
|
10102
|
+
logger.error(e);
|
|
10103
|
+
break;
|
|
10104
|
+
}
|
|
10105
|
+
}
|
|
10106
|
+
};
|
|
10107
|
+
client.on("drain", pipeChunk);
|
|
10108
|
+
await pipeChunk();
|
|
10109
|
+
});
|
|
10110
|
+
});
|
|
10111
|
+
}
|
|
10112
|
+
|
|
9641
10113
|
// shims/http_client.ts
|
|
9642
10114
|
var createHttpClient;
|
|
9643
10115
|
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
@@ -9653,15 +10125,97 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9653
10125
|
return false;
|
|
9654
10126
|
}
|
|
9655
10127
|
}
|
|
9656
|
-
createHttpClient = async () => {
|
|
10128
|
+
createHttpClient = async (logger) => {
|
|
10129
|
+
logger.debug("Using browser fetch as http client");
|
|
9657
10130
|
return new BrowserHttpClient();
|
|
9658
10131
|
};
|
|
9659
10132
|
} else if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
10133
|
+
let RNName = "react-native";
|
|
10134
|
+
let RN;
|
|
10135
|
+
let TcpSocketsName = "react-native-tcp-socket";
|
|
10136
|
+
let TcpSockets;
|
|
10137
|
+
let TcpSocketsError;
|
|
10138
|
+
try {
|
|
10139
|
+
RN = __require(RNName);
|
|
10140
|
+
TcpSockets = __require(TcpSocketsName);
|
|
10141
|
+
if (TcpSockets?.TLSSocket) {
|
|
10142
|
+
if (!RN?.NativeModules?.TcpSockets) {
|
|
10143
|
+
TcpSockets = void 0;
|
|
10144
|
+
throw Error(`'${TcpSocketsName}' but not symbol NativeModules?.TcpSockets, native sockets not available when running 'npx expo start', use 'npx expo run:android' or 'npx expo run:ios' instead`);
|
|
10145
|
+
}
|
|
10146
|
+
}
|
|
10147
|
+
} catch (e) {
|
|
10148
|
+
TcpSocketsError = e;
|
|
10149
|
+
}
|
|
9660
10150
|
class ReactNativeHttpClient {
|
|
9661
|
-
constructor() {
|
|
10151
|
+
constructor(logger) {
|
|
10152
|
+
this.logger = logger;
|
|
9662
10153
|
}
|
|
9663
10154
|
async fetch(input, init) {
|
|
9664
10155
|
init || (init = {});
|
|
10156
|
+
let streamBody;
|
|
10157
|
+
if (input instanceof Request) {
|
|
10158
|
+
if (input.body instanceof ReadableStream) {
|
|
10159
|
+
streamBody = input.body;
|
|
10160
|
+
}
|
|
10161
|
+
} else if (init?.body instanceof ReadableStream) {
|
|
10162
|
+
streamBody = init.body;
|
|
10163
|
+
}
|
|
10164
|
+
if (streamBody) {
|
|
10165
|
+
if (TcpSockets?.TLSSocket !== void 0) {
|
|
10166
|
+
let url;
|
|
10167
|
+
let method;
|
|
10168
|
+
let headers;
|
|
10169
|
+
if (input instanceof Request) {
|
|
10170
|
+
url = new URL(input.url);
|
|
10171
|
+
method = input.method;
|
|
10172
|
+
headers = input.headers;
|
|
10173
|
+
} else {
|
|
10174
|
+
if (input instanceof URL) {
|
|
10175
|
+
url = input;
|
|
10176
|
+
} else {
|
|
10177
|
+
url = new URL(input);
|
|
10178
|
+
}
|
|
10179
|
+
method = init?.method || "POST";
|
|
10180
|
+
headers = new Headers(init?.headers);
|
|
10181
|
+
}
|
|
10182
|
+
let contentLength = void 0;
|
|
10183
|
+
if (headers.has("content-length")) {
|
|
10184
|
+
contentLength = parseInt(headers.get("content-length") || "");
|
|
10185
|
+
} else {
|
|
10186
|
+
headers.append("Transfer-Encoding", "chunked");
|
|
10187
|
+
}
|
|
10188
|
+
return await reactNativeStreamingFetch(
|
|
10189
|
+
url,
|
|
10190
|
+
method,
|
|
10191
|
+
headers,
|
|
10192
|
+
streamBody,
|
|
10193
|
+
contentLength,
|
|
10194
|
+
TcpSockets,
|
|
10195
|
+
this.logger
|
|
10196
|
+
);
|
|
10197
|
+
} else {
|
|
10198
|
+
this.logger.warn(`[${TcpSockets}] Could not load '${TcpSocketsName}' (reason" ${TcpSocketsError}), include this package in your application to enable streamed uploads; without this package local files have to be loaded into memory uploading and this will cause Out-Of-Memory errors for large files.`);
|
|
10199
|
+
try {
|
|
10200
|
+
const chunks = [];
|
|
10201
|
+
const reader = streamBody.getReader();
|
|
10202
|
+
while (true) {
|
|
10203
|
+
const { done, value } = await reader.read();
|
|
10204
|
+
if (done) {
|
|
10205
|
+
break;
|
|
10206
|
+
}
|
|
10207
|
+
chunks.push(value);
|
|
10208
|
+
}
|
|
10209
|
+
if (input instanceof Request) {
|
|
10210
|
+
input = new Request(input, { body: Buffer.concat(chunks) });
|
|
10211
|
+
} else {
|
|
10212
|
+
init.body = Buffer.concat(chunks);
|
|
10213
|
+
}
|
|
10214
|
+
} catch (e) {
|
|
10215
|
+
return Promise.reject(e);
|
|
10216
|
+
}
|
|
10217
|
+
}
|
|
10218
|
+
}
|
|
9665
10219
|
init.reactNative = { textStreaming: true };
|
|
9666
10220
|
return await fetch(input, init);
|
|
9667
10221
|
}
|
|
@@ -9671,8 +10225,9 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9671
10225
|
return true;
|
|
9672
10226
|
}
|
|
9673
10227
|
}
|
|
9674
|
-
createHttpClient = async () => {
|
|
9675
|
-
|
|
10228
|
+
createHttpClient = async (logger) => {
|
|
10229
|
+
logger.debug("using React Native fetch and will attempt direct sockets communication for uploads to workaround the missing request body streaming support in React Native.");
|
|
10230
|
+
return new ReactNativeHttpClient(logger);
|
|
9676
10231
|
};
|
|
9677
10232
|
} else {
|
|
9678
10233
|
class NodeHttpClient {
|
|
@@ -9691,7 +10246,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9691
10246
|
return false;
|
|
9692
10247
|
}
|
|
9693
10248
|
}
|
|
9694
|
-
createHttpClient = async () => {
|
|
10249
|
+
createHttpClient = async (logger) => {
|
|
9695
10250
|
const undici = __require("undici");
|
|
9696
10251
|
const agent = new undici.Agent({
|
|
9697
10252
|
keepAliveTimeout: 1e4,
|
|
@@ -9699,6 +10254,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9699
10254
|
// two parallel streaming requests to the same host seem to deadlock with pipelining > 0
|
|
9700
10255
|
pipelining: 0
|
|
9701
10256
|
});
|
|
10257
|
+
logger.debug("Using node fetch with undici agent as http client");
|
|
9702
10258
|
return new NodeHttpClient(agent);
|
|
9703
10259
|
};
|
|
9704
10260
|
}
|
|
@@ -9868,7 +10424,10 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9868
10424
|
popId: workerOptions.popId,
|
|
9869
10425
|
baseUrl: void 0,
|
|
9870
10426
|
pipelineId: void 0,
|
|
9871
|
-
sandboxId: void 0
|
|
10427
|
+
sandboxId: void 0,
|
|
10428
|
+
authenticationHeaders: () => {
|
|
10429
|
+
return { Authorization: `Bearer ${accessToken}` };
|
|
10430
|
+
}
|
|
9872
10431
|
};
|
|
9873
10432
|
session = workerSession;
|
|
9874
10433
|
} else {
|
|
@@ -9967,7 +10526,7 @@ var Endpoint = class {
|
|
|
9967
10526
|
} else {
|
|
9968
10527
|
return Promise.reject("option secretKey or environment variable EYEPOP_SECRET_KEY is required");
|
|
9969
10528
|
}
|
|
9970
|
-
this._client = await createHttpClient();
|
|
10529
|
+
this._client = await createHttpClient(this._logger);
|
|
9971
10530
|
return await this.reconnect();
|
|
9972
10531
|
}
|
|
9973
10532
|
async disconnect(wait = true) {
|
|
@@ -10402,6 +10961,7 @@ var WorkerEndpoint = class extends Endpoint {
|
|
|
10402
10961
|
const job = new UploadJob(
|
|
10403
10962
|
source.file.stream(),
|
|
10404
10963
|
source.file.type,
|
|
10964
|
+
source.file.size,
|
|
10405
10965
|
source.videoMode,
|
|
10406
10966
|
params,
|
|
10407
10967
|
async () => {
|
|
@@ -10433,6 +10993,7 @@ var WorkerEndpoint = class extends Endpoint {
|
|
|
10433
10993
|
const job = new UploadJob(
|
|
10434
10994
|
source.stream,
|
|
10435
10995
|
source.mimeType,
|
|
10996
|
+
source.size,
|
|
10436
10997
|
source.videoMode,
|
|
10437
10998
|
params,
|
|
10438
10999
|
async () => {
|
|
@@ -10461,10 +11022,11 @@ var WorkerEndpoint = class extends Endpoint {
|
|
|
10461
11022
|
await this._limit.acquire();
|
|
10462
11023
|
try {
|
|
10463
11024
|
this.updateState();
|
|
10464
|
-
const streamSource = await resolvePath(source);
|
|
11025
|
+
const streamSource = await resolvePath(source, this._logger);
|
|
10465
11026
|
const job = new UploadJob(
|
|
10466
11027
|
streamSource.stream,
|
|
10467
11028
|
streamSource.mimeType,
|
|
11029
|
+
streamSource.size,
|
|
10468
11030
|
source.videoMode,
|
|
10469
11031
|
params,
|
|
10470
11032
|
async () => {
|
|
@@ -10667,7 +11229,8 @@ var WorkerEndpoint = class extends Endpoint {
|
|
|
10667
11229
|
if (this.options().stopJobs) {
|
|
10668
11230
|
const body = { sourceType: "NONE" };
|
|
10669
11231
|
const headers3 = {
|
|
10670
|
-
Authorization: await this.authorizationHeader()
|
|
11232
|
+
Authorization: await this.authorizationHeader(),
|
|
11233
|
+
"Content-Type": "application/json"
|
|
10671
11234
|
};
|
|
10672
11235
|
const stop_url = `${this._baseUrl}/pipelines/${this._pipeline.id}/source?mode=preempt&processing=sync`;
|
|
10673
11236
|
let response3 = await this._client.fetch(stop_url, {
|
|
@@ -11707,6 +12270,7 @@ export {
|
|
|
11707
12270
|
EndpointState,
|
|
11708
12271
|
ExportedBy,
|
|
11709
12272
|
EyePop,
|
|
12273
|
+
EyepopLineDecoder,
|
|
11710
12274
|
ForwardOperatorType,
|
|
11711
12275
|
InferenceType,
|
|
11712
12276
|
LoadFromJob,
|