@vapi-ai/web 1.0.168 → 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 +2 -1
- package/dist/vapi.js +23 -13
- package/package.json +1 -1
- package/vapi.ts +20 -13
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
|
|
10
|
+
private handleRemoteParticipantsAudioLevel;
|
|
10
11
|
stop(): void;
|
|
11
12
|
}
|
package/dist/vapi.js
CHANGED
|
@@ -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
|
};
|
|
@@ -11,6 +20,7 @@ class Vapi extends events_1.default {
|
|
|
11
20
|
super();
|
|
12
21
|
this.started = false;
|
|
13
22
|
this.call = null;
|
|
23
|
+
this.speaking = false;
|
|
14
24
|
client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
|
|
15
25
|
client_1.client.setSecurityData(apiToken);
|
|
16
26
|
}
|
|
@@ -24,7 +34,7 @@ class Vapi extends events_1.default {
|
|
|
24
34
|
assistant: typeof assistant === "string" ? undefined : assistant,
|
|
25
35
|
assistantId: typeof assistant === "string" ? assistant : undefined,
|
|
26
36
|
})
|
|
27
|
-
.then(({ data }) => {
|
|
37
|
+
.then(({ data }) => __awaiter(this, void 0, void 0, function* () {
|
|
28
38
|
var _a;
|
|
29
39
|
const { url } = data;
|
|
30
40
|
this.call = daily_js_1.default.createFrame({
|
|
@@ -32,25 +42,25 @@ class Vapi extends events_1.default {
|
|
|
32
42
|
videoSource: false,
|
|
33
43
|
});
|
|
34
44
|
(_a = this.call.iframe()) === null || _a === void 0 ? void 0 : _a.style.setProperty("display", "none");
|
|
35
|
-
this.call.join({ url });
|
|
36
|
-
this.call.
|
|
37
|
-
this.call.
|
|
38
|
-
|
|
39
|
-
console.log(e);
|
|
40
|
-
});
|
|
41
|
-
})
|
|
45
|
+
yield this.call.join({ url });
|
|
46
|
+
this.call.startRemoteParticipantsAudioLevelObserver(500);
|
|
47
|
+
this.call.on("remote-participants-audio-level", this.handleRemoteParticipantsAudioLevel);
|
|
48
|
+
}))
|
|
42
49
|
.catch((error) => {
|
|
43
50
|
console.error(error);
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
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");
|
|
50
59
|
}
|
|
51
60
|
else {
|
|
52
|
-
this.emit("speech-
|
|
61
|
+
this.emit("speech-end");
|
|
53
62
|
}
|
|
63
|
+
this.speaking = isSpeaking;
|
|
54
64
|
}
|
|
55
65
|
stop() {
|
|
56
66
|
var _a;
|
package/package.json
CHANGED
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();
|
|
@@ -29,7 +31,7 @@ export default class Vapi extends EventEmitter {
|
|
|
29
31
|
assistant: typeof assistant === "string" ? undefined : assistant,
|
|
30
32
|
assistantId: typeof assistant === "string" ? assistant : undefined,
|
|
31
33
|
})
|
|
32
|
-
.then(({ data }) => {
|
|
34
|
+
.then(async ({ data }) => {
|
|
33
35
|
const { url } = data;
|
|
34
36
|
|
|
35
37
|
this.call = DailyIframe.createFrame({
|
|
@@ -37,29 +39,34 @@ export default class Vapi extends EventEmitter {
|
|
|
37
39
|
videoSource: false,
|
|
38
40
|
});
|
|
39
41
|
this.call.iframe()?.style.setProperty("display", "none");
|
|
40
|
-
this.call.join({ url });
|
|
42
|
+
await this.call.join({ url });
|
|
41
43
|
|
|
44
|
+
this.call.startRemoteParticipantsAudioLevelObserver(500);
|
|
42
45
|
this.call.on(
|
|
43
|
-
"
|
|
44
|
-
|
|
46
|
+
"remote-participants-audio-level",
|
|
47
|
+
this.handleRemoteParticipantsAudioLevel
|
|
45
48
|
);
|
|
46
|
-
|
|
47
|
-
this.call.startRemoteParticipantsAudioLevelObserver();
|
|
48
|
-
this.call.on("remote-participants-audio-level", (e) => {
|
|
49
|
-
console.log(e);
|
|
50
|
-
});
|
|
51
49
|
})
|
|
52
50
|
.catch((error) => {
|
|
53
51
|
console.error(error);
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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) {
|
|
61
64
|
this.emit("speech-start");
|
|
65
|
+
} else {
|
|
66
|
+
this.emit("speech-end");
|
|
62
67
|
}
|
|
68
|
+
|
|
69
|
+
this.speaking = isSpeaking;
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
stop(): void {
|