@vapi-ai/web 1.0.92 → 1.0.94

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 CHANGED
@@ -10,7 +10,6 @@ export declare class ContinuousPlayer extends EventEmitter {
10
10
  playChunk(audioData: ArrayBuffer): void;
11
11
  private performBufferOperation;
12
12
  private appendNextChunk;
13
- private removeBufferedRange;
14
13
  private removeBuffer;
15
14
  private resetTimestampOffset;
16
15
  private abortBuffer;
package/dist/player.js CHANGED
@@ -42,19 +42,22 @@ class ContinuousPlayer extends events_1.default {
42
42
  this.operationsQueue.push(() => this.appendNextChunk(audioData));
43
43
  }
44
44
  performBufferOperation(operation) {
45
- console.log("performBufferOperation");
46
45
  return new Promise((resolve) => {
47
46
  if (!this.sourceBuffer) {
48
47
  resolve();
49
48
  return;
50
49
  }
51
- this.sourceBuffer.addEventListener("updateend", () => {
52
- console.log("update end");
53
- resolve();
54
- }, {
55
- once: true,
56
- });
50
+ if (this.sourceBuffer.updating) {
51
+ this.sourceBuffer.addEventListener("updateend", () => {
52
+ operation();
53
+ resolve();
54
+ }, {
55
+ once: true,
56
+ });
57
+ return;
58
+ }
57
59
  operation();
60
+ resolve();
58
61
  });
59
62
  }
60
63
  appendNextChunk(chunk) {
@@ -64,19 +67,12 @@ class ContinuousPlayer extends events_1.default {
64
67
  this.sourceBuffer.appendBuffer(chunk);
65
68
  });
66
69
  }
67
- removeBufferedRange() {
68
- return this.performBufferOperation(() => {
69
- if (!this.sourceBuffer)
70
- return;
71
- this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
72
- });
73
- }
74
70
  removeBuffer() {
75
- return __awaiter(this, void 0, void 0, function* () {
71
+ return this.performBufferOperation(() => {
76
72
  if (!this.sourceBuffer)
77
73
  return;
78
- while (this.sourceBuffer.buffered.length > 0) {
79
- yield this.removeBufferedRange();
74
+ if (this.sourceBuffer.buffered.length > 0) {
75
+ this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
80
76
  }
81
77
  });
82
78
  }
@@ -96,7 +92,6 @@ class ContinuousPlayer extends events_1.default {
96
92
  });
97
93
  }
98
94
  clear() {
99
- console.log("oyoiyo");
100
95
  this.operationsQueue.push(() => this.abortBuffer());
101
96
  this.operationsQueue.push(() => this.removeBuffer());
102
97
  this.operationsQueue.push(() => this.resetTimestampOffset());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -44,25 +44,28 @@ export class ContinuousPlayer extends EventEmitter {
44
44
  }
45
45
 
46
46
  private performBufferOperation(operation: () => void) {
47
- console.log("performBufferOperation");
48
47
  return new Promise<void>((resolve) => {
49
48
  if (!this.sourceBuffer) {
50
49
  resolve();
51
50
  return;
52
51
  }
53
52
 
54
- this.sourceBuffer.addEventListener(
55
- "updateend",
56
- () => {
57
- console.log("update end");
58
- resolve();
59
- },
60
- {
61
- once: true,
62
- }
63
- );
53
+ if (this.sourceBuffer.updating) {
54
+ this.sourceBuffer.addEventListener(
55
+ "updateend",
56
+ () => {
57
+ operation();
58
+ resolve();
59
+ },
60
+ {
61
+ once: true,
62
+ }
63
+ );
64
+ return;
65
+ }
64
66
 
65
67
  operation();
68
+ resolve();
66
69
  });
67
70
  }
68
71
 
@@ -73,19 +76,14 @@ export class ContinuousPlayer extends EventEmitter {
73
76
  });
74
77
  }
75
78
 
76
- private removeBufferedRange() {
79
+ private removeBuffer() {
77
80
  return this.performBufferOperation(() => {
78
81
  if (!this.sourceBuffer) return;
79
- this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
80
- });
81
- }
82
82
 
83
- private async removeBuffer() {
84
- if (!this.sourceBuffer) return;
85
-
86
- while (this.sourceBuffer.buffered.length > 0) {
87
- await this.removeBufferedRange();
88
- }
83
+ if (this.sourceBuffer.buffered.length > 0) {
84
+ this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
85
+ }
86
+ });
89
87
  }
90
88
 
91
89
  private resetTimestampOffset() {
@@ -102,7 +100,6 @@ export class ContinuousPlayer extends EventEmitter {
102
100
  }
103
101
 
104
102
  clear() {
105
- console.log("oyoiyo");
106
103
  this.operationsQueue.push(() => this.abortBuffer());
107
104
  this.operationsQueue.push(() => this.removeBuffer());
108
105
  this.operationsQueue.push(() => this.resetTimestampOffset());