@vapi-ai/web 1.0.84 → 1.0.86

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
@@ -4,12 +4,12 @@ export declare class ContinuousPlayer extends EventEmitter {
4
4
  private mediaSource;
5
5
  private sourceBuffer;
6
6
  private audio;
7
- private audioQueue;
7
+ private operationsQueue;
8
8
  constructor();
9
9
  start(): void;
10
10
  playChunk(audioData: ArrayBuffer): void;
11
- private appendNextChunk;
12
11
  private performBufferOperation;
12
+ private appendNextChunk;
13
13
  private removeBuffer;
14
14
  private resetTimestampOffset;
15
15
  private abortBuffer;
package/dist/player.js CHANGED
@@ -26,30 +26,20 @@ class ContinuousPlayer extends events_1.default {
26
26
  this.audio.addEventListener("waiting", () => this.emit("speech-end"));
27
27
  this.audio.src = URL.createObjectURL(this.mediaSource);
28
28
  document.body.appendChild(this.audio);
29
- this.audioQueue = async_1.default.queue((task, callback) => {
30
- this.appendNextChunk(task, callback);
29
+ this.operationsQueue = async_1.default.queue((task, callback) => {
30
+ task().then(() => callback());
31
31
  }, 1);
32
32
  this.mediaSource.addEventListener("sourceopen", () => {
33
33
  this.mediaSource.duration = Number.POSITIVE_INFINITY;
34
34
  this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
35
35
  this.sourceBuffer.mode = "sequence";
36
- this.sourceBuffer.addEventListener("updateend", () => {
37
- this.audioQueue.resume();
38
- });
39
36
  });
40
37
  }
41
38
  start() {
42
39
  this.audio.play();
43
40
  }
44
41
  playChunk(audioData) {
45
- this.audioQueue.push(audioData);
46
- }
47
- appendNextChunk(chunk, callback) {
48
- if (this.sourceBuffer && !this.sourceBuffer.updating) {
49
- this.audioQueue.pause();
50
- this.sourceBuffer.appendBuffer(chunk);
51
- }
52
- callback();
42
+ this.operationsQueue.push(() => this.appendNextChunk(audioData));
53
43
  }
54
44
  performBufferOperation(operation) {
55
45
  return new Promise((resolve) => {
@@ -63,6 +53,13 @@ class ContinuousPlayer extends events_1.default {
63
53
  operation();
64
54
  });
65
55
  }
56
+ appendNextChunk(chunk) {
57
+ return this.performBufferOperation(() => {
58
+ if (!this.sourceBuffer)
59
+ return;
60
+ this.sourceBuffer.appendBuffer(chunk);
61
+ });
62
+ }
66
63
  removeBuffer() {
67
64
  return this.performBufferOperation(() => {
68
65
  if (!this.sourceBuffer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -6,7 +6,7 @@ export class ContinuousPlayer extends EventEmitter {
6
6
  private mediaSource: MediaSource;
7
7
  private sourceBuffer: SourceBuffer | null = null;
8
8
  private audio: HTMLAudioElement;
9
- private audioQueue: QueueObject<ArrayBuffer>;
9
+ private operationsQueue: QueueObject<() => Promise<void>>;
10
10
 
11
11
  constructor() {
12
12
  super();
@@ -22,8 +22,8 @@ export class ContinuousPlayer extends EventEmitter {
22
22
  this.audio.src = URL.createObjectURL(this.mediaSource);
23
23
  document.body.appendChild(this.audio);
24
24
 
25
- this.audioQueue = async.queue((task, callback) => {
26
- this.appendNextChunk(task, callback);
25
+ this.operationsQueue = async.queue((task, callback) => {
26
+ task().then(() => callback());
27
27
  }, 1);
28
28
 
29
29
  this.mediaSource.addEventListener("sourceopen", () => {
@@ -32,10 +32,6 @@ export class ContinuousPlayer extends EventEmitter {
32
32
  'audio/webm; codecs="opus"'
33
33
  );
34
34
  this.sourceBuffer.mode = "sequence";
35
-
36
- this.sourceBuffer.addEventListener("updateend", () => {
37
- this.audioQueue.resume();
38
- });
39
35
  });
40
36
  }
41
37
 
@@ -44,18 +40,7 @@ export class ContinuousPlayer extends EventEmitter {
44
40
  }
45
41
 
46
42
  playChunk(audioData: ArrayBuffer) {
47
- this.audioQueue.push(audioData);
48
- }
49
-
50
- private appendNextChunk(
51
- chunk: ArrayBuffer,
52
- callback: async.ErrorCallback<Error>
53
- ): void {
54
- if (this.sourceBuffer && !this.sourceBuffer.updating) {
55
- this.audioQueue.pause();
56
- this.sourceBuffer.appendBuffer(chunk);
57
- }
58
- callback();
43
+ this.operationsQueue.push(() => this.appendNextChunk(audioData));
59
44
  }
60
45
 
61
46
  private performBufferOperation(operation: () => void) {
@@ -73,6 +58,13 @@ export class ContinuousPlayer extends EventEmitter {
73
58
  });
74
59
  }
75
60
 
61
+ private appendNextChunk(chunk: ArrayBuffer) {
62
+ return this.performBufferOperation(() => {
63
+ if (!this.sourceBuffer) return;
64
+ this.sourceBuffer.appendBuffer(chunk);
65
+ });
66
+ }
67
+
76
68
  private removeBuffer() {
77
69
  return this.performBufferOperation(() => {
78
70
  if (!this.sourceBuffer) return;