@vapi-ai/web 1.0.218 → 1.0.220
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 -2
- package/dist/vapi.js +66 -64
- package/package.json +1 -1
- package/vapi.ts +70 -68
package/dist/vapi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { CreateAssistantDTO } from "./api";
|
|
2
|
+
import { Call, CreateAssistantDTO } from "./api";
|
|
3
3
|
import EventEmitter from "events";
|
|
4
4
|
type VapiEventNames = "call-end" | "call-start" | "volume-level" | "speech-start" | "speech-end" | "error";
|
|
5
5
|
type VapiEventListeners = {
|
|
@@ -22,7 +22,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
22
22
|
private call;
|
|
23
23
|
private speakingTimeout;
|
|
24
24
|
constructor(apiToken: string, apiBaseUrl?: string);
|
|
25
|
-
start(assistant: CreateAssistantDTO | string):
|
|
25
|
+
start(assistant: CreateAssistantDTO | string): Promise<Call | null>;
|
|
26
26
|
private handleRemoteParticipantsAudioLevel;
|
|
27
27
|
stop(): void;
|
|
28
28
|
}
|
package/dist/vapi.js
CHANGED
|
@@ -79,71 +79,73 @@ class Vapi extends VapiEventEmitter {
|
|
|
79
79
|
client_1.client.setSecurityData(apiToken);
|
|
80
80
|
}
|
|
81
81
|
start(assistant) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
82
|
+
var _a;
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
if (this.started) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
this.started = true;
|
|
88
|
+
try {
|
|
89
|
+
const webCall = (yield client_1.client.call.callControllerCreateWebCall({
|
|
90
|
+
assistant: typeof assistant === "string" ? undefined : assistant,
|
|
91
|
+
assistantId: typeof assistant === "string" ? assistant : undefined,
|
|
92
|
+
})).data;
|
|
93
|
+
this.call = daily_js_1.default.createCallObject({
|
|
94
|
+
audioSource: true,
|
|
95
|
+
videoSource: false,
|
|
96
|
+
});
|
|
97
|
+
(_a = this.call.iframe()) === null || _a === void 0 ? void 0 : _a.style.setProperty("display", "none");
|
|
98
|
+
this.call.on("left-meeting", () => {
|
|
99
|
+
this.emit("call-end");
|
|
100
|
+
});
|
|
101
|
+
this.call.on("participant-left", (e) => {
|
|
102
|
+
if (!e)
|
|
103
|
+
return;
|
|
104
|
+
destroyAudioPlayer(e.participant.session_id);
|
|
105
|
+
});
|
|
106
|
+
this.call.on("error", () => {
|
|
107
|
+
// Ignore error
|
|
108
|
+
});
|
|
109
|
+
this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
var _b, _c, _d;
|
|
111
|
+
if (!e || !e.participant)
|
|
112
|
+
return;
|
|
113
|
+
if ((_b = e.participant) === null || _b === void 0 ? void 0 : _b.local)
|
|
114
|
+
return;
|
|
115
|
+
if (e.track.kind !== "audio")
|
|
116
|
+
return;
|
|
117
|
+
yield buildAudioPlayer(e.track, e.participant.session_id);
|
|
118
|
+
if (((_c = e === null || e === void 0 ? void 0 : e.participant) === null || _c === void 0 ? void 0 : _c.user_name) !== "Vapi Speaker")
|
|
119
|
+
return;
|
|
120
|
+
(_d = this.call) === null || _d === void 0 ? void 0 : _d.sendAppMessage("playable");
|
|
121
|
+
this.emit("call-start");
|
|
122
|
+
}));
|
|
123
|
+
this.call.on("participant-joined", (e) => {
|
|
124
|
+
if (!e || !this.call)
|
|
125
|
+
return;
|
|
126
|
+
subscribeToTracks(e, this.call);
|
|
127
|
+
});
|
|
128
|
+
yield this.call.join({
|
|
129
|
+
url: webCall.webCallUrl,
|
|
130
|
+
subscribeToTracksAutomatically: false,
|
|
131
|
+
});
|
|
132
|
+
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
133
|
+
this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
|
|
134
|
+
this.call.updateInputSettings({
|
|
135
|
+
audio: {
|
|
136
|
+
processor: {
|
|
137
|
+
type: "noise-cancellation",
|
|
138
|
+
},
|
|
139
139
|
},
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
});
|
|
141
|
+
return webCall;
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
console.error(e);
|
|
145
|
+
this.emit("error", e);
|
|
146
|
+
this.started = false;
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
147
149
|
});
|
|
148
150
|
}
|
|
149
151
|
handleRemoteParticipantsAudioLevel(e) {
|
package/package.json
CHANGED
package/vapi.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Call, CreateAssistantDTO } from "./api";
|
|
1
2
|
import DailyIframe, {
|
|
2
3
|
DailyCall,
|
|
3
4
|
DailyEventObjectActiveSpeakerChange,
|
|
@@ -5,7 +6,6 @@ import DailyIframe, {
|
|
|
5
6
|
DailyEventObjectRemoteParticipantsAudioLevel,
|
|
6
7
|
} from "@daily-co/daily-js";
|
|
7
8
|
|
|
8
|
-
import { CreateAssistantDTO } from "./api";
|
|
9
9
|
import EventEmitter from "events";
|
|
10
10
|
import { client } from "./client";
|
|
11
11
|
|
|
@@ -102,80 +102,82 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
102
102
|
client.setSecurityData(apiToken);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
start(assistant: CreateAssistantDTO | string):
|
|
105
|
+
async start(assistant: CreateAssistantDTO | string): Promise<Call | null> {
|
|
106
106
|
if (this.started) {
|
|
107
|
-
return;
|
|
107
|
+
return null;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
this.started = true;
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
},
|
|
112
|
+
try {
|
|
113
|
+
const webCall = (
|
|
114
|
+
await client.call.callControllerCreateWebCall({
|
|
115
|
+
assistant: typeof assistant === "string" ? undefined : assistant,
|
|
116
|
+
assistantId: typeof assistant === "string" ? assistant : undefined,
|
|
117
|
+
})
|
|
118
|
+
).data;
|
|
119
|
+
|
|
120
|
+
this.call = DailyIframe.createCallObject({
|
|
121
|
+
audioSource: true,
|
|
122
|
+
videoSource: false,
|
|
123
|
+
});
|
|
124
|
+
this.call.iframe()?.style.setProperty("display", "none");
|
|
125
|
+
|
|
126
|
+
this.call.on("left-meeting", () => {
|
|
127
|
+
this.emit("call-end");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this.call.on("participant-left", (e) => {
|
|
131
|
+
if (!e) return;
|
|
132
|
+
destroyAudioPlayer(e.participant.session_id);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
this.call.on("error", () => {
|
|
136
|
+
// Ignore error
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
this.call.on("track-started", async (e) => {
|
|
140
|
+
if (!e || !e.participant) return;
|
|
141
|
+
if (e.participant?.local) return;
|
|
142
|
+
if (e.track.kind !== "audio") return;
|
|
143
|
+
|
|
144
|
+
await buildAudioPlayer(e.track, e.participant.session_id);
|
|
145
|
+
|
|
146
|
+
if (e?.participant?.user_name !== "Vapi Speaker") return;
|
|
147
|
+
this.call?.sendAppMessage("playable");
|
|
148
|
+
this.emit("call-start");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
this.call.on("participant-joined", (e) => {
|
|
152
|
+
if (!e || !this.call) return;
|
|
153
|
+
subscribeToTracks(e, this.call);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
await this.call.join({
|
|
157
|
+
url: webCall.webCallUrl,
|
|
158
|
+
subscribeToTracksAutomatically: false,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
162
|
+
this.call.on("remote-participants-audio-level", (e) =>
|
|
163
|
+
this.handleRemoteParticipantsAudioLevel(e)
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
this.call.updateInputSettings({
|
|
167
|
+
audio: {
|
|
168
|
+
processor: {
|
|
169
|
+
type: "noise-cancellation",
|
|
171
170
|
},
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
.catch((res) => {
|
|
175
|
-
console.error(res.error);
|
|
176
|
-
this.emit("error", res.error);
|
|
177
|
-
this.started = false;
|
|
171
|
+
},
|
|
178
172
|
});
|
|
173
|
+
|
|
174
|
+
return webCall;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.error(e);
|
|
177
|
+
this.emit("error", e);
|
|
178
|
+
this.started = false;
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
179
181
|
}
|
|
180
182
|
|
|
181
183
|
private handleRemoteParticipantsAudioLevel(
|