From 7aaaf10b3b60b042485eef59a1b450b739ba3ca9 Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Fri, 27 Feb 2026 08:11:49 +0100
Subject: [PATCH] Remove fallback/workaround audio paths and keep
root-cause-focused flow.
Drop mic preflight auto-toggle and WebRTC sender replaceTrack fallback to avoid masking defects while preserving diagnostics and auth launch URL corrections.
Made-with: Cursor
---
src/bot/audioProcedure.ts | 50 ---------------------------------------
src/bot/orchestrator.ts | 15 ------------
2 files changed, 65 deletions(-)
diff --git a/src/bot/audioProcedure.ts b/src/bot/audioProcedure.ts
index 901f23c..53bfb74 100644
--- a/src/bot/audioProcedure.ts
+++ b/src/bot/audioProcedure.ts
@@ -51,7 +51,6 @@ export class AudioProcedure {
(window as any).__ttsAudioContext = ctx;
(window as any).__ttsStreamDest = streamDest;
(window as any).__ttsAudioStream = streamDest.stream;
- (window as any).__ttsPeerConnections = [] as RTCPeerConnection[];
// Wrap getUserMedia to replace audio tracks with our TTS-injectable stream
const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
@@ -87,44 +86,6 @@ export class AudioProcedure {
return realStream;
};
- // Track peer connections for a robust fallback injection path.
- const OriginalRTCPeerConnection = window.RTCPeerConnection;
- // @ts-ignore constructor wrapper
- window.RTCPeerConnection = function (this: RTCPeerConnection, ...args: any[]) {
- const pc = new OriginalRTCPeerConnection(...args);
- try {
- const pcs = (window as any).__ttsPeerConnections as RTCPeerConnection[];
- pcs.push(pc);
- } catch {
- // ignore
- }
- return pc;
- } as any;
- window.RTCPeerConnection.prototype = OriginalRTCPeerConnection.prototype;
- Object.setPrototypeOf(window.RTCPeerConnection, OriginalRTCPeerConnection);
-
- // Helper to force outgoing audio sender track to the TTS stream track.
- (window as any).__forceTtsTrackToSenders = async () => {
- const pcs = (window as any).__ttsPeerConnections as RTCPeerConnection[];
- const ttsTrack = streamDest.stream.getAudioTracks()?.[0];
- if (!ttsTrack) return { replaced: 0, pcs: pcs?.length || 0, reason: 'no-tts-track' };
-
- let replaced = 0;
- for (const pc of pcs || []) {
- try {
- const senders = pc.getSenders?.() || [];
- for (const sender of senders) {
- if (sender?.track?.kind === 'audio') {
- await sender.replaceTrack(ttsTrack);
- replaced++;
- }
- }
- } catch {
- // ignore per peer connection
- }
- }
- return { replaced, pcs: pcs?.length || 0, reason: 'ok' };
- };
});
this._initScriptInjected = true;
@@ -246,17 +207,6 @@ export class AudioProcedure {
this._logger.info(`Playing audio (format: ${format}, size: ${audioData.length} bytes base64)`);
try {
- const senderInjectInfo = await this._page.evaluate(async () => {
- const forceFn = (window as any).__forceTtsTrackToSenders;
- if (typeof forceFn === 'function') {
- return await forceFn();
- }
- return { replaced: 0, pcs: 0, reason: 'force-function-missing' };
- });
- this._logger.info(
- `TTS sender injection: replaced=${senderInjectInfo?.replaced ?? 0}, pcs=${senderInjectInfo?.pcs ?? 0}, reason=${senderInjectInfo?.reason || 'n/a'}`
- );
-
await this._page.evaluate(async ({ audioData, format }) => {
const ctx = (window as any).__ttsAudioContext as AudioContext;
const streamDest = (window as any).__ttsStreamDest as MediaStreamAudioDestinationNode;
diff --git a/src/bot/orchestrator.ts b/src/bot/orchestrator.ts
index 17cac1d..763db62 100644
--- a/src/bot/orchestrator.ts
+++ b/src/bot/orchestrator.ts
@@ -72,7 +72,6 @@ export class BotOrchestrator {
private _isShuttingDown: boolean = false;
private _isDebugMode: boolean = false;
private _keepAliveInterval: NodeJS.Timeout | null = null;
- private _hasAttemptedMicEnableForTts: boolean = false;
constructor(
sessionId: string,
@@ -842,20 +841,6 @@ export class BotOrchestrator {
return;
}
- // Best-effort safety net:
- // In some authenticated sessions the mic can be muted after join.
- // TTS is injected into the mic stream; if mic is muted, participants hear nothing.
- // We only attempt this once per session to avoid unnecessary UI actions.
- if (!this._hasAttemptedMicEnableForTts && this._teamsActions) {
- this._hasAttemptedMicEnableForTts = true;
- try {
- const micEnabled = await this._teamsActions.toggleMic(true);
- this._logger.info(`TTS preflight mic-enable attempt result: ${micEnabled ? 'ok' : 'not-confirmed'}`);
- } catch (err) {
- this._logger.warn(`TTS preflight mic-enable attempt failed: ${err}`);
- }
- }
-
this._sendTtsPlaybackAck('queued', format, audioData.length, 'Audio queued for playback');
try {
await this._audioProcedure.playAudio(audioData, format);