@vapi-ai/web 1.0.82 → 1.0.83
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/player.d.ts +3 -0
- package/dist/player.js +30 -8
- package/package.json +1 -1
- package/player.ts +31 -10
package/dist/player.d.ts
CHANGED
package/dist/player.js
CHANGED
|
@@ -42,22 +42,44 @@ class ContinuousPlayer extends events_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
callback();
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
performOperation(operation) {
|
|
46
46
|
if (this.sourceBuffer) {
|
|
47
47
|
if (this.sourceBuffer.updating) {
|
|
48
|
-
this.sourceBuffer.addEventListener("updateend",
|
|
48
|
+
this.sourceBuffer.addEventListener("updateend", operation, {
|
|
49
49
|
once: true,
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
|
|
54
|
-
while (this.sourceBuffer.buffered.length > 0 &&
|
|
55
|
-
!this.sourceBuffer.updating) {
|
|
56
|
-
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
|
|
57
|
-
}
|
|
58
|
-
this.sourceBuffer.timestampOffset = 0;
|
|
53
|
+
operation();
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
}
|
|
57
|
+
removeBuffer() {
|
|
58
|
+
this.performOperation(() => {
|
|
59
|
+
if (!this.sourceBuffer)
|
|
60
|
+
return;
|
|
61
|
+
while (this.sourceBuffer.buffered.length > 0) {
|
|
62
|
+
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
resetTimestampOffset() {
|
|
67
|
+
this.performOperation(() => {
|
|
68
|
+
if (!this.sourceBuffer)
|
|
69
|
+
return;
|
|
70
|
+
this.sourceBuffer.timestampOffset = 0;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
if (this.sourceBuffer) {
|
|
75
|
+
this.performOperation(() => {
|
|
76
|
+
if (!this.sourceBuffer)
|
|
77
|
+
return;
|
|
78
|
+
this.sourceBuffer.abort();
|
|
79
|
+
this.removeBuffer();
|
|
80
|
+
this.resetTimestampOffset();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
62
84
|
}
|
|
63
85
|
exports.ContinuousPlayer = ContinuousPlayer;
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -58,22 +58,43 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
58
58
|
callback();
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
private performOperation(operation: () => void): void {
|
|
62
62
|
if (this.sourceBuffer) {
|
|
63
63
|
if (this.sourceBuffer.updating) {
|
|
64
|
-
this.sourceBuffer.addEventListener("updateend",
|
|
64
|
+
this.sourceBuffer.addEventListener("updateend", operation, {
|
|
65
65
|
once: true,
|
|
66
66
|
});
|
|
67
67
|
} else {
|
|
68
|
-
|
|
69
|
-
while (
|
|
70
|
-
this.sourceBuffer.buffered.length > 0 &&
|
|
71
|
-
!this.sourceBuffer.updating
|
|
72
|
-
) {
|
|
73
|
-
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
|
|
74
|
-
}
|
|
75
|
-
this.sourceBuffer.timestampOffset = 0;
|
|
68
|
+
operation();
|
|
76
69
|
}
|
|
77
70
|
}
|
|
78
71
|
}
|
|
72
|
+
|
|
73
|
+
private removeBuffer(): void {
|
|
74
|
+
this.performOperation(() => {
|
|
75
|
+
if (!this.sourceBuffer) return;
|
|
76
|
+
while (this.sourceBuffer.buffered.length > 0) {
|
|
77
|
+
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private resetTimestampOffset(): void {
|
|
83
|
+
this.performOperation(() => {
|
|
84
|
+
if (!this.sourceBuffer) return;
|
|
85
|
+
this.sourceBuffer.timestampOffset = 0;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
clear(): void {
|
|
90
|
+
if (this.sourceBuffer) {
|
|
91
|
+
this.performOperation(() => {
|
|
92
|
+
if (!this.sourceBuffer) return;
|
|
93
|
+
|
|
94
|
+
this.sourceBuffer.abort();
|
|
95
|
+
this.removeBuffer();
|
|
96
|
+
this.resetTimestampOffset();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
79
100
|
}
|