From 1caf57ff0097234dcb42d039ff6793707be7d133 Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 7 Oct 2025 11:06:03 +0300 Subject: [PATCH] Cleanup: PR Comments --- ui/src/routes/devices.$id.tsx | 12 +++++------- ui/src/ui.config.ts | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ui/src/routes/devices.$id.tsx b/ui/src/routes/devices.$id.tsx index ef9e0eb3..9fa05af9 100644 --- a/ui/src/routes/devices.$id.tsx +++ b/ui/src/routes/devices.$id.tsx @@ -15,7 +15,7 @@ import { FocusTrap } from "focus-trap-react"; import { motion, AnimatePresence } from "framer-motion"; import useWebSocket from "react-use-websocket"; -import { CLOUD_API, DEVICE_API } from "@/ui.config"; +import { CLOUD_API, DEVICE_API, OPUS_STEREO_PARAMS } from "@/ui.config"; import api from "@/api"; import { checkAuth, isInCloud, isOnDevice } from "@/main"; import { cx } from "@/cva.config"; @@ -191,19 +191,18 @@ export default function KvmIdRoute() { console.warn("[SDP] Opus 48kHz stereo not found in answer - stereo may not work"); } else { const pt = opusMatch[1]; - const stereoParams = 'stereo=1;sprop-stereo=1;maxaveragebitrate=128000;usedtx=1;useinbandfec=1'; const fmtpRegex = new RegExp(`a=fmtp:${pt}\\s+(.+)`, 'i'); const fmtpMatch = remoteDescription.sdp.match(fmtpRegex); if (fmtpMatch && !fmtpMatch[1].includes('stereo=')) { remoteDescription.sdp = remoteDescription.sdp.replace( fmtpRegex, - `a=fmtp:${pt} ${fmtpMatch[1]};${stereoParams}` + `a=fmtp:${pt} ${fmtpMatch[1]};${OPUS_STEREO_PARAMS}` ); } else if (!fmtpMatch) { remoteDescription.sdp = remoteDescription.sdp.replace( opusMatch[0], - `${opusMatch[0]}\r\na=fmtp:${pt} ${stereoParams}` + `${opusMatch[0]}\r\na=fmtp:${pt} ${OPUS_STEREO_PARAMS}` ); } } @@ -463,18 +462,17 @@ export default function KvmIdRoute() { console.warn("[SDP] Opus 48kHz stereo not found in offer - stereo may not work"); } else { const pt = opusMatch[1]; - const stereoParams = 'stereo=1;sprop-stereo=1;maxaveragebitrate=128000;usedtx=1;useinbandfec=1'; const fmtpRegex = new RegExp(`a=fmtp:${pt}\\s+(.+)`, 'i'); const fmtpMatch = offer.sdp.match(fmtpRegex); if (fmtpMatch) { // Modify existing fmtp line if (!fmtpMatch[1].includes('stereo=')) { - offer.sdp = offer.sdp.replace(fmtpRegex, `a=fmtp:${pt} ${fmtpMatch[1]};${stereoParams}`); + offer.sdp = offer.sdp.replace(fmtpRegex, `a=fmtp:${pt} ${fmtpMatch[1]};${OPUS_STEREO_PARAMS}`); } } else { // Add new fmtp line after rtpmap - offer.sdp = offer.sdp.replace(opusMatch[0], `${opusMatch[0]}\r\na=fmtp:${pt} ${stereoParams}`); + offer.sdp = offer.sdp.replace(opusMatch[0], `${opusMatch[0]}\r\na=fmtp:${pt} ${OPUS_STEREO_PARAMS}`); } } } diff --git a/ui/src/ui.config.ts b/ui/src/ui.config.ts index b76dd7c4..ff79ee4f 100644 --- a/ui/src/ui.config.ts +++ b/ui/src/ui.config.ts @@ -2,3 +2,6 @@ export const CLOUD_API = import.meta.env.VITE_CLOUD_API; // In device mode, an empty string uses the current hostname (the JetKVM device's IP) as the API endpoint export const DEVICE_API = ""; + +// Opus codec parameters for stereo audio with error correction +export const OPUS_STEREO_PARAMS = 'stereo=1;sprop-stereo=1;maxaveragebitrate=128000;usedtx=1;useinbandfec=1';