@vapi-ai/web 1.0.169 → 1.0.170

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/vapi.d.ts CHANGED
@@ -4,8 +4,9 @@ import EventEmitter from "events";
4
4
  export default class Vapi extends EventEmitter {
5
5
  private started;
6
6
  private call;
7
+ private speaking;
7
8
  constructor(apiToken: string, apiBaseUrl?: string);
8
9
  start(assistant: CreateAssistantDTO | string): void;
9
- private handleSpeakerChange;
10
+ private handleRemoteParticipantsAudioLevel;
10
11
  stop(): void;
11
12
  }
package/dist/vapi.js CHANGED
@@ -20,6 +20,7 @@ class Vapi extends events_1.default {
20
20
  super();
21
21
  this.started = false;
22
22
  this.call = null;
23
+ this.speaking = false;
23
24
  client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
24
25
  client_1.client.setSecurityData(apiToken);
25
26
  }
@@ -43,22 +44,23 @@ class Vapi extends events_1.default {
43
44
  (_a = this.call.iframe()) === null || _a === void 0 ? void 0 : _a.style.setProperty("display", "none");
44
45
  yield this.call.join({ url });
45
46
  this.call.startRemoteParticipantsAudioLevelObserver(500);
46
- this.call.on("remote-participants-audio-level", (e) => {
47
- console.log(e);
48
- });
47
+ this.call.on("remote-participants-audio-level", this.handleRemoteParticipantsAudioLevel);
49
48
  }))
50
49
  .catch((error) => {
51
50
  console.error(error);
52
51
  });
53
52
  }
54
- handleSpeakerChange(e) {
55
- var _a, _b, _c;
56
- if (e.activeSpeaker.peerId === ((_c = (_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.participants()) === null || _b === void 0 ? void 0 : _b.local) === null || _c === void 0 ? void 0 : _c.user_id)) {
57
- this.emit("speech-end");
53
+ handleRemoteParticipantsAudioLevel(e) {
54
+ const isSpeaking = Object.values(e.participantsAudioLevel).some((v) => v > 0);
55
+ if (isSpeaking === this.speaking)
56
+ return;
57
+ if (isSpeaking) {
58
+ this.emit("speech-start");
58
59
  }
59
60
  else {
60
- this.emit("speech-start");
61
+ this.emit("speech-end");
61
62
  }
63
+ this.speaking = isSpeaking;
62
64
  }
63
65
  stop() {
64
66
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.169",
3
+ "version": "1.0.170",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import DailyIframe, {
2
2
  DailyCall,
3
3
  DailyEventObjectActiveSpeakerChange,
4
+ DailyEventObjectRemoteParticipantsAudioLevel,
4
5
  } from "@daily-co/daily-js";
5
6
 
6
7
  import { CreateAssistantDTO } from "./api";
@@ -10,6 +11,7 @@ import { client } from "./client";
10
11
  export default class Vapi extends EventEmitter {
11
12
  private started: boolean = false;
12
13
  private call: DailyCall | null = null;
14
+ private speaking = false;
13
15
 
14
16
  constructor(apiToken: string, apiBaseUrl?: string) {
15
17
  super();
@@ -40,21 +42,31 @@ export default class Vapi extends EventEmitter {
40
42
  await this.call.join({ url });
41
43
 
42
44
  this.call.startRemoteParticipantsAudioLevelObserver(500);
43
- this.call.on("remote-participants-audio-level", (e) => {
44
- console.log(e);
45
- });
45
+ this.call.on(
46
+ "remote-participants-audio-level",
47
+ this.handleRemoteParticipantsAudioLevel
48
+ );
46
49
  })
47
50
  .catch((error) => {
48
51
  console.error(error);
49
52
  });
50
53
  }
51
54
 
52
- private handleSpeakerChange(e: DailyEventObjectActiveSpeakerChange) {
53
- if (e.activeSpeaker.peerId === this.call?.participants()?.local?.user_id) {
54
- this.emit("speech-end");
55
- } else {
55
+ private handleRemoteParticipantsAudioLevel(
56
+ e: DailyEventObjectRemoteParticipantsAudioLevel
57
+ ) {
58
+ const isSpeaking = Object.values(e.participantsAudioLevel).some(
59
+ (v) => v > 0
60
+ );
61
+ if (isSpeaking === this.speaking) return;
62
+
63
+ if (isSpeaking) {
56
64
  this.emit("speech-start");
65
+ } else {
66
+ this.emit("speech-end");
57
67
  }
68
+
69
+ this.speaking = isSpeaking;
58
70
  }
59
71
 
60
72
  stop(): void {