A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(voice): mirror camera only in local self-view (#3557)
Hampusd3d3a5faaf77
diff --git a/fluxer_app/src/features/voice/commands/VoiceSettingsCommands.ts b/fluxer_app/src/features/voice/commands/VoiceSettingsCommands.tsindex c327d92b6..2bc3fce2f 100644--- a/fluxer_app/src/features/voice/commands/VoiceSettingsCommands.ts+++ b/fluxer_app/src/features/voice/commands/VoiceSettingsCommands.ts@@ -15,7 +15,6 @@ const CAMERA_BACKGROUND_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = ['backgroundImageId','backgroundImages','backgroundBlurStrength',- 'mirrorCamera',];const CAMERA_CAPTURE_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = ['cameraResolution', 'videoDeviceId'];const SCREEN_SHARE_CODEC_NEGOTIATION_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = [diff --git a/fluxer_app/src/features/voice/components/VoiceParticipantTile.module.css b/fluxer_app/src/features/voice/components/VoiceParticipantTile.module.cssindex 000c04add..b8325b58e 100644--- a/fluxer_app/src/features/voice/components/VoiceParticipantTile.module.css+++ b/fluxer_app/src/features/voice/components/VoiceParticipantTile.module.css@@ -142,6 +142,10 @@filter: drop-shadow(0 0.0625rem 0.125rem var(--voice-shadow-strong));}+.mirroredVideo {+ transform: scaleX(-1);+}+.videoDisabledOverlay {position: absolute;inset: 0;diff --git a/fluxer_app/src/features/voice/components/VoiceParticipantTile.tsx b/fluxer_app/src/features/voice/components/VoiceParticipantTile.tsxindex b1ba266d7..76789cb5c 100644--- a/fluxer_app/src/features/voice/components/VoiceParticipantTile.tsx+++ b/fluxer_app/src/features/voice/components/VoiceParticipantTile.tsx@@ -350,6 +350,7 @@ const VoiceParticipantTileInner = observer(function VoiceParticipantTileInner({const {viewerIds, viewerUsers, spectatorEntries} = useStreamSpectators(isScreenShare ? streamKey : '', userId);const hasSpectatorDemand = viewerIds.length > 0;const isCameraTile = isCameraSource(trackRef.source);+ const isMirroredOwnCamera = isCameraTile && isLocalParticipant && VoiceSettings.mirrorCamera;const cameraLocallyDisabled = callId !== '' && isCameraTile && CallMediaPrefs.isVideoDisabled(callId, identity);const screenSharePublicationMigrationVersion = ScreenSharePublicationMigration.version;const publication = useMemo(() => {@@ -920,6 +921,7 @@ const VoiceParticipantTileInner = observer(function VoiceParticipantTileInner({ref={videoRef}trackRef={trackRef}manageSubscription={false}+ className={clsx(isMirroredOwnCamera && styles.mirroredVideo)}data-flx="voice.voice-participant-tile.media-node.video-track"/>);@@ -1000,6 +1002,7 @@ const VoiceParticipantTileInner = observer(function VoiceParticipantTileInner({hasVideo,isActuallySpeaking,isFocusedPlaceholderTile,+ isMirroredOwnCamera,isOwnScreenShare,isScreenShare,participantUser,diff --git a/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.module.css b/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.module.cssindex 40383a10e..aca560b68 100644--- a/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.module.css+++ b/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.module.css@@ -64,6 +64,10 @@object-fit: contain;}+.mirroredVideo {+ transform: scaleX(-1);+}+.overlay {position: absolute;inset: 0;diff --git a/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.tsx b/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.tsxindex 82b4c08f3..b09b0f8d6 100644--- a/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.tsx+++ b/fluxer_app/src/features/voice/components/modals/CameraPreviewModal.tsx@@ -51,6 +51,7 @@ import {VOICE_CHANNEL_CAMERA_USER_LIMIT} from '@fluxer/constants/src/LimitConstaimport {msg} from '@lingui/core/macro';import {Trans, useLingui} from '@lingui/react/macro';import {CameraIcon, ImageIcon} from '@phosphor-icons/react';+import {clsx} from 'clsx';import type {LocalParticipant, LocalVideoTrack, Room} from 'livekit-client';import {createLocalVideoTrack, RoomEvent} from 'livekit-client';import {observer} from 'mobx-react-lite';@@ -102,7 +103,6 @@ interface CameraPreviewConfig {videoDeviceId: string;backgroundImageId: string;backgroundBlurStrength: number;- mirrorCamera: boolean;cameraResolution: 'low' | 'medium' | 'high';videoFrameRate: number;}@@ -169,7 +169,6 @@ function hasSameCameraPreviewTopology(previous: CameraPreviewConfig | null, nextreturn (previous != null &&previous.videoDeviceId === next.videoDeviceId &&- previous.mirrorCamera === next.mirrorCamera &&previous.cameraResolution === next.cameraResolution &&previous.videoFrameRate === next.videoFrameRate);@@ -246,7 +245,6 @@ interface CameraPreviewTrackSetupArgs {videoElement: HTMLVideoElement;effectiveVideoDeviceId: string | null;backgroundImageId: string;- mirrorCamera: boolean;cameraResolution: 'low' | 'medium' | 'high';videoFrameRate: number;isCurrentInitialization: () => boolean;@@ -296,10 +294,7 @@ async function setupPreviewTrackAndProcessor(args: CameraPreviewTrackSetupArgs):args.onResolutionNegotiated(negotiatedResolution);let processor: CameraPreviewProcessor | null = null;try {- processor = await applyBackgroundProcessor(track, {- backgroundImageId: args.backgroundImageId,- mirrorCamera: args.mirrorCamera,- });+ processor = await applyBackgroundProcessor(track, {backgroundImageId: args.backgroundImageId});} catch (error) {logger.warn('Camera background processing failed; falling back to basic camera', {error});}@@ -495,7 +490,6 @@ const CameraPreviewModalContent = observer((props: CameraPreviewModalProps) => {videoDeviceId: effectiveVideoDeviceId ?? 'default',backgroundImageId,backgroundBlurStrength: voiceSettings.backgroundBlurStrength,- mirrorCamera: voiceSettings.mirrorCamera,cameraResolution: voiceSettings.getCameraResolution(),videoFrameRate: voiceSettings.getVideoFrameRate(),};@@ -513,10 +507,7 @@ const CameraPreviewModalContent = observer((props: CameraPreviewModalProps) => {const activeProcessor = processorRef.current;if (activeTrack && activeProcessor && hasSameCameraPreviewTopology(prevConfigRef.current, currentConfig)) {try {- const updatedProcessor = await applyBackgroundProcessor(activeTrack, {- backgroundImageId,- mirrorCamera: currentConfig.mirrorCamera,- });+ const updatedProcessor = await applyBackgroundProcessor(activeTrack, {backgroundImageId});if (!isCurrentInitialization()) {return;}@@ -537,7 +528,6 @@ const CameraPreviewModalContent = observer((props: CameraPreviewModalProps) => {videoElement,effectiveVideoDeviceId,backgroundImageId,- mirrorCamera: currentConfig.mirrorCamera,cameraResolution: voiceSettings.getCameraResolution(),videoFrameRate: voiceSettings.getVideoFrameRate(),isCurrentInitialization,@@ -663,7 +653,6 @@ const CameraPreviewModalContent = observer((props: CameraPreviewModalProps) => {videoDeviceId: voiceSettings.videoDeviceId,backgroundImageId,backgroundBlurStrength: voiceSettings.backgroundBlurStrength,- mirrorCamera: voiceSettings.mirrorCamera,cameraResolution: voiceSettings.getCameraResolution(),videoFrameRate: voiceSettings.getVideoFrameRate(),};@@ -677,14 +666,13 @@ const CameraPreviewModalContent = observer((props: CameraPreviewModalProps) => {VoiceSettings.videoDeviceId,VoiceSettings.backgroundImageId,VoiceSettings.backgroundBlurStrength,- VoiceSettings.mirrorCamera,VoiceSettings.getCameraResolution(),VoiceSettings.getVideoFrameRate(),voiceBackgroundsAvailable,]);const voiceSettings = VoiceSettings;const effectiveVideoDeviceId = resolveEffectiveDeviceId(voiceSettings.videoDeviceId, videoDevices) ?? 'default';- const previewVideoClassName = styles.video;+ const previewVideoClassName = clsx(styles.video, voiceSettings.mirrorCamera && styles.mirroredVideo);const videoDeviceOptions =videoDevices.length > 0? videoDevices.map((device) => ({diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsxindex 506485c18..eac3a996e 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx@@ -1111,7 +1111,6 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {width: options.width,height: options.height,frameRate: options.frameRate,- mirror: options.mirror,backgroundMode: options.backgroundMode,});}@@ -1159,13 +1158,12 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {options: VoiceEngineV2CameraEncodingOptions,): Promise<void> {const touchesEffects =- options.mirror !== undefined ||options.backgroundMode !== undefined ||options.backgroundBlurStrength !== undefined ||options.backgroundCustomMediaPath !== undefined;if (!touchesEffects) return;try {- await applyBackgroundProcessor(track, options.mirror === undefined ? undefined : {mirrorCamera: options.mirror});+ await applyBackgroundProcessor(track);} catch (error) {logger.warn('Failed to apply in-place camera effects', {error});}diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareLiveKitFlows.ts b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareLiveKitFlows.tsindex 358fbfd3f..d2045d587 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareLiveKitFlows.ts+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareLiveKitFlows.ts@@ -45,7 +45,6 @@ import {} from '@app/features/voice/engine/voice_screen_share_manager/shared';import ActiveScreenShareSource from '@app/features/voice/state/ActiveScreenShareSource';import SoftwareEncoderWarning from '@app/features/voice/state/SoftwareEncoderWarning';-import VoiceSettings from '@app/features/voice/state/VoiceSettings';import {prepareHighFidelityScreenShareAudioTrack,SCREEN_SHARE_AUDIO_PUBLISH_OPTIONS,@@ -58,7 +57,6 @@ import {import {commitNativeAudioBridgeReplacement} from '@app/features/voice/utils/NativeAudioCaptureBridge';import {ScreenShareAudioCaptureError} from '@app/features/voice/utils/ScreenShareAudioCaptureError';import {ScreenShareRollbackIncompleteError} from '@app/features/voice/utils/ScreenShareRollbackIncompleteError';-import {applyCameraMirrorProcessor} from '@app/features/voice/utils/VideoBackgroundProcessor';import {createLocalAudioTrack,createLocalVideoTrack,@@ -102,7 +100,6 @@ interface EnforcedScreenSharePublish {interface ScreenShareReplacementSnapshot extends ScreenShareSourceSnapshot {videoTrack: MediaStreamTrack;- videoHadProcessor: boolean;audioPublication?: LocalTrackPublication;audioTrack?: LocalAudioTrack;audioMediaStreamTrack?: MediaStreamTrack;@@ -378,7 +375,6 @@ export class VoiceEngineV2AppScreenShareLiveKitFlows {: undefined,});createdTracks.push(videoTrack);- await applyCameraMirrorProcessor(videoTrack);let audioTrack: LocalAudioTrack | undefined;if (audioDeviceId !== undefined) {audioTrack = await createLocalAudioTrack({@@ -866,10 +862,7 @@ export class VoiceEngineV2AppScreenShareLiveKitFlows {screenShareTrack: LocalVideoTrack,publishOptions: TrackPublishOptions,): ScreenShareReplacementSnapshot {- const videoHadProcessor = screenShareTrack.getProcessor() != null;- const sourceVideoTrack =- screenShareTrack.mediaStream?.getVideoTracks()[0] ??- (videoHadProcessor ? undefined : screenShareTrack.mediaStreamTrack);+ const sourceVideoTrack = screenShareTrack.mediaStream?.getVideoTracks()[0] ?? screenShareTrack.mediaStreamTrack;if (sourceVideoTrack?.readyState !== 'live') {throw new Error('Active screen share has no live source video track to preserve');}@@ -885,7 +878,6 @@ export class VoiceEngineV2AppScreenShareLiveKitFlows {}return {videoTrack: sourceVideoTrack,- videoHadProcessor,...(audioPublication ? {audioPublication} : {}),...(localAudioTrack && sourceAudioTrack? {audioTrack: localAudioTrack, audioMediaStreamTrack: sourceAudioTrack}@@ -941,14 +933,6 @@ export class VoiceEngineV2AppScreenShareLiveKitFlows {if (sourceNeedsReplacement) {await screenShareTrack.stageTrackReplacement(snapshot.videoTrack);}- if (snapshot.videoHadProcessor) {- const restoredProcessor = await applyCameraMirrorProcessor(screenShareTrack, true);- if (!restoredProcessor) {- throw new Error('Screen share rollback could not restore the previous video processor');- }- } else if (screenShareTrack.getProcessor()) {- await screenShareTrack.stopProcessor(false);- }if (snapshot.audioPublication && snapshot.audioTrack && snapshot.audioMediaStreamTrack) {const restoredAudioPublication = Array.from(participant.audioTrackPublications.values()).find((publication) => publication === snapshot.audioPublication,@@ -1324,18 +1308,6 @@ export class VoiceEngineV2AppScreenShareLiveKitFlows {this.adapter.cleanupActiveScreenShareEndListenerInternal();try {await screenShareTrack.stageTrackReplacement(tracks.videoTrack);- if (nextContentSource === 'device') {- const mirrorCamera = VoiceSettings.getMirrorCamera();- const processor = await applyCameraMirrorProcessor(screenShareTrack, mirrorCamera);- if (mirrorCamera && !processor) {- throw new Error('Replacement device share could not apply its required mirror processor');- }- if (!mirrorCamera && screenShareTrack.getProcessor()) {- throw new Error('Replacement device share could not clear its previous video processor');- }- } else if (screenShareTrack.getProcessor()) {- await screenShareTrack.stopProcessor(false);- }const activeVideoTrack = screenShareTrack.mediaStream?.getVideoTracks()[0] ?? screenShareTrack.mediaStreamTrack;if (activeVideoTrack !== tracks.videoTrack) {throw new Error('Replacement screen share video track did not take ownership of its publication');diff --git a/fluxer_app/src/features/voice/utils/CameraVideoProcessor.ts b/fluxer_app/src/features/voice/utils/CameraVideoProcessor.tsindex 5882fcebb..41474abe5 100644--- a/fluxer_app/src/features/voice/utils/CameraVideoProcessor.ts+++ b/fluxer_app/src/features/voice/utils/CameraVideoProcessor.ts@@ -9,34 +9,10 @@ import type {WebCameraEffectConfig} from '@app/features/voice/utils/camera-effecimport type {Track, TrackProcessor, VideoProcessorOptions} from 'livekit-client';const logger = new Logger('CameraVideoProcessor');-const DEFAULT_FALLBACK_WIDTH = 640;-const DEFAULT_FALLBACK_HEIGHT = 360;-const DEFAULT_FALLBACK_FRAME_RATE = 30;-const CONTEXT_LOST_RESTARTS_MAX = 3;type VideoTrackProcessor = TrackProcessor<Track.Kind.Video, VideoProcessorOptions>;-type MediaStreamTrackProcessorInstance = {- readable: ReadableStream<VideoFrame>;-};-type MediaStreamTrackProcessorConstructor = new (options: {- track: MediaStreamTrack;-}) => MediaStreamTrackProcessorInstance;-type MediaStreamTrackGeneratorInstance = MediaStreamTrack & {- writable: WritableStream<VideoFrame>;-};-type MediaStreamTrackGeneratorConstructor = new (options: {- kind: 'video';- signalTarget?: MediaStreamTrack;-}) => MediaStreamTrackGeneratorInstance;-type Canvas2DContext = OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;--interface MediaStreamTrackProcessorGlobals {- MediaStreamTrackProcessor?: MediaStreamTrackProcessorConstructor;- MediaStreamTrackGenerator?: MediaStreamTrackGeneratorConstructor;-}export interface CameraVideoProcessorOptions {- mirror?: boolean;background?: WebCameraEffectConfig | null;}@@ -46,346 +22,9 @@ export interface CameraVideoProcessorHandle extends VideoTrackProcessor {setOperationalFailureHandler(handler: (error: Error) => void): void;}-function isTrackProcessorConstructor(value: unknown): value is MediaStreamTrackProcessorConstructor {- return typeof value === 'function';-}--function isTrackGeneratorConstructor(value: unknown): value is MediaStreamTrackGeneratorConstructor {- return typeof value === 'function';-}--function getTrackProcessorGlobals(): MediaStreamTrackProcessorGlobals {- const processor: unknown = Reflect.get(globalThis, 'MediaStreamTrackProcessor');- const generator: unknown = Reflect.get(globalThis, 'MediaStreamTrackGenerator');- return {- MediaStreamTrackProcessor: isTrackProcessorConstructor(processor) ? processor : undefined,- MediaStreamTrackGenerator: isTrackGeneratorConstructor(generator) ? generator : undefined,- };-}--function createCanvas(width: number, height: number): OffscreenCanvas | HTMLCanvasElement {- if (typeof OffscreenCanvas !== 'undefined') {- return new OffscreenCanvas(width, height);- }- const canvas = document.createElement('canvas');- canvas.width = width;- canvas.height = height;- return canvas;-}--function getCanvasContext(canvas: OffscreenCanvas | HTMLCanvasElement): Canvas2DContext | null {- return canvas.getContext('2d', {alpha: false}) as Canvas2DContext | null;-}--function resizeCanvas(canvas: OffscreenCanvas | HTMLCanvasElement, width: number, height: number): void {- if (canvas.width === width && canvas.height === height) {- return;- }- canvas.width = width;- canvas.height = height;-}--class MirrorVideoProcessor implements VideoTrackProcessor {- name = 'camera-mirror-processor';- processedTrack?: MediaStreamTrack;- private canvas: OffscreenCanvas | HTMLCanvasElement | null = null;- private canvasContext: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null = null;- private abortController: AbortController | null = null;- private pipePromise: Promise<void> | null = null;- private fallbackVideoElement: HTMLVideoElement | null = null;- private fallbackStream: MediaStream | null = null;- private fallbackSourceTrack: MediaStreamTrack | null = null;- private fallbackAnimationFrameId: number | null = null;- private fallbackLastFrameAt = 0;- private fallbackMinFrameIntervalMs = 0;- private lastProcessorOptions: VideoProcessorOptions | null = null;- private contextLostCanvas: OffscreenCanvas | HTMLCanvasElement | null = null;- private contextLostRestartCount = 0;-- async init(opts: VideoProcessorOptions): Promise<void> {- this.lastProcessorOptions = opts;- await this.setup(opts.track);- }-- async restart(opts: VideoProcessorOptions): Promise<void> {- await this.destroy();- this.lastProcessorOptions = opts;- await this.setup(opts.track);- }-- private readonly handleContextLost = (): void => {- const processorOptions = this.lastProcessorOptions;- this.contextLostRestartCount += 1;- if (!processorOptions) {- logger.warn('Camera mirror canvas context lost without restartable processor options');- return;- }- if (this.contextLostRestartCount > CONTEXT_LOST_RESTARTS_MAX) {- logger.error('Camera mirror canvas context lost beyond the restart budget; dropping the processor restart', {- restartCount: this.contextLostRestartCount,- restartsMax: CONTEXT_LOST_RESTARTS_MAX,- });- return;- }- logger.warn('Camera mirror canvas context lost; restarting processor', {- restartCount: this.contextLostRestartCount,- });- void this.restart(processorOptions).catch((error) => {- logger.warn('Failed to restart camera mirror processor after canvas context loss', {error});- });- };-- private registerContextLostListener(canvas: OffscreenCanvas | HTMLCanvasElement): void {- this.contextLostCanvas = canvas;- canvas.addEventListener('contextlost', this.handleContextLost);- }-- private removeContextLostListener(): void {- if (!this.contextLostCanvas) return;- this.contextLostCanvas.removeEventListener('contextlost', this.handleContextLost);- this.contextLostCanvas = null;- }-- private readonly handleFallbackVisibilityChange = (): void => {- this.updateFallbackFrameLoop();- };-- private readonly handleFallbackSourceEnded = (): void => {- this.stopFallbackFrameLoop();- };-- async destroy(): Promise<void> {- this.lastProcessorOptions = null;- this.removeContextLostListener();- this.removeFallbackLifecycleListeners();- this.abortController?.abort();- this.abortController = null;- this.stopFallbackFrameLoop();- if (this.fallbackVideoElement) {- this.fallbackVideoElement.pause();- this.fallbackVideoElement.srcObject = null;- this.fallbackVideoElement.remove();- this.fallbackVideoElement = null;- }- this.fallbackStream?.getTracks().forEach((track) => track.stop());- this.fallbackStream = null;- this.fallbackSourceTrack = null;- this.processedTrack?.stop();- this.processedTrack = undefined;- this.canvas = null;- this.canvasContext = null;- await this.pipePromise?.catch(() => {});- this.pipePromise = null;- }-- private async setup(sourceTrack: MediaStreamTrack): Promise<void> {- const globals = getTrackProcessorGlobals();- if (globals.MediaStreamTrackProcessor && globals.MediaStreamTrackGenerator) {- this.setupStreamProcessor(sourceTrack, globals.MediaStreamTrackProcessor, globals.MediaStreamTrackGenerator);- return;- }- this.setupCanvasFallback(sourceTrack);- }-- private setupStreamProcessor(- sourceTrack: MediaStreamTrack,- Processor: MediaStreamTrackProcessorConstructor,- Generator: MediaStreamTrackGeneratorConstructor,- ): void {- const sourceSettings = sourceTrack.getSettings();- const initialWidth = sourceSettings.width ?? DEFAULT_FALLBACK_WIDTH;- const initialHeight = sourceSettings.height ?? DEFAULT_FALLBACK_HEIGHT;- const canvas = createCanvas(initialWidth, initialHeight);- const canvasContext = getCanvasContext(canvas);- if (!canvasContext) {- throw new Error('Unable to create camera mirror canvas context');- }- this.canvas = canvas;- this.canvasContext = canvasContext;- this.registerContextLostListener(canvas);- const processor = new Processor({track: sourceTrack});- const generator = new Generator({kind: 'video', signalTarget: sourceTrack});- this.abortController = new AbortController();- this.pipePromise = this.pumpFrames(processor.readable, generator.writable, this.abortController.signal);- this.processedTrack = generator;- }-- private async pumpFrames(- readable: ReadableStream<VideoFrame>,- writable: WritableStream<VideoFrame>,- signal: AbortSignal,- ): Promise<void> {- const reader = readable.getReader();- const writer = writable.getWriter();- const cancelReader = () => {- reader.cancel().catch(() => {});- };- signal.addEventListener('abort', cancelReader, {once: true});- try {- while (!signal.aborted) {- const {done, value: frame} = await reader.read();- if (done || !frame) {- return;- }- if (signal.aborted) {- frame.close();- return;- }- await this.writeMirroredFrame(frame, writer);- }- } catch (error) {- if (!signal.aborted) {- logger.warn('Camera mirror stream processor failed', {error});- }- } finally {- signal.removeEventListener('abort', cancelReader);- cancelReader();- writer.close().catch(() => {});- }- }-- private async writeMirroredFrame(frame: VideoFrame, writer: WritableStreamDefaultWriter<VideoFrame>): Promise<void> {- const mirroredFrame = this.createMirroredFrame(frame);- const outputFrame = mirroredFrame ?? frame;- try {- await writer.write(outputFrame);- } catch (error) {- outputFrame.close();- throw error;- } finally {- if (mirroredFrame) {- frame.close();- }- }- }-- private createMirroredFrame(frame: VideoFrame): VideoFrame | null {- const width = frame.displayWidth || frame.codedWidth;- const height = frame.displayHeight || frame.codedHeight;- if (!this.canvas || !this.canvasContext || width <= 0 || height <= 0) {- return null;- }- try {- resizeCanvas(this.canvas, width, height);- this.drawMirrored(frame, width, height);- return new VideoFrame(this.canvas, {- timestamp: frame.timestamp ?? Math.round(performance.now() * 1000),- });- } catch (error) {- logger.warn('Failed to mirror camera frame', {error});- return null;- }- }-- private drawMirrored(source: CanvasImageSource, width: number, height: number): void {- const ctx = this.canvasContext;- if (!ctx) {- return;- }- ctx.save();- ctx.clearRect(0, 0, width, height);- ctx.translate(width, 0);- ctx.scale(-1, 1);- ctx.drawImage(source, 0, 0, width, height);- ctx.restore();- }-- private setupCanvasFallback(sourceTrack: MediaStreamTrack): void {- if (typeof HTMLCanvasElement === 'undefined' || !('captureStream' in HTMLCanvasElement.prototype)) {- throw new Error('Camera mirror processing is not supported in this browser');- }- const sourceSettings = sourceTrack.getSettings();- const width = sourceSettings.width ?? DEFAULT_FALLBACK_WIDTH;- const height = sourceSettings.height ?? DEFAULT_FALLBACK_HEIGHT;- const frameRate = sourceSettings.frameRate ?? DEFAULT_FALLBACK_FRAME_RATE;- const videoElement = document.createElement('video');- videoElement.muted = true;- videoElement.autoplay = true;- videoElement.playsInline = true;- videoElement.srcObject = new MediaStream([sourceTrack]);- const canvas = document.createElement('canvas');- canvas.width = width;- canvas.height = height;- const canvasContext = getCanvasContext(canvas);- if (!canvasContext) {- throw new Error('Unable to create camera mirror fallback canvas context');- }- this.fallbackVideoElement = videoElement;- this.fallbackSourceTrack = sourceTrack;- this.canvas = canvas;- this.canvasContext = canvasContext;- this.registerContextLostListener(canvas);- this.fallbackStream = canvas.captureStream(frameRate);- this.processedTrack = this.fallbackStream.getVideoTracks()[0];- videoElement.play().catch((error) => {- logger.warn('Failed to start camera mirror fallback video element', {error});- });- this.fallbackMinFrameIntervalMs = 1000 / Math.max(1, frameRate);- this.addFallbackLifecycleListeners(sourceTrack);- this.updateFallbackFrameLoop();- }-- private addFallbackLifecycleListeners(sourceTrack: MediaStreamTrack): void {- document.addEventListener('visibilitychange', this.handleFallbackVisibilityChange);- sourceTrack.addEventListener('ended', this.handleFallbackSourceEnded, {once: true});- }-- private removeFallbackLifecycleListeners(): void {- document.removeEventListener('visibilitychange', this.handleFallbackVisibilityChange);- this.fallbackSourceTrack?.removeEventListener('ended', this.handleFallbackSourceEnded);- }-- private shouldRunFallbackFrameLoop(): boolean {- if (!this.fallbackVideoElement) return false;- if (!this.canvas) return false;- if (!this.canvasContext) return false;- if (this.fallbackSourceTrack?.readyState !== 'live') return false;- return document.visibilityState !== 'hidden';- }-- private updateFallbackFrameLoop(): void {- if (this.shouldRunFallbackFrameLoop()) {- this.startFallbackFrameLoop();- return;- }- this.stopFallbackFrameLoop();- }-- private startFallbackFrameLoop(): void {- if (this.fallbackAnimationFrameId !== null) return;- this.fallbackAnimationFrameId = requestAnimationFrame(this.drawFallbackFrame);- }-- private stopFallbackFrameLoop(): void {- if (this.fallbackAnimationFrameId === null) return;- cancelAnimationFrame(this.fallbackAnimationFrameId);- this.fallbackAnimationFrameId = null;- }-- private readonly drawFallbackFrame = (now: number): void => {- this.fallbackAnimationFrameId = null;- if (!this.shouldRunFallbackFrameLoop()) return;- const videoElement = this.fallbackVideoElement;- const canvas = this.canvas;- if (!videoElement) return;- if (!canvas) return;- if (now - this.fallbackLastFrameAt >= this.fallbackMinFrameIntervalMs) {- this.fallbackLastFrameAt = now;- const nextWidth = videoElement.videoWidth || canvas.width;- const nextHeight = videoElement.videoHeight || canvas.height;- resizeCanvas(canvas, nextWidth, nextHeight);- if (videoElement.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {- this.drawMirrored(videoElement, nextWidth, nextHeight);- }- }- this.startFallbackFrameLoop();- };-}-class CameraVideoProcessor implements CameraVideoProcessorHandle {name = 'camera-video-processor';processedTrack?: MediaStreamTrack;- private mirrorProcessor: MirrorVideoProcessor | null = null;private backgroundPipeline: WebCameraPipeline | null = null;private currentOptions: CameraVideoProcessorOptions;private operationTail: Promise<void> = Promise.resolve();@@ -435,11 +74,6 @@ class CameraVideoProcessor implements CameraVideoProcessorHandle {}canUpdate(options: CameraVideoProcessorOptions): boolean {- const currentMirror = this.currentOptions.mirror === true;- const nextMirror = options.mirror === true;- if (currentMirror !== nextMirror) {- return false;- }const currentHasBackground = this.currentOptions.background != null;const nextHasBackground = options.background != null;return currentHasBackground === nextHasBackground;@@ -490,9 +124,7 @@ class CameraVideoProcessor implements CameraVideoProcessorHandle {logger.warn('Failed to signal camera background pipeline stop intent', {error});}}- const mirrorProcessor = this.mirrorProcessor;this.backgroundPipeline = null;- this.mirrorProcessor = null;this.processedTrack = undefined;if (backgroundPipeline) {try {@@ -501,22 +133,14 @@ class CameraVideoProcessor implements CameraVideoProcessorHandle {logger.warn('Failed to stop camera background pipeline', {error});}}- await mirrorProcessor?.destroy();}private async setup(opts: VideoProcessorOptions): Promise<void> {const background = this.currentOptions.background ?? null;try {- let inputTrack = opts.track;- if (this.currentOptions.mirror) {- const mirrorProcessor = new MirrorVideoProcessor();- this.mirrorProcessor = mirrorProcessor;- await mirrorProcessor.init({...opts, track: inputTrack});- inputTrack = mirrorProcessor.processedTrack ?? inputTrack;- }if (background) {const backgroundPipeline = await WebCameraEffectPipeline.create({- source: inputTrack,+ source: opts.track,config: {background},onFailure: (_pipeline, error) => {this.handleBackgroundPipelineFailure(error);@@ -526,7 +150,7 @@ class CameraVideoProcessor implements CameraVideoProcessorHandle {this.processedTrack = backgroundPipeline.outputTrack;return;}- this.processedTrack = inputTrack === opts.track ? undefined : inputTrack;+ this.processedTrack = undefined;} catch (error) {await this.teardown();throw error;diff --git a/fluxer_app/src/features/voice/utils/VideoBackgroundProcessor.ts b/fluxer_app/src/features/voice/utils/VideoBackgroundProcessor.tsindex ec89194ff..dd7a33034 100644--- a/fluxer_app/src/features/voice/utils/VideoBackgroundProcessor.ts+++ b/fluxer_app/src/features/voice/utils/VideoBackgroundProcessor.ts@@ -23,7 +23,6 @@ const logger = new Logger('VideoBackgroundProcessor');export interface BackgroundProcessorOptions {backgroundImageId?: string;backgroundImages?: Array<BackgroundImage>;- mirrorCamera?: boolean;}export interface AppliedBackgroundProcessor {@@ -146,37 +145,18 @@ async function resolveBackgroundEffectConfig(};}-export async function applyCameraMirrorProcessor(- track: LocalVideoTrack,- mirrorCamera = VoiceSettings.getMirrorCamera(),-) {- try {- if (!mirrorCamera) {- await clearCameraVideoProcessor(track);- logger.debug('No camera mirror processor applied');- return null;- }- return applyCameraVideoProcessor(track, {mirror: true}, 'Applied camera mirror');- } catch (error) {- logger.warn('Failed to apply camera mirror processor', error);- throw error;- }-}-export async function applyBackgroundProcessor(track: LocalVideoTrack,options?: BackgroundProcessorOptions,): Promise<AppliedBackgroundProcessor | null> {try {- const mirrorCamera = options?.mirrorCamera ?? VoiceSettings.getMirrorCamera();const background = await resolveBackgroundEffectConfig(options);- if (!mirrorCamera && background == null) {+ if (background == null) {await clearCameraVideoProcessor(track);logger.debug('No camera video processor applied');return null;}- const logLabel = background == null ? 'Applied camera mirror' : `Applied camera background (${background.mode})`;- return applyCameraVideoProcessor(track, {mirror: mirrorCamera, background}, logLabel);+ return applyCameraVideoProcessor(track, {background}, `Applied camera background (${background.mode})`);} catch (error) {logger.warn('Failed to apply camera video processor', error);throw error;diff --git a/packages/voice_engine_v2/fixtures/event_logs/camera_in_place_update.json b/packages/voice_engine_v2/fixtures/event_logs/camera_in_place_update.jsonindex 5c881a716..c543afcb2 100644--- a/packages/voice_engine_v2/fixtures/event_logs/camera_in_place_update.json+++ b/packages/voice_engine_v2/fixtures/event_logs/camera_in_place_update.json@@ -8,7 +8,7 @@{"type": "connection.connectSucceeded", "operationId": 1},{"type": "camera.publishRequested",- "options": {"deviceId": "camera-1", "width": 1280, "height": 720, "mirror": false}+ "options": {"deviceId": "camera-1", "width": 1280, "height": 720}},{"type": "camera.publishSucceeded", "operationId": 2},{@@ -17,7 +17,6 @@"width": 1920,"height": 1080,"frameRate": 60,- "mirror": true,"backgroundMode": "blur","backgroundBlurStrength": 60}@@ -33,7 +32,7 @@{"type": "camera.publish","operationId": 2,- "options": {"deviceId": "camera-1", "width": 1280, "height": 720, "mirror": false}+ "options": {"deviceId": "camera-1", "width": 1280, "height": 720}},{"type": "camera.updateEncoding",@@ -42,7 +41,6 @@"width": 1920,"height": 1080,"frameRate": 60,- "mirror": true,"backgroundMode": "blur","backgroundBlurStrength": 60}@@ -54,7 +52,6 @@"cameraDeviceId": "camera-1","cameraWidth": 1920,"cameraFrameRate": 60,- "cameraMirror": true,"cameraBackgroundMode": "blur","lastFailureCode": null}diff --git a/packages/voice_engine_v2/fixtures/policies/camera_share_encoding_plan.json b/packages/voice_engine_v2/fixtures/policies/camera_share_encoding_plan.jsonindex 32d23c333..7873adb28 100644--- a/packages/voice_engine_v2/fixtures/policies/camera_share_encoding_plan.json+++ b/packages/voice_engine_v2/fixtures/policies/camera_share_encoding_plan.json@@ -1,15 +1,4 @@[- {- "name": "mirror toggle updates in place",- "input": {- "published": {"deviceId": "camera-1", "width": 1280, "height": 720, "mirror": false},- "desired": null,- "update": {"mirror": true}- },- "expectedAction": "updateEncoding",- "expectedReason": "effectsOrEncodingChanged",- "expectedMirror": true- },{"name": "background mode and blur strength update in place","input": {@@ -57,9 +46,9 @@{"name": "identical options is a no-op","input": {- "published": {"deviceId": "camera-1", "width": 1280, "height": 720, "mirror": true},+ "published": {"deviceId": "camera-1", "width": 1280, "height": 720},"desired": null,- "update": {"width": 1280, "height": 720, "mirror": true}+ "update": {"width": 1280, "height": 720}},"expectedAction": "noop","expectedReason": "unchanged"@@ -69,7 +58,7 @@"input": {"published": null,"desired": null,- "update": {"mirror": true}+ "update": {"backgroundMode": "blur"}},"expectedAction": "reject","expectedReason": "missingPublishedCamera",diff --git a/packages/voice_engine_v2/src/core/fixtures.test.ts b/packages/voice_engine_v2/src/core/fixtures.test.tsindex ba9c7ac31..b0e11212b 100644--- a/packages/voice_engine_v2/src/core/fixtures.test.ts+++ b/packages/voice_engine_v2/src/core/fixtures.test.ts@@ -39,7 +39,6 @@ interface VoiceEngineV2ScreenFixtureExpected {cameraDeviceId?: string | null;cameraWidth?: number;cameraFrameRate?: number;- cameraMirror?: boolean;cameraBackgroundMode?: string;screenStatus?: string;screenCaptureId?: string | null;@@ -113,9 +112,6 @@ describe('voice engine v2 shared fixtures', () => {if (fixture.expected.cameraFrameRate !== undefined) {expect(snapshot.camera.published?.frameRate).toBe(fixture.expected.cameraFrameRate);}- if (fixture.expected.cameraMirror !== undefined) {- expect(snapshot.camera.published?.mirror).toBe(fixture.expected.cameraMirror);- }if (fixture.expected.cameraBackgroundMode !== undefined) {expect(snapshot.camera.published?.backgroundMode).toBe(fixture.expected.cameraBackgroundMode);}diff --git a/packages/voice_engine_v2/src/core/reducer.test.ts b/packages/voice_engine_v2/src/core/reducer.test.tsindex 4fa8595e4..ebfeb1ad6 100644--- a/packages/voice_engine_v2/src/core/reducer.test.ts+++ b/packages/voice_engine_v2/src/core/reducer.test.ts@@ -521,13 +521,13 @@ describe('transitionVoiceEngineV2', () => {expect(updated.snapshot.screen.desired?.maxFramerate).toBe(60);});- it('updates camera encoding in place for mirror, background, resolution, and frame rate', () => {+ it('updates camera encoding in place for background, resolution, and frame rate', () => {const snapshot = applyEvents(initialSnapshot(), [{type: 'connection.connectRequested', options: {url: 'wss://voice', token: 'token'}},{type: 'connection.connectSucceeded', operationId: 1},{type: 'camera.publishRequested',- options: {deviceId: 'camera-1', width: 1280, height: 720, frameRate: 30, mirror: false},+ options: {deviceId: 'camera-1', width: 1280, height: 720, frameRate: 30},},{type: 'camera.publishSucceeded', operationId: 2},]);@@ -538,7 +538,6 @@ describe('transitionVoiceEngineV2', () => {width: 1920,height: 1080,frameRate: 60,- mirror: true,backgroundMode: 'blur',backgroundBlurStrength: 80,},@@ -552,7 +551,6 @@ describe('transitionVoiceEngineV2', () => {width: 1920,height: 1080,frameRate: 60,- mirror: true,backgroundMode: 'blur',backgroundBlurStrength: 80,},@@ -565,7 +563,6 @@ describe('transitionVoiceEngineV2', () => {width: 1920,height: 1080,frameRate: 60,- mirror: true,backgroundMode: 'blur',backgroundBlurStrength: 80,});@@ -575,22 +572,24 @@ describe('transitionVoiceEngineV2', () => {const snapshot = applyEvents(initialSnapshot(), [{type: 'connection.connectRequested', options: {url: 'wss://voice', token: 'token'}},{type: 'connection.connectSucceeded', operationId: 1},- {type: 'camera.publishRequested', options: {deviceId: 'camera-1', width: 1280, height: 720, mirror: false}},+ {type: 'camera.publishRequested', options: {deviceId: 'camera-1', width: 1280, height: 720}},{type: 'camera.publishSucceeded', operationId: 2},]);const updated = transitionVoiceEngineV2(snapshot, {type: 'camera.updateEncodingRequested',- options: {mirror: true},+ options: {backgroundMode: 'blur'},});const succeeded = transitionVoiceEngineV2(updated.snapshot, {type: 'camera.updateEncodingSucceeded',operationId: 3,});- expect(updated.commands).toEqual([{type: 'camera.updateEncoding', operationId: 3, options: {mirror: true}}]);+ expect(updated.commands).toEqual([+ {type: 'camera.updateEncoding', operationId: 3, options: {backgroundMode: 'blur'}},+ ]);expect(succeeded.snapshot.camera.status).toBe('published');- expect(succeeded.snapshot.camera.published).toMatchObject({deviceId: 'camera-1', mirror: true});+ expect(succeeded.snapshot.camera.published).toMatchObject({deviceId: 'camera-1', backgroundMode: 'blur'});});it('republishes the camera when the device id or codec changes', () => {@@ -634,7 +633,7 @@ describe('transitionVoiceEngineV2', () => {const updated = transitionVoiceEngineV2(snapshot, {type: 'camera.updateEncodingRequested',- options: {mirror: true},+ options: {backgroundMode: 'blur'},});expect(updated.commands).toEqual([]);@@ -646,13 +645,13 @@ describe('transitionVoiceEngineV2', () => {const snapshot = applyEvents(initialSnapshot(), [{type: 'connection.connectRequested', options: {url: 'wss://voice', token: 'token'}},{type: 'connection.connectSucceeded', operationId: 1},- {type: 'camera.publishRequested', options: {deviceId: 'camera-1', width: 1280, height: 720, mirror: true}},+ {type: 'camera.publishRequested', options: {deviceId: 'camera-1', width: 1280, height: 720}},{type: 'camera.publishSucceeded', operationId: 2},]);const updated = transitionVoiceEngineV2(snapshot, {type: 'camera.updateEncodingRequested',- options: {width: 1280, height: 720, mirror: true},+ options: {width: 1280, height: 720},});expect(updated.commands).toEqual([]);diff --git a/packages/voice_engine_v2/src/policies/cameraShare.ts b/packages/voice_engine_v2/src/policies/cameraShare.tsindex 9ed3f84e7..e4d8e130f 100644--- a/packages/voice_engine_v2/src/policies/cameraShare.ts+++ b/packages/voice_engine_v2/src/policies/cameraShare.ts@@ -57,7 +57,6 @@ export function applyVoiceEngineV2CameraEncodingOptions(if (update.frameRate !== undefined) desired.frameRate = update.frameRate;if (update.codec !== undefined) desired.codec = update.codec;if (update.maxBitrateBps !== undefined) desired.maxBitrateBps = update.maxBitrateBps;- if (update.mirror !== undefined) desired.mirror = update.mirror;if (update.backgroundMode !== undefined) desired.backgroundMode = update.backgroundMode;if (update.backgroundBlurStrength !== undefined) desired.backgroundBlurStrength = update.backgroundBlurStrength;if (update.backgroundCustomMediaPath !== undefined) {@@ -76,7 +75,6 @@ function sameCameraEncodingState(a: VoiceEngineV2CameraOptions, b: VoiceEngineV2if (a.frameRate !== b.frameRate) return false;if (a.codec !== b.codec) return false;if (a.maxBitrateBps !== b.maxBitrateBps) return false;- if (a.mirror !== b.mirror) return false;if (a.backgroundMode !== b.backgroundMode) return false;if (a.backgroundBlurStrength !== b.backgroundBlurStrength) return false;if (a.backgroundCustomMediaPath !== b.backgroundCustomMediaPath) return false;diff --git a/packages/voice_engine_v2/src/policies/policies.test.ts b/packages/voice_engine_v2/src/policies/policies.test.tsindex 4df8f447e..d8061c9d1 100644--- a/packages/voice_engine_v2/src/policies/policies.test.ts+++ b/packages/voice_engine_v2/src/policies/policies.test.ts@@ -71,7 +71,6 @@ interface CameraShareEncodingPlanFixture {expectedAction: string;expectedReason: string;expectedCodec?: string;- expectedMirror?: boolean;expectedBackgroundMode?: string;expectedWidth?: number;expectedFrameRate?: number;@@ -136,9 +135,6 @@ describe('voice engine v2 policies', () => {if (fixture.expectedCodec !== undefined) {expect(plan.desired?.codec).toBe(fixture.expectedCodec);}- if (fixture.expectedMirror !== undefined) {- expect(plan.desired?.mirror).toBe(fixture.expectedMirror);- }if (fixture.expectedBackgroundMode !== undefined) {expect(plan.desired?.backgroundMode).toBe(fixture.expectedBackgroundMode);}diff --git a/packages/voice_engine_v2/src/protocol/types.ts b/packages/voice_engine_v2/src/protocol/types.tsindex c62a8e084..9775a687f 100644--- a/packages/voice_engine_v2/src/protocol/types.ts+++ b/packages/voice_engine_v2/src/protocol/types.ts@@ -181,7 +181,6 @@ export interface VoiceEngineV2CameraOptions {frameRate?: number;codec?: VoiceEngineV2VideoCodec;maxBitrateBps?: number;- mirror?: boolean;backgroundMode?: VoiceEngineV2CameraBackgroundMode;backgroundBlurStrength?: number;backgroundCustomMediaPath?: string;@@ -196,7 +195,6 @@ export interface VoiceEngineV2CameraEncodingOptions {frameRate?: number;codec?: VoiceEngineV2VideoCodec;maxBitrateBps?: number;- mirror?: boolean;backgroundMode?: VoiceEngineV2CameraBackgroundMode;backgroundBlurStrength?: number;backgroundCustomMediaPath?: string;diff --git a/packages/voice_engine_v2/src/testing/conformance.ts b/packages/voice_engine_v2/src/testing/conformance.tsindex 363b761c0..bdee8aba2 100644--- a/packages/voice_engine_v2/src/testing/conformance.ts+++ b/packages/voice_engine_v2/src/testing/conformance.ts@@ -120,12 +120,12 @@ export function runVoiceEngineV2ConformanceSuite(await waitForRuntime();runtime.dispatch({type: 'camera.publishRequested',- options: {deviceId: 'camera-1', width: 1280, height: 720, mirror: false},+ options: {deviceId: 'camera-1', width: 1280, height: 720},});await waitForRuntime();runtime.dispatch({type: 'camera.updateEncodingRequested',- options: {width: 1920, height: 1080, frameRate: 60, mirror: true, backgroundMode: 'blur'},+ options: {width: 1920, height: 1080, frameRate: 60, backgroundMode: 'blur'},});await waitForRuntime();@@ -135,7 +135,6 @@ export function runVoiceEngineV2ConformanceSuite(width: 1920,height: 1080,frameRate: 60,- mirror: true,backgroundMode: 'blur',});});