From bbef615e0c30c0d7d4c34ec8b2e55c364937de6f Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Fri, 6 Mar 2026 14:20:42 +0100
Subject: [PATCH] commcoach: add TTS audio lifecycle logging for mobile
diagnosis
Made-with: Cursor
---
src/hooks/useCommcoach.ts | 20 ++++++++++++++++++-
.../views/commcoach/CommcoachDossierView.tsx | 3 ++-
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/hooks/useCommcoach.ts b/src/hooks/useCommcoach.ts
index df9ab1d..a2abe8f 100644
--- a/src/hooks/useCommcoach.ts
+++ b/src/hooks/useCommcoach.ts
@@ -124,17 +124,35 @@ export function useCommcoach(): CommcoachHookReturn {
try {
const audio = new Audio(`data:audio/mp3;base64,${audioB64}`);
currentAudioRef.current = audio;
+ // #region agent log
+ audio.onpause = () => { (window as any).__dlog?.('TTS-PAUSE', `t=${audio.currentTime.toFixed(1)} dur=${audio.duration.toFixed(1)}`); };
+ // #endregion
audio.onended = () => {
+ // #region agent log
+ (window as any).__dlog?.('TTS-ENDED', `dur=${audio.duration.toFixed(1)}`);
+ // #endregion
currentAudioRef.current = null;
isTtsPlayingRef.current = false;
};
- audio.play().catch(() => { isTtsPlayingRef.current = false; });
+ audio.play().then(() => {
+ // #region agent log
+ (window as any).__dlog?.('TTS-PLAY', `dur=${audio.duration.toFixed(1)}`);
+ // #endregion
+ }).catch((e) => {
+ // #region agent log
+ (window as any).__dlog?.('TTS-PLAY-ERR', e?.message || 'unknown');
+ // #endregion
+ isTtsPlayingRef.current = false;
+ });
} catch {
isTtsPlayingRef.current = false;
}
}, []);
const stopTts = useCallback(() => {
+ // #region agent log
+ (window as any).__dlog?.('STOP-TTS', `playing=${isTtsPlayingRef.current} hasAudio=${!!currentAudioRef.current}`);
+ // #endregion
if (currentAudioRef.current) {
currentAudioRef.current.pause();
}
diff --git a/src/pages/views/commcoach/CommcoachDossierView.tsx b/src/pages/views/commcoach/CommcoachDossierView.tsx
index 5de9196..450dc6f 100644
--- a/src/pages/views/commcoach/CommcoachDossierView.tsx
+++ b/src/pages/views/commcoach/CommcoachDossierView.tsx
@@ -61,8 +61,9 @@ export const CommcoachDossierView: React.FC = () => {
const ts = `${t.getMinutes()}:${String(t.getSeconds()).padStart(2,'0')}.${String(t.getMilliseconds()).padStart(3,'0')}`;
const entry = `[${ts}] ${tag}${info ? ' ' + info : ''}`;
debugLogsRef.current.push(entry);
- if (debugLogsRef.current.length > 60) debugLogsRef.current.shift();
+ if (debugLogsRef.current.length > 80) debugLogsRef.current.shift();
}, []);
+ useEffect(() => { (window as any).__dlog = _dlog; return () => { delete (window as any).__dlog; }; }, [_dlog]);
// #endregion
// Auto-select first context