@vapi-ai/web 1.0.122 → 1.0.124

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.
@@ -1,11 +1,14 @@
1
1
  import async, { QueueObject } from "async";
2
2
 
3
- class AtomicMediaSource {
3
+ import EventEmitter from "events";
4
+
5
+ class AtomicMediaSource extends EventEmitter {
4
6
  mediaSource: MediaSource;
5
7
  private sourceBuffer: SourceBuffer | null = null;
6
8
  private operationsQueue: QueueObject<() => Promise<void>>;
7
9
 
8
10
  constructor() {
11
+ super();
9
12
  this.mediaSource = new MediaSource();
10
13
  this.operationsQueue = this.createOperationQueue();
11
14
 
@@ -19,17 +22,17 @@ class AtomicMediaSource {
19
22
  }
20
23
 
21
24
  public appendBuffer(buffer: ArrayBuffer) {
22
- console.log("APPEND OP PUSHED");
23
25
  this.operationsQueue.push(() => {
24
- console.log("APPEND OP START");
25
-
26
26
  return new Promise((resolve, reject) => {
27
27
  if (this.sourceBuffer) {
28
- this.sourceBuffer.addEventListener("updateend", () => {
29
- console.log("APPEND OP END");
30
-
31
- resolve();
32
- });
28
+ this.sourceBuffer.addEventListener(
29
+ "updateend",
30
+ () => {
31
+ this.emit("audio-loaded");
32
+ resolve();
33
+ },
34
+ { once: true }
35
+ );
33
36
  this.sourceBuffer.appendBuffer(buffer);
34
37
  } else {
35
38
  reject();
@@ -45,10 +48,14 @@ class AtomicMediaSource {
45
48
 
46
49
  return new Promise((resolve, reject) => {
47
50
  if (this.sourceBuffer) {
48
- this.sourceBuffer.addEventListener("updateend", () => {
49
- console.log("CLEAR OP END");
50
- resolve();
51
- });
51
+ this.sourceBuffer.addEventListener(
52
+ "updateend",
53
+ () => {
54
+ console.log("CLEAR OP END");
55
+ resolve();
56
+ },
57
+ { once: true }
58
+ );
52
59
  this.sourceBuffer.remove(0, this.mediaSource.duration);
53
60
  } else {
54
61
  reject();
@@ -1,4 +1,6 @@
1
- declare class AtomicMediaSource {
1
+ /// <reference types="node" />
2
+ import EventEmitter from "events";
3
+ declare class AtomicMediaSource extends EventEmitter {
2
4
  mediaSource: MediaSource;
3
5
  private sourceBuffer;
4
6
  private operationsQueue;
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const async_1 = __importDefault(require("async"));
7
- class AtomicMediaSource {
7
+ const events_1 = __importDefault(require("events"));
8
+ class AtomicMediaSource extends events_1.default {
8
9
  constructor() {
10
+ super();
9
11
  this.sourceBuffer = null;
10
12
  this.mediaSource = new MediaSource();
11
13
  this.operationsQueue = this.createOperationQueue();
@@ -16,15 +18,13 @@ class AtomicMediaSource {
16
18
  });
17
19
  }
18
20
  appendBuffer(buffer) {
19
- console.log("APPEND OP PUSHED");
20
21
  this.operationsQueue.push(() => {
21
- console.log("APPEND OP START");
22
22
  return new Promise((resolve, reject) => {
23
23
  if (this.sourceBuffer) {
24
24
  this.sourceBuffer.addEventListener("updateend", () => {
25
- console.log("APPEND OP END");
25
+ this.emit("audio-loaded");
26
26
  resolve();
27
- });
27
+ }, { once: true });
28
28
  this.sourceBuffer.appendBuffer(buffer);
29
29
  }
30
30
  else {
@@ -42,7 +42,7 @@ class AtomicMediaSource {
42
42
  this.sourceBuffer.addEventListener("updateend", () => {
43
43
  console.log("CLEAR OP END");
44
44
  resolve();
45
- });
45
+ }, { once: true });
46
46
  this.sourceBuffer.remove(0, this.mediaSource.duration);
47
47
  }
48
48
  else {
package/dist/player.js CHANGED
@@ -9,11 +9,12 @@ const events_1 = __importDefault(require("events"));
9
9
  class ContinuousPlayer extends events_1.default {
10
10
  constructor() {
11
11
  super();
12
- this.atomic = new AtomicMediaSource_1.default();
13
12
  this.audio = document.createElement("audio");
14
13
  this.audio.addEventListener("playing", () => this.emit("speech-start"));
15
14
  this.audio.addEventListener("play", () => this.emit("speech-start"));
15
+ this.audio.addEventListener("canplay", () => this.audio.play());
16
16
  this.audio.addEventListener("waiting", () => this.emit("speech-end"));
17
+ this.atomic = new AtomicMediaSource_1.default();
17
18
  this.audio.src = URL.createObjectURL(this.atomic.mediaSource);
18
19
  document.body.appendChild(this.audio);
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.122",
3
+ "version": "1.0.124",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/player.ts CHANGED
@@ -7,14 +7,17 @@ export class ContinuousPlayer extends EventEmitter {
7
7
 
8
8
  constructor() {
9
9
  super();
10
- this.atomic = new AtomicMediaSource();
11
10
 
12
11
  this.audio = document.createElement("audio");
13
12
 
14
13
  this.audio.addEventListener("playing", () => this.emit("speech-start"));
15
14
  this.audio.addEventListener("play", () => this.emit("speech-start"));
15
+ this.audio.addEventListener("canplay", () => this.audio.play());
16
+
16
17
  this.audio.addEventListener("waiting", () => this.emit("speech-end"));
17
18
 
19
+ this.atomic = new AtomicMediaSource();
20
+
18
21
  this.audio.src = URL.createObjectURL(this.atomic.mediaSource);
19
22
  document.body.appendChild(this.audio);
20
23
  }