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
This commit is contained in:
parent
e6d0cfdad2
commit
7aaaf10b3b
2 changed files with 0 additions and 65 deletions
|
|
@ -51,7 +51,6 @@ export class AudioProcedure {
|
||||||
(window as any).__ttsAudioContext = ctx;
|
(window as any).__ttsAudioContext = ctx;
|
||||||
(window as any).__ttsStreamDest = streamDest;
|
(window as any).__ttsStreamDest = streamDest;
|
||||||
(window as any).__ttsAudioStream = streamDest.stream;
|
(window as any).__ttsAudioStream = streamDest.stream;
|
||||||
(window as any).__ttsPeerConnections = [] as RTCPeerConnection[];
|
|
||||||
|
|
||||||
// Wrap getUserMedia to replace audio tracks with our TTS-injectable stream
|
// Wrap getUserMedia to replace audio tracks with our TTS-injectable stream
|
||||||
const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
||||||
|
|
@ -87,44 +86,6 @@ export class AudioProcedure {
|
||||||
return realStream;
|
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;
|
this._initScriptInjected = true;
|
||||||
|
|
@ -246,17 +207,6 @@ export class AudioProcedure {
|
||||||
this._logger.info(`Playing audio (format: ${format}, size: ${audioData.length} bytes base64)`);
|
this._logger.info(`Playing audio (format: ${format}, size: ${audioData.length} bytes base64)`);
|
||||||
|
|
||||||
try {
|
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 }) => {
|
await this._page.evaluate(async ({ audioData, format }) => {
|
||||||
const ctx = (window as any).__ttsAudioContext as AudioContext;
|
const ctx = (window as any).__ttsAudioContext as AudioContext;
|
||||||
const streamDest = (window as any).__ttsStreamDest as MediaStreamAudioDestinationNode;
|
const streamDest = (window as any).__ttsStreamDest as MediaStreamAudioDestinationNode;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ export class BotOrchestrator {
|
||||||
private _isShuttingDown: boolean = false;
|
private _isShuttingDown: boolean = false;
|
||||||
private _isDebugMode: boolean = false;
|
private _isDebugMode: boolean = false;
|
||||||
private _keepAliveInterval: NodeJS.Timeout | null = null;
|
private _keepAliveInterval: NodeJS.Timeout | null = null;
|
||||||
private _hasAttemptedMicEnableForTts: boolean = false;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
|
|
@ -842,20 +841,6 @@ export class BotOrchestrator {
|
||||||
return;
|
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');
|
this._sendTtsPlaybackAck('queued', format, audioData.length, 'Audio queued for playback');
|
||||||
try {
|
try {
|
||||||
await this._audioProcedure.playAudio(audioData, format);
|
await this._audioProcedure.playAudio(audioData, format);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue