feat(frontend): scaffold PWA with LiveKit join flow

Vite + React + TS + Tailwind v4, installable PWA. Join-pod UI that fetches a
LiveKit token from the backend, connects to the pod room, and publishes screen
+ mic so PodMan can watch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Kartikeya
2026-06-27 14:17:08 -07:00
parent 6559ad3944
commit ca0ca37adc
10 changed files with 214 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { Room, RoomEvent } from 'livekit-client';
const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:8787';
/** Ask the backend for a LiveKit token to join a pod. */
export async function fetchPodToken(
podId: string,
identity: string,
name: string,
): Promise<{ token: string; url: string }> {
const res = await fetch(`${BACKEND_URL}/pods/${encodeURIComponent(podId)}/token`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ identity, name }),
});
if (!res.ok) throw new Error(`token request failed: ${res.status}`);
return res.json();
}
/**
* Join a pod: connect to the LiveKit room and publish screen + mic so PodMan
* can watch. Returns the connected Room.
*/
export async function joinPod(podId: string, identity: string, name: string): Promise<Room> {
const { token, url } = await fetchPodToken(podId, identity, name);
const room = new Room({ adaptiveStream: true, dynacast: true });
room.on(RoomEvent.Disconnected, () => console.log('[podman] disconnected'));
await room.connect(url, token);
const screen = await navigator.mediaDevices.getDisplayMedia({ video: true });
for (const track of screen.getTracks()) {
await room.localParticipant.publishTrack(track);
}
await room.localParticipant.setMicrophoneEnabled(true);
return room;
}