From 333fa55ec632f48384f9f2a08b5326eccde810d1 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Mon, 18 May 2026 18:50:33 -0500 Subject: [PATCH] remove outdated sound suppression --- src/app/hooks/useCallSignaling.ts | 6 +- src/app/plugins/call/CallControl.ts | 139 +--------------------------- 2 files changed, 2 insertions(+), 143 deletions(-) diff --git a/src/app/hooks/useCallSignaling.ts b/src/app/hooks/useCallSignaling.ts index eb99d63d5..854957923 100644 --- a/src/app/hooks/useCallSignaling.ts +++ b/src/app/hooks/useCallSignaling.ts @@ -295,12 +295,9 @@ export function useIncomingCallSignaling() { const stopOutgoingRing = useCallback(() => { outgoingAudioRef.current?.pause(); if (outgoingAudioRef.current) outgoingAudioRef.current.currentTime = 0; - if (callEmbed) { - callEmbed.control.setOutputOverrideMuted(false); - } outgoingRingRoomIdRef.current = null; outgoingStartRef.current = null; - }, [callEmbed]); + }, []); const clearIncomingCall = useCallback(() => { const activeIncomingCall = incomingCallRef.current; @@ -800,7 +797,6 @@ export function useIncomingCallSignaling() { return; } - callEmbed.control.setOutputOverrideMuted(true); outgoingAudioRef.current?.play().catch(() => { Sentry.metrics.count('sable.call.ringback.blocked', 1); }); diff --git a/src/app/plugins/call/CallControl.ts b/src/app/plugins/call/CallControl.ts index f639e3434..d25b21d6f 100644 --- a/src/app/plugins/call/CallControl.ts +++ b/src/app/plugins/call/CallControl.ts @@ -24,12 +24,6 @@ export class CallControl extends EventEmitter implements CallControlState { private iframe: HTMLIFrameElement; private controlMutationObserver: MutationObserver; - private audioMutationObserver: MutationObserver; - private outputOverrideMuted = false; - private patchedWindow: Window | undefined; - private readonly trackedAudioContexts = new Set(); - private readonly runningContextsBeforeOverride = new WeakMap(); - private readonly audioPatchRestores: Array<() => void> = []; private get document(): Document | undefined { return this.iframe.contentDocument ?? this.iframe.contentWindow?.document; @@ -63,9 +57,6 @@ export class CallControl extends EventEmitter implements CallControlState { this.iframe = iframe; this.controlMutationObserver = new MutationObserver(this.onControlMutation.bind(this)); - this.audioMutationObserver = new MutationObserver(() => { - this.applyOutputMute(); - }); } public getState(): CallControlState { @@ -126,34 +117,6 @@ export class CallControl extends EventEmitter implements CallControlState { this.setSound(this.sound); } - public setOutputOverrideMuted(muted: boolean) { - const win = this.iframe.contentWindow; - const callDocument = this.iframe.contentDocument ?? this.iframe.contentWindow?.document; - const windowChanged = !!win && this.patchedWindow !== win; - if (this.outputOverrideMuted === muted && !windowChanged) return; - this.outputOverrideMuted = muted; - - if (muted) { - const target = callDocument?.body; - if (target) { - this.audioMutationObserver.observe(target, { - childList: true, - subtree: true, - }); - } - if (win) { - this.ensureAudioPatches(win); - this.collectExistingAudioContexts(win); - this.suspendTrackedAudioContexts(); - } - } else { - this.audioMutationObserver.disconnect(); - this.resumeTrackedAudioContexts(); - this.teardownAudioPatches(); - } - this.applyOutputMute(); - } - private setMediaState(state: ElementMediaStatePayload) { return this.call.transport.send(ElementWidgetActions.DeviceMute, state); } @@ -164,7 +127,7 @@ export class CallControl extends EventEmitter implements CallControlState { private applyOutputMute(sound = this.sound): void { const callDocument = this.iframe.contentDocument ?? this.iframe.contentWindow?.document; - const shouldMute = this.outputOverrideMuted || !sound; + const shouldMute = !sound; if (callDocument) { callDocument.querySelectorAll('audio, video').forEach((el) => { el.muted = shouldMute; @@ -173,103 +136,6 @@ export class CallControl extends EventEmitter implements CallControlState { } } - private ensureAudioPatches(win: Window): void { - if (this.patchedWindow === win) return; - this.teardownAudioPatches(); - this.patchedWindow = win; - - this.patchAudioContextConstructor(win, 'AudioContext'); - this.patchAudioContextConstructor(win, 'webkitAudioContext'); - } - - private patchAudioContextConstructor(win: Window, key: 'AudioContext' | 'webkitAudioContext') { - const scopedWindow = win as Window & - Partial>; - const originalCtor = scopedWindow[key]; - if (typeof originalCtor !== 'function') return; - - const resumeDescriptor = Object.getOwnPropertyDescriptor(originalCtor.prototype, 'resume'); - const originalResumeImpl = resumeDescriptor?.value as - | ((this: AudioContext) => Promise) - | undefined; - if (typeof originalResumeImpl !== 'function') return; - const originalResume = (context: AudioContext): Promise => - originalResumeImpl.call(context); - const trackedContexts = this.trackedAudioContexts; - const isOverrideMuted = () => this.outputOverrideMuted; - originalCtor.prototype.resume = function patchedResume(this: AudioContext) { - trackedContexts.add(this); - if (isOverrideMuted()) { - return Promise.resolve(); - } - return originalResume(this); - }; - this.audioPatchRestores.push(() => { - originalCtor.prototype.resume = originalResumeImpl; - }); - - const wrappedCtor = function patchedAudioContext( - this: unknown, - ...args: ConstructorParameters - ) { - const context = Reflect.construct( - originalCtor, - args, - new.target ?? originalCtor - ) as AudioContext; - trackedContexts.add(context); - if (isOverrideMuted()) { - void context.suspend().catch(() => {}); - } - return context; - } as unknown as typeof AudioContext; - wrappedCtor.prototype = originalCtor.prototype; - Object.setPrototypeOf(wrappedCtor, originalCtor); - - scopedWindow[key] = wrappedCtor; - this.audioPatchRestores.push(() => { - scopedWindow[key] = originalCtor; - }); - } - - private teardownAudioPatches(): void { - this.audioPatchRestores.splice(0).forEach((restore) => restore()); - this.patchedWindow = undefined; - } - - private collectExistingAudioContexts(win: Window): void { - const scopedWindow = win as Window & - Partial>; - const audioCtor = scopedWindow.AudioContext; - if (!audioCtor) return; - - Object.values(win as unknown as Record).forEach((value) => { - if (value instanceof audioCtor) { - this.trackedAudioContexts.add(value); - } - }); - } - - private suspendTrackedAudioContexts(): void { - this.trackedAudioContexts.forEach((context) => { - const wasRunning = context.state === 'running'; - this.runningContextsBeforeOverride.set(context, wasRunning); - if (wasRunning) { - void context.suspend().catch(() => {}); - } - }); - } - - private resumeTrackedAudioContexts(): void { - this.trackedAudioContexts.forEach((context) => { - const wasRunning = this.runningContextsBeforeOverride.get(context) ?? false; - if (wasRunning) { - void context.resume().catch(() => {}); - } - this.runningContextsBeforeOverride.delete(context); - }); - } - public onMediaState(evt: CustomEvent) { const { data } = evt.detail; if (!data) return; @@ -362,9 +228,6 @@ export class CallControl extends EventEmitter implements CallControlState { public dispose() { this.controlMutationObserver.disconnect(); - this.audioMutationObserver.disconnect(); - this.resumeTrackedAudioContexts(); - this.teardownAudioPatches(); } private emitStateUpdate() {