@vapi-ai/web 1.0.115 → 1.0.117
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/AtomicMediaSource.ts +37 -14
- package/dist/AtomicMediaSource.js +36 -10
- package/package.json +1 -1
package/AtomicMediaSource.ts
CHANGED
|
@@ -40,23 +40,46 @@ class AtomicMediaSource {
|
|
|
40
40
|
|
|
41
41
|
public resetBuffer() {
|
|
42
42
|
this.operationsQueue.push(async () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
try {
|
|
44
|
+
// Check if mediaSource exists
|
|
45
|
+
if (!this.mediaSource) {
|
|
46
|
+
console.error("mediaSource is not available.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Remove existing source buffer if it exists
|
|
51
|
+
if (this.sourceBuffer) {
|
|
52
|
+
const removalPromise = new Promise<void>((resolve, reject) => {
|
|
53
|
+
const onRemoval = () => {
|
|
54
|
+
this.mediaSource.removeEventListener("updateend", onRemoval);
|
|
50
55
|
resolve();
|
|
51
|
-
}
|
|
52
|
-
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
this.mediaSource.addEventListener("updateend", onRemoval, {
|
|
59
|
+
once: true,
|
|
60
|
+
});
|
|
61
|
+
try {
|
|
62
|
+
this.mediaSource.removeSourceBuffer(this.sourceBuffer!);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await removalPromise;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Add a new source buffer
|
|
72
|
+
try {
|
|
73
|
+
this.sourceBuffer = this.mediaSource.addSourceBuffer(
|
|
74
|
+
'audio/webm; codecs="opus"'
|
|
53
75
|
);
|
|
54
|
-
|
|
76
|
+
this.sourceBuffer.mode = "sequence";
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("Error adding source buffer:", error);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Error in resetBuffer:", error);
|
|
55
82
|
}
|
|
56
|
-
this.sourceBuffer = this.mediaSource.addSourceBuffer(
|
|
57
|
-
'audio/webm; codecs="opus"'
|
|
58
|
-
);
|
|
59
|
-
this.sourceBuffer.mode = "sequence";
|
|
60
83
|
});
|
|
61
84
|
}
|
|
62
85
|
|
|
@@ -40,17 +40,43 @@ class AtomicMediaSource {
|
|
|
40
40
|
}
|
|
41
41
|
resetBuffer() {
|
|
42
42
|
this.operationsQueue.push(() => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
try {
|
|
44
|
+
// Check if mediaSource exists
|
|
45
|
+
if (!this.mediaSource) {
|
|
46
|
+
console.error("mediaSource is not available.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Remove existing source buffer if it exists
|
|
50
|
+
if (this.sourceBuffer) {
|
|
51
|
+
const removalPromise = new Promise((resolve, reject) => {
|
|
52
|
+
const onRemoval = () => {
|
|
53
|
+
this.mediaSource.removeEventListener("updateend", onRemoval);
|
|
54
|
+
resolve();
|
|
55
|
+
};
|
|
56
|
+
this.mediaSource.addEventListener("updateend", onRemoval, {
|
|
57
|
+
once: true,
|
|
58
|
+
});
|
|
59
|
+
try {
|
|
60
|
+
this.mediaSource.removeSourceBuffer(this.sourceBuffer);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
yield removalPromise;
|
|
67
|
+
}
|
|
68
|
+
// Add a new source buffer
|
|
69
|
+
try {
|
|
70
|
+
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
|
|
71
|
+
this.sourceBuffer.mode = "sequence";
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error("Error adding source buffer:", error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error("Error in resetBuffer:", error);
|
|
51
79
|
}
|
|
52
|
-
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
|
|
53
|
-
this.sourceBuffer.mode = "sequence";
|
|
54
80
|
}));
|
|
55
81
|
}
|
|
56
82
|
createOperationQueue() {
|