Skip to content

Fix intro message cut-off issue #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 12 additions & 37 deletions vapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default class Vapi extends VapiEventEmitter {
private speakingTimeout: NodeJS.Timeout | null = null;
private dailyCallConfig: DailyAdvancedConfig = {};
private dailyCallObject: DailyFactoryOptions = {};
private introRequested: boolean = false;

constructor(
apiToken: string,
Expand All @@ -171,20 +172,6 @@ export default class Vapi extends VapiEventEmitter {
this.speakingTimeout = null;
}

private isMobileDevice() {
if (typeof navigator === 'undefined') {
return false;
}
const userAgent = navigator.userAgent;
return /android|iphone|ipad|ipod|iemobile|blackberry|bada/i.test(
userAgent.toLowerCase(),
);
}

private async sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async start(
assistant?: CreateAssistantDTO | string,
assistantOverrides?: AssistantOverrides,
Expand Down Expand Up @@ -268,19 +255,18 @@ export default class Vapi extends VapiEventEmitter {

this.call.on('participant-joined', (e) => {
if (!e || !this.call) return;
subscribeToTracks(
e,
this.call,
isVideoRecordingEnabled,
isVideoEnabled,
);
});

// Allow mobile devices to finish processing the microphone permissions
// request before joining the call and playing the assistant's audio
if (this.isMobileDevice()) {
await this.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we likely still need this, keep both?

}
if (!this.introRequested && !e.participant.local) {
this.introRequested = true;

this.send({
type: 'control',
control: 'say-first-message',
});
}

subscribeToTracks(e, this.call, isVideoRecordingEnabled, isVideoEnabled);
});

await this.call.join({
// @ts-expect-error This exists
Expand All @@ -289,8 +275,6 @@ export default class Vapi extends VapiEventEmitter {
});

if (isVideoRecordingEnabled) {
const recordingRequestedTime = new Date().getTime();

this.call.startRecording({
width: 1280,
height: 720,
Expand All @@ -299,15 +283,6 @@ export default class Vapi extends VapiEventEmitter {
preset: 'default',
},
});

this.call.on('recording-started', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is needed when people have video recording enabled

this.send({
type: 'control',
control: 'say-first-message',
videoRecordingStartDelaySeconds:
(new Date().getTime() - recordingRequestedTime) / 1000,
});
});
}

this.call.startRemoteParticipantsAudioLevelObserver(100);
Expand Down