diff --git a/vapi.ts b/vapi.ts index 293b1a5..d5aa293 100644 --- a/vapi.ts +++ b/vapi.ts @@ -29,7 +29,11 @@ async function buildAudioPlayer(track: any, participantId: string) { await startPlayer(player, track); return player; } -function subscribeToTracks(e: DailyEventObjectParticipant, call: DailyCall, isVideoRecordingEnabled?: boolean) { +function subscribeToTracks( + e: DailyEventObjectParticipant, + call: DailyCall, + isVideoRecordingEnabled?: boolean, +) { if (e.participant.local) return; call.updateParticipant(e.participant.session_id, { @@ -47,7 +51,7 @@ export interface AddMessageMessage { export interface ControlMessages { type: 'control'; - control: 'mute-assistant' | 'unmute-assistant' | 'resume-call'; + control: 'mute-assistant' | 'unmute-assistant' | 'say-first-message'; videoRecordingStartDelay?: number; } @@ -146,9 +150,7 @@ export default class Vapi extends VapiEventEmitter { if (this.call) { this.cleanup(); } - const isVideoRecordingEnabled = - webCall?.artifactPlan?.videoRecordingEnabled ?? - false; + const isVideoRecordingEnabled = webCall?.artifactPlan?.videoRecordingEnabled ?? false; this.call = DailyIframe.createCallObject({ audioSource: true, @@ -203,7 +205,8 @@ export default class Vapi extends VapiEventEmitter { if (isVideoRecordingEnabled) { const recordingRequestedTime = new Date().getTime(); - await this.call.startRecording({ + + this.call.startRecording({ width: 1280, height: 720, backgroundColor: '#FF1F2D3D', @@ -215,9 +218,9 @@ export default class Vapi extends VapiEventEmitter { this.call.on('recording-started', () => { this.send({ type: 'control', - control: 'resume-call', + control: 'say-first-message', videoRecordingStartDelay: new Date().getTime() - recordingRequestedTime, - }) + }); }); } @@ -337,18 +340,17 @@ export default class Vapi extends VapiEventEmitter { public say(message: string, endCallAfterSpoken?: boolean) { this.send({ - type:'say', + type: 'say', message, - endCallAfterSpoken - }) + endCallAfterSpoken, + }); } - public setInputDevicesAsync(options: Parameters[0]) { - this.call?.setInputDevicesAsync(options) + this.call?.setInputDevicesAsync(options); } public setOutputDeviceAsync(options: Parameters[0]) { - this.call?.setOutputDeviceAsync(options) + this.call?.setOutputDeviceAsync(options); } }