@vapi-ai/web 1.0.91 → 1.0.93

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,6 +10,7 @@ export declare class ContinuousPlayer extends EventEmitter {
10
10
  playChunk(audioData: ArrayBuffer): void;
11
11
  private performBufferOperation;
12
12
  private appendNextChunk;
13
+ private removeBufferedRange;
13
14
  private removeBuffer;
14
15
  private resetTimestampOffset;
15
16
  private abortBuffer;
package/dist/player.js CHANGED
@@ -42,41 +42,48 @@ 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) {
61
- console.log("appendNextChunk");
62
64
  return this.performBufferOperation(() => {
63
65
  if (!this.sourceBuffer)
64
66
  return;
65
67
  this.sourceBuffer.appendBuffer(chunk);
66
68
  });
67
69
  }
68
- removeBuffer() {
69
- console.log("removeBuffer");
70
+ removeBufferedRange() {
70
71
  return this.performBufferOperation(() => {
72
+ if (!this.sourceBuffer)
73
+ return;
74
+ this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
75
+ });
76
+ }
77
+ removeBuffer() {
78
+ return __awaiter(this, void 0, void 0, function* () {
71
79
  if (!this.sourceBuffer)
72
80
  return;
73
81
  while (this.sourceBuffer.buffered.length > 0) {
74
- this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
82
+ yield this.removeBufferedRange();
75
83
  }
76
84
  });
77
85
  }
78
86
  resetTimestampOffset() {
79
- console.log("resetTimestampOffset");
80
87
  return this.performBufferOperation(() => {
81
88
  if (!this.sourceBuffer)
82
89
  return;
@@ -92,7 +99,6 @@ class ContinuousPlayer extends events_1.default {
92
99
  });
93
100
  }
94
101
  clear() {
95
- console.log("oyoiyo");
96
102
  this.operationsQueue.push(() => this.abortBuffer());
97
103
  this.operationsQueue.push(() => this.removeBuffer());
98
104
  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.91",
3
+ "version": "1.0.93",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -44,48 +44,54 @@ 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
 
69
72
  private appendNextChunk(chunk: ArrayBuffer) {
70
- console.log("appendNextChunk");
71
73
  return this.performBufferOperation(() => {
72
74
  if (!this.sourceBuffer) return;
73
75
  this.sourceBuffer.appendBuffer(chunk);
74
76
  });
75
77
  }
76
78
 
77
- private removeBuffer() {
78
- console.log("removeBuffer");
79
+ private removeBufferedRange() {
79
80
  return this.performBufferOperation(() => {
80
81
  if (!this.sourceBuffer) return;
81
- while (this.sourceBuffer.buffered.length > 0) {
82
- this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
83
- }
82
+ this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
84
83
  });
85
84
  }
86
85
 
86
+ private async removeBuffer() {
87
+ if (!this.sourceBuffer) return;
88
+
89
+ while (this.sourceBuffer.buffered.length > 0) {
90
+ await this.removeBufferedRange();
91
+ }
92
+ }
93
+
87
94
  private resetTimestampOffset() {
88
- console.log("resetTimestampOffset");
89
95
  return this.performBufferOperation(() => {
90
96
  if (!this.sourceBuffer) return;
91
97
  this.sourceBuffer.timestampOffset = 0;
@@ -99,7 +105,6 @@ export class ContinuousPlayer extends EventEmitter {
99
105
  }
100
106
 
101
107
  clear() {
102
- console.log("oyoiyo");
103
108
  this.operationsQueue.push(() => this.abortBuffer());
104
109
  this.operationsQueue.push(() => this.removeBuffer());
105
110
  this.operationsQueue.push(() => this.resetTimestampOffset());