Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"lucide-react": "^1.61.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"socket.io-client": "^4.8.0"
"socket.io-client": "^4.8.0",
"uqr": "^0.1.3"
},
"devDependencies": {
"@types/react": "^19.0.0",
Expand Down
24 changes: 23 additions & 1 deletion apps/client/src/ActiveSpeakers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@ import { useEffect, useRef, useState } from "react";
import { activeSpeakerIds } from "@watchparty/shared";
import { Avatar } from "./Avatar.js";
import type { AudioLevels } from "./AudioLevels.js";

export interface Speaker { id: string; name: string; speaking: boolean }

function SpeakerWave({ id, levels, speaking }: { id: string; levels: AudioLevels; speaking: boolean }) {
const ref = useRef<HTMLElement>(null);
useEffect(() => levels.subscribe(id, (value) => {
const node = ref.current;
if (!node) return;
const level = speaking ? value : 0;
node.style.setProperty("--wave-a", String(0.35 + level * 0.75));
node.style.setProperty("--wave-b", String(0.45 + level * 1.15));
node.style.setProperty("--wave-c", String(0.3 + level * 0.9));
}), [id, levels, speaking]);
useEffect(() => {
if (!speaking && ref.current) {
ref.current.style.setProperty("--wave-a", "0.35");
ref.current.style.setProperty("--wave-b", "0.45");
ref.current.style.setProperty("--wave-c", "0.3");
}
}, [speaking]);
return <i ref={ref} className="speaker-wave" aria-hidden="true"><b /><b /><b /></i>;
}

export function ActiveSpeakers({ people, levels }: { people: Speaker[]; levels: AudioLevels }) {
const [visible, setVisible] = useState<string[]>([]);
const shown = useRef<string[]>([]);
Expand All @@ -27,6 +49,6 @@ export function ActiveSpeakers({ people, levels }: { people: Speaker[]; levels:
useEffect(() => () => { for (const timer of timers.current.values()) clearTimeout(timer); timers.current.clear(); }, []);
return <div className="active-speakers" aria-label="Speaking participants">{visible.map((id) => {
const person = people.find((value) => value.id === id);
return person && <div key={id} className={`active-speaker ${person.speaking ? "" : "speaker-release"}`}><Avatar {...person} levels={levels} /><span>{person.name}</span><i className="speaker-wave" aria-hidden="true"><b /><b /><b /></i></div>;
return person && <div key={id} className={`active-speaker ${person.speaking ? "is-speaking" : "speaker-release"}`}><Avatar {...person} levels={levels} /><span>{person.name}</span><SpeakerWave id={id} levels={levels} speaking={person.speaking} /></div>;
})}</div>;
}
8 changes: 7 additions & 1 deletion apps/client/src/ChatPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SmilePlus,
} from "lucide-react";
import { Button, IconButton } from "./ui/index.js";
import { SoloInviteCard } from "./SoloInviteCard.js";
const GifPicker = lazy(() =>
import("./GifPicker.js").then((module) => ({ default: module.GifPicker })),
);
Expand Down Expand Up @@ -39,10 +40,14 @@ export function ChatPanel({
visible,
selfId,
onCopyInvite,
participantCount,
roomCode,
}: {
visible: boolean;
selfId?: string;
onCopyInvite: () => void;
participantCount: number;
roomCode: string;
messages: Message[];
connected: boolean;
inputRef: React.RefObject<HTMLTextAreaElement | null>;
Expand Down Expand Up @@ -184,6 +189,7 @@ export function ChatPanel({
}
}}
>
<SoloInviteCard roomCode={roomCode} visible={participantCount === 1} />
{!messages.length && (
<div className="empty-chat">
<span className="empty-chat-icon">
Expand Down Expand Up @@ -449,7 +455,7 @@ const ChatMessageRow = memo(
<strong>{message.name}</strong>
<time dateTime={new Date(message.at).toISOString()}>
{new Date(message.at).toLocaleTimeString([], {
hour: "2-digit",
hour: "numeric",
minute: "2-digit",
})}
</time>
Expand Down
7 changes: 4 additions & 3 deletions apps/client/src/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { clockSync, syncStore, subscribeResync } from "./lib/syncRuntime.js";
import { ActiveSpeakers, type Speaker } from "./ActiveSpeakers.js";
import type { AudioLevels } from "./AudioLevels.js";
import { useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState, type CSSProperties } from "react";
import { ReactionOverlay } from "./ReactionOverlay.js";
import { useDucking } from "./useDucking.js";
import type { VisibleReaction } from "./useReactions.js";
Expand Down Expand Up @@ -692,11 +692,11 @@ export function Player({
<>
<IconButton
className="icon-button"
aria-label={muted ? "Unmute" : "Mute"}
aria-label={muted || volume.baseVolume <= 0.001 ? "Unmute" : "Mute"}
onClick={toggleMute}
disabled={!media || !ready}
>
{muted ? (
{muted || volume.baseVolume <= 0.001 ? (
<VolumeX aria-hidden="true" />
) : (
<Volume2 aria-hidden="true" />
Expand All @@ -710,6 +710,7 @@ export function Player({
max="1"
step="0.01"
value={volume.baseVolume}
style={{ "--volume": `${Math.round(volume.baseVolume * 100)}%` } as CSSProperties}
onChange={(event) => volume.choose(Number(event.target.value))}
disabled={!media || !ready}
/>
Expand Down
32 changes: 26 additions & 6 deletions apps/client/src/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { lazy, Suspense, useEffect, useRef, useState } from "react";
import {
Check,
Copy,
Headphones,
Keyboard,
Link2,
LogOut,
Expand Down Expand Up @@ -202,6 +203,11 @@ export default function RoomView({
: localVoice.muted
? "Unmute microphone"
: "Mute microphone";
const micText = !localVoice.joined
? "Join voice"
: localVoice.muted
? "Muted"
: "Mic on";
const sourceForm = (
<form
className="media-form"
Expand Down Expand Up @@ -289,6 +295,8 @@ export default function RoomView({
<IconButton
ref={keysButton}
aria-label="Keyboard shortcuts"
data-tooltip="Keyboard shortcuts"
title="Keyboard shortcuts"
aria-expanded={popup === "keys"}
onClick={() => setPopup(popup === "keys" ? null : "keys")}
>
Expand Down Expand Up @@ -326,6 +334,8 @@ export default function RoomView({
<IconButton
ref={settingsButton}
aria-label="Audio settings"
data-tooltip="Settings"
title="Settings"
aria-expanded={popup === "settings"}
onClick={() => setPopup(popup === "settings" ? null : "settings")}
>
Expand Down Expand Up @@ -372,22 +382,29 @@ export default function RoomView({
</Popover>
)}
</div>
<IconButton
className={`mic-button ${localVoice.speaking ? "is-speaking" : ""}`}
<Button
className={`voice-pill ${localVoice.speaking ? "is-speaking" : ""} ${localVoice.joined && !localVoice.muted ? "is-live" : ""}`}
variant="ghost"
aria-label={micLabel}
aria-pressed={localVoice.joined && !localVoice.muted}
disabled={!connected || voice?.busy}
onClick={() => mic(true)}
>
{localVoice.joined && !localVoice.muted ? (
<Mic aria-hidden="true" />
) : (
{!localVoice.joined ? (
<Headphones aria-hidden="true" />
) : localVoice.muted ? (
<MicOff aria-hidden="true" />
) : (
<Mic aria-hidden="true" />
)}
</IconButton>
<span>{micText}</span>
{localVoice.joined && !localVoice.muted && <i className="voice-live-dot" aria-hidden="true" />}
</Button>
<IconButton
className="leave-button"
aria-label="Leave room"
data-tooltip="Leave room"
title="Leave room"
onClick={() => {
voiceRef.current?.stop();
leave();
Expand Down Expand Up @@ -524,6 +541,8 @@ export default function RoomView({
visible={tab === "chat" && !collapsed}
selfId={socket.id}
onCopyInvite={() => void copy()}
participantCount={room.participants.length}
roomCode={room.code}
/>
</div>
</aside>
Expand All @@ -533,6 +552,7 @@ export default function RoomView({
connected={connected}
status={status}
phase={metrics.state}
host={host}
debug={new URLSearchParams(location.search).get("debug") === "1"}
onSource={host ? openSource : undefined}
sourceOpen={sourceOpen && host}
Expand Down
62 changes: 62 additions & 0 deletions apps/client/src/SoloInviteCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useEffect, useState } from "react";
import { Check, Copy, QrCode, X } from "lucide-react";
import { Button, IconButton } from "./ui/index.js";

export function SoloInviteCard({ roomCode, visible }: { roomCode: string; visible: boolean }) {
const [copied, setCopied] = useState(false);
const [qrOpen, setQrOpen] = useState(false);
const [qrSvg, setQrSvg] = useState("");
const inviteUrl = `${location.origin}/room/${roomCode}`;

useEffect(() => {
if (!visible) setQrOpen(false);
}, [visible]);

useEffect(() => {
if (!qrOpen || qrSvg) return;
let cancelled = false;
void import("uqr").then(({ renderSVG }) => {
if (!cancelled) setQrSvg(renderSVG(inviteUrl, { border: 2 }));
}).catch(() => {
if (!cancelled) setQrSvg("");
});
return () => { cancelled = true; };
}, [inviteUrl, qrOpen, qrSvg]);

async function copyInvite() {
try {
await navigator.clipboard.writeText(inviteUrl);
setCopied(true);
window.setTimeout(() => setCopied(false), 1500);
} catch {
setCopied(false);
}
}

return (
<aside className={`solo-invite-card ${visible ? "" : "is-hidden"}`} aria-hidden={!visible}>
<div className="solo-invite-copy">
<strong>You’re the only one here</strong>
<span>Invite someone from another device.</span>
</div>
<code>{roomCode}</code>
<div className="solo-invite-actions">
<Button variant="secondary" onClick={() => void copyInvite()} disabled={!visible}>
{copied ? <Check aria-hidden="true" /> : <Copy aria-hidden="true" />}
{copied ? "Copied" : "Copy link"}
</Button>
<Button variant="ghost" onClick={() => setQrOpen(true)} disabled={!visible}>
<QrCode aria-hidden="true" />
Show QR
</Button>
</div>
{qrOpen && visible && (
<div className="solo-qr-popover" role="dialog" aria-label="Room invite QR code">
<IconButton aria-label="Close QR code" onClick={() => setQrOpen(false)}><X aria-hidden="true" /></IconButton>
<div className="solo-qr-code" aria-label={`QR code for room ${roomCode}`} dangerouslySetInnerHTML={{ __html: qrSvg }} />
<span>Scan to join {roomCode}</span>
</div>
)}
</aside>
);
}
11 changes: 9 additions & 2 deletions apps/client/src/SyncStatusline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function SyncStatusline({
connected,
status,
phase,
host,
debug,
onSource,
sourceOpen,
Expand All @@ -21,6 +22,7 @@ export function SyncStatusline({
connected: boolean;
status: string;
phase: PlaybackMetrics["state"];
host: boolean;
debug: boolean;
onSource?: () => void;
sourceOpen?: boolean;
Expand Down Expand Up @@ -89,6 +91,7 @@ export function SyncStatusline({
<Chip
role="status"
aria-label="Connection"
title="Drift: how far your playback is from the host. RTT: round trip to the server."
className={`connection-chip sync-${state}`}
>
<span className="sync-dot" />
Expand All @@ -99,9 +102,13 @@ export function SyncStatusline({
)}
<span>{connected ? state : status.toLowerCase()}</span>
<span data-testid="drift">
{drift === null
{unavailable
? "--"
: `${drift >= 0 ? "+" : ""}${(drift / 1000).toFixed(2)}s`}
: host
? "host"
: drift === null
? "--"
: `${drift >= 0 ? "+" : ""}${(drift / 1000).toFixed(2)}s`}
</span>
<span data-testid="rtt">
{connected && metrics.rttMs !== null
Expand Down
Loading
Loading