Add Docker deployment and fix crash in insecure (non-HTTPS) contexts

Adds a multi-stage Dockerfile (Rust connector + gateway + web build) and
docker-compose.yml for running the whole stack as a single container behind
a reverse proxy; the gateway now serves the built web app and the WebSocket
endpoint (/ws) from one port, and the frontend derives its gateway URL from
window.location in production instead of a hardcoded localhost address.

Also guards all navigator.mediaDevices usage against being undefined, which
happens when the page is loaded over plain HTTP on a non-localhost address
(not a secure context) - previously this crashed the whole React app on
mount instead of just disabling the affected voice features.
This commit is contained in:
Moepchi committed 2026-07-29 18:45:23 +02:00
1 parent 3715a52de6
commit c48534dbc4
8 files changed
+129 -8

No files matched your search

+6 -1
View File
@@ -9,7 +9,12 @@ import {
pickAudioOutputDevice,
} from "./voice";
const GATEWAY_URL = "ws://localhost:8080";
// In dev, the gateway runs standalone on its own port. In production it's
// served from the same origin/port as the web app (single container behind a
// reverse proxy), so derive the WebSocket URL from the current location.
const GATEWAY_URL = import.meta.env.DEV
? "ws://localhost:8080"
: `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/ws`;
const LAST_HOST_KEY = "ts-web-client:last-host";
const LAST_NICKNAME_KEY = "ts-web-client:last-nickname";
+6
View File
@@ -55,6 +55,9 @@ export class MicCapture {
}
async start(): Promise<void> {
if (!navigator.mediaDevices) {
throw new Error("Microphone access requires HTTPS (or localhost) - the site is not a secure context.");
}
this.stream = await navigator.mediaDevices.getUserMedia({
audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true },
});
@@ -117,6 +120,7 @@ export class MicCapture {
/** Output ("audiooutput") devices available for playback, e.g. for a device picker. */
export async function listAudioOutputDevices(): Promise<MediaDeviceInfo[]> {
if (!navigator.mediaDevices) return [];
const devices = await navigator.mediaDevices.enumerateDevices();
return devices.filter((d) => d.kind === "audiooutput");
}
@@ -125,6 +129,7 @@ type MediaDevicesWithPicker = MediaDevices & { selectAudioOutput?: () => Promise
/** Whether the browser supports the native OS output-device picker (Chrome/Edge 105+). */
export function hasNativeOutputPicker(): boolean {
if (!navigator.mediaDevices) return false;
return typeof (navigator.mediaDevices as MediaDevicesWithPicker).selectAudioOutput === "function";
}
@@ -135,6 +140,7 @@ export function hasNativeOutputPicker(): boolean {
* the user to pick one, each call - no persistent listing to keep in sync.
*/
export async function pickAudioOutputDevice(): Promise<MediaDeviceInfo | null> {
if (!navigator.mediaDevices) return null;
const md = navigator.mediaDevices as MediaDevicesWithPicker;
if (typeof md.selectAudioOutput !== "function") return null;
return md.selectAudioOutput();