All files / app-play/src recording-format-choice.ts

100% Statements 10/10
80% Branches 4/5
100% Functions 10/10
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                          159x         23x 121x 13x             1x 7x           43x         4x    
import {
  DEFAULT_RECORDING_FORMAT,
  RECORDING_FORMATS,
  RECORDING_QUALITIES,
  describeRecordingFormat,
  describeRecordingQuality,
  type RecordingFormat,
  type RecordingQuality,
} from '@be-music/player-browser/recording';
import { optionDefault } from './option-defaults.ts';
 
/** A recording format as one string, for the Options dialog value and `localStorage`: `mp4/avc`, `webm/vp9`. */
export function recordingFormatKey(format: RecordingFormat): string {
  return `${format.container}/${format.videoCodec}`;
}
 
/** The format a key names, or the default (MP4 · H.264) for anything the recorder does not offer. */
export function parseRecordingFormatKey(key: string | null | undefined): RecordingFormat {
  return (
    RECORDING_FORMATS.find((format) => recordingFormatKey(format) === key) ??
    RECORDING_FORMATS.find((format) => recordingFormatKey(format) === optionDefault<string>('recordingFormat')) ??
    DEFAULT_RECORDING_FORMAT
  );
}
 
/** The Options dialog's "Video format" choices: label → key, MP4 first. */
export function recordingFormatOptions(): Record<string, string> {
  return Object.fromEntries(
    RECORDING_FORMATS.map((format) => [describeRecordingFormat(format), recordingFormatKey(format)]),
  );
}
 
/** The quality a stored key names, or the default (Standard) for anything else. */
export function parseRecordingQuality(key: string | null | undefined): RecordingQuality {
  return RECORDING_QUALITIES.find((quality) => quality === key) ?? optionDefault('recordingQuality');
}
 
/** The Options dialog's "Video quality" choices: label → key, smallest file first. */
export function recordingQualityOptions(): Record<string, RecordingQuality> {
  return Object.fromEntries(RECORDING_QUALITIES.map((quality) => [describeRecordingQuality(quality), quality]));
}