Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.24",
"version": "1.1.26",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions src/services/socket-manager/message-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function handleAudioTranscribedMessage(
return;
}

// Mark the last assistant message as interrupted when new user input arrives via server-side STT
const lastMessage = items.messages[items.messages.length - 1];
if (lastMessage?.role === 'assistant' && !lastMessage.interrupted) {
lastMessage.interrupted = true;
}

const userMessage: Message = {
id: data.id || `user-${Date.now()}`,
role: data.role,
Expand Down
25 changes: 25 additions & 0 deletions src/services/streaming-manager/livekit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export async function createLiveKitStreamingManager<T extends CreateSessionV2Opt
dynacast: true,
});

let trackSubscriptionTimeoutId: ReturnType<typeof setTimeout> | null = null;
const TRACK_SUBSCRIPTION_TIMEOUT_MS = 20000;

const streamApi = createStreamApiV2(auth, baseURL || didApiUrl, agentId, callbacks.onError);
let sessionId: string | undefined;

Expand Down Expand Up @@ -147,6 +150,17 @@ export async function createLiveKitStreamingManager<T extends CreateSessionV2Opt
await room.connect(url, token);
log('LiveKit room joined successfully');

trackSubscriptionTimeoutId = setTimeout(() => {
log('Track subscription timeout - no track subscribed within 30 seconds after connect');
trackSubscriptionTimeoutId = null;
analytics.track('connectivity-error', {
error: 'Track subscription timeout',
sessionId,
});
callbacks.onError?.(new Error('Track subscription timeout'), { sessionId });
disconnect();
}, TRACK_SUBSCRIPTION_TIMEOUT_MS);

isInitialConnection = false;
} catch (error) {
handleInitError(error, log, callbacks, () => {
Expand Down Expand Up @@ -224,6 +238,12 @@ export async function createLiveKitStreamingManager<T extends CreateSessionV2Opt
function handleTrackSubscribed(track: RemoteTrack, publication: any, participant: RemoteParticipant): void {
log(`Track subscribed: ${track.kind} from ${participant.identity}`);

if (trackSubscriptionTimeoutId) {
clearTimeout(trackSubscriptionTimeoutId);
trackSubscriptionTimeoutId = null;
log('Track subscription timeout cleared');
}

const mediaStreamTrack = track.mediaStreamTrack;
if (!mediaStreamTrack) {
log(`No mediaStreamTrack available for ${track.kind}`);
Expand Down Expand Up @@ -442,6 +462,11 @@ export async function createLiveKitStreamingManager<T extends CreateSessionV2Opt
}

async function disconnect() {
if (trackSubscriptionTimeoutId) {
clearTimeout(trackSubscriptionTimeoutId);
trackSubscriptionTimeoutId = null;
}

if (room) {
await unpublishMicrophoneStream();
await room.disconnect();
Expand Down