/ concept-collection / commonroom
Sign in
concept-collection / commonroom
commonroom / src / p2p / settings.ts
39 lines · 1.7 KBBlameHistoryRaw
1// Shared room settings. Everyone in the room sees and controls ONE settings
2// object; anyone can change any setting and it applies to the whole room.
3// Changes sync over the per-peer control data channels with per-key
4// last-writer-wins (see network.ts).
5//
6// To add a future setting: extend RoomSettings, DEFAULT_SETTINGS, and
7// SETTING_VALIDATORS, then handle its side effect in Network.settingChanged.
9export const VIDEO_QUALITIES = ['low', 'medium', 'high', 'auto'] as const
10export type VideoQuality = (typeof VIDEO_QUALITIES)[number]
12export interface RoomSettings {
13 videoQuality: VideoQuality
16export const DEFAULT_SETTINGS: RoomSettings = {videoQuality: 'medium'}
18/** Encoder caps for each preset, applied by EACH participant to every one of
19 * its outgoing video senders (the setting is room-wide and symmetric).
20 * 'auto' clears all caps and leaves adaptation entirely to the browser's
21 * congestion control; the others are proactive ceilings — important in a
22 * mesh, where upload cost multiplies by the number of other participants. */
23export const QUALITY_PARAMS: Record<
24 VideoQuality,
25 {maxBitrate?: number; scaleResolutionDownBy?: number; maxFramerate?: number}
26> = {
27 auto: {},
28 high: {maxBitrate: 2_500_000, maxFramerate: 30},
29 medium: {maxBitrate: 800_000, scaleResolutionDownBy: 2, maxFramerate: 24},
30 low: {maxBitrate: 200_000, scaleResolutionDownBy: 4, maxFramerate: 15}
33/** Settings arrive over the network, so every value is validated before use. */
34export const SETTING_VALIDATORS: {
35 [K in keyof RoomSettings]: (v: unknown) => v is RoomSettings[K]
36} = {
37 videoQuality: (v): v is VideoQuality =>
38 (VIDEO_QUALITIES as readonly unknown[]).includes(v)
moveopenescclose