A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(app): flatten voice engine and model decisions
Hampus6a4d62541518
diff --git a/fluxer_app/src/features/voice/components/VoiceGridLayoutMetrics.ts b/fluxer_app/src/features/voice/components/VoiceGridLayoutMetrics.tsindex 6b6490c72..58e9d86ae 100644--- a/fluxer_app/src/features/voice/components/VoiceGridLayoutMetrics.ts+++ b/fluxer_app/src/features/voice/components/VoiceGridLayoutMetrics.ts@@ -26,7 +26,7 @@ interface VoiceGridLayoutMetricsInput {edgeToEdge?: boolean;}-export interface VoiceGridVisibleTileCapacityInput extends VoiceGridLayoutMetricsInput {+interface VoiceGridVisibleTileCapacityInput extends VoiceGridLayoutMetricsInput {minTileWidth?: number;minTileHeight?: number;}@@ -49,7 +49,7 @@ interface VoiceGridLayoutMetrics {contentHeight: number;}-export interface VoiceGridPackedLayoutMetrics extends VoiceGridLayoutMetrics {+interface VoiceGridPackedLayoutMetrics extends VoiceGridLayoutMetrics {visibleTileCount: number;}@@ -150,29 +150,29 @@ function getVoiceGridPadding({}const width = sanitizeDimension(containerWidth);const height = sanitizeDimension(containerHeight);- const sidePadding = compact- ? clamp(height * 0.02, 6, 12)- : width <= 419- ? 6- : width <= 759- ? 8- : VOICE_GRID_DEFAULT_SIDE_PADDING_PX;- const verticalPadding = compact- ? clamp(height * 0.018, 5, 10)- : height <= 359- ? 8- : height <= 519- ? 10- : VOICE_GRID_DEFAULT_VERTICAL_PADDING_PX;+ let sidePadding: number;+ if (compact) {+ sidePadding = clamp(height * 0.02, 6, 12);+ } else if (width <= 419) {+ sidePadding = 6;+ } else if (width <= 759) {+ sidePadding = 8;+ } else {+ sidePadding = VOICE_GRID_DEFAULT_SIDE_PADDING_PX;+ }+ let verticalPadding: number;+ if (compact) {+ verticalPadding = clamp(height * 0.018, 5, 10);+ } else if (height <= 359) {+ verticalPadding = 8;+ } else if (height <= 519) {+ verticalPadding = 10;+ } else {+ verticalPadding = VOICE_GRID_DEFAULT_VERTICAL_PADDING_PX;+ }return {sidePadding, verticalPadding};}-function getVoiceGridMinTileSize(compact = false): {minTileWidth: number; minTileHeight: number} {- return compact- ? {minTileWidth: VOICE_GRID_COMPACT_MIN_TILE_WIDTH_PX, minTileHeight: VOICE_GRID_COMPACT_MIN_TILE_HEIGHT_PX}- : {minTileWidth: VOICE_GRID_MIN_TILE_WIDTH_PX, minTileHeight: VOICE_GRID_MIN_TILE_HEIGHT_PX};-}-function resolveVoiceGridLayoutMetricsForColumns({tileCount,containerWidth,@@ -252,7 +252,9 @@ export function resolveVoiceGridPackedLayoutMetrics({visibleTileCount: 0,};}- const minSize = getVoiceGridMinTileSize(compact);+ const minSize = compact+ ? {minTileWidth: VOICE_GRID_COMPACT_MIN_TILE_WIDTH_PX, minTileHeight: VOICE_GRID_COMPACT_MIN_TILE_HEIGHT_PX}+ : {minTileWidth: VOICE_GRID_MIN_TILE_WIDTH_PX, minTileHeight: VOICE_GRID_MIN_TILE_HEIGHT_PX};const effectiveMinTileWidth = sanitizeDimension(minTileWidth ?? minSize.minTileWidth);const effectiveMinTileHeight = sanitizeDimension(minTileHeight ?? minSize.minTileHeight);for (let visibleCount = count; visibleCount >= 1; visibleCount--) {diff --git a/fluxer_app/src/features/voice/components/media_player/VideoPlayerRenderStateMachine.ts b/fluxer_app/src/features/voice/components/media_player/VideoPlayerRenderStateMachine.tsindex 25217d2d2..eeca56428 100644--- a/fluxer_app/src/features/voice/components/media_player/VideoPlayerRenderStateMachine.ts+++ b/fluxer_app/src/features/voice/components/media_player/VideoPlayerRenderStateMachine.ts@@ -3,11 +3,11 @@import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';type VideoPlayerRenderState = 'poster' | 'playing' | 'paused' | 'ended' | 'error';-export type VideoPlayerPlayPauseIndicator = 'play' | 'pause';+type VideoPlayerPlayPauseIndicator = 'play' | 'pause';type VideoPlayerPreloadAttribute = 'none' | 'metadata' | undefined;-export interface VideoPlayerRenderSignals {+interface VideoPlayerRenderSignals {autoPlay: boolean;hasPlayed: boolean;wantsMetadata: boolean;@@ -17,7 +17,7 @@ export interface VideoPlayerRenderSignals {hasError: boolean;}-export interface VideoPlayerRenderModel {+interface VideoPlayerRenderModel {renderState: VideoPlayerRenderState;shouldAttachSource: boolean;preloadAttribute: VideoPlayerPreloadAttribute;@@ -31,7 +31,7 @@ interface VideoPlayerPlaybackSignals {isPlaying: boolean;}-export type VideoPlayerRenderEvent =+type VideoPlayerRenderEvent =| {type: 'video.evaluateRender'; signals: VideoPlayerRenderSignals}| {type: 'video.observePlayback'; signals: VideoPlayerPlaybackSignals};@@ -63,10 +63,19 @@ function selectRenderState(signals: VideoPlayerRenderSignals): VideoPlayerRenderfunction createRenderModel(signals: VideoPlayerRenderSignals): VideoPlayerRenderModel {const renderState = selectRenderState(signals);+ const shouldAttachSource = signals.hasPlayed || signals.wantsMetadata;+ let preloadAttribute: VideoPlayerPreloadAttribute;+ if (signals.hasPlayed) {+ preloadAttribute = undefined;+ } else if (signals.wantsMetadata) {+ preloadAttribute = 'metadata';+ } else {+ preloadAttribute = 'none';+ }return {renderState,- shouldAttachSource: signals.hasPlayed || signals.wantsMetadata,- preloadAttribute: signals.hasPlayed ? undefined : signals.wantsMetadata ? 'metadata' : 'none',+ shouldAttachSource,+ preloadAttribute,shouldHideVideo: !signals.hasPlayed,shouldShowPosterOverlay: !signals.hasPlayed && !signals.autoPlay,shouldShowControlsOverlay: signals.hasPlayed || signals.autoPlay,@@ -124,7 +133,7 @@ const videoPlayerRenderStateMachine = setup({},});-export type VideoPlayerRenderSnapshot = SnapshotFrom<typeof videoPlayerRenderStateMachine>;+type VideoPlayerRenderSnapshot = SnapshotFrom<typeof videoPlayerRenderStateMachine>;export function createVideoPlayerRenderSnapshot(): VideoPlayerRenderSnapshot {return initialTransition(videoPlayerRenderStateMachine)[0];diff --git a/fluxer_app/src/features/voice/components/voice_connection_status/LocalParticipantControlsStateMachine.ts b/fluxer_app/src/features/voice/components/voice_connection_status/LocalParticipantControlsStateMachine.tsindex 3d6b1095b..8a7a6d8ff 100644--- a/fluxer_app/src/features/voice/components/voice_connection_status/LocalParticipantControlsStateMachine.ts+++ b/fluxer_app/src/features/voice/components/voice_connection_status/LocalParticipantControlsStateMachine.ts@@ -17,7 +17,7 @@ type LocalParticipantScreenShareLabelKey =| 'shareScreen';type LocalParticipantScreenShareClickAction = 'none' | 'openPicker' | 'openMenu';-export interface LocalParticipantControlSignals {+interface LocalParticipantControlSignals {isConnected: boolean;canStream: boolean;isCameraEnabled: boolean;@@ -47,7 +47,7 @@ interface LocalParticipantScreenShareControlState {canPreloadPicker: boolean;}-export interface LocalParticipantControlsViewState {+interface LocalParticipantControlsViewState {camera: LocalParticipantCameraControlState;screenShare: LocalParticipantScreenShareControlState;}@@ -132,6 +132,14 @@ export function selectLocalParticipantControlsViewState(const screenShareValue = selectLocalParticipantMediaControlState('screenShare', signals);const cameraDisabled = isDisabled(cameraValue);const screenShareDisabled = isDisabled(screenShareValue);+ let clickAction: LocalParticipantScreenShareClickAction;+ if (screenShareValue === 'active') {+ clickAction = 'openMenu';+ } else if (screenShareValue === 'ready') {+ clickAction = 'openPicker';+ } else {+ clickAction = 'none';+ }return {camera: {value: cameraValue,@@ -143,7 +151,7 @@ export function selectLocalParticipantControlsViewState(value: screenShareValue,labelKey: SCREEN_SHARE_LABEL_BY_STATE[screenShareValue],disabled: screenShareDisabled,- clickAction: screenShareValue === 'active' ? 'openMenu' : screenShareValue === 'ready' ? 'openPicker' : 'none',+ clickAction,canOpenMenu: screenShareValue === 'active',canPreloadPicker: screenShareValue === 'ready',},diff --git a/fluxer_app/src/features/voice/engine/VoiceMediaStateMachine.ts b/fluxer_app/src/features/voice/engine/VoiceMediaStateMachine.tsindex 108c7ce51..cfc092f6d 100644--- a/fluxer_app/src/features/voice/engine/VoiceMediaStateMachine.ts+++ b/fluxer_app/src/features/voice/engine/VoiceMediaStateMachine.ts@@ -603,11 +603,18 @@ const voiceMediaStateMachine = setup({event.type === 'camera.success' ? {...context, camera: event.enabled ? 'enabled' : 'disabled'} : context,),failCamera: assign(({context, event}) => {- if (event.type !== 'camera.failure') return context;- return {- ...context,- camera: event.permissionDenied ? 'permissionDenied' : event.actualEnabled ? 'enabled' : 'disabled',- };+ if (event.type !== 'camera.failure') {+ return context;+ }+ const nextContext = {...context};+ if (event.permissionDenied) {+ nextContext.camera = 'permissionDenied';+ } else if (event.actualEnabled) {+ nextContext.camera = 'enabled';+ } else {+ nextContext.camera = 'disabled';+ }+ return nextContext;}),reset: assign(() => initialContext()),clearCommands: assign(({context}) =>diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppLiveKitExecutionAdapter.ts b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppLiveKitExecutionAdapter.tsindex e487782b7..67c30f365 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppLiveKitExecutionAdapter.ts+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppLiveKitExecutionAdapter.ts@@ -232,7 +232,7 @@ export class VoiceEngineV2AppLiveKitExecutionAdapter implements LiveKitMediaPortthis.logger.info('disconnect requested', {reason});const delegate = this.connection.disconnectFromVoiceChannel;if (typeof delegate !== 'function') return;- const mapped = reason === 'user' ? 'user' : reason === 'server' ? 'server' : 'error';+ const mapped = reason === 'user' || reason === 'server' ? reason : 'error';try {delegate.call(this.connection, mapped);} catch (error) {diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareExecutionAdapter.tsx b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareExecutionAdapter.tsxindex d4518a847..207ebd039 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareExecutionAdapter.tsx+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppScreenShareExecutionAdapter.tsx@@ -255,14 +255,13 @@ class VoiceEngineV2AppScreenShareExecutionAdapter extends Store {}private transitionScreenShareCodecReadiness(status: ScreenShareCodecReadinessStatus): void {- this.transitionScreenShareLifecycleInternal({- type:- status === 'loading'- ? 'share.codecReadiness.loading'- : status === 'ready'- ? 'share.codecReadiness.ready'- : 'share.codecReadiness.timeout',- });+ if (status === 'loading') {+ this.transitionScreenShareLifecycleInternal({type: 'share.codecReadiness.loading'});+ } else if (status === 'ready') {+ this.transitionScreenShareLifecycleInternal({type: 'share.codecReadiness.ready'});+ } else {+ this.transitionScreenShareLifecycleInternal({type: 'share.codecReadiness.timeout'});+ }}async getEffectivePublishOptionsInternal(@@ -858,7 +857,6 @@ class VoiceEngineV2AppScreenShareExecutionAdapter extends Store {async ensureLinuxScreenShareAudioPublication(room: Room | null,linuxRule?: NonNullable<NativeAudioStartOptions['linuxRule']>,- options: {includeSelfWindowAudio?: boolean; replaceExisting?: boolean} = {},): Promise<boolean> {const participant = room?.localParticipant;if (!participant?.isScreenShareEnabled) return false;diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppSelectors.ts b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppSelectors.tsindex dd99de419..225757918 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppSelectors.ts+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppSelectors.ts@@ -2,6 +2,7 @@import assert from 'node:assert/strict';import {assertNonNullObject, assertString} from '@app/features/voice/engine/v2/VoiceEngineV2AppAdapterAssertions';+import {compareStrings} from '@app/lib/list/CompareStrings';import {selectVoiceEngineV2Model} from '@fluxer/voice_engine_v2/src/core/selectors';import type {VoiceEngineV2Snapshot} from '@fluxer/voice_engine_v2/src/core/state';import type {@@ -10,10 +11,9 @@ import type {VoiceEngineV2ConnectionStatus,VoiceEngineV2MediaStatus,VoiceEngineV2Model,- VoiceEngineV2Participant,} from '@fluxer/voice_engine_v2/src/protocol/types';-export type VoiceEngineV2AppProjectionSource = VoiceEngineV2Model | VoiceEngineV2Snapshot;+type VoiceEngineV2AppProjectionSource = VoiceEngineV2Model | VoiceEngineV2Snapshot;export type VoiceEngineV2AppParticipantSnapshot = Readonly<{identity: string;@@ -37,7 +37,7 @@ export type VoiceEngineV2AppParticipantSnapshot = Readonly<{lastSpokeAt: number | null;}>;-export interface VoiceEngineV2AppConnectionProjection {+interface VoiceEngineV2AppConnectionProjection {status: VoiceEngineV2ConnectionStatus;connected: boolean;connecting: boolean;@@ -55,7 +55,7 @@ export interface VoiceEngineV2AppConnectionProjection {serverRegion: string | null;}-export interface VoiceEngineV2AppConnectionFallback {+interface VoiceEngineV2AppConnectionFallback {connected?: boolean;connecting?: boolean;reconnecting?: boolean;@@ -85,7 +85,7 @@ interface VoiceEngineV2AppLocalMediaProjection {screenCaptureId: string | null;}-export interface VoiceEngineV2AppParticipantProjection {+interface VoiceEngineV2AppParticipantProjection {participants: Array<VoiceEngineV2AppParticipantSnapshot>;participantIdentities: Array<string>;}@@ -133,22 +133,6 @@ export function selectVoiceEngineV2AppConnection(};}-function isProjectionDefinitiveConnection(projection: VoiceEngineV2AppConnectionProjection): boolean {- if (projection.connected) return true;- if (projection.connecting) return true;- if (projection.reconnecting) return true;- if (projection.channelId) return true;- return false;-}--function isFallbackEmpty(fallback: VoiceEngineV2AppConnectionFallback): boolean {- if (fallback.connected) return false;- if (fallback.connecting) return false;- if (fallback.reconnecting) return false;- if (fallback.channelId) return false;- return true;-}-export function selectVoiceEngineV2AppConnectionWithFallback(source: VoiceEngineV2AppProjectionSource,fallback: VoiceEngineV2AppConnectionFallback,@@ -156,14 +140,28 @@ export function selectVoiceEngineV2AppConnectionWithFallback(assertNonNullObject(source, 'source');assertNonNullObject(fallback, 'fallback');const projection = selectVoiceEngineV2AppConnection(source);- if (isProjectionDefinitiveConnection(projection)) return projection;- if (isFallbackEmpty(fallback)) return projection;+ if (projection.connected || projection.connecting || projection.reconnecting || projection.channelId) {+ return projection;+ }+ if (!fallback.connected && !fallback.connecting && !fallback.reconnecting && !fallback.channelId) {+ return projection;+ }const connected = fallback.connected ?? projection.connected;const connecting = fallback.connecting ?? projection.connecting;const reconnecting = fallback.reconnecting ?? projection.reconnecting;+ let status: VoiceEngineV2ConnectionStatus;+ if (connected) {+ status = 'connected';+ } else if (connecting) {+ status = 'connecting';+ } else if (reconnecting) {+ status = 'reconnecting';+ } else {+ status = projection.status;+ }return {...projection,- status: connected ? 'connected' : connecting ? 'connecting' : reconnecting ? 'reconnecting' : projection.status,+ status,connected,connecting,reconnecting,@@ -267,7 +265,9 @@ export function selectVoiceEngineV2AppParticipants(source: VoiceEngineV2AppProjectionSource,): VoiceEngineV2AppParticipantProjection {assertNonNullObject(source, 'source');- const participants = sortVoiceEngineV2Participants([...voiceEngineV2AppModel(source).participants]);+ const participants = [...voiceEngineV2AppModel(source).participants].sort(+ (left, right) => compareStrings(left.identity, right.identity) || compareStrings(left.sid, right.sid),+ ) as Array<VoiceEngineV2AppParticipantSnapshot>;assert.ok(Array.isArray(participants), 'participants must be array');return {participants,@@ -303,17 +303,3 @@ function voiceEngineV2AppModel(source: VoiceEngineV2AppProjectionSource): VoiceEfunction isVoiceEngineV2Snapshot(source: VoiceEngineV2AppProjectionSource): source is VoiceEngineV2Snapshot {return 'nextOperationId' in source;}--function sortVoiceEngineV2Participants(- participants: Array<VoiceEngineV2Participant>,-): Array<VoiceEngineV2AppParticipantSnapshot> {- return participants.sort(- (left, right) => compareStrings(left.identity, right.identity) || compareStrings(left.sid, right.sid),- ) as Array<VoiceEngineV2AppParticipantSnapshot>;-}--function compareStrings(left: string, right: string): number {- if (left < right) return -1;- if (left > right) return 1;- return 0;-}diff --git a/fluxer_app/src/features/voice/hooks/useUserVoiceActivities.ts b/fluxer_app/src/features/voice/hooks/useUserVoiceActivities.tsindex 13bcf0850..c50dfcc41 100644--- a/fluxer_app/src/features/voice/hooks/useUserVoiceActivities.ts+++ b/fluxer_app/src/features/voice/hooks/useUserVoiceActivities.ts@@ -82,11 +82,8 @@ function useUserVoiceActivities(userId: string): ReadonlyArray<UserVoiceActivityconst channel = Channels.getChannel(channelId);const guild = effectiveGuildId ? Guilds.getGuild(effectiveGuildId) : undefined;const isStreaming = vs.self_stream === true;- const streamKey = isStreaming- ? effectiveGuildId- ? `${effectiveGuildId}:${channelId}:${connectionId}`- : `dm:${channelId}:${connectionId}`- : null;+ const streamScope = effectiveGuildId ? effectiveGuildId : 'dm';+ const streamKey = isStreaming ? `${streamScope}:${channelId}:${connectionId}` : null;const {participantUserIds, participantUsers} = collectParticipantUsers(channelStates);activities.push({voiceState: vs,diff --git a/fluxer_app/src/features/voice/utils/CodecCapabilityDetector.ts b/fluxer_app/src/features/voice/utils/CodecCapabilityDetector.tsindex de6b67167..4192377d1 100644--- a/fluxer_app/src/features/voice/utils/CodecCapabilityDetector.ts+++ b/fluxer_app/src/features/voice/utils/CodecCapabilityDetector.ts@@ -14,7 +14,6 @@ import {getGpuEncoderReportSync, type HardwareEncodeAnswer} from '@app/features/import {getNativeHardwareEncoderCapabilitiesSync,hasNativeHardwareEncoder,- resetNativeHardwareEncoderCapabilities,} from '@app/features/voice/utils/NativeHardwareEncoderCapabilities';import {LAST_RESORT_VIDEO_CODEC,@@ -246,14 +245,16 @@ function buildReport(): CodecCapabilityReport {}const supportedByNativeHardware = hasPublishPathNativeHardwareEncoder(codec, context);if (caps[codec]) {+ let detail = 'Available on your system.';+ if (supportedByNativeHardware) {+ detail = 'Available through the native hardware encoder.';+ } else if (linuxNvidiaWebRtcEncodeLimited && hwAccel(codec) === 'software') {+ detail = 'Available through Chromium software encoding. NVIDIA NVENC is not exposed to WebRTC on Linux.';+ }return {supported: true,reason: 'supported',- detail: supportedByNativeHardware- ? 'Available through the native hardware encoder.'- : linuxNvidiaWebRtcEncodeLimited && hwAccel(codec) === 'software'- ? 'Available through Chromium software encoding. NVIDIA NVENC is not exposed to WebRTC on Linux.'- : 'Available on your system.',+ detail,hardwareAccelerated: hwAccel(codec),};}@@ -270,15 +271,17 @@ function buildReport(): CodecCapabilityReport {nativeHardwareEncoder?.backend === 'nvenc' && nativeHardwareEncoder.reason? ` Native NVENC is unavailable: ${nativeHardwareEncoder.reason}.`: '';+ let h265Detail = 'H.265 (HEVC) encoding requires a Chromium-based browser with hardware HEVC support.';+ if (context.chromium && linuxNvidiaWebRtcEncodeLimited) {+ h265Detail = `Chromium on Linux does not expose NVIDIA NVENC to WebRTC, and the NVIDIA VA-API bridge used by Chromium does not support encoding.${nativeNvencDetail}`;+ } else if (context.chromium) {+ h265Detail =+ 'Your browser/system doesn\u2019t expose an H.265 (HEVC) encoder. H.265 needs hardware support on most platforms.';+ }return unsupported(codec, {supported: false,reason: 'unsupported-system',- detail:- context.chromium && linuxNvidiaWebRtcEncodeLimited- ? `Chromium on Linux does not expose NVIDIA NVENC to WebRTC, and the NVIDIA VA-API bridge used by Chromium does not support encoding.${nativeNvencDetail}`- : context.chromium- ? 'Your browser/system doesn\u2019t expose an H.265 (HEVC) encoder. H.265 needs hardware support on most platforms.'- : 'H.265 (HEVC) encoding requires a Chromium-based browser with hardware HEVC support.',+ detail: h265Detail,});}if (codec === 'av1') {@@ -364,7 +367,12 @@ export function selectOptimalCameraCodec(preference: CodecPreference = 'auto'):export function buildScreenShareCodecProfile(): ScreenShareCodecProfile {const report = getCodecCapabilityReport();- const browser: ScreenShareCodecBrowser = isFirefoxBrowser() ? 'firefox' : isChromiumBrowser() ? 'chromium' : 'other';+ let browser: ScreenShareCodecBrowser = 'other';+ if (isFirefoxBrowser()) {+ browser = 'firefox';+ } else if (isChromiumBrowser()) {+ browser = 'chromium';+ }const entry = (codec: VideoCodec): ScreenShareCodecProfileEntry => ({allowed: isVideoCodecAllowedForPublish(codec),supported: report[codec].supported,@@ -432,7 +440,7 @@ export function selectOptimalScreenShareCodec(return selectAutomaticScreenShareCodec(encoderMode).codec;}-export function markScreenShareCodecEncodeRuntimeFailure(codec: VideoCodec, reason: string): boolean {+function markScreenShareCodecEncodeRuntimeFailure(codec: VideoCodec, reason: string): boolean {if (codec === 'vp8') return false;if (runtimeEncodeFailureCodecs.has(codec)) return false;runtimeEncodeFailureCodecs.add(codec);@@ -475,7 +483,7 @@ export type ScreenShareEncoderVerificationAction =alternative: VideoCodec | null;};-export function getVideoPublishCodecDenial(codec: VideoCodec): VideoPublishCodecDenial | null {+function getVideoPublishCodecDenial(codec: VideoCodec): VideoPublishCodecDenial | null {if (!supportsVideoCodec(codec)) return 'sender-cannot-encode';if (getScreenShareCodecPolicyUnsupported(codec, buildScreenShareCodecPolicyContext())) return 'policy';if (runtimeEncodeFailureCodecs.has(codec)) return 'runtime-failed';@@ -488,7 +496,7 @@ export function isVideoCodecAllowedForPublish(codec: VideoCodec): boolean {return getVideoPublishCodecDenial(codec) === null;}-export function getAllowedVideoPublishCodecs(): ReadonlyArray<VideoCodec> {+function getAllowedVideoPublishCodecs(): ReadonlyArray<VideoCodec> {return LIVEKIT_SUPPORTED_CODECS.filter(isVideoCodecAllowedForPublish);}@@ -582,16 +590,3 @@ export function resolveScreenShareEncoderVerificationAction(}export type ScreenShareContentSource = 'app' | 'device' | 'display';--export function resetCachedCodecCapabilities(): void {- cachedCapabilities = null;- cachedReport = null;- cachedReportGpuKey = undefined;- cachedReportNativeHardwareEncoderKey = undefined;- cachedReportHardwareAccelerationDisabled = undefined;- cachedReportAv1OptIn = undefined;- cachedReportHevcOptIn = undefined;- runtimeEncodeFailureCodecs.clear();- observedSoftwareEncodeCodecs.clear();- resetNativeHardwareEncoderCapabilities();-}diff --git a/fluxer_app/src/features/voice/utils/ScreenShareCodecSelection.ts b/fluxer_app/src/features/voice/utils/ScreenShareCodecSelection.tsindex f320bfbc1..cf147019b 100644--- a/fluxer_app/src/features/voice/utils/ScreenShareCodecSelection.ts+++ b/fluxer_app/src/features/voice/utils/ScreenShareCodecSelection.ts@@ -83,7 +83,7 @@ export interface ScreenShareCodecProfile {h264SoftwareClamped?: boolean;}-export interface ScreenShareCodecRankingInput {+interface ScreenShareCodecRankingInput {profile: ScreenShareCodecProfile;encoderModeSetting: ScreenShareEncoderMode;pin: CodecPreference;@@ -109,14 +109,16 @@ export function rankScreenShareCodecs(input: ScreenShareCodecRankingInput): Screif (codec === 'h265') return pin === 'h265' || (input.encoderModeSetting !== 'software' && isHardware('h265'));return true;};- const preference =- input.profile.browser === 'firefox'- ? GECKO_CODEC_PREFERENCE- : h264Clamped- ? CLAMPED_H264_CODEC_PREFERENCE- : isHardware('h264')- ? CODEC_PREFERENCE- : SOFTWARE_H264_CODEC_PREFERENCE;+ let preference: ReadonlyArray<VideoCodec>;+ if (input.profile.browser === 'firefox') {+ preference = GECKO_CODEC_PREFERENCE;+ } else if (h264Clamped) {+ preference = CLAMPED_H264_CODEC_PREFERENCE;+ } else if (isHardware('h264')) {+ preference = CODEC_PREFERENCE;+ } else {+ preference = SOFTWARE_H264_CODEC_PREFERENCE;+ }const survivors = preference.filter(survives);const ranked =input.encoderModeSetting === 'software'diff --git a/fluxer_app/src/features/voice/utils/ScreenShareOptions.ts b/fluxer_app/src/features/voice/utils/ScreenShareOptions.tsindex c220254fd..0a01c6366 100644--- a/fluxer_app/src/features/voice/utils/ScreenShareOptions.ts+++ b/fluxer_app/src/features/voice/utils/ScreenShareOptions.ts@@ -191,6 +191,10 @@ export function buildScreenShareOptions(config: ScreenShareBuildConfig): BuiltSccursor: resolveScreenShareCursorCapture(config.preferredDisplaySurface),...(config.preferredDisplaySurface ? {displaySurface: config.preferredDisplaySurface} : {}),};+ let windowAudio: 'system' | 'window' | 'exclude' = 'exclude';+ if (config.includeAudio) {+ windowAudio = config.useBrowserAudioPicker ? 'system' : 'window';+ }return {captureOptions: {audio: config.includeAudio,@@ -199,7 +203,7 @@ export function buildScreenShareOptions(config: ScreenShareBuildConfig): BuiltScselfBrowserSurface: 'include',monitorTypeSurfaces: config.preferredDisplaySurface === 'window' ? 'exclude' : 'include',systemAudio: config.includeAudio && config.useBrowserAudioPicker ? 'include' : 'exclude',- windowAudio: config.includeAudio ? (config.useBrowserAudioPicker ? 'system' : 'window') : 'exclude',+ windowAudio,resolution: {width, height, frameRate: resolvedFrameRate},video,},diff --git a/fluxer_app/src/features/voice/utils/ScreenShareStartFlow.ts b/fluxer_app/src/features/voice/utils/ScreenShareStartFlow.tsindex cbf73b57b..871589941 100644--- a/fluxer_app/src/features/voice/utils/ScreenShareStartFlow.ts+++ b/fluxer_app/src/features/voice/utils/ScreenShareStartFlow.ts@@ -466,11 +466,12 @@ async function runConfiguredDisplayScreenShare(? await resolveAppShareAudioScope(ActiveScreenShareSource.getPendingWindowAudioScope()): null;const appShareAudioRoute = appShareAudioScope == null ? null : selectAppShareAudioRouteForScope(appShareAudioScope);- const linuxAudioSourceMode = requestedAppAudioOnLinux- ? appShareAudioRouteToSourceMode(appShareAudioRoute)- : electronApi.platform === 'linux' && (requestedDesktopAudio || requestedNativePickerAudioOnLinux)- ? VoiceSettings.getEffectiveScreenShareAudioSourceMode()- : null;+ let linuxAudioSourceMode: ReturnType<typeof appShareAudioRouteToSourceMode> = null;+ if (requestedAppAudioOnLinux) {+ linuxAudioSourceMode = appShareAudioRouteToSourceMode(appShareAudioRoute);+ } else if (electronApi.platform === 'linux' && (requestedDesktopAudio || requestedNativePickerAudioOnLinux)) {+ linuxAudioSourceMode = VoiceSettings.getEffectiveScreenShareAudioSourceMode();+ }if (requestedAppAudioOnLinux && appShareAudioRoute === 'window') {try {nativeAudioArmed = await armNativeAudioForNextCapture(sourceId ?? '');