Adds a "Screen sharing" section to Settings > Video with controls for: - Resolution (576p to 4K) - Framerate (5-60 fps slider) - Bitrate (0.5-15 Mbps slider) - Codec (VP8/VP9/H.264/AV1) Gated behind an "Advanced screen share settings" toggle. When enabled, settings are passed to LiveKit's setScreenShareEnabled as both capture constraints and publish options. When disabled, falls back to config.json media_quality defaults. Settings are persisted in localStorage via the existing Setting<T> system. The Slider component is extended with a tooltipFormatter prop for custom tooltip display. Inspired by pirosuki's advanced-screen-share-settings branch, but reimplemented cleanly: settings are read directly in LocalMember.ts (no signature changes), the existing Slider is extended (no component duplication), and proper form components are used throughout. Signed-off-by: Ryan Emmick <ryanemmick4@gmail.com>
180 lines
4.7 KiB
TypeScript
180 lines
4.7 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { logger } from "matrix-js-sdk/lib/logger";
|
|
import { BehaviorSubject } from "rxjs";
|
|
|
|
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
|
|
import { type Behavior } from "../state/Behavior";
|
|
import { useBehavior } from "../useBehavior";
|
|
|
|
export class Setting<T> {
|
|
public constructor(
|
|
key: string,
|
|
public readonly defaultValue: T,
|
|
) {
|
|
this.key = `matrix-setting-${key}`;
|
|
|
|
const storedValue = localStorage.getItem(this.key);
|
|
let initialValue = defaultValue;
|
|
if (storedValue !== null) {
|
|
try {
|
|
initialValue = JSON.parse(storedValue);
|
|
} catch (e) {
|
|
logger.warn(
|
|
`Invalid value stored for setting ${key}: ${storedValue}.`,
|
|
e,
|
|
);
|
|
}
|
|
}
|
|
|
|
this._value$ = new BehaviorSubject(initialValue);
|
|
this.value$ = this._value$;
|
|
this._lastUpdateReason$ = new BehaviorSubject<string | null>(null);
|
|
this.lastUpdateReason$ = this._lastUpdateReason$;
|
|
}
|
|
|
|
private readonly key: string;
|
|
|
|
private readonly _value$: BehaviorSubject<T>;
|
|
private readonly _lastUpdateReason$: BehaviorSubject<string | null>;
|
|
public readonly value$: Behavior<T>;
|
|
public readonly lastUpdateReason$: Behavior<string | null>;
|
|
|
|
public readonly setValue = (value: T, reason?: string): void => {
|
|
this._value$.next(value);
|
|
this._lastUpdateReason$.next(reason ?? null);
|
|
localStorage.setItem(this.key, JSON.stringify(value));
|
|
};
|
|
public readonly getValue = (): T => {
|
|
return this._value$.getValue();
|
|
};
|
|
}
|
|
|
|
/**
|
|
* React hook that returns a settings's current value and a setter.
|
|
*/
|
|
export function useSetting<T>(setting: Setting<T>): [T, (value: T) => void] {
|
|
return [useBehavior(setting.value$), setting.setValue];
|
|
}
|
|
|
|
// null = undecided
|
|
export const optInAnalytics = new Setting<boolean | null>(
|
|
"opt-in-analytics",
|
|
null,
|
|
);
|
|
// TODO: This setting can be disabled. Work out an approach to disableable
|
|
// settings thats works for Observables in addition to React.
|
|
export const useOptInAnalytics = (): [
|
|
boolean | null,
|
|
((value: boolean | null) => void) | null,
|
|
] => {
|
|
const setting = useSetting(optInAnalytics);
|
|
return PosthogAnalytics.instance.isEnabled() ? setting : [false, null];
|
|
};
|
|
|
|
export const developerMode = new Setting("developer-settings-tab", false);
|
|
|
|
export const duplicateTiles = new Setting("duplicate-tiles", 0);
|
|
|
|
export const debugTileLayout = new Setting("debug-tile-layout", false);
|
|
|
|
export const showConnectionStats = new Setting<boolean>(
|
|
"show-connection-stats",
|
|
false,
|
|
);
|
|
|
|
export const audioInput = new Setting<string | undefined>(
|
|
"audio-input",
|
|
undefined,
|
|
);
|
|
export const audioOutput = new Setting<string | undefined>(
|
|
"audio-output",
|
|
undefined,
|
|
);
|
|
export const videoInput = new Setting<string | undefined>(
|
|
"video-input",
|
|
undefined,
|
|
);
|
|
|
|
export const backgroundBlur = new Setting<boolean>("background-blur", false);
|
|
|
|
export const showHandRaisedTimer = new Setting<boolean>(
|
|
"hand-raised-show-timer",
|
|
false,
|
|
);
|
|
|
|
export const showReactions = new Setting<boolean>("reactions-show", true);
|
|
|
|
export const playReactionsSound = new Setting<boolean>(
|
|
"reactions-play-sound",
|
|
true,
|
|
);
|
|
|
|
export const soundEffectVolume = new Setting<number>(
|
|
"sound-effect-volume",
|
|
0.5,
|
|
);
|
|
|
|
export const muteAllAudio = new Setting<boolean>("mute-all-audio", false);
|
|
|
|
export const alwaysShowSelf = new Setting<boolean>("always-show-self", true);
|
|
|
|
export const alwaysShowIphoneEarpiece = new Setting<boolean>(
|
|
"always-show-iphone-earpiece",
|
|
false,
|
|
);
|
|
|
|
export enum MatrixRTCMode {
|
|
Legacy = "legacy",
|
|
Compatibility = "compatibility",
|
|
/** This implies using
|
|
* - sticky events
|
|
* - hashed RTC backend identity
|
|
* - the new endpoint for the jwt token on the local membership (remote memberships will always try the new jwt endpoint first -> then the legacy one)
|
|
* - use the hashed identity for the local membership
|
|
*/
|
|
Matrix_2_0 = "matrix_2_0",
|
|
}
|
|
|
|
export const matrixRTCMode = new Setting<MatrixRTCMode>(
|
|
"matrix-rtc-mode",
|
|
MatrixRTCMode.Legacy,
|
|
);
|
|
|
|
export const customLivekitUrl = new Setting<string | null>(
|
|
"custom-livekit-url",
|
|
null,
|
|
);
|
|
|
|
export type VideoCodec = "vp8" | "vp9" | "h264" | "av1";
|
|
|
|
export const advancedScreenShare = new Setting<boolean>(
|
|
"advanced-screen-share",
|
|
false,
|
|
);
|
|
|
|
export const screenShareResolution = new Setting<string>(
|
|
"screen-share-resolution",
|
|
"1920x1080",
|
|
);
|
|
|
|
export const screenShareFramerate = new Setting<number>(
|
|
"screen-share-framerate",
|
|
30,
|
|
);
|
|
|
|
export const screenShareBitrate = new Setting<number>(
|
|
"screen-share-bitrate",
|
|
5_000_000,
|
|
);
|
|
|
|
export const screenShareCodec = new Setting<VideoCodec>(
|
|
"screen-share-codec",
|
|
"vp9",
|
|
);
|