@vapi-ai/web 1.0.95 → 1.0.97

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
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import async from "async";
2
3
  import EventEmitter from "events";
3
4
  export declare class ContinuousPlayer extends EventEmitter {
4
5
  private mediaSource;
@@ -6,12 +7,12 @@ export declare class ContinuousPlayer extends EventEmitter {
6
7
  private audio;
7
8
  private operationsQueue;
8
9
  constructor();
10
+ createOperationQueue(): async.QueueObject<() => Promise<void>>;
9
11
  start(): void;
10
12
  playChunk(audioData: ArrayBuffer): void;
11
13
  private performBufferOperation;
12
14
  private appendNextChunk;
13
15
  private removeBuffer;
14
16
  private resetTimestampOffset;
15
- private abortBuffer;
16
17
  clear(): void;
17
18
  }
package/dist/player.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -26,15 +17,18 @@ class ContinuousPlayer extends events_1.default {
26
17
  this.audio.addEventListener("waiting", () => this.emit("speech-end"));
27
18
  this.audio.src = URL.createObjectURL(this.mediaSource);
28
19
  document.body.appendChild(this.audio);
29
- this.operationsQueue = async_1.default.queue((task, callback) => {
30
- task().then(() => callback());
31
- }, 1);
20
+ this.operationsQueue = this.createOperationQueue();
32
21
  this.mediaSource.addEventListener("sourceopen", () => {
33
22
  this.mediaSource.duration = Number.POSITIVE_INFINITY;
34
23
  this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
35
24
  this.sourceBuffer.mode = "sequence";
36
25
  });
37
26
  }
27
+ createOperationQueue() {
28
+ return async_1.default.queue((task, callback) => {
29
+ task().then(() => callback());
30
+ }, 1);
31
+ }
38
32
  start() {
39
33
  this.audio.play();
40
34
  }
@@ -83,16 +77,12 @@ class ContinuousPlayer extends events_1.default {
83
77
  this.sourceBuffer.timestampOffset = 0;
84
78
  });
85
79
  }
86
- abortBuffer() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- if (!this.sourceBuffer)
89
- return;
90
- // This does not emit updateend
91
- this.sourceBuffer.abort();
92
- });
93
- }
94
80
  clear() {
95
- this.operationsQueue.push(() => this.abortBuffer());
81
+ if (!this.sourceBuffer)
82
+ return;
83
+ this.sourceBuffer.abort();
84
+ this.operationsQueue.kill();
85
+ this.operationsQueue = this.createOperationQueue();
96
86
  this.operationsQueue.push(() => this.removeBuffer());
97
87
  this.operationsQueue.push(() => this.resetTimestampOffset());
98
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -22,9 +22,7 @@ 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.operationsQueue = async.queue((task, callback) => {
26
- task().then(() => callback());
27
- }, 1);
25
+ this.operationsQueue = this.createOperationQueue();
28
26
 
29
27
  this.mediaSource.addEventListener("sourceopen", () => {
30
28
  this.mediaSource.duration = Number.POSITIVE_INFINITY;
@@ -35,6 +33,12 @@ export class ContinuousPlayer extends EventEmitter {
35
33
  });
36
34
  }
37
35
 
36
+ createOperationQueue() {
37
+ return async.queue<() => Promise<void>>((task, callback) => {
38
+ task().then(() => callback());
39
+ }, 1);
40
+ }
41
+
38
42
  start() {
39
43
  this.audio.play();
40
44
  }
@@ -96,14 +100,13 @@ export class ContinuousPlayer extends EventEmitter {
96
100
  });
97
101
  }
98
102
 
99
- private async abortBuffer() {
103
+ clear() {
100
104
  if (!this.sourceBuffer) return;
101
- // This does not emit updateend
102
105
  this.sourceBuffer.abort();
103
- }
104
106
 
105
- clear() {
106
- this.operationsQueue.push(() => this.abortBuffer());
107
+ this.operationsQueue.kill();
108
+ this.operationsQueue = this.createOperationQueue();
109
+
107
110
  this.operationsQueue.push(() => this.removeBuffer());
108
111
  this.operationsQueue.push(() => this.resetTimestampOffset());
109
112
  }