@vapi-ai/web 1.0.109 → 1.0.111

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.
@@ -10,11 +10,7 @@ class AtomicMediaSource {
10
10
  this.operationsQueue = this.createOperationQueue();
11
11
 
12
12
  this.mediaSource.addEventListener("sourceopen", () => {
13
- this.mediaSource.duration = Number.POSITIVE_INFINITY;
14
- this.sourceBuffer = this.mediaSource.addSourceBuffer(
15
- 'audio/webm; codecs="opus"'
16
- );
17
- this.sourceBuffer.mode = "sequence";
13
+ this.resetBuffer();
18
14
  });
19
15
  }
20
16
 
@@ -27,26 +23,22 @@ class AtomicMediaSource {
27
23
  });
28
24
  this.sourceBuffer.appendBuffer(buffer);
29
25
  } else {
26
+ console.error("No source buffer");
30
27
  reject();
31
28
  }
32
29
  });
33
30
  });
34
31
  }
35
32
 
36
- public clearBuffer() {
37
- this.operationsQueue.push(() => {
38
- return new Promise((resolve, reject) => {
39
- if (this.sourceBuffer) {
40
- this.sourceBuffer.addEventListener("updateend", () => {
41
- this.mediaSource.duration = Number.POSITIVE_INFINITY;
42
- this.sourceBuffer!.timestampOffset = 0;
43
- resolve();
44
- });
45
- this.sourceBuffer.remove(0, this.mediaSource.duration);
46
- } else {
47
- reject();
48
- }
49
- });
33
+ public resetBuffer() {
34
+ this.operationsQueue.push(async () => {
35
+ if (!this.sourceBuffer) return;
36
+
37
+ this.mediaSource.removeSourceBuffer(this.sourceBuffer);
38
+ this.sourceBuffer = this.mediaSource.addSourceBuffer(
39
+ 'audio/webm; codecs="opus"'
40
+ );
41
+ this.sourceBuffer.mode = "sequence";
50
42
  });
51
43
  }
52
44
 
@@ -4,7 +4,7 @@ declare class AtomicMediaSource {
4
4
  private operationsQueue;
5
5
  constructor();
6
6
  appendBuffer(buffer: ArrayBuffer): void;
7
- clearBuffer(): void;
7
+ resetBuffer(): void;
8
8
  private createOperationQueue;
9
9
  }
10
10
  export default AtomicMediaSource;
@@ -1,4 +1,13 @@
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -10,9 +19,7 @@ class AtomicMediaSource {
10
19
  this.mediaSource = new MediaSource();
11
20
  this.operationsQueue = this.createOperationQueue();
12
21
  this.mediaSource.addEventListener("sourceopen", () => {
13
- this.mediaSource.duration = Number.POSITIVE_INFINITY;
14
- this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
15
- this.sourceBuffer.mode = "sequence";
22
+ this.resetBuffer();
16
23
  });
17
24
  }
18
25
  appendBuffer(buffer) {
@@ -25,27 +32,20 @@ class AtomicMediaSource {
25
32
  this.sourceBuffer.appendBuffer(buffer);
26
33
  }
27
34
  else {
35
+ console.error("No source buffer");
28
36
  reject();
29
37
  }
30
38
  });
31
39
  });
32
40
  }
33
- clearBuffer() {
34
- this.operationsQueue.push(() => {
35
- return new Promise((resolve, reject) => {
36
- if (this.sourceBuffer) {
37
- this.sourceBuffer.addEventListener("updateend", () => {
38
- this.mediaSource.duration = Number.POSITIVE_INFINITY;
39
- this.sourceBuffer.timestampOffset = 0;
40
- resolve();
41
- });
42
- this.sourceBuffer.remove(0, this.mediaSource.duration);
43
- }
44
- else {
45
- reject();
46
- }
47
- });
48
- });
41
+ resetBuffer() {
42
+ this.operationsQueue.push(() => __awaiter(this, void 0, void 0, function* () {
43
+ if (!this.sourceBuffer)
44
+ return;
45
+ this.mediaSource.removeSourceBuffer(this.sourceBuffer);
46
+ this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
47
+ this.sourceBuffer.mode = "sequence";
48
+ }));
49
49
  }
50
50
  createOperationQueue() {
51
51
  return async_1.default.queue((task, callback) => {
package/dist/player.js CHANGED
@@ -24,7 +24,7 @@ class ContinuousPlayer extends events_1.default {
24
24
  this.atomic.appendBuffer(audioData);
25
25
  }
26
26
  clear() {
27
- this.atomic.clearBuffer();
27
+ this.atomic.resetBuffer();
28
28
  }
29
29
  }
30
30
  exports.ContinuousPlayer = ContinuousPlayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.109",
3
+ "version": "1.0.111",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -28,6 +28,6 @@ export class ContinuousPlayer extends EventEmitter {
28
28
  }
29
29
 
30
30
  clear() {
31
- this.atomic.clearBuffer();
31
+ this.atomic.resetBuffer();
32
32
  }
33
33
  }