opus-codec-worker 0.0.33 → 0.0.35
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/actions/Client.d.ts +2 -0
- package/actions/Client.js +24 -0
- package/package.json +1 -1
package/actions/Client.d.ts
CHANGED
package/actions/Client.js
CHANGED
|
@@ -13,6 +13,8 @@ class Client {
|
|
|
13
13
|
constructor(worker) {
|
|
14
14
|
this.#worker = worker;
|
|
15
15
|
worker.addEventListener('message', this.onMessage);
|
|
16
|
+
worker.addEventListener('messageerror', this.onMessageError);
|
|
17
|
+
worker.addEventListener('error', this.onError);
|
|
16
18
|
}
|
|
17
19
|
close() {
|
|
18
20
|
this.#worker.terminate();
|
|
@@ -25,17 +27,33 @@ class Client {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
sendMessage(data) {
|
|
30
|
+
const waitTimeBeforeResolvingAutomaticallyInMilliseconds = 10000;
|
|
28
31
|
return new Promise((resolve, reject) => {
|
|
29
32
|
if (this.#pending.has(data.requestId)) {
|
|
30
33
|
reject(new Error(`Request already exists: ${data.requestId}`));
|
|
31
34
|
return;
|
|
32
35
|
}
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
resolve({
|
|
38
|
+
requestId: data.requestId,
|
|
39
|
+
failures: [
|
|
40
|
+
`Timeout expired. It took more than ${waitTimeBeforeResolvingAutomaticallyInMilliseconds} to resolve this request.`,
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
}, waitTimeBeforeResolvingAutomaticallyInMilliseconds);
|
|
33
44
|
this.#pending.set(data.requestId, (data) => {
|
|
45
|
+
clearTimeout(timeoutId);
|
|
34
46
|
resolve(data);
|
|
35
47
|
});
|
|
36
48
|
this.#worker.postMessage(data);
|
|
37
49
|
});
|
|
38
50
|
}
|
|
51
|
+
onMessageError(e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
54
|
+
onError(e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
}
|
|
39
57
|
onMessage(e) {
|
|
40
58
|
const data = e.data;
|
|
41
59
|
const request = this.#pending.get(data.requestId);
|
|
@@ -46,6 +64,12 @@ class Client {
|
|
|
46
64
|
request(data);
|
|
47
65
|
}
|
|
48
66
|
}
|
|
67
|
+
__decorate([
|
|
68
|
+
autobind_decorator_1.boundMethod
|
|
69
|
+
], Client.prototype, "onMessageError", null);
|
|
70
|
+
__decorate([
|
|
71
|
+
autobind_decorator_1.boundMethod
|
|
72
|
+
], Client.prototype, "onError", null);
|
|
49
73
|
__decorate([
|
|
50
74
|
autobind_decorator_1.boundMethod
|
|
51
75
|
], Client.prototype, "onMessage", null);
|