@vapi-ai/web 1.0.24 → 1.0.26

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.js CHANGED
@@ -11,34 +11,32 @@ class ContinuousPlayer extends events_1.default {
11
11
  this.sourceBuffer = null;
12
12
  this.audioQueue = [];
13
13
  this.mediaSource = new MediaSource();
14
+ this.audio = document.createElement("audio");
15
+ document.body.appendChild(this.audio);
14
16
  this.mediaSource.addEventListener("sourceopen", () => {
15
17
  this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
18
+ this.audio.src = URL.createObjectURL(this.mediaSource);
16
19
  this.sourceBuffer.addEventListener("updateend", () => {
17
20
  this.appendNextChunk();
18
21
  });
19
22
  });
20
- this.audio = document.createElement("audio");
21
- document.body.appendChild(this.audio);
22
- this.audio.src = URL.createObjectURL(this.mediaSource);
23
23
  }
24
- start() { }
24
+ start() {
25
+ this.audio.play();
26
+ }
25
27
  playChunk(audioData) {
26
28
  this.audioQueue.push(audioData);
27
29
  this.appendNextChunk();
28
30
  }
29
31
  appendNextChunk() {
30
- var _a, _b;
32
+ var _a;
31
33
  console.log(this.sourceBuffer, (_a = this.sourceBuffer) === null || _a === void 0 ? void 0 : _a.updating, this.audioQueue.length);
32
34
  if (this.sourceBuffer &&
33
35
  !this.sourceBuffer.updating &&
34
36
  this.audioQueue.length > 0) {
35
- console.log("appended2");
36
37
  const chunk = this.audioQueue.shift();
37
38
  if (chunk) {
38
- console.log("chunk");
39
39
  this.sourceBuffer.appendBuffer(chunk);
40
- (_b = this.audio) === null || _b === void 0 ? void 0 : _b.play();
41
- console.log(this.audio);
42
40
  }
43
41
  }
44
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -9,21 +9,23 @@ export class ContinuousPlayer extends EventEmitter {
9
9
  constructor() {
10
10
  super();
11
11
  this.mediaSource = new MediaSource();
12
+ this.audio = document.createElement("audio");
13
+ document.body.appendChild(this.audio);
12
14
 
13
15
  this.mediaSource.addEventListener("sourceopen", () => {
14
16
  this.sourceBuffer = this.mediaSource.addSourceBuffer(
15
17
  'audio/webm; codecs="opus"'
16
18
  );
19
+ this.audio.src = URL.createObjectURL(this.mediaSource);
17
20
  this.sourceBuffer.addEventListener("updateend", () => {
18
21
  this.appendNextChunk();
19
22
  });
20
23
  });
21
- this.audio = document.createElement("audio");
22
- document.body.appendChild(this.audio);
23
- this.audio.src = URL.createObjectURL(this.mediaSource);
24
24
  }
25
25
 
26
- start() {}
26
+ start() {
27
+ this.audio.play();
28
+ }
27
29
 
28
30
  playChunk(audioData: ArrayBuffer) {
29
31
  this.audioQueue.push(audioData);
@@ -42,13 +44,9 @@ export class ContinuousPlayer extends EventEmitter {
42
44
  !this.sourceBuffer.updating &&
43
45
  this.audioQueue.length > 0
44
46
  ) {
45
- console.log("appended2");
46
47
  const chunk = this.audioQueue.shift();
47
48
  if (chunk) {
48
- console.log("chunk");
49
49
  this.sourceBuffer.appendBuffer(chunk);
50
- this.audio?.play();
51
- console.log(this.audio);
52
50
  }
53
51
  }
54
52
  }