@vapi-ai/web 2.1.9 → 2.2.0
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 +5 -2
- package/dist/vapi.js +31 -10
- package/package.json +1 -1
- package/vapi.ts +45 -14
package/dist/vapi.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ChatCompletionMessageParam } from 'openai/resources';
|
|
3
|
-
import { DailyCall, DailyAdvancedConfig, DailyFactoryOptions } from '@daily-co/daily-js';
|
|
3
|
+
import { DailyCall, DailyAdvancedConfig, DailyFactoryOptions, DailyParticipant, DailyVideoSendSettings } from '@daily-co/daily-js';
|
|
4
4
|
import EventEmitter from 'events';
|
|
5
5
|
import { Call, CreateSquadDTO, CreateAssistantDTO, AssistantOverrides } from './api';
|
|
6
6
|
export interface AddMessageMessage {
|
|
@@ -18,7 +18,7 @@ export interface SayMessage {
|
|
|
18
18
|
endCallAfterSpoken?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type VapiClientToServerMessage = AddMessageMessage | ControlMessages | SayMessage;
|
|
21
|
-
type VapiEventNames = 'call-end' | 'call-start' | 'volume-level' | 'speech-start' | 'speech-end' | 'message' | 'video' | 'error';
|
|
21
|
+
type VapiEventNames = 'call-end' | 'call-start' | 'volume-level' | 'speech-start' | 'speech-end' | 'message' | 'video' | 'error' | 'daily-participant-updated';
|
|
22
22
|
type VapiEventListeners = {
|
|
23
23
|
'call-end': () => void;
|
|
24
24
|
'call-start': () => void;
|
|
@@ -28,6 +28,7 @@ type VapiEventListeners = {
|
|
|
28
28
|
video: (track: MediaStreamTrack) => void;
|
|
29
29
|
message: (message: any) => void;
|
|
30
30
|
error: (error: any) => void;
|
|
31
|
+
'daily-participant-updated': (participant: DailyParticipant) => void;
|
|
31
32
|
};
|
|
32
33
|
declare class VapiEventEmitter extends EventEmitter {
|
|
33
34
|
on<E extends VapiEventNames>(event: E, listener: VapiEventListeners[E]): this;
|
|
@@ -57,5 +58,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
57
58
|
setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): void;
|
|
58
59
|
setOutputDeviceAsync(options: Parameters<DailyCall['setOutputDeviceAsync']>[0]): void;
|
|
59
60
|
getDailyCallObject(): DailyCall | null;
|
|
61
|
+
startScreenSharing(displayMediaOptions?: DisplayMediaStreamOptions, screenVideoSendSettings?: DailyVideoSendSettings): void;
|
|
62
|
+
stopScreenSharing(): void;
|
|
60
63
|
}
|
|
61
64
|
export {};
|
package/dist/vapi.js
CHANGED
|
@@ -119,11 +119,6 @@ class Vapi extends VapiEventEmitter {
|
|
|
119
119
|
}
|
|
120
120
|
this.cleanup();
|
|
121
121
|
});
|
|
122
|
-
this.call.on('participant-left', (e) => {
|
|
123
|
-
if (!e)
|
|
124
|
-
return;
|
|
125
|
-
destroyAudioPlayer(e.participant.session_id);
|
|
126
|
-
});
|
|
127
122
|
this.call.on('error', (error) => {
|
|
128
123
|
this.emit('error', error);
|
|
129
124
|
if (isVideoRecordingEnabled) {
|
|
@@ -134,12 +129,15 @@ class Vapi extends VapiEventEmitter {
|
|
|
134
129
|
this.emit('error', error);
|
|
135
130
|
});
|
|
136
131
|
this.call.on('track-started', async (e) => {
|
|
137
|
-
if (!e || !e.participant)
|
|
132
|
+
if (!e || !e.participant) {
|
|
138
133
|
return;
|
|
139
|
-
|
|
134
|
+
}
|
|
135
|
+
if (e.participant?.local) {
|
|
140
136
|
return;
|
|
141
|
-
|
|
137
|
+
}
|
|
138
|
+
if (e.participant?.user_name !== 'Vapi Speaker') {
|
|
142
139
|
return;
|
|
140
|
+
}
|
|
143
141
|
if (e.track.kind === 'video') {
|
|
144
142
|
this.emit('video', e.track);
|
|
145
143
|
}
|
|
@@ -153,6 +151,18 @@ class Vapi extends VapiEventEmitter {
|
|
|
153
151
|
return;
|
|
154
152
|
subscribeToTracks(e, this.call, isVideoRecordingEnabled, isVideoEnabled);
|
|
155
153
|
});
|
|
154
|
+
this.call.on('participant-updated', (e) => {
|
|
155
|
+
if (!e) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.emit('daily-participant-updated', e.participant);
|
|
159
|
+
});
|
|
160
|
+
this.call.on('participant-left', (e) => {
|
|
161
|
+
if (!e) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
destroyAudioPlayer(e.participant.session_id);
|
|
165
|
+
});
|
|
156
166
|
// Allow mobile devices to finish processing the microphone permissions
|
|
157
167
|
// request before joining the call and playing the assistant's audio
|
|
158
168
|
if (this.isMobileDevice()) {
|
|
@@ -220,8 +230,9 @@ class Vapi extends VapiEventEmitter {
|
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
232
|
onAppMessage(e) {
|
|
223
|
-
if (!e)
|
|
233
|
+
if (!e) {
|
|
224
234
|
return;
|
|
235
|
+
}
|
|
225
236
|
try {
|
|
226
237
|
if (e.data === 'listening') {
|
|
227
238
|
return this.emit('call-start');
|
|
@@ -244,8 +255,9 @@ class Vapi extends VapiEventEmitter {
|
|
|
244
255
|
const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
|
|
245
256
|
this.emit('volume-level', Math.min(1, speechLevel / 0.15));
|
|
246
257
|
const isSpeaking = speechLevel > 0.01;
|
|
247
|
-
if (!isSpeaking)
|
|
258
|
+
if (!isSpeaking) {
|
|
248
259
|
return;
|
|
260
|
+
}
|
|
249
261
|
if (this.speakingTimeout) {
|
|
250
262
|
clearTimeout(this.speakingTimeout);
|
|
251
263
|
this.speakingTimeout = null;
|
|
@@ -294,5 +306,14 @@ class Vapi extends VapiEventEmitter {
|
|
|
294
306
|
getDailyCallObject() {
|
|
295
307
|
return this.call;
|
|
296
308
|
}
|
|
309
|
+
startScreenSharing(displayMediaOptions, screenVideoSendSettings) {
|
|
310
|
+
this.call?.startScreenShare({
|
|
311
|
+
displayMediaOptions,
|
|
312
|
+
screenVideoSendSettings,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
stopScreenSharing() {
|
|
316
|
+
this.call?.stopScreenShare();
|
|
317
|
+
}
|
|
297
318
|
}
|
|
298
319
|
exports.default = Vapi;
|
package/package.json
CHANGED
package/vapi.ts
CHANGED
|
@@ -7,6 +7,8 @@ import DailyIframe, {
|
|
|
7
7
|
DailyEventObjectAppMessage,
|
|
8
8
|
DailyEventObjectParticipant,
|
|
9
9
|
DailyEventObjectRemoteParticipantsAudioLevel,
|
|
10
|
+
DailyParticipant,
|
|
11
|
+
DailyVideoSendSettings,
|
|
10
12
|
} from '@daily-co/daily-js';
|
|
11
13
|
import EventEmitter from 'events';
|
|
12
14
|
|
|
@@ -48,7 +50,8 @@ type VapiEventNames =
|
|
|
48
50
|
| 'speech-end'
|
|
49
51
|
| 'message'
|
|
50
52
|
| 'video'
|
|
51
|
-
| 'error'
|
|
53
|
+
| 'error'
|
|
54
|
+
| 'daily-participant-updated';
|
|
52
55
|
|
|
53
56
|
type VapiEventListeners = {
|
|
54
57
|
'call-end': () => void;
|
|
@@ -59,6 +62,7 @@ type VapiEventListeners = {
|
|
|
59
62
|
video: (track: MediaStreamTrack) => void;
|
|
60
63
|
message: (message: any) => void;
|
|
61
64
|
error: (error: any) => void;
|
|
65
|
+
'daily-participant-updated': (participant: DailyParticipant) => void;
|
|
62
66
|
};
|
|
63
67
|
|
|
64
68
|
async function startAudioPlayer(
|
|
@@ -234,11 +238,6 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
234
238
|
this.cleanup();
|
|
235
239
|
});
|
|
236
240
|
|
|
237
|
-
this.call.on('participant-left', (e) => {
|
|
238
|
-
if (!e) return;
|
|
239
|
-
destroyAudioPlayer(e.participant.session_id);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
241
|
this.call.on('error', (error: any) => {
|
|
243
242
|
this.emit('error', error);
|
|
244
243
|
if (isVideoRecordingEnabled) {
|
|
@@ -251,18 +250,21 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
251
250
|
});
|
|
252
251
|
|
|
253
252
|
this.call.on('track-started', async (e) => {
|
|
254
|
-
if (!e || !e.participant)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
if (!e || !e.participant) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (e.participant?.local) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (e.participant?.user_name !== 'Vapi Speaker') {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
258
262
|
if (e.track.kind === 'video') {
|
|
259
263
|
this.emit('video', e.track);
|
|
260
264
|
}
|
|
261
|
-
|
|
262
265
|
if (e.track.kind === 'audio') {
|
|
263
266
|
await buildAudioPlayer(e.track, e.participant.session_id);
|
|
264
267
|
}
|
|
265
|
-
|
|
266
268
|
this.call?.sendAppMessage('playable');
|
|
267
269
|
});
|
|
268
270
|
|
|
@@ -276,6 +278,20 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
276
278
|
);
|
|
277
279
|
});
|
|
278
280
|
|
|
281
|
+
this.call.on('participant-updated', (e) => {
|
|
282
|
+
if (!e) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
this.emit('daily-participant-updated', e.participant);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
this.call.on('participant-left', (e) => {
|
|
289
|
+
if (!e) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
destroyAudioPlayer(e.participant.session_id);
|
|
293
|
+
});
|
|
294
|
+
|
|
279
295
|
// Allow mobile devices to finish processing the microphone permissions
|
|
280
296
|
// request before joining the call and playing the assistant's audio
|
|
281
297
|
if (this.isMobileDevice()) {
|
|
@@ -353,7 +369,9 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
353
369
|
}
|
|
354
370
|
|
|
355
371
|
private onAppMessage(e?: DailyEventObjectAppMessage) {
|
|
356
|
-
if (!e)
|
|
372
|
+
if (!e) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
357
375
|
try {
|
|
358
376
|
if (e.data === 'listening') {
|
|
359
377
|
return this.emit('call-start');
|
|
@@ -382,7 +400,9 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
382
400
|
|
|
383
401
|
const isSpeaking = speechLevel > 0.01;
|
|
384
402
|
|
|
385
|
-
if (!isSpeaking)
|
|
403
|
+
if (!isSpeaking) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
386
406
|
|
|
387
407
|
if (this.speakingTimeout) {
|
|
388
408
|
clearTimeout(this.speakingTimeout);
|
|
@@ -444,4 +464,15 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
444
464
|
public getDailyCallObject(): DailyCall | null {
|
|
445
465
|
return this.call;
|
|
446
466
|
}
|
|
467
|
+
|
|
468
|
+
public startScreenSharing(displayMediaOptions?: DisplayMediaStreamOptions, screenVideoSendSettings?: DailyVideoSendSettings) {
|
|
469
|
+
this.call?.startScreenShare({
|
|
470
|
+
displayMediaOptions,
|
|
471
|
+
screenVideoSendSettings,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
public stopScreenSharing() {
|
|
476
|
+
this.call?.stopScreenShare();
|
|
477
|
+
}
|
|
447
478
|
}
|