feat(ui): neues Dark-Theme (blau/lila), bessere Kontraste, Lautstärke-Regler; feat(server): Volume-Support (inlineVolume)
This commit is contained in:
parent
2c8340081e
commit
7d95858a3e
4 changed files with 83 additions and 30 deletions
|
|
@ -174,12 +174,14 @@ app.get('/api/channels', (_req: Request, res: Response) => {
|
||||||
|
|
||||||
app.post('/api/play', async (req: Request, res: Response) => {
|
app.post('/api/play', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const { soundName, guildId, channelId } = req.body as {
|
const { soundName, guildId, channelId, volume } = req.body as {
|
||||||
soundName?: string;
|
soundName?: string;
|
||||||
guildId?: string;
|
guildId?: string;
|
||||||
channelId?: string;
|
channelId?: string;
|
||||||
|
volume?: number; // 0..1
|
||||||
};
|
};
|
||||||
if (!soundName || !guildId || !channelId) return res.status(400).json({ error: 'soundName, guildId, channelId erforderlich' });
|
if (!soundName || !guildId || !channelId) return res.status(400).json({ error: 'soundName, guildId, channelId erforderlich' });
|
||||||
|
const safeVolume = typeof volume === 'number' && Number.isFinite(volume) ? Math.max(0, Math.min(1, volume)) : 1;
|
||||||
|
|
||||||
const filePath = path.join(SOUNDS_DIR, `${soundName}.mp3`);
|
const filePath = path.join(SOUNDS_DIR, `${soundName}.mp3`);
|
||||||
if (!fs.existsSync(filePath)) return res.status(404).json({ error: 'Sound nicht gefunden' });
|
if (!fs.existsSync(filePath)) return res.status(404).json({ error: 'Sound nicht gefunden' });
|
||||||
|
|
@ -266,7 +268,11 @@ app.post('/api/play', async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`${new Date().toISOString()} | createAudioResource: ${filePath}`);
|
console.log(`${new Date().toISOString()} | createAudioResource: ${filePath}`);
|
||||||
const resource = createAudioResource(filePath);
|
const resource = createAudioResource(filePath, { inlineVolume: true });
|
||||||
|
if (resource.volume) {
|
||||||
|
resource.volume.setVolume(safeVolume);
|
||||||
|
console.log(`${new Date().toISOString()} | setVolume(${safeVolume}) for ${soundName}`);
|
||||||
|
}
|
||||||
state.player.stop();
|
state.player.stop();
|
||||||
state.player.play(resource);
|
state.player.play(resource);
|
||||||
console.log(`${new Date().toISOString()} | player.play() called for ${soundName}`);
|
console.log(`${new Date().toISOString()} | player.play() called for ${soundName}`);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ export default function App() {
|
||||||
const [selected, setSelected] = useState<string>('');
|
const [selected, setSelected] = useState<string>('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [volume, setVolume] = useState<number>(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -43,7 +44,7 @@ export default function App() {
|
||||||
const [guildId, channelId] = selected.split(':');
|
const [guildId, channelId] = selected.split(':');
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await playSound(name, guildId, channelId);
|
await playSound(name, guildId, channelId, volume);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setError(e?.message || 'Play fehlgeschlagen');
|
setError(e?.message || 'Play fehlgeschlagen');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -59,12 +60,15 @@ export default function App() {
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section className="controls">
|
<section className="controls">
|
||||||
|
<div className="control search">
|
||||||
<input
|
<input
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
placeholder="Nach Sounds suchen..."
|
placeholder="Nach Sounds suchen..."
|
||||||
aria-label="Suche"
|
aria-label="Suche"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="control select">
|
||||||
<select value={selected} onChange={(e) => setSelected(e.target.value)} aria-label="Voice-Channel">
|
<select value={selected} onChange={(e) => setSelected(e.target.value)} aria-label="Voice-Channel">
|
||||||
{channels.map((c) => (
|
{channels.map((c) => (
|
||||||
<option key={`${c.guildId}:${c.channelId}`} value={`${c.guildId}:${c.channelId}`}>
|
<option key={`${c.guildId}:${c.channelId}`} value={`${c.guildId}:${c.channelId}`}>
|
||||||
|
|
@ -72,6 +76,19 @@ export default function App() {
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="control volume">
|
||||||
|
<label>🔊 {Math.round(volume * 100)}%</label>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={1}
|
||||||
|
step={0.01}
|
||||||
|
value={volume}
|
||||||
|
onChange={(e) => setVolume(parseFloat(e.target.value))}
|
||||||
|
aria-label="Lautstärke"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{error && <div className="error">{error}</div>}
|
{error && <div className="error">{error}</div>}
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ export async function fetchChannels(): Promise<VoiceChannelInfo[]> {
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function playSound(soundName: string, guildId: string, channelId: string): Promise<void> {
|
export async function playSound(soundName: string, guildId: string, channelId: string, volume: number): Promise<void> {
|
||||||
const res = await fetch(`${API_BASE}/play`, {
|
const res = await fetch(`${API_BASE}/play`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ soundName, guildId, channelId })
|
body: JSON.stringify({ soundName, guildId, channelId, volume })
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const data = await res.json().catch(() => ({}));
|
const data = await res.json().catch(() => ({}));
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,50 @@
|
||||||
:root { color-scheme: dark light; }
|
:root { color-scheme: dark; }
|
||||||
* { box-sizing: border-box; }
|
* { box-sizing: border-box; }
|
||||||
body { margin: 0; font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"; background: linear-gradient(120deg, #1e3c72, #2a5298); min-height: 100vh; color: #111; }
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
|
||||||
|
background: radial-gradient(1200px 800px at 20% -10%, #2a2f4f 0%, transparent 60%),
|
||||||
|
radial-gradient(1200px 800px at 120% 10%, #4c2a85 0%, transparent 60%),
|
||||||
|
linear-gradient(180deg, #0b1020 0%, #0f1530 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
color: #e7e7ee;
|
||||||
|
}
|
||||||
|
|
||||||
.container { max-width: 1000px; margin: 0 auto; padding: 24px; }
|
.container { max-width: 1200px; margin: 0 auto; padding: 28px; }
|
||||||
header { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
|
header { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
|
||||||
header h1 { margin: 0; }
|
header h1 { margin: 0; font-weight: 800; letter-spacing: .3px; }
|
||||||
|
header p { opacity: .8; }
|
||||||
|
|
||||||
.controls { display: flex; gap: 12px; margin-bottom: 16px; }
|
.controls { display: grid; grid-template-columns: 1fr minmax(240px, 300px) 220px; gap: 12px; align-items: center; margin-bottom: 18px; }
|
||||||
.controls input { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.9); }
|
.control input, .control select {
|
||||||
.controls select { padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.9); }
|
width: 100%;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255,255,255,.12);
|
||||||
|
background: rgba(18, 24, 48, .8);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.control input::placeholder { color: #c8c8d8; }
|
||||||
|
|
||||||
.error { background: #ffefef; color: #900; border: 1px solid #fcc; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
|
.control.volume { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
|
||||||
|
.control.volume label { font-weight: 700; opacity: .9; }
|
||||||
|
.control.volume input[type="range"] { accent-color: #8b5cf6; }
|
||||||
|
|
||||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
|
.error { background: rgba(255, 99, 99, .12); color: #ffd1d1; border: 1px solid rgba(255, 99, 99, .3); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; }
|
||||||
.sound { padding: 18px; border-radius: 14px; border: 0; background: linear-gradient(135deg, #ff8a00, #e52e71); color: #fff; cursor: pointer; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.2); letter-spacing: .2px; }
|
|
||||||
.sound:hover { filter: brightness(1.05); }
|
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
|
||||||
|
.sound {
|
||||||
|
padding: 18px 16px;
|
||||||
|
border-radius: 14px;
|
||||||
|
border: 1px solid rgba(255,255,255,.08);
|
||||||
|
background: linear-gradient(135deg, rgba(88, 28, 135, 0.9), rgba(59, 130, 246, 0.9));
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: .2px;
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,.25);
|
||||||
|
}
|
||||||
|
.sound:hover { filter: brightness(1.06); }
|
||||||
.sound:disabled { opacity: 0.6; cursor: not-allowed; }
|
.sound:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||||
|
|
||||||
.hint { opacity: .7; padding: 24px 0; }
|
.hint { opacity: .7; padding: 24px 0; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue