@formant/data-sdk 0.0.95 → 0.0.98
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/data-sdk.es.js
CHANGED
|
@@ -18601,6 +18601,9 @@ class DataChannel {
|
|
|
18601
18601
|
constructor(dataChannel) {
|
|
18602
18602
|
__publicField(this, "ready", false);
|
|
18603
18603
|
__publicField(this, "listeners", []);
|
|
18604
|
+
__publicField(this, "openListeners", []);
|
|
18605
|
+
__publicField(this, "closeListeners", []);
|
|
18606
|
+
__publicField(this, "errorListeners", []);
|
|
18604
18607
|
__publicField(this, "binaryListeners", []);
|
|
18605
18608
|
__publicField(this, "error");
|
|
18606
18609
|
__publicField(this, "decoder", new TextDecoder());
|
|
@@ -18608,13 +18611,16 @@ class DataChannel {
|
|
|
18608
18611
|
this.dataChannel.binaryType = "arraybuffer";
|
|
18609
18612
|
this.dataChannel.onopen = () => {
|
|
18610
18613
|
this.ready = true;
|
|
18614
|
+
this.openListeners.forEach((listener) => listener());
|
|
18611
18615
|
};
|
|
18612
18616
|
this.dataChannel.onclose = () => {
|
|
18613
18617
|
this.ready = false;
|
|
18618
|
+
this.closeListeners.forEach((listener) => listener());
|
|
18614
18619
|
};
|
|
18615
18620
|
this.dataChannel.onerror = (e) => {
|
|
18616
18621
|
console.error(e);
|
|
18617
18622
|
this.error = "An error occurred in DataChannel";
|
|
18623
|
+
this.errorListeners.forEach((listener) => listener(e));
|
|
18618
18624
|
};
|
|
18619
18625
|
this.dataChannel.onmessage = (m) => {
|
|
18620
18626
|
this.listeners.forEach((_) => {
|
|
@@ -18627,6 +18633,24 @@ class DataChannel {
|
|
|
18627
18633
|
});
|
|
18628
18634
|
};
|
|
18629
18635
|
}
|
|
18636
|
+
addOpenListener(listener) {
|
|
18637
|
+
this.openListeners.push(listener);
|
|
18638
|
+
}
|
|
18639
|
+
removeOpenListener(listener) {
|
|
18640
|
+
this.openListeners = this.openListeners.filter((_) => _ !== listener);
|
|
18641
|
+
}
|
|
18642
|
+
addCloseListener(listener) {
|
|
18643
|
+
this.closeListeners.push(listener);
|
|
18644
|
+
}
|
|
18645
|
+
removeCloseListener(listener) {
|
|
18646
|
+
this.closeListeners = this.closeListeners.filter((l) => l !== listener);
|
|
18647
|
+
}
|
|
18648
|
+
addErrorListener(listener) {
|
|
18649
|
+
this.errorListeners.push(listener);
|
|
18650
|
+
}
|
|
18651
|
+
removeErrorListener(listener) {
|
|
18652
|
+
this.errorListeners = this.errorListeners.filter((l) => l !== listener);
|
|
18653
|
+
}
|
|
18630
18654
|
async waitTilReady() {
|
|
18631
18655
|
if (this.ready) {
|
|
18632
18656
|
return true;
|
|
@@ -18745,6 +18769,24 @@ class RequestDataChannel {
|
|
|
18745
18769
|
this.channel_name = channel_name;
|
|
18746
18770
|
this.timeout = timeout;
|
|
18747
18771
|
}
|
|
18772
|
+
addOpenListener(listener) {
|
|
18773
|
+
defined(this.channel, "channel not initalized").addOpenListener(listener);
|
|
18774
|
+
}
|
|
18775
|
+
removeOpenListener(listener) {
|
|
18776
|
+
defined(this.channel, "channel not initalized").removeOpenListener(listener);
|
|
18777
|
+
}
|
|
18778
|
+
addCloseListener(listener) {
|
|
18779
|
+
defined(this.channel, "channel not initalized").addCloseListener(listener);
|
|
18780
|
+
}
|
|
18781
|
+
removeCloseListener(listener) {
|
|
18782
|
+
defined(this.channel, "channel not initalized").removeCloseListener(listener);
|
|
18783
|
+
}
|
|
18784
|
+
addErrorListener(listener) {
|
|
18785
|
+
defined(this.channel, "channel not initalized").addErrorListener(listener);
|
|
18786
|
+
}
|
|
18787
|
+
removeErrorListener(listener) {
|
|
18788
|
+
defined(this.channel, "channel not initalized").removeErrorListener(listener);
|
|
18789
|
+
}
|
|
18748
18790
|
}
|
|
18749
18791
|
class BinaryRequestDataChannel extends RequestDataChannel {
|
|
18750
18792
|
constructor() {
|
|
@@ -18801,19 +18843,21 @@ class BinaryRequestDataChannel extends RequestDataChannel {
|
|
|
18801
18843
|
if (success) {
|
|
18802
18844
|
return payload;
|
|
18803
18845
|
} else {
|
|
18804
|
-
|
|
18846
|
+
console.error({
|
|
18805
18847
|
name: "AdapterError",
|
|
18806
18848
|
message: this.decoder.decode(payload)
|
|
18807
|
-
};
|
|
18849
|
+
});
|
|
18850
|
+
throw new Error("Binary request datachannel adapter error");
|
|
18808
18851
|
}
|
|
18809
18852
|
}
|
|
18810
18853
|
}
|
|
18811
18854
|
}
|
|
18812
18855
|
requestIdToResponseMap.delete(id);
|
|
18813
|
-
|
|
18856
|
+
console.error({
|
|
18814
18857
|
name: "TimeoutError",
|
|
18815
18858
|
message: `Request timed out after ${timeout / 1e3} seconds`
|
|
18816
|
-
};
|
|
18859
|
+
});
|
|
18860
|
+
throw new Error("Binary request data channel request timed out");
|
|
18817
18861
|
}
|
|
18818
18862
|
}
|
|
18819
18863
|
class TextRequestDataChannel extends RequestDataChannel {
|
|
@@ -18863,19 +18907,21 @@ class TextRequestDataChannel extends RequestDataChannel {
|
|
|
18863
18907
|
return data2;
|
|
18864
18908
|
}
|
|
18865
18909
|
if (error) {
|
|
18866
|
-
|
|
18910
|
+
console.error({
|
|
18867
18911
|
name: "AdapterError",
|
|
18868
18912
|
message: error
|
|
18869
|
-
};
|
|
18913
|
+
});
|
|
18914
|
+
throw new Error("Text request datachannel adapter error");
|
|
18870
18915
|
}
|
|
18871
18916
|
}
|
|
18872
18917
|
}
|
|
18873
18918
|
}
|
|
18874
18919
|
requestIdToResponseMap.delete(id);
|
|
18875
|
-
|
|
18920
|
+
console.error({
|
|
18876
18921
|
name: "TimeoutError",
|
|
18877
18922
|
message: `Request timed out after ${timeout / 1e3} seconds`
|
|
18878
|
-
};
|
|
18923
|
+
});
|
|
18924
|
+
throw new Error("Text request datachannel request timed out");
|
|
18879
18925
|
}
|
|
18880
18926
|
}
|
|
18881
18927
|
const SessionType = {
|
|
@@ -19762,9 +19808,6 @@ class KeyValue {
|
|
|
19762
19808
|
try {
|
|
19763
19809
|
const result = await fetch(FORMANT_API_URL + `/v1/admin/key-value/${key}`, {
|
|
19764
19810
|
method: "GET",
|
|
19765
|
-
body: JSON.stringify({
|
|
19766
|
-
organizationId: defined(Authentication.currentUser).organizationId
|
|
19767
|
-
}),
|
|
19768
19811
|
headers: {
|
|
19769
19812
|
"Content-Type": "application/json",
|
|
19770
19813
|
Authorization: "Bearer " + Authentication.token
|
|
@@ -19779,6 +19822,41 @@ class KeyValue {
|
|
|
19779
19822
|
throw e;
|
|
19780
19823
|
}
|
|
19781
19824
|
}
|
|
19825
|
+
static async list() {
|
|
19826
|
+
try {
|
|
19827
|
+
const result = await fetch(FORMANT_API_URL + "/v1/admin/key-value", {
|
|
19828
|
+
method: "GET",
|
|
19829
|
+
headers: {
|
|
19830
|
+
"Content-Type": "application/json",
|
|
19831
|
+
Authorization: "Bearer " + Authentication.token
|
|
19832
|
+
}
|
|
19833
|
+
});
|
|
19834
|
+
const keyValueList = await result.json();
|
|
19835
|
+
if (result.status !== 200) {
|
|
19836
|
+
throw new Error(keyValueList.message);
|
|
19837
|
+
}
|
|
19838
|
+
return keyValueList.items;
|
|
19839
|
+
} catch (e) {
|
|
19840
|
+
throw e;
|
|
19841
|
+
}
|
|
19842
|
+
}
|
|
19843
|
+
static async delete(key) {
|
|
19844
|
+
try {
|
|
19845
|
+
const result = await fetch(FORMANT_API_URL + `/v1/admin/key-value/${key}`, {
|
|
19846
|
+
method: "DELETE",
|
|
19847
|
+
headers: {
|
|
19848
|
+
"Content-Type": "application/json",
|
|
19849
|
+
Authorization: "Bearer " + Authentication.token
|
|
19850
|
+
}
|
|
19851
|
+
});
|
|
19852
|
+
if (!result.ok) {
|
|
19853
|
+
throw new Error("Unable to handle request");
|
|
19854
|
+
}
|
|
19855
|
+
return;
|
|
19856
|
+
} catch (e) {
|
|
19857
|
+
throw e;
|
|
19858
|
+
}
|
|
19859
|
+
}
|
|
19782
19860
|
}
|
|
19783
19861
|
const accessLevels = ["viewer", "operator", "administrator"];
|
|
19784
19862
|
const viewer = "viewer";
|