mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
refactor(voice): pin screen share to a fixed 7 Mbps bitrate (#2381)
This commit is contained in:
1 parent
501adff13d
commit
7263b21a06
45 files changed
+1253
-1857
No files matched your search
+1
-69
@@ -14,7 +14,7 @@ import styles from '@app/features/user/components/modals/tabs/AdvancedSettingsTa
|
||||
import {CompactComboboxRow} from '@app/features/user/components/modals/tabs/components/CompactComboboxRow';
|
||||
import PrivacyPreferences from '@app/features/user/state/PrivacyPreferences';
|
||||
import * as VoiceSettingsCommands from '@app/features/voice/commands/VoiceSettingsCommands';
|
||||
import VoiceSettings, {DEFAULT_SCREEN_SHARE_MAX_BITRATE_MBPS} from '@app/features/voice/state/VoiceSettings';
|
||||
import VoiceSettings from '@app/features/voice/state/VoiceSettings';
|
||||
import type {
|
||||
CodecPreference,
|
||||
ScreenShareBackupCodecMode,
|
||||
@@ -157,23 +157,10 @@ const CONTENT_HINT_TEXT_DESCRIPTOR = msg({
|
||||
message: 'Text',
|
||||
comment: 'Option label for a WebRTC content hint select.',
|
||||
});
|
||||
const MAX_BITRATE_DESCRIPTOR = msg({
|
||||
message: 'Maximum screen share bitrate',
|
||||
comment: 'Label for an advanced screen-share bitrate select.',
|
||||
});
|
||||
const MAX_BITRATE_DESCRIPTION_DESCRIPTOR = msg({
|
||||
message: 'Upper bitrate cap before WebRTC adapts to the network.',
|
||||
comment: 'Description for the maximum screen share bitrate select. Keep WebRTC literal.',
|
||||
});
|
||||
const CONFIGURE_DESCRIPTOR = msg({
|
||||
message: 'Configure',
|
||||
comment: 'Button label that opens a dedicated advanced settings modal for configuring screen-share encoder controls.',
|
||||
});
|
||||
const MBPS_DESCRIPTOR = msg({
|
||||
message: '{megabits} Mbps',
|
||||
comment: 'Screen share bitrate option label. Mbps means megabits per second.',
|
||||
});
|
||||
|
||||
const DECODE_CODEC_CAP_DESCRIPTOR = msg({
|
||||
message: 'Emulate decode codec (testing)',
|
||||
comment: 'Label for an advanced select that caps the best video codec this client advertises it can decode.',
|
||||
@@ -183,38 +170,6 @@ const DECODE_CODEC_CAP_AUTO_DESCRIPTOR = msg({
|
||||
comment: 'Option label for the emulated decode codec select. Means advertise true decode support.',
|
||||
});
|
||||
|
||||
const SCREEN_SHARE_MAX_BITRATE_OPTIONS = [1, 5, 10, 15, 25, 50] as const;
|
||||
|
||||
const getNearestNumericOptionValue = <V extends number>(
|
||||
value: number,
|
||||
options: ReadonlyArray<ComboboxOption<V>>,
|
||||
): V | undefined => {
|
||||
let nearestOption: ComboboxOption<V> | undefined;
|
||||
let nearestDistance = Number.POSITIVE_INFINITY;
|
||||
for (const option of options) {
|
||||
const distance = Math.abs(option.value - value);
|
||||
if (distance < nearestDistance) {
|
||||
nearestDistance = distance;
|
||||
nearestOption = option;
|
||||
}
|
||||
}
|
||||
return nearestOption?.value;
|
||||
};
|
||||
|
||||
const resolveScreenShareBitrateInput = (
|
||||
inputValue: string,
|
||||
options: ReadonlyArray<ComboboxOption<number>>,
|
||||
): number | undefined => {
|
||||
const normalized = inputValue.trim().toLowerCase();
|
||||
if (!normalized) return undefined;
|
||||
const numericMatch = normalized.match(/([0-9]+(?:\.[0-9]+)?)/);
|
||||
if (!numericMatch) return undefined;
|
||||
const parsedValue = Number(numericMatch[1]);
|
||||
if (!Number.isFinite(parsedValue)) return undefined;
|
||||
const valueInMbps = normalized.includes('kbps') ? parsedValue / 1000 : parsedValue;
|
||||
return getNearestNumericOptionValue(valueInMbps, options);
|
||||
};
|
||||
|
||||
const PREFERRED_SCREEN_SHARE_CODEC_DESCRIPTOR = msg({
|
||||
message: 'Preferred screen share codec',
|
||||
comment: 'Accessible label for the advanced screen-share codec preference select.',
|
||||
@@ -415,18 +370,6 @@ const ScreenShareEncoderControlsContent = observer(() => {
|
||||
{value: 'detail', label: i18n._(CONTENT_HINT_DETAIL_DESCRIPTOR)},
|
||||
{value: 'text', label: i18n._(CONTENT_HINT_TEXT_DESCRIPTOR)},
|
||||
];
|
||||
const bitrateOptions: ReadonlyArray<ComboboxOption<number>> = SCREEN_SHARE_MAX_BITRATE_OPTIONS.map((megabits) => ({
|
||||
value: megabits,
|
||||
label: i18n._(MBPS_DESCRIPTOR, {megabits}),
|
||||
}));
|
||||
const storedMaxBitrate = VoiceSettings.screenShareMaxBitrateMbps;
|
||||
const selectedMaxBitrate =
|
||||
getNearestNumericOptionValue(storedMaxBitrate, bitrateOptions) ?? DEFAULT_SCREEN_SHARE_MAX_BITRATE_MBPS;
|
||||
useEffect(() => {
|
||||
if (storedMaxBitrate !== selectedMaxBitrate) {
|
||||
VoiceSettingsCommands.update({screenShareMaxBitrateMbps: selectedMaxBitrate});
|
||||
}
|
||||
}, [selectedMaxBitrate, storedMaxBitrate]);
|
||||
return (
|
||||
<div className={styles.controlStackCompact} data-flx="user.advanced-settings-tab.screen-share-encoder-controls">
|
||||
<CompactComboboxRow<ScreenShareEncoderMode>
|
||||
@@ -484,17 +427,6 @@ const ScreenShareEncoderControlsContent = observer(() => {
|
||||
dataFlx="user.advanced-settings-tab.select.screen-share-content-hint"
|
||||
data-flx="user.advanced-settings-tab.advanced-video-controls.screen-share-encoder-controls-content.compact-combobox-row.update--5"
|
||||
/>
|
||||
<CompactComboboxRow<number>
|
||||
label={i18n._(MAX_BITRATE_DESCRIPTOR)}
|
||||
description={i18n._(MAX_BITRATE_DESCRIPTION_DESCRIPTOR)}
|
||||
value={selectedMaxBitrate}
|
||||
options={bitrateOptions}
|
||||
onChange={(value) => VoiceSettingsCommands.update({screenShareMaxBitrateMbps: value})}
|
||||
autoSelectValueFromInput={resolveScreenShareBitrateInput}
|
||||
controlWidth="small"
|
||||
dataFlx="user.advanced-settings-tab.select.screen-share-max-bitrate"
|
||||
data-flx="user.advanced-settings-tab.advanced-video-controls.screen-share-encoder-controls-content.compact-combobox-row.update--6"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user