diff --git a/web/src/App.css b/web/src/App.css index 56213eb..073e184 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -541,6 +541,20 @@ background: color-mix(in srgb, var(--log-error) 30%, var(--button-bg-1)) !important; } +.ts-recording-on { + background: color-mix(in srgb, var(--log-error) 35%, var(--button-bg-1)) !important; + animation: ts-recording-pulse 1.4s ease-in-out infinite; +} + +@keyframes ts-recording-pulse { + 0%, 100% { + opacity: 1; + } + 50% { + opacity: 0.55; + } +} + .ts-client-away-message { color: var(--text-muted); font-style: italic; diff --git a/web/src/App.tsx b/web/src/App.tsx index a06fc30..b010a4d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -2049,6 +2049,7 @@ function AppInner() { const nicknameBackdrop = useBackdropDismiss(() => setChangeNicknameOpen(false)); const [contacts, setContacts] = useState(() => loadContacts()); const [contactsOpen, setContactsOpen] = useState(false); + const [recording, setRecording] = useState(false); const whisperLogIdRef = useRef(0); const prevWhisperTargetsRef = useRef<{ channels: Set; clients: Set } | null>(null); @@ -2067,6 +2068,9 @@ function AppInner() { const audioContextRef = useRef(null); const audioPlayerRef = useRef(null); const micCaptureRef = useRef(null); + const recorderRef = useRef(null); + const recordDestRef = useRef(null); + const recordedChunksRef = useRef([]); const activeTabRef = useRef("channel"); const hasConnectedRef = useRef(false); // Set when a "disconnected" event is received, so the socket's onclose @@ -2266,6 +2270,7 @@ function AppInner() { previousSocket.close(); } stopMic(); + stopRecording(); audioPlayerRef.current?.dispose(); audioPlayerRef.current = null; audioContextRef.current?.close(); @@ -2450,6 +2455,7 @@ function AppInner() { setWhisperLog([]); prevWhisperTargetsRef.current = null; stopMic(); + stopRecording(); appendLog({ text: `Disconnected: ${data.reason}`, kind: "info" }); logClient("info", "Connection", `Disconnected: ${data.reason}`); if (wasConnected) void playSound("disconnect"); @@ -2484,6 +2490,7 @@ function AppInner() { cleanDisconnectRef.current = false; setConnected(false); stopMic(); + stopRecording(); audioPlayerRef.current?.dispose(); audioPlayerRef.current = null; audioContextRef.current?.close(); @@ -2761,6 +2768,7 @@ function AppInner() { setMicOn(true); refreshOutputDevices(); refreshInputDevices(); + connectMicToRecorder(); } catch (error) { appendLog({ text: `Microphone error: ${(error as Error).message}`, kind: "error" }); } @@ -2822,6 +2830,56 @@ function AppInner() { socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current })); }; + // Connects the current mic (if any) into the active recording, so a device + // switch or a mic (re)start mid-recording doesn't silently drop it from the mix. + const connectMicToRecorder = () => { + const dest = recordDestRef.current; + const source = micCaptureRef.current?.getSourceNode(); + if (dest && source) source.connect(dest); + }; + + const startRecording = () => { + if (recorderRef.current) return; + const audioContext = ensureAudioContext(); + const dest = audioContext.createMediaStreamDestination(); + recordDestRef.current = dest; + audioPlayerRef.current?.getInputNode().connect(dest); + connectMicToRecorder(); + + recordedChunksRef.current = []; + const recorder = new MediaRecorder(dest.stream); + recorder.ondataavailable = (event) => { + if (event.data.size > 0) recordedChunksRef.current.push(event.data); + }; + recorder.onstop = () => { + const blob = new Blob(recordedChunksRef.current, { type: recorder.mimeType || "audio/webm" }); + recordedChunksRef.current = []; + const extension = blob.type.includes("ogg") ? "ogg" : "webm"; + const safeServerName = (serverName || "session").replace(/[\\/:*?"<>|]+/g, "_").trim() || "session"; + const filename = `webspeak3-${safeServerName}-${new Date().toISOString().replace(/[:.]/g, "-")}.${extension}`; + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = filename; + document.body.appendChild(a); + a.click(); + a.remove(); + URL.revokeObjectURL(url); + logClient("info", "Recording", `Saved recording as ${filename}`); + }; + recorder.start(); + recorderRef.current = recorder; + setRecording(true); + logClient("info", "Recording", "Started local recording"); + }; + + const stopRecording = () => { + recorderRef.current?.stop(); + recorderRef.current = null; + recordDestRef.current = null; + setRecording(false); + }; + const handleSetNickname = (newNickname: string) => { socketRef.current?.send(JSON.stringify({ type: "setNickname", nickname: newNickname })); }; @@ -3230,17 +3288,34 @@ function AppInner() { ))}
- {[ - { icon: "🔴", label: t("menu.extras.startRecording"), shortcut: "Strg+Umschalt+R" }, - { icon: "🔴", label: t("menu.extras.startMultitrackRecording") }, - { icon: "âšī¸", label: t("menu.extras.stopRecording"), shortcut: "Strg+Umschalt+T" }, - ].map((item) => ( - - ))} + + +
+ )}