cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

ci/pipeline-ergonomics
goq / portal / audio-ui.mjs
audio-ui.mjs 1.7K
1import { BoundedAudioMessageTracker } from './audio-ring.mjs';23export function newAudioSession({ muted = false } = {}) {4 return {5 expectedGeneration: null,6 acceptsNativeEvents: false,7 pendingTerminalStates: [],8 failed: false,9 failureDetail: null,10 stopRequested: false,11 channel: null,12 context: null,13 decoder: null,14 workletNode: null,15 available: false,16 muted,17 state: 'unavailable',18 stateDetail: 'not connected',19 packetsReceived: 0,20 decoderDropped: 0,21 bufferedFrames: 0,22 underflows: 0,23 underflowDurationMicros: 0,24 silentDurationMicros: 0,25 transportDropped: 0,26 frontendDropped: 0,27 workletDroppedFrames: 0,28 workletRecoveryDiscardedFrames: 0,29 audioTimeline: null,30 avSyncEpoch: 0,31 messageTracker: new BoundedAudioMessageTracker(),32 };33}3435export function audioButtonPresentation({ available, muted, state, detail }) {36 const normalizedState = typeof state === 'string' && state.length > 0 ? state : 'unavailable';37 const normalizedDetail = typeof detail === 'string' && detail.length > 038 ? detail39 : normalizedState;4041 let label;42 if (!available || muted || normalizedState === 'error' || normalizedState === 'unavailable') {43 label = 'vol off';44 } else if (normalizedState === 'playing') {45 label = 'vol on';46 } else {47 label = 'vol ...';48 }4950 const action = available51 ? muted ? 'Unmute audio' : 'Mute audio'52 : 'Audio unavailable';53 const audibleState = muted && available ? 'muted' : normalizedState;54 return {55 label,56 ariaLabel: `${action}. Audio ${audibleState}. ${normalizedDetail}`,57 title: `Audio ${audibleState}: ${normalizedDetail}`,58 };59}